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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | none | none | 0 | [
"none"
] | null | null | Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly *k* of the nodes should be exit-nodes, that means that each of them should... | The first line contains two integers *n* and *k* (3<=≤<=*n*<=≤<=2·105, 2<=≤<=*k*<=≤<=*n*<=-<=1) — the total number of nodes and the number of exit-nodes.
Note that it is always possible to build at least one network with *n* nodes and *k* exit-nodes within the given constraints. | In the first line print the minimum possible distance between the two most distant exit-nodes. In each of the next *n*<=-<=1 lines print two integers: the ids of the nodes connected by a wire. The description of each wire should be printed exactly once. You can print wires and wires' ends in arbitrary order. The nodes ... | [
"3 2\n",
"5 3\n"
] | [
"2\n1 2\n2 3\n",
"3\n1 2\n2 3\n3 4\n3 5\n"
] | In the first example the only network is shown on the left picture.
In the second example one of optimal networks is shown on the right picture.
Exit-nodes are highlighted. | 0 | [
{
"input": "3 2",
"output": "2\n1 2\n2 3"
},
{
"input": "5 3",
"output": "3\n1 2\n2 3\n3 4\n3 5"
},
{
"input": "4 2",
"output": "3\n1 2\n2 3\n3 4"
},
{
"input": "4 3",
"output": "2\n1 2\n2 3\n2 4"
},
{
"input": "5 2",
"output": "4\n1 2\n2 3\n3 4\n4 5"
},
{... | 1,499,797,577 | 6,077 | PyPy 3 | WRONG_ANSWER | PRETESTS | 2 | 93 | 23,142,400 | n,k=list(map(int,input().strip().split(' ')))
import math
L=math.ceil((n-(k+1))/(k-1))
remain=(n-(k+1))%(k-1)
#print(L,remain,'L,remain')
print(L+2)
print(1,2)
if n>2:
temp=0
end=k+1
for j in range(3,k+1+1):
print(2,j)
if temp<remain:
for p in range(0,L):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two ... | ```python
n,k=list(map(int,input().strip().split(' ')))
import math
L=math.ceil((n-(k+1))/(k-1))
remain=(n-(k+1))%(k-1)
#print(L,remain,'L,remain')
print(L+2)
print(1,2)
if n>2:
temp=0
end=k+1
for j in range(3,k+1+1):
print(2,j)
if temp<remain:
for p in range(0,L):... | 0 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,692,990,667 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | s=int(input())
print(5**s) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
s=int(input())
print(5**s)
``` | 0 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,515,300,461 | 2,861 | Python 3 | WRONG_ANSWER | TESTS | 47 | 109 | 6,758,400 | a = ["2"] * 100010
a[1] = "1"
for i in range(2, 100001):
if a[i] == "2":
for j in range(i * i, 100001, i):
a[j] = "1"
# print(a[0:100])
n = int(input())
if n <= 2:
print(1)
print(' '.join(["1"] * n))
else:
print(2)
print(' '.join(a[2:n + 2]))
| Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
a = ["2"] * 100010
a[1] = "1"
for i in range(2, 100001):
if a[i] == "2":
for j in range(i * i, 100001, i):
a[j] = "1"
# print(a[0:100])
n = int(input())
if n <= 2:
print(1)
print(' '.join(["1"] * n))
else:
print(2)
print(' '.join(a[2:n + 2]))
``` | 0 | |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,650,190,869 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 46 | 0 | n = int(input())
if not n:
print(1)
else:
print((3 ** (n - 1)) % ((10 ** 6) + 3))
| Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
n = int(input())
if not n:
print(1)
else:
print((3 ** (n - 1)) % ((10 ** 6) + 3))
``` | 3.977 |
831 | C | Jury Marks | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms"
] | null | null | Polycarp watched TV-show where *k* jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the marks were one by one added to his score. It is known that the *i*-th jury member gave *a**i* po... | The first line contains two integers *k* and *n* (1<=≤<=*n*<=≤<=*k*<=≤<=2<=000) — the number of jury members and the number of scores Polycarp remembers.
The second line contains *k* integers *a*1,<=*a*2,<=...,<=*a**k* (<=-<=2<=000<=≤<=*a**i*<=≤<=2<=000) — jury's marks in chronological order.
The third line contains ... | Print the number of options for the score the participant could have before the judges rated the participant. If Polycarp messes something up and there is no options, print "0" (without quotes). | [
"4 1\n-5 5 0 20\n10\n",
"2 2\n-2000 -2000\n3998000 4000000\n"
] | [
"3\n",
"1\n"
] | The answer for the first example is 3 because initially the participant could have - 10, 10 or 15 points.
In the second example there is only one correct initial score equaling to 4 002 000. | 1,000 | [
{
"input": "4 1\n-5 5 0 20\n10",
"output": "3"
},
{
"input": "2 2\n-2000 -2000\n3998000 4000000",
"output": "1"
},
{
"input": "1 1\n-577\n1273042",
"output": "1"
},
{
"input": "2 1\n614 -1943\n3874445",
"output": "2"
},
{
"input": "3 1\n1416 -1483 1844\n3261895",
... | 1,666,133,289 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 57 | 217 | 10,649,600 | k, n = map(int, input().split())
marks = list(map(int, input().split()))
polycarps = list(map(int, input().split()))
def psa_init(arr):
psa = [0] * len(arr)
psa[0] = arr[0]
for i in range(1, len(arr)):
psa[i] = arr[i] + psa[i-1]
return psa
psa = psa_init(marks)
possible_starts =... | Title: Jury Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp watched TV-show where *k* jury members one by one rated a participant by adding him a certain number of points (may be negative, i. e. points were subtracted). Initially the participant had some score, and each the ... | ```python
k, n = map(int, input().split())
marks = list(map(int, input().split()))
polycarps = list(map(int, input().split()))
def psa_init(arr):
psa = [0] * len(arr)
psa[0] = arr[0]
for i in range(1, len(arr)):
psa[i] = arr[i] + psa[i-1]
return psa
psa = psa_init(marks)
possibl... | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,696,167,865 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 0 | def def1(x):
if x.isupper() or x[1:].isupper():
return x.swapcase()
else:
return x
x1 = input().strip()
trans = def1(x1)
print(trans)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
def def1(x):
if x.isupper() or x[1:].isupper():
return x.swapcase()
else:
return x
x1 = input().strip()
trans = def1(x1)
print(trans)
``` | 0 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,688,144,008 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | a, b = input().split()
f=1
ans=''
for i in range(1, len(a)):
if ord(a[i]) >= ord(b[0]):
ans=a[0:i] + b[0]
f=0
break
if(f==0):
print(ans)
else:
print(a + b[0]) | Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
a, b = input().split()
f=1
ans=''
for i in range(1, len(a)):
if ord(a[i]) >= ord(b[0]):
ans=a[0:i] + b[0]
f=0
break
if(f==0):
print(ans)
else:
print(a + b[0])
``` | 3 | |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,694,786,546 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 93 | 13,926,400 | n = int(input())
arr = list(map(int, input().split()))
ans, br, cur = 0, 0, 0
for x in range(0, n):
val = arr[x]
if val < br:
ans = max(ans, cur)
cur = 1
else:
cur += 1
br = val
ans = max(ans, cur)
print(ans)
| Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n = int(input())
arr = list(map(int, input().split()))
ans, br, cur = 0, 0, 0
for x in range(0, n):
val = arr[x]
if val < br:
ans = max(ans, cur)
cur = 1
else:
cur += 1
br = val
ans = max(ans, cur)
print(ans)
``` | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,693,288,998 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 124 | 2,764,800 | import sys
y = int(sys.stdin.readline()) + 1
while len(set(y)) < 4: y += 1
sys.stdout.write(str(y)) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
import sys
y = int(sys.stdin.readline()) + 1
while len(set(y)) < 4: y += 1
sys.stdout.write(str(y))
``` | -1 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,600,439,961 | 2,147,483,647 | PyPy 3 | OK | TESTS | 14 | 217 | 2,355,200 | import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))
def main():
n = I()
s = input()
s = list(s)
n = len(s) - 1
c... | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))
def main():
n = I()
s = input()
s = list(s)
n = len(s)... | 3 | |
873 | D | Merge Sort | PROGRAMMING | 1,800 | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+... | The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print a... | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | 0 | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27... | 1,515,139,013 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 23,961,600 | import os
import sys
import copy
num = 0
b = None
# sys.stdin = open(os.path.join(os.path.dirname(__file__),'3.in'))
def solve():
n, k = map(lambda x:int(x), input().split())
a = [_+1 for _ in range(n)]
# print(a)
global b
b = a
def mgsort(a, l, r):
global num,b
num += 1
... | Title: Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-desce... | ```python
import os
import sys
import copy
num = 0
b = None
# sys.stdin = open(os.path.join(os.path.dirname(__file__),'3.in'))
def solve():
n, k = map(lambda x:int(x), input().split())
a = [_+1 for _ in range(n)]
# print(a)
global b
b = a
def mgsort(a, l, r):
global num,b
num += ... | 0 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,587,774,601 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 218 | 0 | standing = input() #RGB
inst = input() #RRR
standing_on = 0
for char in inst:
if char == standing[standing_on]:
standing_on+=1
print(standing_on + 1) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
standing = input() #RGB
inst = input() #RRR
standing_on = 0
for char in inst:
if char == standing[standing_on]:
standing_on+=1
print(standing_on + 1)
``` | 3 | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,696,779,461 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | a = int(input())
sq = list(map(int,input().split()))
b = int(input())
sw = list(map(int,input().split()))
sq.sort()
sw.sort()
i = 0
u = 0
y = 0
while i < a and u < b:
if abs(sq[i] - sw[u]) <= 1:
y += 1
i += 1
u += 1
elif sq[i] < sw[u]:
i += 1
else:
u ... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
a = int(input())
sq = list(map(int,input().split()))
b = int(input())
sw = list(map(int,input().split()))
sq.sort()
sw.sort()
i = 0
u = 0
y = 0
while i < a and u < b:
if abs(sq[i] - sw[u]) <= 1:
y += 1
i += 1
u += 1
elif sq[i] < sw[u]:
i += 1
else:
... | 3 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,518,960,267 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 6,758,400 | import statistics
import cv2
import numpy as np
s = input();
s+= s[::-1]
print(s) | Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
import statistics
import cv2
import numpy as np
s = input();
s+= s[::-1]
print(s)
``` | -1 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,646,038,621 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | k=int(input())
x = k//2
if(x>18):
print(-1)
else:
res="8"*x
if(k%2!=0):
res+="1"
print(res) | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k=int(input())
x = k//2
if(x>18):
print(-1)
else:
res="8"*x
if(k%2!=0):
res+="1"
print(res)
``` | 0 | |
808 | C | Tea Party | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that:
- Every cup... | The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.
If it's impossible to pour all the tea and satisfy all conditions then output -1. | [
"2 10\n8 7\n",
"4 4\n1 1 1 1\n",
"3 10\n9 8 10\n"
] | [
"6 4 \n",
"1 1 1 1 \n",
"-1\n"
] | In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. | 0 | [
{
"input": "2 10\n8 7",
"output": "6 4 "
},
{
"input": "4 4\n1 1 1 1",
"output": "1 1 1 1 "
},
{
"input": "3 10\n9 8 10",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "1 "
},
{
"input": "1 1\n2",
"output": "1 "
},
{
"input": "1 10\n20",
"output... | 1,625,917,176 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 108 | 0 | n, w = map(int, input().split())
a = sorted([(n, i) for i, n in enumerate(map(int, input().split()))])
tea = [0]*n
for i in range(n):
tea[a[i][1]] += (a[i][0]+1) // 2
w -= sum(tea)
i = n-1
while w > 0:
x = min(a[i][0]-tea[a[i][1]], w)
tea[a[i][1]] += x
w -= x
i -= 1
if w < 0:... | Title: Tea Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<... | ```python
n, w = map(int, input().split())
a = sorted([(n, i) for i, n in enumerate(map(int, input().split()))])
tea = [0]*n
for i in range(n):
tea[a[i][1]] += (a[i][0]+1) // 2
w -= sum(tea)
i = n-1
while w > 0:
x = min(a[i][0]-tea[a[i][1]], w)
tea[a[i][1]] += x
w -= x
i -= 1
... | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,672,310,095 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | ln = int(input())
crds = list(map(int, input().split(" ")))
h = 0
d = 0
trn = 1
while len(crds)>0:
if crds[0]>crds[-1]:
mx = crds[0]
del crds[0]
else:
mx = crds[-1]
del crds[-1]
if trn%2!=0:
h += mx
else:
d += mx
trn += 1
print(h, d) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
ln = int(input())
crds = list(map(int, input().split(" ")))
h = 0
d = 0
trn = 1
while len(crds)>0:
if crds[0]>crds[-1]:
mx = crds[0]
del crds[0]
else:
mx = crds[-1]
del crds[-1]
if trn%2!=0:
h += mx
else:
d += mx
trn += 1
pri... | 3 | |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,669,566,063 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | v=int(input())
r=int(input())
o=int(input())
e=int(input())
if v==1:
print(0)
elif v==2:
print(abs(o-r))
elif v==3:
print(abs(o-r)+abs(e-o))
| Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
v=int(input())
r=int(input())
o=int(input())
e=int(input())
if v==1:
print(0)
elif v==2:
print(abs(o-r))
elif v==3:
print(abs(o-r)+abs(e-o))
``` | 0 | |
858 | A | k-rounding | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
W... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). | Print the *k*-rounding of *n*. | [
"375 4\n",
"10000 1\n",
"38101 0\n",
"123456789 8\n"
] | [
"30000\n",
"10000\n",
"38101\n",
"12345678900000000\n"
] | none | 750 | [
{
"input": "375 4",
"output": "30000"
},
{
"input": "10000 1",
"output": "10000"
},
{
"input": "38101 0",
"output": "38101"
},
{
"input": "123456789 8",
"output": "12345678900000000"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output":... | 1,506,079,901 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
s=input().split()
n=int(s[0])
k=int(s[1])
lcm(n,10**k)
print(lcm) | Title: k-rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*.
For example, 4-rounding of 375 is 375·80<==<=30000.... | ```python
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
s=input().split()
n=int(s[0])
k=int(s[1])
lcm(n,10**k)
print(lcm)
``` | 0 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,587,098,363 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 140 | 0 | n = int(input())
arr = [int(i) for i in input().split()]
for i in range(n):
arr[i] = (arr[i], i+1)
arr.sort(key=lambda x: x[0])
for i in range(n//2):
print(arr[i][1], arr[n-i-1][1]) | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
n = int(input())
arr = [int(i) for i in input().split()]
for i in range(n):
arr[i] = (arr[i], i+1)
arr.sort(key=lambda x: x[0])
for i in range(n//2):
print(arr[i][1], arr[n-i-1][1])
``` | 3 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,689,395,846 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 61 | 2,867,200 | limited_notes=[1,5,10,20,100]
limited_notes=sorted(limited_notes,reverse=True)
target=int(input())
count=0
i=0
total=0
n=1
while total<target:
if limited_notes[i]>target:
i+=1
elif (total+(limited_notes[i]*n))<=target:
total+=(limited_notes[i]*n)
n+=1
count+=1
... | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
limited_notes=[1,5,10,20,100]
limited_notes=sorted(limited_notes,reverse=True)
target=int(input())
count=0
i=0
total=0
n=1
while total<target:
if limited_notes[i]>target:
i+=1
elif (total+(limited_notes[i]*n))<=target:
total+=(limited_notes[i]*n)
n+=1
cou... | -1 | |
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,698,833,703 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | k, l, m, n, d = [int(input(_)) for _ in range(5)]
count = 0
for i in range(1, d+1):
if i%k==0 or i%l==0 or i%m==0 or i%n==0:
count += 1
print(counter)
| 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
k, l, m, n, d = [int(input(_)) for _ in range(5)]
count = 0
for i in range(1, d+1):
if i%k==0 or i%l==0 or i%m==0 or i%n==0:
count += 1
print(counter)
``` | -1 | |
986 | D | Perfect Encoding | PROGRAMMING | 3,100 | [
"fft",
"math"
] | null | null | You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o... | In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. | Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. | [
"36\n",
"37\n",
"12345678901234567890123456789\n"
] | [
"10\n",
"11\n",
"177\n"
] | none | 2,500 | [
{
"input": "36",
"output": "10"
},
{
"input": "37",
"output": "11"
},
{
"input": "12345678901234567890123456789",
"output": "177"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input... | 1,528,660,694 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 2,000 | 15,769,600 | import math
a = int(input())
if (a <= 3):
print(a)
exit(0)
def pwr(a, n):
ans = 1
while (n != 0):
if (n & 1):
ans *= a
a *= a
n >>= 1
return ans
def calc(sm):
if (sm <= 0):
return -10000000000000000
if (sm == 1):
return 1
rem = sm % 3
if (rem == 1):
return 4 * pwr(3, (... | Title: Perfect Encoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the paramete... | ```python
import math
a = int(input())
if (a <= 3):
print(a)
exit(0)
def pwr(a, n):
ans = 1
while (n != 0):
if (n & 1):
ans *= a
a *= a
n >>= 1
return ans
def calc(sm):
if (sm <= 0):
return -10000000000000000
if (sm == 1):
return 1
rem = sm % 3
if (rem == 1):
return 4 ... | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,480,918,823 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 0 | A = list(input())
B = list(input())
n = len(A)
Z = []
i = 0
while i < n:
if int(A[i])+int(B[i]) == 1:
Z.append(1)
else:
Z.append(0)
i += 1
a = 0
while a < n:
print(Z[a],end = '')
a = a + 1 | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
A = list(input())
B = list(input())
n = len(A)
Z = []
i = 0
while i < n:
if int(A[i])+int(B[i]) == 1:
Z.append(1)
else:
Z.append(0)
i += 1
a = 0
while a < n:
print(Z[a],end = '')
a = a + 1
``` | 3.9845 |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine ... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109) — the number of elements in the permutation and the lexicographical number of the permutation. | If the *k*-th permutation of numbers from 1 to *n* does not exist, print the single number "-1" (without the quotes). Otherwise, print the answer to the problem: the number of such indexes *i*, that *i* and *a**i* are both lucky numbers. | [
"7 4\n",
"4 7\n"
] | [
"1\n",
"1\n"
] | A permutation is an ordered set of *n* elements, where each integer from 1 to *n* occurs exactly once. The element of permutation in position with index *i* is denoted as *a*<sub class="lower-index">*i*</sub> (1 ≤ *i* ≤ *n*). Permutation *a* is lexicographically smaller that permutation *b* if there is such a *i* (1 ≤ ... | 0 | [
{
"input": "7 4",
"output": "1"
},
{
"input": "4 7",
"output": "1"
},
{
"input": "7 1",
"output": "2"
},
{
"input": "7 5040",
"output": "1"
},
{
"input": "10 1023",
"output": "0"
},
{
"input": "7 7477",
"output": "-1"
},
{
"input": "10 1000... | 1,691,179,969 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1691179968.7152607")# 1691179968.7152777 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Pe... | ```python
print("_RANDOM_GUESS_1691179968.7152607")# 1691179968.7152777
``` | 0 | |
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES... | 1,585,023,279 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 109 | 0 | n = int(input())
home = 1234567
car = 123456
comp = 1234
ans = False
for a in range(0, n+1, home):
tot = n - a
if(a > n or ans):
break
for b in range(0, tot+1, car):
tot = tot - b
if(tot % comp == 0):
ans = True
break
if(ans):
print("YES... | Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.... | ```python
n = int(input())
home = 1234567
car = 123456
comp = 1234
ans = False
for a in range(0, n+1, home):
tot = n - a
if(a > n or ans):
break
for b in range(0, tot+1, car):
tot = tot - b
if(tot % comp == 0):
ans = True
break
if(ans):
... | 0 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,667,334,508 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | ci,o=map(int,input().split())
cr=list(map(int,input().split()))
res=0
r,l,i=0,0,0
while i<ci:
r=o+i
l=o-i
if r<ci and l>=0:
if cr[l]==1 and cr[r]==1:
res+=2
elif l>=0:
if cr[l]==1:
res+=1
elif r<ci:
if cr[r]==1:
... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
ci,o=map(int,input().split())
cr=list(map(int,input().split()))
res=0
r,l,i=0,0,0
while i<ci:
r=o+i
l=o-i
if r<ci and l>=0:
if cr[l]==1 and cr[r]==1:
res+=2
elif l>=0:
if cr[l]==1:
res+=1
elif r<ci:
if cr[r... | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,589,770,049 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 6,656,000 | s = input()
qaq = 0
for i in range(0, len(s)):
# find an A
if s[i] == 'A':
# find Qs before A
before = s[:i].count('Q')
# find Qs after A
after = s[i+1:].count('Q')
# add before * after to qaq
qaq += before * after
print(qaq) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
s = input()
qaq = 0
for i in range(0, len(s)):
# find an A
if s[i] == 'A':
# find Qs before A
before = s[:i].count('Q')
# find Qs after A
after = s[i+1:].count('Q')
# add before * after to qaq
qaq += before * after
print(qaq)
``` | 3 | |
225 | C | Barcode | PROGRAMMING | 1,700 | [
"dp",
"matrices"
] | null | null | You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulfilled:
- All pixels in each column are of the same color. - The width of each monochrome ... | The first line contains four space-separated integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*,<=*x*,<=*y*<=≤<=1000; *x*<=≤<=*y*).
Then follow *n* lines, describing the original image. Each of these lines contains exactly *m* characters. Character "." represents a white pixel and "#" represents a black pixel. The pictur... | In the first line print the minimum number of pixels to repaint. It is guaranteed that the answer exists. | [
"6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..\n",
"2 5 1 1\n#####\n.....\n"
] | [
"11\n",
"5\n"
] | In the first test sample the picture after changing some colors can looks as follows:
In the second test sample the picture after changing some colors can looks as follows: | 1,500 | [
{
"input": "6 5 1 2\n##.#.\n.###.\n###..\n#...#\n.##.#\n###..",
"output": "11"
},
{
"input": "10 5 3 7\n.####\n###..\n##.##\n#..#.\n.#...\n#.##.\n.##..\n.#.##\n#.#..\n.#..#",
"output": "24"
},
{
"input": "6 3 1 4\n##.\n#..\n#..\n..#\n.#.\n#.#",
"output": "6"
},
{
"input": "5 ... | 1,617,256,828 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 498 | 9,728,000 | inf = 9999999999
def f(ll,n,m,x,y):
W = [0]*m #White
for i in range(n):
for j in range(m):
if ll[i][j]=='.':
W[j] += 1
B = [n-c for c in W] #Black
Bw = [inf]*(y+1)
Ww = [inf]*(y+1)
Bw[1] = B[0]
Ww[1] = W[0]
Bv = B[0] if x=... | Title: Barcode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an *n*<=×<=*m* pixel picture. Each pixel can be white or black. Your task is to change the colors of as few pixels as possible to obtain a barcode picture.
A picture is a barcode if the following conditions are fulf... | ```python
inf = 9999999999
def f(ll,n,m,x,y):
W = [0]*m #White
for i in range(n):
for j in range(m):
if ll[i][j]=='.':
W[j] += 1
B = [n-c for c in W] #Black
Bw = [inf]*(y+1)
Ww = [inf]*(y+1)
Bw[1] = B[0]
Ww[1] = W[0]
Bv = ... | 3 | |
601 | A | The Two Routes | PROGRAMMING | 1,600 | [
"graphs",
"shortest paths"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=... | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo... | 500 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "... | 1,621,278,875 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 409,600 | import math
def bfs(adj, tar):
visited = []
queue = [(1, 0)]
while(len(queue) > 0):
currI, currDist = queue.pop(0)
visited.append(currI)
for i in adj[currI]:
if i == tar:
return currDist + 1
if i not in visited:
queue.append((i, currDist + 1))
return -1
n, m = list(map(... | Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet... | ```python
import math
def bfs(adj, tar):
visited = []
queue = [(1, 0)]
while(len(queue) > 0):
currI, currDist = queue.pop(0)
visited.append(currI)
for i in adj[currI]:
if i == tar:
return currDist + 1
if i not in visited:
queue.append((i, currDist + 1))
return -1
n, m =... | 0 | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,501,429,786 | 4,486 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 46 | 4,608,000 | import sys
x = sys.stdin.readline().split()
y = sys.stdin.readline().rstrip("\n")
nums = list(map(int, x))
k = nums[1]
e = list(map(str, y))
s = list(set(e))
s.sort()
c = []
for x in range(len(s)):
cnt = e.count(s[x])
c.append(cnt)
sec = [0]*len(c)
count = 0
for y in range(len(e)):
... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
import sys
x = sys.stdin.readline().split()
y = sys.stdin.readline().rstrip("\n")
nums = list(map(int, x))
k = nums[1]
e = list(map(str, y))
s = list(set(e))
s.sort()
c = []
for x in range(len(s)):
cnt = e.count(s[x])
c.append(cnt)
sec = [0]*len(c)
count = 0
for y in range(len(... | 0 | |
38 | B | Chess | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | B. Chess | 2 | 256 | Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board b... | The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way... | Print a single number which is the required number of ways. | [
"a1\nb2\n",
"a8\nd4\n"
] | [
"44\n",
"38\n"
] | none | 0 | [
{
"input": "a1\nb2",
"output": "44"
},
{
"input": "a8\nd4",
"output": "38"
},
{
"input": "a8\nf1",
"output": "42"
},
{
"input": "f8\nh3",
"output": "42"
},
{
"input": "g8\nb7",
"output": "42"
},
{
"input": "h1\ng5",
"output": "42"
},
{
"inp... | 1,690,384,585 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def is_valid(x, y, rx, ry, kx, ky):
# Check if the position (x, y) is not occupied by rook, knight, and is empty
return (x, y) != (rx, ry) and (x, y) != (kx, ky) and 1 <= x <= 8 and 1 <= y <= 8
def count_valid_knight_positions(rook_pos, knight_pos):
rx, ry = ord(rook_pos[0]) - ord('a') + 1, int(rook_p... | Title: Chess
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one.
Your task is to find the number of wa... | ```python
def is_valid(x, y, rx, ry, kx, ky):
# Check if the position (x, y) is not occupied by rook, knight, and is empty
return (x, y) != (rx, ry) and (x, y) != (kx, ky) and 1 <= x <= 8 and 1 <= y <= 8
def count_valid_knight_positions(rook_pos, knight_pos):
rx, ry = ord(rook_pos[0]) - ord('a') + 1, ... | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,595,316,195 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 6,963,200 | s=input()
cn=0
for i in range(len(s)):
if(cn==0 and s[i]=='h'):
cn=1
elif(cn==1 and s[i]=='e'):
cn=2
elif(cn==2 and s[i]=='l'):
cn=3
elif(cn==3 and s[i]=='l'):
cn=4
elif(cn==4 and s[i]=='o'):
cn=5
if cn==5:
print("YES")
else:
print(... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
cn=0
for i in range(len(s)):
if(cn==0 and s[i]=='h'):
cn=1
elif(cn==1 and s[i]=='e'):
cn=2
elif(cn==2 and s[i]=='l'):
cn=3
elif(cn==3 and s[i]=='l'):
cn=4
elif(cn==4 and s[i]=='o'):
cn=5
if cn==5:
print("YES")
else:
... | 3.93253 |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,653,990,693 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | t = int(input())
l = list(map(int,input().strip().split()))
mx = max(l)
c = 0
for i in l:
while not i == mx:
i+=1
c+=1
print(c) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
t = int(input())
l = list(map(int,input().strip().split()))
mx = max(l)
c = 0
for i in l:
while not i == mx:
i+=1
c+=1
print(c)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 0 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,488,723,186 | 4,086 | Python 3 | OK | TESTS | 56 | 249 | 19,046,400 | n = int(input())
line = input()
l = [int(x) for x in line.split()]
# print(l)
dic = {}
i = 0
m = 0
for x in l :
if(dic.get(x, 0) == 0) :
dic[x] = 1
i += 1
m = max(m, i)
else :
dic[x] = 0
i -= 1
print(m) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*... | ```python
n = int(input())
line = input()
l = [int(x) for x in line.split()]
# print(l)
dic = {}
i = 0
m = 0
for x in l :
if(dic.get(x, 0) == 0) :
dic[x] = 1
i += 1
m = max(m, i)
else :
dic[x] = 0
i -= 1
print(m)
``` | 3 | |
27 | E | Number With The Given Amount Of Divisors | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"number theory"
] | E. Number With The Given Amount Of Divisors | 2 | 256 | Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). | Output the smallest positive integer with exactly *n* divisors. | [
"4\n",
"6\n"
] | [
"6\n",
"12\n"
] | none | 2,500 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "64"
},
{
"input": "8",
"output": "24"
},
{
"input": "9",
"output": "36"
},
{
"input": "10",
"output": "48"
},
{
"input": "15",
"output": "144"
},
{
"input": "20",
"output": "24... | 1,641,293,337 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 92 | 0 | def prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return 0
return 1
def res(a,b):
k=1
for i in range(len(a)):
k*=b[i]**(a[i]-1)
return k
def prod(a):
k=1
for i in a:
k*=i
return k
def f(a,l):
global m,arr
if prod(a)>m:
... | Title: Number With The Given Amount Of Divisors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
Input Specification:
The first line... | ```python
def prime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return 0
return 1
def res(a,b):
k=1
for i in range(len(a)):
k*=b[i]**(a[i]-1)
return k
def prod(a):
k=1
for i in a:
k*=i
return k
def f(a,l):
global m,arr
if p... | 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,694,793,494 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a,b=map(int,input().split())
k1=min(a,b)
k2=(max(a,b)-min(a,b))//2
print(k1,k2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a,b=map(int,input().split())
k1=min(a,b)
k2=(max(a,b)-min(a,b))//2
print(k1,k2)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,659,400,209 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | word= input ()
n=len (word)
count =0
flag=0
while count <n-4:
if word[count]=='h'and word[count+1]=='e' and word[count+2]=='l' and word[count+3] =='l' and word[count+4]=='o':
flag=1
count+=1
if flag==1:
print ('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
word= input ()
n=len (word)
count =0
flag=0
while count <n-4:
if word[count]=='h'and word[count+1]=='e' and word[count+2]=='l' and word[count+3] =='l' and word[count+4]=='o':
flag=1
count+=1
if flag==1:
print ('YES')
else:
print('NO')
``` | 0 |
496 | C | Removing Columns | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
we obtain the table:
A table is called... | The first line contains two integers — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Next *n* lines contain *m* small English letters each — the characters of the table. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | [
"1 10\ncodeforces\n",
"4 4\ncase\ncare\ntest\ncode\n",
"5 4\ncode\nforc\nesco\ndefo\nrces\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample the table is already good.
In the second sample you may remove the first and third column.
In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).
Let strings *s* and *t* have equal length. Then, *s* is lexicographica... | 1,750 | [
{
"input": "1 10\ncodeforces",
"output": "0"
},
{
"input": "4 4\ncase\ncare\ntest\ncode",
"output": "2"
},
{
"input": "5 4\ncode\nforc\nesco\ndefo\nrces",
"output": "4"
},
{
"input": "2 2\nfb\nye",
"output": "0"
},
{
"input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrz... | 1,418,996,524 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 77 | 0 | n = input()
n = n.split()
for i in range(len(n)):
n[i] = int(n[i])
m = n[1]
n = n[0]
charlist = []
for i in range(n):
s = input()
s = list(s)
charlist.append(s)
count = 0
for i in range(m):
t = 1
u = 0
for j in range(len(charlist) - 1):
if charlist[j] <= charlist[j + ... | Title: Removing Columns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For e... | ```python
n = input()
n = n.split()
for i in range(len(n)):
n[i] = int(n[i])
m = n[1]
n = n[0]
charlist = []
for i in range(n):
s = input()
s = list(s)
charlist.append(s)
count = 0
for i in range(m):
t = 1
u = 0
for j in range(len(charlist) - 1):
if charlist[j] <= cha... | 0 | |
236 | B | Easy Number Challenge | PROGRAMMING | 1,300 | [
"implementation",
"number theory"
] | null | null | Let's denote *d*(*n*) as the number of divisors of a positive integer *n*. You are given three integers *a*, *b* and *c*. Your task is to calculate the following sum:
Find the sum modulo 1073741824 (230). | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=100). | Print a single integer — the required sum modulo 1073741824 (230). | [
"2 2 2\n",
"5 6 7\n"
] | [
"20\n",
"1520\n"
] | For the first example.
- *d*(1·1·1) = *d*(1) = 1; - *d*(1·1·2) = *d*(2) = 2; - *d*(1·2·1) = *d*(2) = 2; - *d*(1·2·2) = *d*(4) = 3; - *d*(2·1·1) = *d*(2) = 2; - *d*(2·1·2) = *d*(4) = 3; - *d*(2·2·1) = *d*(4) = 3; - *d*(2·2·2) = *d*(8) = 4.
So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20. | 1,000 | [
{
"input": "2 2 2",
"output": "20"
},
{
"input": "5 6 7",
"output": "1520"
},
{
"input": "91 42 25",
"output": "3076687"
},
{
"input": "38 47 5",
"output": "160665"
},
{
"input": "82 29 45",
"output": "3504808"
},
{
"input": "40 15 33",
"output": "... | 1,698,981,248 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 0 | from itertools import permutations
def factors(n):
fac = 0
for i in range(1,int(n**.5)+1):
if not n % i:
fac += 1
if i != n // i:
fac += 1
return fac
a, b , c = map(int ,input().split())
sm = 0
for i in range(1,a+1):
for j in range(1,b+... | Title: Easy Number Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote *d*(*n*) as the number of divisors of a positive integer *n*. You are given three integers *a*, *b* and *c*. Your task is to calculate the following sum:
Find the sum modulo 1073741824 (230).
Input ... | ```python
from itertools import permutations
def factors(n):
fac = 0
for i in range(1,int(n**.5)+1):
if not n % i:
fac += 1
if i != n // i:
fac += 1
return fac
a, b , c = map(int ,input().split())
sm = 0
for i in range(1,a+1):
for j in ... | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,698,051,865 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 186 | 1,331,200 | a=input()
h=0
for i in a :
if h==0:
print(i.capitalize(),end="")
h+=1
else:
print(i,end="")
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
a=input()
h=0
for i in a :
if h==0:
print(i.capitalize(),end="")
h+=1
else:
print(i,end="")
``` | 3 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,428,858,413 | 4,013 | PyPy 3 | WRONG_ANSWER | PRETESTS | 4 | 92 | 0 | n = int(input())
if n < 3:
print('1')
print('1')
exit(0)
if n == 3:
print('2')
print('1 3')
exit(0)
if n == 4:
print('3')
print('1 4 2')
exit(0)
print(n)
if (n/2 == n//2):
print(' '.join(['{0} {1}'.format(i+1, i+n//2+1) for i in range(n//2)]))
... | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
n = int(input())
if n < 3:
print('1')
print('1')
exit(0)
if n == 3:
print('2')
print('1 3')
exit(0)
if n == 4:
print('3')
print('1 4 2')
exit(0)
print(n)
if (n/2 == n//2):
print(' '.join(['{0} {1}'.format(i+1, i+n//2+1) for i in range(n//2... | 0 | |
903 | D | Almost Difference | PROGRAMMING | 2,200 | [
"data structures",
"math"
] | null | null | Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=200000) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) — elements of the array. | Print one integer — the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*. | [
"5\n1 2 3 1 3\n",
"4\n6 6 5 5\n",
"4\n6 6 4 4\n"
] | [
"4\n",
"0\n",
"-8\n"
] | In the first example:
1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>) = 0; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">3</sub>) = 2; 1. *d*(*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">4</sub>) = 0; 1. *d*(*a*<sub class="lower-index">... | 0 | [
{
"input": "5\n1 2 3 1 3",
"output": "4"
},
{
"input": "4\n6 6 5 5",
"output": "0"
},
{
"input": "4\n6 6 4 4",
"output": "-8"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1000000000",
"output"... | 1,564,654,126 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 14,438,400 | n = int(input())
l = [int(i) for i in input().split()]
summ = 0
for i in range(len(l)):
for j in range(i + 1, len(l)):
if abs(l[i] - l[j]) > 1:
summ += l[j] - l[i]
print(summ)
| Title: Almost Difference
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote a function
You are given an array *a* consisting of *n* integers. You have to calculate the sum of *d*(*a**i*,<=*a**j*) over all pairs (*i*,<=*j*) such that 1<=≤<=*i*<=≤<=*j*<=≤<=*n*.
Input Specifica... | ```python
n = int(input())
l = [int(i) for i in input().split()]
summ = 0
for i in range(len(l)):
for j in range(i + 1, len(l)):
if abs(l[i] - l[j]) > 1:
summ += l[j] - l[i]
print(summ)
``` | 0 | |
161 | D | Distance in Tree | PROGRAMMING | 1,800 | [
"dfs and similar",
"dp",
"trees"
] | null | null | A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices and a positive number *k*. Find the number of distinct pairs of the vertices which have a distance of ex... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50000, 1<=≤<=*k*<=≤<=500) — the number of vertices and the required distance between the vertices.
Next *n*<=-<=1 lines describe the edges as "*a**i* *b**i*" (without the quotes) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**i*<=≠<=*b**i*), where *a**i* and *b**i* ... | Print a single integer — the number of distinct pairs of the tree's vertices which have a distance of exactly *k* between them.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"5 2\n1 2\n2 3\n3 4\n2 5\n",
"5 3\n1 2\n2 3\n3 4\n4 5\n"
] | [
"4\n",
"2\n"
] | In the first sample the pairs of vertexes at distance 2 from each other are (1, 3), (1, 5), (3, 5) and (2, 4). | 2,000 | [
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "4"
},
{
"input": "5 3\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10 1\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "9"
},
{
"input": "10 2\n2 1\n3 1\n4 3\n5 4\n6 5\n7 1\n8 6\n9 2\n10 6",
"output": "10"
... | 1,555,942,155 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 9,523,200 |
n, k = map(int, input().split())
m = [set() for _ in range (n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
m[a].add(b)
m[b].add(a)
setK = dict()
for i in range(1, n+1):
traveled = [False] * (n + 1)
st = [(i, 0)]
traveled[i] = True
while len(st) > 0:
fr, d... | Title: Distance in Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is a connected graph that doesn't contain any cycles.
The distance between two vertices of a tree is the length (in edges) of the shortest path between these vertices.
You are given a tree with *n* vertices an... | ```python
n, k = map(int, input().split())
m = [set() for _ in range (n+1)]
for _ in range(n-1):
a, b = map(int, input().split())
m[a].add(b)
m[b].add(a)
setK = dict()
for i in range(1, n+1):
traveled = [False] * (n + 1)
st = [(i, 0)]
traveled[i] = True
while len(st) > 0:
... | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,594,495,234 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 202 | 23,449,600 | def call(l):
x,y=0,len(l)-1
n=len(l)
s1,s2=0,0
yo=0
while(x<=y):
if(s1==s2):
yo=s1
s1+=l[x]
x+=1
elif(s1>s2):
s2+=l[y]
y-=1
else:
s1+=l[x]
x+=1
#(x,y)=(x+1,y-1)
if... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
def call(l):
x,y=0,len(l)-1
n=len(l)
s1,s2=0,0
yo=0
while(x<=y):
if(s1==s2):
yo=s1
s1+=l[x]
x+=1
elif(s1>s2):
s2+=l[y]
y-=1
else:
s1+=l[x]
x+=1
#(x,y)=(x+1,y-... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,696,003,699 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 30 | 0 | numbers = input()
numbers_list = numbers.split()
numbers_list_ = []
for num in numbers_list:
numbers_list_.append(int(num))
n,m,a,b = numbers_list_
if (b/m) < a and n/m >= 1:
if (n//m*b + (n-(n//m)*m)*a) < (n//m*b + b):
print (n//m*b + (n-(n//m)*m)*a)
else:
print(n//m*b + b)
... | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
numbers = input()
numbers_list = numbers.split()
numbers_list_ = []
for num in numbers_list:
numbers_list_.append(int(num))
n,m,a,b = numbers_list_
if (b/m) < a and n/m >= 1:
if (n//m*b + (n-(n//m)*m)*a) < (n//m*b + b):
print (n//m*b + (n-(n//m)*m)*a)
else:
print(n/... | 0 | |
825 | C | Multi-judge Solving | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty *d* on Decoforces is as hard as the problem with difficulty *d* on any other judge).... | The first line contains two integer numbers *n*, *k* (1<=≤<=*n*<=≤<=103, 1<=≤<=*k*<=≤<=109).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces. | [
"3 3\n2 1 9\n",
"4 20\n10 3 6 3\n"
] | [
"1\n",
"0\n"
] | In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.
In the second ... | 0 | [
{
"input": "3 3\n2 1 9",
"output": "1"
},
{
"input": "4 20\n10 3 6 3",
"output": "0"
},
{
"input": "1 1000000000\n1",
"output": "0"
},
{
"input": "1 1\n3",
"output": "1"
},
{
"input": "50 100\n74 55 33 5 83 24 75 59 30 36 13 4 62 28 96 17 6 35 45 53 33 11 37 93 34... | 1,500,510,594 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 4,812,800 | inp = input().split()
n = int(inp[0])
k = int(inp[1])
prob = [int(i) for i in input().split()]
solvable = k * 2
prob.sort()
ans = 0
for p in prob:
if p <= solvable:
solvable = max(solvable,p*2)
else:
ans += 1
solvable *= 2
print(ans)
| Title: Multi-judge Solving
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the pro... | ```python
inp = input().split()
n = int(inp[0])
k = int(inp[1])
prob = [int(i) for i in input().split()]
solvable = k * 2
prob.sort()
ans = 0
for p in prob:
if p <= solvable:
solvable = max(solvable,p*2)
else:
ans += 1
solvable *= 2
print(ans)
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,628,258,479 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 6,656,000 | n=int(input())
arry=[int(a) for a in input().split()]
arry.sort()
ind=arry[int(n/2)] if len(arry)%2==0 else arry[int((n+1)/2)-1]
print(ind) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n=int(input())
arry=[int(a) for a in input().split()]
arry.sort()
ind=arry[int(n/2)] if len(arry)%2==0 else arry[int((n+1)/2)-1]
print(ind)
``` | 0 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,696,925,987 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | d = [int(input()),int(input()),int(input())]
d.sort()
if 0 < d.count(1) < 3 :
print((d[0] + d[1]) * d[2])
elif d.count(1) == 3:
print(3)
else:
print(d[0] * d[1] * d[2]) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
d = [int(input()),int(input()),int(input())]
d.sort()
if 0 < d.count(1) < 3 :
print((d[0] + d[1]) * d[2])
elif d.count(1) == 3:
print(3)
else:
print(d[0] * d[1] * d[2])
``` | 0 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,579,960,357 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 |
# N, K
# Values for N days
N, K = map(int, input().split(" "))
Values = list(map(int, input().split(" ")))
Bran = 0
# print(N, K)
# print(Values)
idx = 0
for i, val in enumerate(Values):
if(Bran >= K):
idx = i
break
else:
if val <= 8:
Bran += val
if val > 8:
... | Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
# N, K
# Values for N days
N, K = map(int, input().split(" "))
Values = list(map(int, input().split(" ")))
Bran = 0
# print(N, K)
# print(Values)
idx = 0
for i, val in enumerate(Values):
if(Bran >= K):
idx = i
break
else:
if val <= 8:
Bran += val
if val ... | 0 | |
701 | A | Cards | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player.
Find the way to distribute cards such that the sum of values written of the cards ... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even.
The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card. | Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input.
It is guaranteed that solution exists. If there are several correct answers, you are allowed to print... | [
"6\n1 5 7 4 4 3\n",
"4\n10 10 10 10\n"
] | [
"1 3\n6 2\n4 5\n",
"1 2\n3 4\n"
] | In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8.
In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable. | 500 | [
{
"input": "6\n1 5 7 4 4 3",
"output": "1 3\n6 2\n4 5"
},
{
"input": "4\n10 10 10 10",
"output": "1 4\n2 3"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,550,034,630 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | def main():
n = int(input())
nums = list(map(int,input().split()))
cards = []
for i in range(n):
cards.append((nums[i],i+1))
cards = sorted(cards,key = lambda x: x[0])
ans = []
#print (cards)
for i in range(int(n/2)):
ans.append((cards[i][1],cards[n-i-1]... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p... | ```python
def main():
n = int(input())
nums = list(map(int,input().split()))
cards = []
for i in range(n):
cards.append((nums[i],i+1))
cards = sorted(cards,key = lambda x: x[0])
ans = []
#print (cards)
for i in range(int(n/2)):
ans.append((cards[i][1],ca... | 3 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,627,932 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri Nov 10 22:17:24 2023
@author: HXY
"""
n=int(input())
list0=list(map(int,input().split()))
a=sum(list0)
if n<=2 :
print(0)
if a%3!=0:
print(0)
else:
x=a/3
for i in range(1,n):
list0[i]+=list0[i-1]
re=0
for i in range(n... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Nov 10 22:17:24 2023
@author: HXY
"""
n=int(input())
list0=list(map(int,input().split()))
a=sum(list0)
if n<=2 :
print(0)
if a%3!=0:
print(0)
else:
x=a/3
for i in range(1,n):
list0[i]+=list0[i-1]
re=0
for i ... | 0 | |
145 | A | Lucky Conversion | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 500 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,666,277,780 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 124 | 2,048,000 | ch = 0
s = 0
a = input()
b = input()
for i in range(len(a)):
if a[i] != b[i]:
if b[i] == "7":
s += 1
elif b[i] == "4":
ch += 1
print(max(s, ch)) | Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no... | ```python
ch = 0
s = 0
a = input()
b = input()
for i in range(len(a)):
if a[i] != b[i]:
if b[i] == "7":
s += 1
elif b[i] == "4":
ch += 1
print(max(s, ch))
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,684,357,125 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 39 | 92 | 0 | prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
def pair(a, b):
if a in prime:
i = prime.index(a)
if prime[i + 1] == b:
return "YES"
else:
return "NO"
a, b = input().split()
a = int(a)
b = int(b)
print(pair(a, b))
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
def pair(a, b):
if a in prime:
i = prime.index(a)
if prime[i + 1] == b:
return "YES"
else:
return "NO"
a, b = input().split()
a = int(a)
b = int(b)
print(pair(a, b))
``` | -1 |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,679,127,932 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n,m=map(int,input().split())
list1=[0]*2
list2=[]
list2=([list1]*n)
for i in range(1,n+1):
list3=list(map(int,input().split()))
list2[i-1]=list3
sum=0
for i in range(1,n):
if list2[i-1][1]>=list2[i][0]:
sum+=1
if sum==n-1 and list2[n-1][1]>=m:
print("YES")
else :
print("NO")
... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n,m=map(int,input().split())
list1=[0]*2
list2=[]
list2=([list1]*n)
for i in range(1,n+1):
list3=list(map(int,input().split()))
list2[i-1]=list3
sum=0
for i in range(1,n):
if list2[i-1][1]>=list2[i][0]:
sum+=1
if sum==n-1 and list2[n-1][1]>=m:
print("YES")
else :
print("NO")
... | 0 | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,651,259,006 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 46 | 0 | def e_compativel(a, b):
if abs(a - b) < 3 and abs(a - b) > 0:
return True;
return False;
def testar_compatibilidade_com_conjunto(a, bolas):
for i in bolas:
if not e_compativel(a, i):
return False;
return True;
def testar_combinacoes(bolas, bolasJaSelecionadas, n, nJaSelecio... | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
def e_compativel(a, b):
if abs(a - b) < 3 and abs(a - b) > 0:
return True;
return False;
def testar_compatibilidade_com_conjunto(a, bolas):
for i in bolas:
if not e_compativel(a, i):
return False;
return True;
def testar_combinacoes(bolas, bolasJaSelecionadas, n, ... | 3 | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,600,793,799 | 2,147,483,647 | Python 3 | OK | TESTS | 98 | 467 | 2,355,200 | r,c=map(int,input().split())
mat=[]
flag=0
for i in range(r):
k=[]
s=input()
for z in s:
k.append(z)
mat.append(k)
for i in range(r):
for j in range(c):
if(mat[i][j]=="W"):
if(i-1>=0):
if(mat[i-1][j]=="S"):
flag=1
... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
r,c=map(int,input().split())
mat=[]
flag=0
for i in range(r):
k=[]
s=input()
for z in s:
k.append(z)
mat.append(k)
for i in range(r):
for j in range(c):
if(mat[i][j]=="W"):
if(i-1>=0):
if(mat[i-1][j]=="S"):
flag=... | 3 | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,567,180,799 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 124 | 409,600 | from functools import reduce; input()
a = reduce(lambda x, y: int(x) | int(y), input().split())
b = reduce(lambda x, y: int(x) | int(y), input().split())
print(a + b) | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
from functools import reduce; input()
a = reduce(lambda x, y: int(x) | int(y), input().split())
b = reduce(lambda x, y: int(x) | int(y), input().split())
print(a + b)
``` | 0 | |
479 | C | Exams | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.
According to the schedule, a st... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=5000) — the number of exams Valera will take.
Each of the next *n* lines contains two positive space-separated integers *a**i* and *b**i* (1<=≤<=*b**i*<=<<=*a**i*<=≤<=109) — the date of the exam in the schedule and the early date of passing the *i... | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | [
"3\n5 2\n3 1\n4 2\n",
"3\n6 1\n5 2\n4 3\n"
] | [
"2\n",
"6\n"
] | In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark ... | 1,500 | [
{
"input": "3\n5 2\n3 1\n4 2",
"output": "2"
},
{
"input": "3\n6 1\n5 2\n4 3",
"output": "6"
},
{
"input": "1\n1000000000 999999999",
"output": "999999999"
},
{
"input": "1\n2 1",
"output": "1"
},
{
"input": "2\n3 2\n3 2",
"output": "2"
},
{
"input": "... | 1,694,104,006 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | d={}
ans=0
for _ in range(int(input())):
a,b=map(int,input().split())
d.setdefault(a,[])
d[a].append(b)
num = sorted(d.keys())
days=-1
for x in num:
d[x].sort()
if days<d[x][0]:
days= d[x][0]
else:
days=x
print(days)
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly *n* exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Beside... | ```python
d={}
ans=0
for _ in range(int(input())):
a,b=map(int,input().split())
d.setdefault(a,[])
d[a].append(b)
num = sorted(d.keys())
days=-1
for x in num:
d[x].sort()
if days<d[x][0]:
days= d[x][0]
else:
days=x
print(days)
``` | 0 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,679,068,495 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 77 | 2,764,800 | def miniSin(angle):
return (2 - angle) * (angle % 2)
n = int(input())
gridList = [[i for i in input()] for x in range(n) ]
def checkOs():
for RowIndex in range(n):
for columnIndex in range(n):
numberOfOs = 0
for i in range(4):
RI = RowIndex + miniSin... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
def miniSin(angle):
return (2 - angle) * (angle % 2)
n = int(input())
gridList = [[i for i in input()] for x in range(n) ]
def checkOs():
for RowIndex in range(n):
for columnIndex in range(n):
numberOfOs = 0
for i in range(4):
RI = RowIndex... | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,658,557,056 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,m = map(int,input().split())
x = n
while n!=0:
x+=n//m
n//=m
print(x) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
n,m = map(int,input().split())
x = n
while n!=0:
x+=n//m
n//=m
print(x)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet... | The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$. | none | [
"5 2\n1\n-1\n-1\n1\n0\n"
] | [
"1\n2\n4\n5\n3\n"
] | In the example, hacking would look like this:
5 2 3
1 0
This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...
Really:
on the first query ($1$) the correct answer is $1$, the rocket... | 0 | [
{
"input": "5 2 3\n1 0",
"output": "3 queries, x=3"
},
{
"input": "1 1 1\n1",
"output": "1 queries, x=1"
},
{
"input": "3 2 3\n1 0",
"output": "4 queries, x=3"
},
{
"input": "6 3 5\n1 1 1",
"output": "5 queries, x=5"
},
{
"input": "10 4 3\n0 0 1 0",
"output": ... | 1,532,687,957 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 124 | 0 | from sys import stdout
def scan(obj = map, type = int, sep = ' '):
return obj(type, input().split(sep))
def output(text):
print(f'{text}\n')
stdout.flush()
return int(input())
m, n = scan()
p = []
ans = 0
for i in range(n):
ans = output('1')
if ans == 0 or ans == -2:
e... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem.
Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. Sh... | ```python
from sys import stdout
def scan(obj = map, type = int, sep = ' '):
return obj(type, input().split(sep))
def output(text):
print(f'{text}\n')
stdout.flush()
return int(input())
m, n = scan()
p = []
ans = 0
for i in range(n):
ans = output('1')
if ans == 0 or ans == -2:
... | 0 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,665,773,877 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | gereken, pişme, pişmiş, yapma=map(str,input().split())
if gereken>pişmiş and pişme>yapma:
print("YES")
elif gereken==pişmiş or gereken<pişmiş:
print("NO")
else:
print("NO")
exit() | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
gereken, pişme, pişmiş, yapma=map(str,input().split())
if gereken>pişmiş and pişme>yapma:
print("YES")
elif gereken==pişmiş or gereken<pişmiş:
print("NO")
else:
print("NO")
exit()
``` | 0 | |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,351,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def prime(i):
import math
for x in range(2, int(math.sqrt(int(i ** 0.5))) + 1):
if int(i ** 0.5) % x == 0:
return False
return True
n = int(input())
num = list(map(int, input().split()))
import math
for i in num:
if math.ceil(i ** 0.5) == int(i ** 0.5):
if ... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
def prime(i):
import math
for x in range(2, int(math.sqrt(int(i ** 0.5))) + 1):
if int(i ** 0.5) % x == 0:
return False
return True
n = int(input())
num = list(map(int, input().split()))
import math
for i in num:
if math.ceil(i ** 0.5) == int(i ** 0.5):
... | 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,653,188,918 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | def ncr(n):
return (fact(n)/(2*fact(n-2)))
def fact(n):
r=1
for i in range(2, n+1):
r=r*i
return r
n,m=map(int,input().split())
if(m==1):
c=int(ncr(n))
print(c,c)
else:
v=n%m
if(v==0):
print(int(ncr(m)),end=" ")
else:
c=ncr(n//m)
c1=(... | 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
def ncr(n):
return (fact(n)/(2*fact(n-2)))
def fact(n):
r=1
for i in range(2, n+1):
r=r*i
return r
n,m=map(int,input().split())
if(m==1):
c=int(ncr(n))
print(c,c)
else:
v=n%m
if(v==0):
print(int(ncr(m)),end=" ")
else:
c=ncr(n//m)
... | 0 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,657,103,244 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 139 | 8,396,800 | n = int(input())
s = list(map(int, input().split(" ")))
odd = []
even = []
for i in s:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
odd.sort(reverse = True)
if len(odd) % 2 == 0:
print(sum(s))
else:
print(sum(even) + sum(odd[0:len(odd)-1])) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
s = list(map(int, input().split(" ")))
odd = []
even = []
for i in s:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
odd.sort(reverse = True)
if len(odd) % 2 == 0:
print(sum(s))
else:
print(sum(even) + sum(odd[0:len(odd)-1]))
``` | 3 | |
710 | B | Optimal Point on a Line | PROGRAMMING | 1,400 | [
"brute force",
"sortings"
] | null | null | You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of points on the line.
The second line contains *n* integers *x**i* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the given *n* points. | Print the only integer *x* — the position of the optimal point on the line. If there are several optimal points print the position of the leftmost one. It is guaranteed that the answer is always the integer. | [
"4\n1 2 3 4\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "5\n-1 -10 2 6 7",
"output": "2"
},
{
"input": "10\n-68 10 87 22 30 89 82 -97 -52 25",
"output": "22"
},
{
"input": "100\n457 827 807 17 871 935 907 -415 536 170 551 -988 865 758 -457 -892 -875 -488 684 19 0 555 -807 -624 -... | 1,477,350,973 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | count = int(input())
nums = input().split()
total = 0
for num in nums:
total += int(num)
possible1 = total // count
possible2 = possible1 + 1
total1 = 0
total2 = 0
for num in nums:
total1 += abs(int(num) - possible1)
total2 += abs(int(num) - possible2)
if total1 < total2:
print(possible1)
else:
pri... | Title: Optimal Point on a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* points on a line with their coordinates *x**i*. Find the point *x* so the sum of distances to the given points is minimal.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=... | ```python
count = int(input())
nums = input().split()
total = 0
for num in nums:
total += int(num)
possible1 = total // count
possible2 = possible1 + 1
total1 = 0
total2 = 0
for num in nums:
total1 += abs(int(num) - possible1)
total2 += abs(int(num) - possible2)
if total1 < total2:
print(possible1)
els... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*.
String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".
Dr. Moriarty plans to take string *s* and c... | The first line contains a non-empty string *s*, consisting of lowercase Latin letters. The second line contains a non-empty string *u*, consisting of lowercase Latin letters. The lengths of both strings are in the range from 1 to 2000, inclusive. | Print the only integer — the minimum number of changes that Dr. Moriarty has to make with the string that you choose. | [
"aaaaa\naaa\n",
"abcabc\nbcd\n",
"abcdef\nklmnopq\n"
] | [
"0\n",
"1\n",
"7\n"
] | In the first sample Moriarty can take any substring of length 3, and it will be equal to the required message *u*, so Moriarty won't have to make any changes.
In the second sample you should take a substring consisting of characters from second to fourth ("bca") or from fifth to sixth ("bc"). Then you will only have t... | 0 | [
{
"input": "aaaaa\naaa",
"output": "0"
},
{
"input": "abcabc\nbcd",
"output": "1"
},
{
"input": "abcdef\nklmnopq",
"output": "7"
},
{
"input": "aaabbbaaa\naba",
"output": "1"
},
{
"input": "a\na",
"output": "0"
},
{
"input": "z\nz",
"output": "0"
... | 1,584,899,807 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 2,048,000 | from collections import *
s1, s2 = input(), input()
l1, l2, mem1 = len(s1), len(s2), defaultdict(int)
ans = l2
for i in range(l1):
for j in range(l1 - i):
mem1[s1[j:j + i + 1]] = 1
for i in range(l2):
for j in range(l2 - i):
if mem1[s2[j:j + i + 1]]:
ans = min(ans, l2... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string *s*.
String *p* is called a substring of string *s* if you can read it starting from some position in the string *s*. For example, string "aba" has six ... | ```python
from collections import *
s1, s2 = input(), input()
l1, l2, mem1 = len(s1), len(s2), defaultdict(int)
ans = l2
for i in range(l1):
for j in range(l1 - i):
mem1[s1[j:j + i + 1]] = 1
for i in range(l2):
for j in range(l2 - i):
if mem1[s2[j:j + i + 1]]:
ans = m... | 0 | |
429 | A | Xor-tree | PROGRAMMING | 1,300 | [
"dfs and similar",
"trees"
] | null | null | Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). Each of the next *n*<=-<=1 lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*; *u**i*<=≠<=*v**i*) meaning there is an edge between nodes *u**i* and *v**i*.
The next line contains *n* integer numbers, the *i*-th of them corresponds t... | In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. | [
"10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1\n"
] | [
"2\n4\n7\n"
] | none | 500 | [
{
"input": "10\n2 1\n3 1\n4 2\n5 1\n6 2\n7 5\n8 6\n9 8\n10 5\n1 0 1 1 0 1 0 1 0 1\n1 0 1 0 0 1 1 1 0 1",
"output": "2\n4\n7"
},
{
"input": "15\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n10 9\n11 10\n12 11\n13 12\n14 13\n15 14\n0 1 0 0 1 1 1 1 1 1 0 0 0 1 1\n1 1 1 1 0 0 1 1 0 1 0 0 1 1 0",
"output"... | 1,465,745,799 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 748 | 26,931,200 | from collections import defaultdict, deque, Counter, OrderedDict
from bisect import insort, bisect_right, bisect_left
import threading
def main():
n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1
... | Title: Xor-tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees.
The game is played ... | ```python
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import insort, bisect_right, bisect_left
import threading
def main():
n = int(input())
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
a, b = map(int, input().split())
a, b = a - 1, b - 1... | 3 | |
958 | B1 | Maximum Control (easy) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect s... | The first line of the input contains an integer *N* (2<=≤<=*N*<=≤<=1000) – the number of planets in the galaxy.
The next *N*<=-<=1 lines describe the hyperspace tunnels between the planets. Each of the *N*<=-<=1 lines contains two space-separated integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*N*) indicating that there is ... | A single integer denoting the number of remote planets. | [
"5\n4 1\n4 2\n1 3\n1 5\n",
"4\n1 2\n4 3\n1 4\n"
] | [
"3\n",
"2\n"
] | In the first example, only planets 2, 3 and 5 are connected by a single tunnel.
In the second example, the remote planets are 2 and 3.
Note that this problem has only two versions – easy and medium. | 0 | [
{
"input": "5\n4 1\n4 2\n1 3\n1 5",
"output": "3"
},
{
"input": "4\n1 2\n4 3\n1 4",
"output": "2"
},
{
"input": "10\n4 3\n2 6\n10 1\n5 7\n5 8\n10 6\n5 9\n9 3\n2 9",
"output": "4"
}
] | 1,523,697,549 | 8,049 | Python 3 | OK | TESTS | 9 | 186 | 12,390,400 | n = int(input())
counter = 0
a = [[0 for j in range(n)] for i in range(n)]
for i in range(n - 1):
i, j = map(int, input().split())
a[i - 1][j - 1] = 1
a[j - 1][i - 1] = 1
for element in a:
if element.count(1) == 1:
counter += 1
print(counter) | Title: Maximum Control (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in s... | ```python
n = int(input())
counter = 0
a = [[0 for j in range(n)] for i in range(n)]
for i in range(n - 1):
i, j = map(int, input().split())
a[i - 1][j - 1] = 1
a[j - 1][i - 1] = 1
for element in a:
if element.count(1) == 1:
counter += 1
print(counter)
``` | 3 | |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is ... | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": ... | 1,591,450,946 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 218 | 307,200 | def solve(n):
if(n==1):
print("1")
elif(n==2):
print("2")
elif(n==3):
print("6")
elif(n&1):
print(n*(n-1)*(n-2))
else:
if(n%3==0):
print((n-1)*(n-2)*(n-3))
else:
print(n*(n-1)*(n-3))
return
def main():
n=int(input())
... | Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive... | ```python
def solve(n):
if(n==1):
print("1")
elif(n==2):
print("2")
elif(n==3):
print("6")
elif(n&1):
print(n*(n-1)*(n-2))
else:
if(n%3==0):
print((n-1)*(n-2)*(n-3))
else:
print(n*(n-1)*(n-3))
return
def main():
n=int(i... | 3 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,624,187,480 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 62 | 0 | s1,s2=map(str,input().split())
print(s1 if s1==s2 else 1) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
s1,s2=map(str,input().split())
print(s1 if s1==s2 else 1)
``` | 3 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,625,667,027 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | # from sys import stdin, stdout
# import re
# import math
# import statistics
# import itertools
# import collections
# import cmath
# import calendar
# import datetime
# import operator
#----------Profiling----------
# import cProfile
# import pstats
n, t = map(int, input().split())
songs = l... | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
# from sys import stdin, stdout
# import re
# import math
# import statistics
# import itertools
# import collections
# import cmath
# import calendar
# import datetime
# import operator
#----------Profiling----------
# import cProfile
# import pstats
n, t = map(int, input().split())
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 0 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,041,959 | 4,059 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 30 | 5,529,600 | V1 = int(input())
V2 = int(input())
V3 = int(input())
Vm = int(input())
import random
max_ = 2*min(V3, Vm)
min_ = max(V3, Vm)
if min_ <= max_:
print(V1, V2, random.randint(min_, max_))
else:
print(-1) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can cli... | ```python
V1 = int(input())
V2 = int(input())
V3 = int(input())
Vm = int(input())
import random
max_ = 2*min(V3, Vm)
min_ = max(V3, Vm)
if min_ <= max_:
print(V1, V2, random.randint(min_, max_))
else:
print(-1)
``` | -1 | |
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil... | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes eq... | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "... | 1,606,026,139 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 140 | 0 | n, m, a, b = map(int, input().split())
destroy = n%m
build = m - destroy
dest = destroy* b
bui = build*a
print(min(dest, bui)) | Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou... | ```python
n, m, a, b = map(int, input().split())
destroy = n%m
build = m - destroy
dest = destroy* b
bui = build*a
print(min(dest, bui))
``` | 3 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,638,568,155 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 28 | 93 | 3,379,200 | n=int(input())
d=input()
z=0
for i,k in enumerate((l:=bin(int(d[::-1],2)+1)[:1:-1][:n])+'0'*(n-len(str(l)))):
if k!=d[i]:z+=1
print(z)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n=int(input())
d=input()
z=0
for i,k in enumerate((l:=bin(int(d[::-1],2)+1)[:1:-1][:n])+'0'*(n-len(str(l)))):
if k!=d[i]:z+=1
print(z)
``` | -1 | |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,646,960,392 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 93 | 8,908,800 | #sa7afy
#a,b = map(int,input().split())
#arr=[]
#arr=list(map(int,input().split()))
#arr = list(dict.fromkeys(arr))
#arr.sort()
#n = int(input())
#for i in range():
#print(*list)
#────────▓▓▓▓▓▓▓────────────▒▒▒▒▒▒
#──────▓▓▒▒▒▒▒▒▒▓▓────────▒▒░░░░░░▒▒
#────▓▓▒▒▒▒▒▒▒▒▒▒▒▓▓────▒▒░░░░░░░░░▒▒▒
#───▓▓▒▒▒▒▒▒▒▒▒▒... | Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
#sa7afy
#a,b = map(int,input().split())
#arr=[]
#arr=list(map(int,input().split()))
#arr = list(dict.fromkeys(arr))
#arr.sort()
#n = int(input())
#for i in range():
#print(*list)
#────────▓▓▓▓▓▓▓────────────▒▒▒▒▒▒
#──────▓▓▒▒▒▒▒▒▒▓▓────────▒▒░░░░░░▒▒
#────▓▓▒▒▒▒▒▒▒▒▒▒▒▓▓────▒▒░░░░░░░░░▒▒▒
#───▓▓... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul has found a tolerable string *s* of length *n*. Help him find the lexicographically next to... | The first line contains two space-separated integers: *n* and *p* (1<=≤<=*n*<=≤<=1000; 1<=≤<=*p*<=≤<=26). The second line contains string *s*, consisting of *n* small English letters. It is guaranteed that the string is tolerable (according to the above definition). | If the lexicographically next tolerable string of the same length exists, print it. Otherwise, print "NO" (without the quotes). | [
"3 3\ncba\n",
"3 4\ncba\n",
"4 4\nabcd\n"
] | [
"NO\n",
"cbd\n",
"abda\n"
] | String *s* is lexicographically larger (or simply larger) than string *t* with the same length, if there is number *i*, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, ..., *s*<sub class="lower-index">*i*</sub> = *t*<sub class="lower-index">*i*</sub>, *s*<sub class="lower-index">*i*... | 0 | [
{
"input": "3 3\ncba",
"output": "NO"
},
{
"input": "3 4\ncba",
"output": "cbd"
},
{
"input": "4 4\nabcd",
"output": "abda"
},
{
"input": "2 2\nab",
"output": "ba"
},
{
"input": "2 2\nba",
"output": "NO"
},
{
"input": "1 2\na",
"output": "b"
},
... | 1,661,508,839 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n,p = map(int, input().split())
a = list(input())
c = False
for i in range(n-1,-1,-1):
for k in range(p):
ch = chr(ord('a')+k)
if ch>a[i] and (i>0 and ch!=a[i-1]) and (i>1 and ch!=a[i-2]):
a[i] = ch
c = True
break
if c:
break
if not c:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more.
Paul h... | ```python
n,p = map(int, input().split())
a = list(input())
c = False
for i in range(n-1,-1,-1):
for k in range(p):
ch = chr(ord('a')+k)
if ch>a[i] and (i>0 and ch!=a[i-1]) and (i>1 and ch!=a[i-2]):
a[i] = ch
c = True
break
if c:
break
if n... | 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,584,991,921 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | n = int(input())
l = list(map(int,input().split()))
count1,count2,count3,count4,count6 = 0,0,0,0,0
t = True
count1 = l.count(1)
count2 = l.count(2)
count3 = l.count(3)
count4 = l.count(4)
count6 = l.count(6)
#print(count1,count2,count3,count4,count6)
x = count2+count3
y = count4+count6
#print(x,y)
c ... | 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())
l = list(map(int,input().split()))
count1,count2,count3,count4,count6 = 0,0,0,0,0
t = True
count1 = l.count(1)
count2 = l.count(2)
count3 = l.count(3)
count4 = l.count(4)
count6 = l.count(6)
#print(count1,count2,count3,count4,count6)
x = count2+count3
y = count4+count6
#prin... | 0 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,655,309,913 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | a, b, c = map(int, input().split())
if a==b and c==0:
print("yes")
elif ((b-a)%c==0):
print("yes")
else :
print("no") | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a, b, c = map(int, input().split())
if a==b and c==0:
print("yes")
elif ((b-a)%c==0):
print("yes")
else :
print("no")
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**... | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 +... | 0 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
... | 1,689,365,108 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689365108.6634629")# 1689365108.6634822 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of p... | ```python
print("_RANDOM_GUESS_1689365108.6634629")# 1689365108.6634822
``` | 0 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,684,552,633 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | pos1 = list(input())
pos1[0] = ord(pos1[0])-97
pos1[1] = int(pos1[1])
pos2 = list(input())
pos2[0] = ord(pos2[0])-97
pos2[1] = int(pos2[1])
moves = []
steps=0
while True:
if pos1[0] < pos2[0] and pos1[1] < pos2[1]:
pos1[0]+=1
pos1[1]+=1
moves.append("RU")
elif pos1[0] > pos2... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
pos1 = list(input())
pos1[0] = ord(pos1[0])-97
pos1[1] = int(pos1[1])
pos2 = list(input())
pos2[0] = ord(pos2[0])-97
pos2[1] = int(pos2[1])
moves = []
steps=0
while True:
if pos1[0] < pos2[0] and pos1[1] < pos2[1]:
pos1[0]+=1
pos1[1]+=1
moves.append("RU")
elif pos1... | 3.938 |
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,596,650,336 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 186 | 6,963,200 | n=int(input())
x=[int(a) for a in input().split()]
y=[int(a) for a in input().split()]
z=[int(a) for a in input().split()]
count=0
for i in range(3):
if x[i]+y[i]+z[i]==0:
count+=1
if count==3:
print("YES")
else:
print("NO")
| 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
n=int(input())
x=[int(a) for a in input().split()]
y=[int(a) for a in input().split()]
z=[int(a) for a in input().split()]
count=0
for i in range(3):
if x[i]+y[i]+z[i]==0:
count+=1
if count==3:
print("YES")
else:
print("NO")
``` | 0 |
353 | A | Domino | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.
To do... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half... | Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1. | [
"2\n4 2\n6 4\n",
"1\n2 3\n",
"3\n1 4\n2 3\n4 4\n"
] | [
"0\n",
"-1\n",
"1\n"
] | In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.
In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the... | 500 | [
{
"input": "2\n4 2\n6 4",
"output": "0"
},
{
"input": "1\n2 3",
"output": "-1"
},
{
"input": "3\n1 4\n2 3\n4 4",
"output": "1"
},
{
"input": "5\n5 4\n5 4\n1 5\n5 5\n3 3",
"output": "1"
},
{
"input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n... | 1,594,845,737 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 310 | 20,172,800 | #Codeforces353A
upper = 0
lower = 0
double = 0
opposite = 0
for i in range(int(input())):
bol = 0
dom = input().split()
if int(dom[0]) % 2 == 1:
upper += 1
bol += 1
if int(dom[1]) % 2 == 1:
lower += 1
bol += 1
if bol == 2:
... | Title: Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n... | ```python
#Codeforces353A
upper = 0
lower = 0
double = 0
opposite = 0
for i in range(int(input())):
bol = 0
dom = input().split()
if int(dom[0]) % 2 == 1:
upper += 1
bol += 1
if int(dom[1]) % 2 == 1:
lower += 1
bol += 1
if bol == ... | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,675,228,585 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 921,600 | s = input()
t = input()
s_size, t_size = len(s) - 1 , len(t) - 1
cnt = 0
while s_size >= 0 and t_size >= 0:
if s[s_size] == t [t_size]: cnt += 2
else: break
s_size -= 1
t_size -= 1
print(len(s) + len(t) - cnt)
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
s = input()
t = input()
s_size, t_size = len(s) - 1 , len(t) - 1
cnt = 0
while s_size >= 0 and t_size >= 0:
if s[s_size] == t [t_size]: cnt += 2
else: break
s_size -= 1
t_size -= 1
print(len(s) + len(t) - cnt)
``` | 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,606,934,077 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 204,800 | import sys
a=int(input())
d=dict()
arr=list(map(int,input().split()))
for i in arr:
d[i]=1
s=set()
for i in range(1,a+1):
if(i not in d):
s.add(i)
d=dict()
for i in range(0,len(arr)):
if(arr[i] in d):
arr[i]=s.pop()
else:
d[arr[i]]=1
print(" ".join(map(str,arr)))
| 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
import sys
a=int(input())
d=dict()
arr=list(map(int,input().split()))
for i in arr:
d[i]=1
s=set()
for i in range(1,a+1):
if(i not in d):
s.add(i)
d=dict()
for i in range(0,len(arr)):
if(arr[i] in d):
arr[i]=s.pop()
else:
d[arr[i]]=1
print(" ".join(map(str,arr)))
``` | -1 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,693,057,574 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 154 | 0 | n = input()
if int(n) >= 0:
print(n)
else:
n = int(n[1:])
print(-min(n//10, n//100*10 + n%10)) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n = input()
if int(n) >= 0:
print(n)
else:
n = int(n[1:])
print(-min(n//10, n//100*10 + n%10))
``` | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,655,058,564 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | s = input()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
idx1 = 0
sm = 0
for i in s:
idx2 = a.index(i)
# print(idx2, idx21)
if idx2 > idx1:
dis = (25 - idx2) + idx1 + 1
else:
dis = (... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
s = input()
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
idx1 = 0
sm = 0
for i in s:
idx2 = a.index(i)
# print(idx2, idx21)
if idx2 > idx1:
dis = (25 - idx2) + idx1 + 1
else:
... | 3 | |
355 | B | Vasya and Public Transport | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are numbered by integers from 1 to *m*.
Public transport is not free. There are 4 types of tickets:
1. A ticket fo... | The first line contains four integers *c*1,<=*c*2,<=*c*3,<=*c*4 (1<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4<=≤<=1000) — the costs of the tickets.
The second line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of buses and trolleys Vasya is going to use.
The third line contains *n* integers *a**i* (0<=... | Print a single number — the minimum sum of burles Vasya will have to spend on the tickets. | [
"1 3 7 19\n2 3\n2 5\n4 4 4\n",
"4 3 2 1\n1 3\n798\n1 2 3\n",
"100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n"
] | [
"12\n",
"1\n",
"16\n"
] | In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.
In the second sample the profitable strategy is to buy one ticket of t... | 1,000 | [
{
"input": "1 3 7 19\n2 3\n2 5\n4 4 4",
"output": "12"
},
{
"input": "4 3 2 1\n1 3\n798\n1 2 3",
"output": "1"
},
{
"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42",
"output": "16"
},
{
"input": "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0",
"output"... | 1,381,679,428 | 1,228 | Python 3 | OK | TESTS | 27 | 62 | 307,200 | c1, c2, c3, c4 = map(int, input().split())
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum1 = 0
for i in range(n):
sum1 += min(a[i] * c1, c2)
sum2 = 0
for i in range(m):
sum2 += min(b[i] * c1, c2)
print(min(c4, 2 * c3, c3 + sum1, c3 + sum2, ... | Title: Vasya and Public Transport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are nu... | ```python
c1, c2, c3, c4 = map(int, input().split())
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum1 = 0
for i in range(n):
sum1 += min(a[i] * c1, c2)
sum2 = 0
for i in range(m):
sum2 += min(b[i] * c1, c2)
print(min(c4, 2 * c3, c3 + sum1, 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,676,505,470 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 92 | 2,662,400 | # DO NOT EDIT THIS
import math
import sys
input = sys.stdin.readline
from collections import deque, defaultdict
import heapq
def counter(a):
c = defaultdict(lambda : 0) # way faster than Counter
for el in a:
c[el] += 1
return c
def inp(): return [int(k) for k in input().split()]
def si... | 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
# DO NOT EDIT THIS
import math
import sys
input = sys.stdin.readline
from collections import deque, defaultdict
import heapq
def counter(a):
c = defaultdict(lambda : 0) # way faster than Counter
for el in a:
c[el] += 1
return c
def inp(): return [int(k) for k in input().split(... | 3 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,604,690,940 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 278 | 0 | n = str(input())
ans = 0
for i in n:
if i == '0' or i == '1':
ans += 1
if ans == len(n):
print(ans)
else:
print(0)
| Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
n = str(input())
ans = 0
for i in n:
if i == '0' or i == '1':
ans += 1
if ans == len(n):
print(ans)
else:
print(0)
``` | 0 |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,697,347,956 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k,r=map(int,input().split())
num_s=1
while (num_s*k)%10!=0 and ((num_s*k)-r)%10!=0:
num_s+=1
print(num_s)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k,r=map(int,input().split())
num_s=1
while (num_s*k)%10!=0 and ((num_s*k)-r)%10!=0:
num_s+=1
print(num_s)
``` | 3 | |
656 | G | You're a Professional | PROGRAMMING | 1,900 | [
"*special"
] | null | null | A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be... | The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-t... | Output an integer — the number of items liked by at least *T* of user's friends. | [
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] | [
"2\n",
"4\n"
] | none | 0 | [
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\... | 1,459,533,565 | 7,165 | Python 3 | OK | TESTS | 33 | 62 | 5,120,000 | n,kitten,t= map(int, input().split())
a=[str(input()) for i in range(n)]
q=0
for i in range(kitten):
l=0
for j in range(n):
if (a[j][i]=="Y"):
l+=1
if (l >= t):
q+=1
print(q) | Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a li... | ```python
n,kitten,t= map(int, input().split())
a=[str(input()) for i in range(n)]
q=0
for i in range(kitten):
l=0
for j in range(n):
if (a[j][i]=="Y"):
l+=1
if (l >= t):
q+=1
print(q)
``` | 3 | |
837 | D | Round Subset | PROGRAMMING | 2,100 | [
"dp",
"math"
] | null | null | Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected numbers will be maximum possible. | The first line contains two integer numbers *n* and *k* (1<=≤<=*n*<=≤<=200,<=1<=≤<=*k*<=≤<=*n*).
The second line contains *n* space-separated integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1018). | Print maximal roundness of product of the chosen subset of length *k*. | [
"3 2\n50 4 20\n",
"5 3\n15 16 3 25 9\n",
"3 3\n9 77 13\n"
] | [
"3\n",
"3\n",
"0\n"
] | In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0. | 0 | [
{
"input": "3 2\n50 4 20",
"output": "3"
},
{
"input": "5 3\n15 16 3 25 9",
"output": "3"
},
{
"input": "3 3\n9 77 13",
"output": "0"
},
{
"input": "1 1\n200000000",
"output": "8"
},
{
"input": "1 1\n3",
"output": "0"
},
{
"input": "3 1\n10000000000000... | 1,501,922,716 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 4,812,800 | def dob(cur,ans,a):
cur *= a
while (cur % 10 == 0):
ans += 1
cur /= 10
return cur, ans
n,k = map(int,input().split())
des = []
pyat = []
chet = []
inp = list(map(int,input().split()))
des.sort()
for el in inp:
if el % 10 == 0:
des.append(el)
elif el % 5 =... | Title: Round Subset
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of *n* numbers. You need to choose a subset of exactly *k* numbers so that the roundness of the product of the selected number... | ```python
def dob(cur,ans,a):
cur *= a
while (cur % 10 == 0):
ans += 1
cur /= 10
return cur, ans
n,k = map(int,input().split())
des = []
pyat = []
chet = []
inp = list(map(int,input().split()))
des.sort()
for el in inp:
if el % 10 == 0:
des.append(el)
eli... | 0 | |
808 | C | Tea Party | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that:
- Every cup... | The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.
If it's impossible to pour all the tea and satisfy all conditions then output -1. | [
"2 10\n8 7\n",
"4 4\n1 1 1 1\n",
"3 10\n9 8 10\n"
] | [
"6 4 \n",
"1 1 1 1 \n",
"-1\n"
] | In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. | 0 | [
{
"input": "2 10\n8 7",
"output": "6 4 "
},
{
"input": "4 4\n1 1 1 1",
"output": "1 1 1 1 "
},
{
"input": "3 10\n9 8 10",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "1 "
},
{
"input": "1 1\n2",
"output": "1 "
},
{
"input": "1 10\n20",
"output... | 1,646,185,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n, w = map(int, input().split())
cups = list(map(int, input().split()))
output = []
for cup in cups:
fill = -(-cup // 2)
if w < fill:
print(-1)
exit()
output.append(fill)
w -= fill
output.sort(reverse=True)
for i in range(len(cups)):
cup = cups[i]
o = ou... | Title: Tea Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<... | ```python
n, w = map(int, input().split())
cups = list(map(int, input().split()))
output = []
for cup in cups:
fill = -(-cup // 2)
if w < fill:
print(-1)
exit()
output.append(fill)
w -= fill
output.sort(reverse=True)
for i in range(len(cups)):
cup = cups[i]
... | 0 | |
468 | A | 24 Game | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbe... | [
"1\n",
"8\n"
] | [
"NO\n",
"YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n"
] | none | 500 | [
{
"input": "1",
"output": "NO"
},
{
"input": "8",
"output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24"
},
{
"input": "12",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 =... | 1,609,744,624 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n = int(input())
if n <= 3:
print("NO")
else:
print("YES")
while n > 5:
print("{} - {} = 1".format(n, n-1))
n -= 2
if n == 4:
print("4 * 3 = 12")
print("2 * 1 = 2")
print("12 * 2 = 24")
else:
print("5 * 4 = 20")
print("3 + 2 = 5... | Title: 24 Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them... | ```python
n = int(input())
if n <= 3:
print("NO")
else:
print("YES")
while n > 5:
print("{} - {} = 1".format(n, n-1))
n -= 2
if n == 4:
print("4 * 3 = 12")
print("2 * 1 = 2")
print("12 * 2 = 24")
else:
print("5 * 4 = 20")
print(... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).
A group of soldiers is effective if and only if their names... | The first line of the input contains two integers *n* and *k* (2<=≤<=*k*<=≤<=*n*<=≤<=50) — the number of soldiers and the size of a group respectively.
The second line contains *n*<=-<=*k*<=+<=1 strings *s*1,<=*s*2,<=...,<=*s**n*<=-<=*k*<=+<=1. The string *s**i* is "YES" if the group of soldiers *i* through *i*<=+<=*k... | Find any solution satisfying all given conditions. In one line print *n* space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10.
... | [
"8 3\nNO NO YES YES YES NO\n",
"9 8\nYES NO\n",
"3 2\nNO NO\n"
] | [
"Adam Bob Bob Cpqepqwer Limak Adam Bob Adam",
"R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc",
"Na Na Na"
] | In the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:
- First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string *s*<sub class="lower-index">1</... | 0 | [
{
"input": "8 3\nNO NO YES YES YES NO",
"output": "Ab Ac Ab Ac Af Ag Ah Ag "
},
{
"input": "9 8\nYES NO",
"output": "Ab Ac Ad Ae Af Ag Ah Ai Ac "
},
{
"input": "3 2\nNO NO",
"output": "Ab Ab Ab "
},
{
"input": "2 2\nYES",
"output": "Ab Ac "
},
{
"input": "2 2\nNO"... | 1,489,853,426 | 2,126 | Python 3 | OK | TESTS | 59 | 62 | 4,608,000 | def get_name(i):
first = i // 26
second = i % 26
return chr(first + ord('A')) + chr(second + ord('a'))
def main():
n, k = map(int, input().split())
commands = input().split()
names = [get_name(i) for i in range(k)]
if commands[0] == "NO":
names[0] = names[1]
ptr = 1
next_i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scou... | ```python
def get_name(i):
first = i // 26
second = i % 26
return chr(first + ord('A')) + chr(second + ord('a'))
def main():
n, k = map(int, input().split())
commands = input().split()
names = [get_name(i) for i in range(k)]
if commands[0] == "NO":
names[0] = names[1]
ptr = 1
... | 3 | |
437 | A | The Child and Homework | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct.
Fortunately the child knows how to solve such complicated test. The chi... | The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description... | Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). | [
"A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n",
"A.ab\nB.abcde\nC.ab\nD.abc\n",
"A.c\nB.cc\nC.c\nD.c\n"
] | [
"D\n",
"C\n",
"B\n"
] | In the first sample, the first choice has length 39, the second one has length 35, the third one has length 37, and the last one has length 15. The choice D (length 15) is twice shorter than all other choices', so it is great choice. There is no other great choices so the child will choose D.
In the second sample, no ... | 500 | [
{
"input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute",
"output": "D"
},
{
"input": "A.ab\nB.abcde\nC.ab\nD.abc",
"output": "C"
},
{
"input": "A.c\nB.cc\nC.c\nD.c",
"output": "B"
},
... | 1,616,254,897 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 27 | 62 | 307,200 | a=input()
b=input()
c=input()
d=input()
x={}
a=len(a)-2
b=len(b)-2
c=len(c)-2
d=len(d)-2
x['A']=a
x['B']=b
x['C']=c
x['D']=d
c=sorted(x)
c.sort(reverse=True,key=lambda i:x[i])
if x[c[0]]>=x[c[1]]*2:
print(c[0])
elif x[c[-1]]<=x[c[-2]]//2:
print(c[-1])
else:
print("C") | Title: The Child and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should fin... | ```python
a=input()
b=input()
c=input()
d=input()
x={}
a=len(a)-2
b=len(b)-2
c=len(c)-2
d=len(d)-2
x['A']=a
x['B']=b
x['C']=c
x['D']=d
c=sorted(x)
c.sort(reverse=True,key=lambda i:x[i])
if x[c[0]]>=x[c[1]]*2:
print(c[0])
elif x[c[-1]]<=x[c[-2]]//2:
print(c[-1])
else:
print("C")
``` | 0 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,666,785,383 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 500 | 0 | steps = int(input())
result = int(input())
thimbles = [0, 0, 0]
thimbles[result] = 1
for i in range(steps, 0, -1):
if i % 2 == 0 and (thimbles[1] == 0 or thimbles[2] == 0):
thimbles[1], thimbles[2] = thimbles[2], thimbles[1]
elif i%2 != 0 and (thimbles[0] == 0 or thimbles[1] == 0):
thimbles[0], thimbles[1... | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
steps = int(input())
result = int(input())
thimbles = [0, 0, 0]
thimbles[result] = 1
for i in range(steps, 0, -1):
if i % 2 == 0 and (thimbles[1] == 0 or thimbles[2] == 0):
thimbles[1], thimbles[2] = thimbles[2], thimbles[1]
elif i%2 != 0 and (thimbles[0] == 0 or thimbles[1] == 0):
thimbles[0], ... | 0 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,520,508,998 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,632,000 | digits = list(map(int, list(input())))
max_len = max(digits)
answer = []
for i, d in enumerate(reversed(digits)):
row = [10**i] * d + [0] * (max_len - d)
answer.append(row)
print(answer)
result = ''
for j in range(max_len):
result += str(sum([row[j] for row in answer])) + ' '
print(max_len... | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
digits = list(map(int, list(input())))
max_len = max(digits)
answer = []
for i, d in enumerate(reversed(digits)):
row = [10**i] * d + [0] * (max_len - d)
answer.append(row)
print(answer)
result = ''
for j in range(max_len):
result += str(sum([row[j] for row in answer])) + ' '
pri... | 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.