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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,610,590,296 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 307,200 | n,m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans=0
t=0
if b[0]>a[len(a)-1]:
ans=n
else:
i=0
for j in range (len(b)):
if b[j]>=a[i]:
t+=1
i+=1
if i==len(a):
break
ans=n-t
print(ans) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
n,m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans=0
t=0
if b[0]>a[len(a)-1]:
ans=n
else:
i=0
for j in range (len(b)):
if b[j]>=a[i]:
t+=1
i+=1
if i==len(a):
break
ans=n-t
pri... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023. | Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input. | [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n"
] | [
"2\n| 3\n^ 2\n",
"1\n& 1\n",
"0\n"
] | You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the ... | 0 | [
{
"input": "3\n| 3\n^ 2\n| 1",
"output": "2\n| 3\n^ 2"
},
{
"input": "3\n& 1\n& 3\n& 5",
"output": "1\n& 1"
},
{
"input": "3\n^ 1\n^ 2\n^ 3",
"output": "0"
},
{
"input": "2\n| 999\n^ 689",
"output": "2\n| 999\n^ 689"
},
{
"input": "3\n& 242\n^ 506\n^ 522",
"ou... | 1,686,019,537 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 8,704,000 | a, b = 0, 1023
# commands = []
for i in range(int(input())):
cmd = input()
# commands.append(cmd)
c, x = cmd.split()
x = int(x)
if c == "|":
a, b = a | x, b | x
elif c == "&":
a, b = a & x, b & x
else:
a, b = a ^ x, b ^ x
# a, b = eval("a " + cmd), ev... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise opera... | ```python
a, b = 0, 1023
# commands = []
for i in range(int(input())):
cmd = input()
# commands.append(cmd)
c, x = cmd.split()
x = int(x)
if c == "|":
a, b = a | x, b | x
elif c == "&":
a, b = a & x, b & x
else:
a, b = a ^ x, b ^ x
# a, b = eval("a " ... | 0 | |
36 | B | Fractal | PROGRAMMING | 1,600 | [
"implementation"
] | B. Fractal | 2 | 64 | Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a... | The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has... | Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm. | [
"2 3\n.*\n..\n",
"3 2\n.*.\n***\n.*.\n"
] | [
".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n",
".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n"
] | none | 1,000 | [
{
"input": "2 3\n.*\n..",
"output": ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........"
},
{
"input": "3 2\n.*.\n***\n.*.",
"output": ".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*."
},
{
"input": "2 1\n..\n.... | 1,602,681,987 | 1,287 | Python 3 | OK | TESTS | 30 | 218 | 921,600 | import sys
from array import array # noqa: F401
def input1():
with open('input.txt') as fp:
return fp.readlines()
def output1(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
def input2():
return [line.decode('utf-8') for line in sys.stdin.buffer.readli... | Title: Fractal
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He tak... | ```python
import sys
from array import array # noqa: F401
def input1():
with open('input.txt') as fp:
return fp.readlines()
def output1(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
def input2():
return [line.decode('utf-8') for line in sys.stdin.buf... | 3.938634 |
402 | B | Trees in a Row | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a... | The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row. | In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line... | [
"4 1\n1 2 1 5\n",
"4 1\n1 2 3 4\n"
] | [
"2\n+ 3 2\n- 4 1\n",
"0\n"
] | none | 1,000 | [
{
"input": "4 1\n1 2 1 5",
"output": "2\n+ 3 2\n- 4 1"
},
{
"input": "4 1\n1 2 3 4",
"output": "0"
},
{
"input": "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "0"
},
... | 1,402,172,495 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | def main():
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = {}
for i, v in enumerate(a):
good_first = v - k * i
if good_first >= 1:
if good_first not in d:
d[good_first] = 0
d[good_first] += 1
... | Title: Trees in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wan... | ```python
def main():
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = {}
for i, v in enumerate(a):
good_first = v - k * i
if good_first >= 1:
if good_first not in d:
d[good_first] = 0
d[good_first] += 1... | -1 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,687,495,357 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
mishka_wins=0
chris_wins=0
for i in range(n):
m,c=map(int,input().split())
if m>c:
mishka_wins += 1
if c>m:
chris_wins +=1
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
print("Chris")
else:
print("Friendship is magic") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n=int(input())
mishka_wins=0
chris_wins=0
for i in range(n):
m,c=map(int,input().split())
if m>c:
mishka_wins += 1
if c>m:
chris_wins +=1
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
print("Chris")
else:
print("Friendship is ... | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | 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:
- ... | 500 | [
{
"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,536,098,890 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 10,854,400 | n = int(input())
h = input().split(' ')
s = list()
m = 0
for i in h :
if s.count(i)>0 :
s.remove(i)
else :
s.append(i)
if len(s)>m :
m = len(s)
print(m)
| Title: Andryusha and Socks
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 numbere... | ```python
n = int(input())
h = input().split(' ')
s = list()
m = 0
for i in h :
if s.count(i)>0 :
s.remove(i)
else :
s.append(i)
if len(s)>m :
m = len(s)
print(m)
``` | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,634,645,672 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 0 | n=int(input())
d={}
l=[]
for test in range(n):
a,b=input().split()
l.append((a,b))
d[a]=int(b)+d.get(a,0)
m=0
for item in d.items():
m=max(m,item[1])
d={}
x=[]
for a,b in l:
c=int(b)+d.get(a,0)
d[a]=c
if(c>=m):
x.append(a)
r=""
for c in x:
if d[c]==m:
r=c
break
print(r)
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n=int(input())
d={}
l=[]
for test in range(n):
a,b=input().split()
l.append((a,b))
d[a]=int(b)+d.get(a,0)
m=0
for item in d.items():
m=max(m,item[1])
d={}
x=[]
for a,b in l:
c=int(b)+d.get(a,0)
d[a]=c
if(c>=m):
x.append(a)
r=""
for c in x:
if d[c]==m:
r=c
break
print(r)
... | 3.938 |
803 | B | Distances to Zero | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109). | Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*. | [
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 1 2 3 4\n",
"7\n5 6 0 1 -2 3 4\n"
] | [
"2 1 0 1 0 0 1 2 3 ",
"0 1 2 3 4 ",
"2 1 0 1 2 3 4 "
] | none | 0 | [
{
"input": "9\n2 1 0 3 0 0 3 2 4",
"output": "2 1 0 1 0 0 1 2 3 "
},
{
"input": "5\n0 1 2 3 4",
"output": "0 1 2 3 4 "
},
{
"input": "7\n5 6 0 1 -2 3 4",
"output": "2 1 0 1 2 3 4 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
... | 1,577,973,306 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | a=list(map(int, input().split()))
for i in range(len(a)):
if a[i]!=0:
b=[a[:i + 1], a[i:]]
b[0]=list(reversed(b[0]))
left=len(a)+1
right=len(a)+1
for j in range(len(b[0])):
if b[0][j]==0:
left=j
break
for k in ... | Title: Distances to Zero
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the give... | ```python
a=list(map(int, input().split()))
for i in range(len(a)):
if a[i]!=0:
b=[a[:i + 1], a[i:]]
b[0]=list(reversed(b[0]))
left=len(a)+1
right=len(a)+1
for j in range(len(b[0])):
if b[0][j]==0:
left=j
break
... | 0 | |
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,688,808,564 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | s = list(input())
r = 0
current = "a"
for l in s:
d = min((ord(l) - ord(current)) % 26, (ord(current) - ord(l)) % 26)
r += d
current = l
print(r)
# This porblem was solved with a lot of help from ChatGPT,
# I could not figure out who to rotate around and it gave me two big hints:
# I can rotate around ... | 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 = list(input())
r = 0
current = "a"
for l in s:
d = min((ord(l) - ord(current)) % 26, (ord(current) - ord(l)) % 26)
r += d
current = l
print(r)
# This porblem was solved with a lot of help from ChatGPT,
# I could not figure out who to rotate around and it gave me two big hints:
# I can rota... | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,684,322,879 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 62 | 0 | a = input()
if len(a)<7:
print("NO")
else:
cur='2'
count=0
for i in range(len(a)):
if i == len(a)-1 and count<7:
print("NO")
break
if count==7:
print('YES')
break
if a[i] == cur:
count+=1
else:
... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
a = input()
if len(a)<7:
print("NO")
else:
cur='2'
count=0
for i in range(len(a)):
if i == len(a)-1 and count<7:
print("NO")
break
if count==7:
print('YES')
break
if a[i] == cur:
count+=1
... | 0 |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,687,540,441 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 154 | 1,536,000 | p=int(input())
g=0
for x in range(1,p):
i=x
u=1
o=0
while u<p-1:
x%=p
if (x-1)%p==0:
break
x*=i
u+=1
else:
if (x-1)%p==0:
g+=1
print(g) | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
p=int(input())
g=0
for x in range(1,p):
i=x
u=1
o=0
while u<p-1:
x%=p
if (x-1)%p==0:
break
x*=i
u+=1
else:
if (x-1)%p==0:
g+=1
print(g)
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,619,061,876 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | a, b = input(), input()
print(''.join([str(int(a[i] != b[i])) for i in range(len(a))])) | 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, b = input(), input()
print(''.join([str(int(a[i] != b[i])) for i in range(len(a))]))
``` | 3.98075 |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,655,146,091 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | dict={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
user=int(input())
string=[]
for i in range(user):
user1=str(input())
string.append(user1)
print(6-user)
for i in dict:
if i not in string:
print(dict[i])
... | Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
dict={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
user=int(input())
string=[]
for i in range(user):
user1=str(input())
string.append(user1)
print(6-user)
for i in dict:
if i not in string:
print(dict[i])
... | 3 | |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,626,507,355 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 24,985,600 | # link: https://codeforces.com/problemset/problem/701/C
for _ in range(1):
n = int(input())
p = list(input())
pokemons = len(set(p))
ans = float('inf')
for i in range(n):
temp = set()
count = 0
for j in range(i, n):
if p[j] not in temp:
... | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
# link: https://codeforces.com/problemset/problem/701/C
for _ in range(1):
n = int(input())
p = list(input())
pokemons = len(set(p))
ans = float('inf')
for i in range(n):
temp = set()
count = 0
for j in range(i, n):
if p[j] not in temp:
... | 0 | |
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output"... | 1,613,559,291 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 307,200 | n=int(input())
lst=list(map(int,input().split(" ")))
m=abs(lst[0]-lst[n-1])
p=0
k,h=0,n-1
for i in range(len(lst)-1):
p=abs(lst[i]-lst[i+1])
if p<m:
m=abs(lst[i]-lst[i+1])
k,h=i,i+1
print(k+1,h+1)
# 6
# 744 359 230 586 944 442 | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So... | ```python
n=int(input())
lst=list(map(int,input().split(" ")))
m=abs(lst[0]-lst[n-1])
p=0
k,h=0,n-1
for i in range(len(lst)-1):
p=abs(lst[i]-lst[i+1])
if p<m:
m=abs(lst[i]-lst[i+1])
k,h=i,i+1
print(k+1,h+1)
# 6
# 744 359 230 586 944 442
``` | 3.968428 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,684,666,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | l=list(map(int, input().split()))
l.sort()
m=(l[0]+l[2])//2
print(abs(m-l[0])+abs(m-l[1])+abs(m-l[2])) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
l=list(map(int, input().split()))
l.sort()
m=(l[0]+l[2])//2
print(abs(m-l[0])+abs(m-l[1])+abs(m-l[2]))
``` | 0 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,665,584,367 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | n = int(input())
if n % 2 == 0:
num1 = n//2 - 1
num2 = n//2 + 1
else:
num1 = n//2
num2 = n//2 + 1
prime = []
for x in range(2, n+1):
count = 0
for y in range(1, x+1):
if x % y == 0:
count += 1
if count <= 2:
prime.append(x)
while True:
... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
n = int(input())
if n % 2 == 0:
num1 = n//2 - 1
num2 = n//2 + 1
else:
num1 = n//2
num2 = n//2 + 1
prime = []
for x in range(2, n+1):
count = 0
for y in range(1, x+1):
if x % y == 0:
count += 1
if count <= 2:
prime.append(x)
whi... | 0 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,676,091,320 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | def has_AB_BA(s):
# Check if the string s contains "AB" and "BA"
return "AB" in s and "BA" in s
def main():
s = input().strip()
if has_AB_BA(s):
# Check if "AB" and "BA" are non-overlapping
for i in range(len(s) - 1):
if s[i:i+2] == "AB" and s[i+2:i+4] == "BA":
... | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
def has_AB_BA(s):
# Check if the string s contains "AB" and "BA"
return "AB" in s and "BA" in s
def main():
s = input().strip()
if has_AB_BA(s):
# Check if "AB" and "BA" are non-overlapping
for i in range(len(s) - 1):
if s[i:i+2] == "AB" and s[i+2:i+4] == ... | 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,675,898,015 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | asList=[int(i) for i in input().split()]
x=(asList[0]+asList[2]-1)/asList[2]
oven1=0
oven2=asList[3]
for i in range(len(asList)):
if oven1<oven2:
oven1+=1
else:
oven2+=1
if max(oven1,oven2)<x*asList[1]:
print("YES")
else:
print("NO")
| Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
asList=[int(i) for i in input().split()]
x=(asList[0]+asList[2]-1)/asList[2]
oven1=0
oven2=asList[3]
for i in range(len(asList)):
if oven1<oven2:
oven1+=1
else:
oven2+=1
if max(oven1,oven2)<x*asList[1]:
print("YES")
else:
print("NO")
``` | 0 | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,674,170,748 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 |
n = int(input())
k = int(input())
primos = [3, 5]
contagem = 2
for numero in range(7, n+1, 2):
i = 0
while (i < contagem) and (numero % primos[i] != 0):
i += 1
if i == contagem:
for j in range(1, contagem):
if primos[j] + primos[j-1] + 1 == numero:
k -= 1
... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
n = int(input())
k = int(input())
primos = [3, 5]
contagem = 2
for numero in range(7, n+1, 2):
i = 0
while (i < contagem) and (numero % primos[i] != 0):
i += 1
if i == contagem:
for j in range(1, contagem):
if primos[j] + primos[j-1] + 1 == numero:
k -... | -1 |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves... | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* ... | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182... | 1,677,339,810 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
x=[]
y=[]
for i in range(n) :
k=input().split()
x.append(int(k[0]))
y.append(int(k[1]))
print(x)
print(y)
def test(xi,yi,x,y,another):
if x.count(xi)>1 or y.count(yi)>1 or another==1 :
another=0
return(0)
else :
another=1
return 1
... | Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha... | ```python
n=int(input())
x=[]
y=[]
for i in range(n) :
k=input().split()
x.append(int(k[0]))
y.append(int(k[1]))
print(x)
print(y)
def test(xi,yi,x,y,another):
if x.count(xi)>1 or y.count(yi)>1 or another==1 :
another=0
return(0)
else :
another=1
retu... | 0 | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,689,026,138 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 233 | 38,195,200 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
N,K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp1,dp2 = defaultdict(int),defaultdict(int)
for a in A:
if a%K==0:
ans += dp2[a//K]
dp2[a]+=dp1[a//K]
dp... | Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
N,K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp1,dp2 = defaultdict(int),defaultdict(int)
for a in A:
if a%K==0:
ans += dp2[a//K]
dp2[a]+=dp1[a//... | 3 | |
165 | B | Burning Midnight Oil | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin... | The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. | Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. | [
"7 2\n",
"59 9\n"
] | [
"4\n",
"54\n"
] | In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following por... | 1,000 | [
{
"input": "7 2",
"output": "4"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "11 2",
"output": "7"
},
{
"input": "747 2",
"output": "376"
},
{
"input": "6578 2",
"output": "3293"
},
{
"input": "37212... | 1,655,834,597 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 92 | 0 | def test(n,k):
sumi = n
i = 1
while n >= k **i :
sumi += n // k**i
i+=1
return sumi
n,k = map(int,input().split())
start = 1
end = n
ans = -1
while start <= end :
mid = (start +end) //2
res = test(mid,k)
if res < n :
start = mid +1
elif res >= n :
ans = mid
end = mid -1
print(ans... | Title: Burning Midnight Oil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of c... | ```python
def test(n,k):
sumi = n
i = 1
while n >= k **i :
sumi += n // k**i
i+=1
return sumi
n,k = map(int,input().split())
start = 1
end = n
ans = -1
while start <= end :
mid = (start +end) //2
res = test(mid,k)
if res < n :
start = mid +1
elif res >= n :
ans = mid
end = mid -1
... | 3 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,603,994,831 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 12,595,200 | n,m=map(int,input().split())
l=input().split()
c=l.count("-1")
c=min(c,n-c)
res=""
for i in range(m):
l,r=map(int,input().split())
if (r-l)%2==1 and c>=(r-l+1)/2:
res+="1\n"
else:
res+="0\n"
print(res) | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n,m=map(int,input().split())
l=input().split()
c=l.count("-1")
c=min(c,n-c)
res=""
for i in range(m):
l,r=map(int,input().split())
if (r-l)%2==1 and c>=(r-l+1)/2:
res+="1\n"
else:
res+="0\n"
print(res)
``` | 0 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,591,442,789 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 405 | 6,348,800 | def is_same(l1,l2):
if(len(l1)==len(l2)):
for i in range(0,len(l1)):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
return True
else:
for i in range(0,min(len(l1),len(l2... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
def is_same(l1,l2):
if(len(l1)==len(l2)):
for i in range(0,len(l1)):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
return True
else:
for i in range(0,min(len(... | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,699,845,370 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 0 | string = input()
newString = ''.split()
#checks if each inversed digit would reduce the number
for digit in string:
newString += str(min((9 - int(digit), int(digit))))
if int(newString[0]) < 1: #prevents trailing zeros
newString[0] = '9'
#prints the new number as a full string
for digit in newStrin... | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
string = input()
newString = ''.split()
#checks if each inversed digit would reduce the number
for digit in string:
newString += str(min((9 - int(digit), int(digit))))
if int(newString[0]) < 1: #prevents trailing zeros
newString[0] = '9'
#prints the new number as a full string
for digit i... | 3 | |
18 | B | Platforms | PROGRAMMING | 1,700 | [
"brute force",
"math"
] | B. Platforms | 2 | 64 | In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*], and *l*<=<<=*m*. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly *d* units right. Fin... | The first input line contains 4 integer numbers *n*, *d*, *m*, *l* (1<=≤<=*n*,<=*d*,<=*m*,<=*l*<=≤<=106,<=*l*<=<<=*m*) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers *m* and *l* needed to find coordinates of the *k*-th platform: [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*]. | Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down. | [
"2 2 5 3\n",
"5 4 11 8\n"
] | [
"4\n",
"20\n"
] | none | 0 | [
{
"input": "2 2 5 3",
"output": "4"
},
{
"input": "5 4 11 8",
"output": "20"
},
{
"input": "228385 744978 699604 157872",
"output": "2979912"
},
{
"input": "773663 427904 329049 243542",
"output": "1283712"
},
{
"input": "835293 627183 442142 361649",
"output"... | 1,570,117,784 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 966 | 50,892,800 | class Node:
def __init__(self, low, high):
self.low = low
self.high = high
self.max = high
self.left = None
self.right = None
def insert(root, low, high):
if not root:
return Node(low, high)
l = root.low
if low < l:
root.left = insert(root.left, ... | Title: Platforms
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*], and *l*<=<<=*m*. Grasshopper Bob starts to j... | ```python
class Node:
def __init__(self, low, high):
self.low = low
self.high = high
self.max = high
self.left = None
self.right = None
def insert(root, low, high):
if not root:
return Node(low, high)
l = root.low
if low < l:
root.left = insert(r... | -1 |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are... | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15... | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n684... | 1,521,829,680 | 6,780 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 77 | 7,065,600 | h, m = [int(x) for x in input().split()]
H, D, C, N = [int(x) for x in input().split()]
current_time = h * 60 + m
current_buns = H//N
if H%N != 0:
current_buns += 1
if current_time > 1200:
print(current_buns * C)
else:
later_hunger = H + D * (1200-current_time)
later_buns = later_hunger//N
if later... | Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo... | ```python
h, m = [int(x) for x in input().split()]
H, D, C, N = [int(x) for x in input().split()]
current_time = h * 60 + m
current_buns = H//N
if H%N != 0:
current_buns += 1
if current_time > 1200:
print(current_buns * C)
else:
later_hunger = H + D * (1200-current_time)
later_buns = later_hunger//N
... | 0 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,589,002,350 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 7,065,600 | # bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
import random
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
shot = []
line = []
for i in range(m):
x, y = map(int, input().split())
line.append(x)
shot.append(y)
for i in ran... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
import random
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
shot = []
line = []
for i in range(m):
x, y = map(int, input().split())
line.append(x)
shot.append(y)
fo... | 0 | |
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexit... | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ... | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"inp... | 1,529,066,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = input().split()
a = int(n[1])
b = int(n[2])
n = int(n[0])
x = list(map(int,input().split()))
x.sort()
res = x[a] - x[a-1]
print(res) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th... | ```python
n = input().split()
a = int(n[1])
b = int(n[2])
n = int(n[0])
x = list(map(int,input().split()))
x.sort()
res = x[a] - x[a-1]
print(res)
``` | 0 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,628,668,135 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 154 | 7,168,000 | a=input()
i=a.find('0')
if i!=-1:
a=a[:i]+a[i+1:]
else:
a=a[:-1]
print(a) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
a=input()
i=a.find('0')
if i!=-1:
a=a[:i]+a[i+1:]
else:
a=a[:-1]
print(a)
``` | 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,480,509,547 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | f,n,t=map(int,input().split())
s=0
y=[0]*n
for i in range(f):
a=input()
for j in range(n):
if a[j]=='Y':
y[j]+=1;
for i in range(n):
if y[i] >= t:
s += 1
print(s) | 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
f,n,t=map(int,input().split())
s=0
y=[0]*n
for i in range(f):
a=input()
for j in range(n):
if a[j]=='Y':
y[j]+=1;
for i in range(n):
if y[i] >= t:
s += 1
print(s)
``` | 0 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,582,148,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | n = int(input())+1
l = sum(list(map(int,input().split())))
ways = 0
for i in range(1,6):
#print(i)
if (l + i ) % n == 0 :
ways +=1
#print(ways)
if l % 2 == 0 :
print(ways + 1)
else:
print(ways)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())+1
l = sum(list(map(int,input().split())))
ways = 0
for i in range(1,6):
#print(i)
if (l + i ) % n == 0 :
ways +=1
#print(ways)
if l % 2 == 0 :
print(ways + 1)
else:
print(ways)
``` | 0 | |
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must... | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: ... | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
... | 1,498,578,871 | 4,771 | Python 3 | OK | TESTS | 46 | 62 | 5,529,600 | n, alp = map(int, input().split())
a = 180 / n
if alp >= (n-2)*180/n:
print("1 2 3")
else:
k1 = int(alp / a)
if (k1 + 1) * a - alp < alp - k1 * a:
k1 += 1
if k1 == 0:
print("2 1 3")
else:
print(1, 2, n + 1 - k1)
| Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *... | ```python
n, alp = map(int, input().split())
a = 180 / n
if alp >= (n-2)*180/n:
print("1 2 3")
else:
k1 = int(alp / a)
if (k1 + 1) * a - alp < alp - k1 * a:
k1 += 1
if k1 == 0:
print("2 1 3")
else:
print(1, 2, n + 1 - k1)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,682,539,922 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 154 | 0 | n = int(input())
s = list(map(int, input().split()))
fi = [0]*n
for i in range(n):
fi[s[i] - 1] = str(i + 1)
print(str(' '.join(fi))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = int(input())
s = list(map(int, input().split()))
fi = [0]*n
for i in range(n):
fi[s[i] - 1] = str(i + 1)
print(str(' '.join(fi)))
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,676,731,503 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | from math import floor
m,n=map(int,input().split())
k=(m*n)/2
print(floor(k)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
from math import floor
m,n=map(int,input().split())
k=(m*n)/2
print(floor(k))
``` | 3.977 |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,550,410,205 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 202 | 6,656,000 | cnt=lambda s,i:s.count(i)
ii=lambda:int(input())
si=lambda:input()
f=lambda:map(int,input().split())
il=lambda:list(map(int,input().split()))
n,a,b=f()
l=il()
sm=sum(l)
k=l.pop(0)
c=0
l.sort(reverse=True)
for i in range(0,n-1):
if (k*a)/sm<b:
c+=1
sm-=l[i]
l[i] = 0
else:
... | Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
cnt=lambda s,i:s.count(i)
ii=lambda:int(input())
si=lambda:input()
f=lambda:map(int,input().split())
il=lambda:list(map(int,input().split()))
n,a,b=f()
l=il()
sm=sum(l)
k=l.pop(0)
c=0
l.sort(reverse=True)
for i in range(0,n-1):
if (k*a)/sm<b:
c+=1
sm-=l[i]
l[i] = 0
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the c... | If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them). | [
"2 1 0\n",
"2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n"
] | [
"FIRST\n1 0 1 1\n",
"SECOND\n"
] | none | 0 | [] | 1,693,505,806 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1693505806.7356255")# 1693505806.7356417 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. ... | ```python
print("_RANDOM_GUESS_1693505806.7356255")# 1693505806.7356417
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,622,092,957 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | a = list(map(int, input().split()))
o = []
e = []
for i in a:
if(i%2 == 0):
e.append(i)
else:
o.append(i)
if(len(e) > len(o) and len(o) == 1):
f = 0
break
elif(len(o) > len(e) and len(e) == 1):
f = 1
break
if(f == 0):
print(a.index(o[0])... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
a = list(map(int, input().split()))
o = []
e = []
for i in a:
if(i%2 == 0):
e.append(i)
else:
o.append(i)
if(len(e) > len(o) and len(o) == 1):
f = 0
break
elif(len(o) > len(e) and len(e) == 1):
f = 1
break
if(f == 0):
print(a.i... | -1 |
821 | B | Okabe and Banana Trees | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ... | The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). | Print the maximum number of bananas Okabe can get from the trees he cuts. | [
"1 5\n",
"2 3\n"
] | [
"30\n",
"25\n"
] | The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | 1,000 | [
{
"input": "1 5",
"output": "30"
},
{
"input": "2 3",
"output": "25"
},
{
"input": "4 6",
"output": "459"
},
{
"input": "6 3",
"output": "171"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 1",
"output": "55"
},
{
"input": "20 10",
... | 1,498,405,947 | 4,647 | Python 3 | OK | TESTS | 38 | 78 | 5,529,600 | def get2(n):
res = n*(n+1)*(2*n+1)//6 + n*(n+1)//2
res //= 2;
return res
def get(x,y):
return get2(x+y) - get2(x-1) - get2(y-1)
m,b = input().split()
m = int(m)
b = int(b)
mv = 0
for i in range(b+1):
j = m*b-m*i
cur = get(j,i)
if cur > mv:
mv = cur
print(mv) | Title: Okabe and Banana Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers a... | ```python
def get2(n):
res = n*(n+1)*(2*n+1)//6 + n*(n+1)//2
res //= 2;
return res
def get(x,y):
return get2(x+y) - get2(x-1) - get2(y-1)
m,b = input().split()
m = int(m)
b = int(b)
mv = 0
for i in range(b+1):
j = m*b-m*i
cur = get(j,i)
if cur > mv:
mv = cur
print(mv)
``` | 3 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,656,625,910 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | s = input()
x = len(s)
c = 0
for i in range(int(x / 2)):
c += int(s[i] != s[x - i - 1])
if c == 1:
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
s = input()
x = len(s)
c = 0
for i in range(int(x / 2)):
c += int(s[i] != s[x - i - 1])
if c == 1:
print("YES")
else:
print("NO")
``` | 0 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,617,392,937 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 92 | 204,800 | num = int(input())
participants = []
for i in range(num):
participant = input().split()
participants.append(participant)
i =0
for j in range(num):
if int(participants[j][0])!= int(participants[j][1]) :
print('rated')
break
elif j == num -1:
while i < num -1:
... | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
num = int(input())
participants = []
for i in range(num):
participant = input().split()
participants.append(participant)
i =0
for j in range(num):
if int(participants[j][0])!= int(participants[j][1]) :
print('rated')
break
elif j == num -1:
while i < num -1:... | 3 | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,679,101,362 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | entrada = int(input())
cartas = input()
lista_cartas = cartas.split(" ")
operacoes = 0
if '1' not in lista_cartas:
print(0)
else:
index = -1
for i in range(len(lista_cartas)):
if lista_cartas[i] == '1':
if(index < 0 or index + 1 == i):
operacoes +=1
else:
operacoes +=2
... | Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
entrada = int(input())
cartas = input()
lista_cartas = cartas.split(" ")
operacoes = 0
if '1' not in lista_cartas:
print(0)
else:
index = -1
for i in range(len(lista_cartas)):
if lista_cartas[i] == '1':
if(index < 0 or index + 1 == i):
operacoes +=1
else:
opera... | 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,610,366,081 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | f,kitten,n=map(int,input().split())
a=zip(*[input() for _ in range(f)])
print(sum(sum(f=='Y' for f in e)>=n for e in a))
| 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
f,kitten,n=map(int,input().split())
a=zip(*[input() for _ in range(f)])
print(sum(sum(f=='Y' for f in e)>=n for e in a))
``` | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,601,713,436 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 140 | 0 | a,b,c,d=map(int,input().split())
r=a/b
R=c/d
r1=1-r
r2=1-R
print(r*(1/(1-r1*r2)))
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d=map(int,input().split())
r=a/b
R=c/d
r1=1-r
r2=1-R
print(r*(1/(1-r1*r2)))
``` | 3 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,622,522,770 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | if __name__=="__main__":
s=[int(x) for x in input().split()]
n,k=s[0],s[1]
if (n==k) or (n-k<k):
print("YES")
if(n-k==k) or (n-k>k):
print("NO")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
if __name__=="__main__":
s=[int(x) for x in input().split()]
n,k=s[0],s[1]
if (n==k) or (n-k<k):
print("YES")
if(n-k==k) or (n-k>k):
print("NO")
``` | 0 | |
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other ... | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if ... | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.pn... | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
... | 1,666,605,303 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | d, L, v1, v2 = map(int, input().split())
t = 1
e = 10e-14
a = 0
b = L
result = 0.0
while True:
if b-a > d:
if (b-v2) - (a+v1) < d:
v1 /= 2
v2 /= 2
t /= 2
continue
else:
a += v1
b -= v2
res... | Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a strai... | ```python
d, L, v1, v2 = map(int, input().split())
t = 1
e = 10e-14
a = 0
b = L
result = 0.0
while True:
if b-a > d:
if (b-v2) - (a+v1) < d:
v1 /= 2
v2 /= 2
t /= 2
continue
else:
a += v1
b -= v2
... | 3 | |
413 | B | Spyke Chatting | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | The R2 company has *n* employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.
R2 has *m* Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges... | The first line contains three space-separated integers *n*, *m* and *k* (2<=≤<=*n*<=≤<=2·104; 1<=≤<=*m*<=≤<=10; 1<=≤<=*k*<=≤<=2·105) — the number of the employees, the number of chats and the number of events in the log, correspondingly.
Next *n* lines contain matrix *a* of size *n*<=×<=*m*, consisting of numbers zer... | Print in the single line *n* space-separated integers, where the *i*-th integer shows the number of message notifications the *i*-th employee receives. | [
"3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2\n",
"4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3\n"
] | [
"3 3 1 ",
"0 2 3 0 "
] | none | 1,000 | [
{
"input": "3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2",
"output": "3 3 1 "
},
{
"input": "4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3",
"output": "0 2 3 0 "
},
{
"input": "2 1 1\n1\n1\n1 1",
"output": "0 1 "
},
{
"input": "3 3 1\n1 1 1\n1 1 1\n1 1 1\... | 1,397,982,509 | 5,309 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 9 | 1,000 | 10,956,800 | n, m, k = map(int, input().split())
list_of_a = [list(map(int, input().split())) for i in range(n)]
list_of_xy = [list(map(int, input().split())) for i in range(k)]
list_of_n = [0] * n
for sotrud in range(n):
for matriza in list_of_xy:
if list_of_a[sotrud][matriza[1] - 1] == 1:
if matriza... | Title: Spyke Chatting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R2 company has *n* employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.
R2 has ... | ```python
n, m, k = map(int, input().split())
list_of_a = [list(map(int, input().split())) for i in range(n)]
list_of_xy = [list(map(int, input().split())) for i in range(k)]
list_of_n = [0] * n
for sotrud in range(n):
for matriza in list_of_xy:
if list_of_a[sotrud][matriza[1] - 1] == 1:
... | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,641,554,472 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 218 | 1,228,800 | # complexity O(n^3) ?!, I believe that there is a better way to solve it in O(n^2).
n = int(input())
list1 = list(map(int,input().strip().split()))[:n]
def foo(list1):
list2 = []
for i in range(0,len(list1) - 2):
for j in range(1,len(list1) - 1):
for k in range(2, len(list1)):... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
# complexity O(n^3) ?!, I believe that there is a better way to solve it in O(n^2).
n = int(input())
list1 = list(map(int,input().strip().split()))[:n]
def foo(list1):
list2 = []
for i in range(0,len(list1) - 2):
for j in range(1,len(list1) - 1):
for k in range(2, le... | 3.943211 |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the differe... | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
... | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
... | 1,683,320,774 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import math
def main():
n = int(input())
m = list(map(int, input().split()))
min_load = m[0]
max_load = m[0]
for i in range(1, n):
if m[i] < min_load:
min_load = m[i]
elif m[i] > max_load:
max_load = m[i]
print(max_load - min_load)
if __name__ == "__main__":
ma... | Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server... | ```python
import math
def main():
n = int(input())
m = list(map(int, input().split()))
min_load = m[0]
max_load = m[0]
for i in range(1, n):
if m[i] < min_load:
min_load = m[i]
elif m[i] > max_load:
max_load = m[i]
print(max_load - min_load)
if __name__ == "__main... | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,652,416,474 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 0 | n = int(input())
if n<10: print(0)
else:
k,sum=0,0
while True:
sum+=n%10
n//=10
k+=1
if n==0: n=sum
print(k) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
n = int(input())
if n<10: print(0)
else:
k,sum=0,0
while True:
sum+=n%10
n//=10
k+=1
if n==0: n=sum
print(k)
``` | 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,579,363,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | string=input()
if string.count('h')>=1 and string.count('e')>=1 and string.count('ll')>=1 and string.count('o')>=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
string=input()
if string.count('h')>=1 and string.count('e')>=1 and string.count('ll')>=1 and string.count('o')>=1:
print('YES')
else:
print("NO")
``` | 0 |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,687,445,423 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 |
n = int(input())
res = 0
x = 0
for i in range(n):
a, b = [int(i) for i in input().split()]
x -= a
x += b
if res < x:
res = x
print(res) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n = int(input())
res = 0
x = 0
for i in range(n):
a, b = [int(i) for i in input().split()]
x -= a
x += b
if res < x:
res = x
print(res)
``` | 3 | |
612 | D | The Union of k-Segments | PROGRAMMING | 1,800 | [
"greedy",
"sortings"
] | null | null | You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. ... | First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right. | [
"3 2\n0 5\n-3 2\n3 8\n",
"3 2\n0 5\n-3 3\n3 8\n"
] | [
"2\n0 2\n3 5\n",
"1\n0 5\n"
] | none | 0 | [
{
"input": "3 2\n0 5\n-3 2\n3 8",
"output": "2\n0 2\n3 5"
},
{
"input": "3 2\n0 5\n-3 3\n3 8",
"output": "1\n0 5"
},
{
"input": "1 1\n-1 1",
"output": "1\n-1 1"
},
{
"input": "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78",
"output": "1\... | 1,451,094,534 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 4,000 | 158,924,800 | import sys
n,k=map(int,input().split())
ss=[0]*n
ee=[0]*(n+1); ee[n]=2e9
for i,inp in enumerate(sys.stdin.readlines()):
s, e = map(int,inp.split())
ss[i] = s
ee[i] = e
ss.sort()
ee.sort()
m,i,j,p=0,0,0,0
s = ""
while j<n:
if i<n and ss[i] < ee[j]:
x = ss[i]
else:
x = ... | Title: The Union of k-Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordi... | ```python
import sys
n,k=map(int,input().split())
ss=[0]*n
ee=[0]*(n+1); ee[n]=2e9
for i,inp in enumerate(sys.stdin.readlines()):
s, e = map(int,inp.split())
ss[i] = s
ee[i] = e
ss.sort()
ee.sort()
m,i,j,p=0,0,0,0
s = ""
while j<n:
if i<n and ss[i] < ee[j]:
x = ss[i]
else:
... | 0 | |
673 | B | Problems for Round | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset ... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<... | Print one integer — the number of ways to split problems in two divisions. | [
"5 2\n1 4\n5 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"3 2\n3 1\n3 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sa... | 750 | [
{
"input": "5 2\n1 4\n5 2",
"output": "2"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "0"
},
{
"input": "3 2\n3 1\n3 2",
"output": "1"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 0",
"output": "2"
... | 1,621,286,334 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 779 | 12,288,000 | n,m=map(int,input().split())
l1=set()
l2=set()
for i in range(m):
k,t=sorted(map(int,input().split()))
l1.add(k)
l2.add(t)
if m == 0:
print(n-1)
else:
l3=set()
for i in l1:
l3.add(i)
for i in l2:
l3.add(i)
if len(l3) != len(l1)+len(l2):
print(0)
... | Title: Problems for Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems... | ```python
n,m=map(int,input().split())
l1=set()
l2=set()
for i in range(m):
k,t=sorted(map(int,input().split()))
l1.add(k)
l2.add(t)
if m == 0:
print(n-1)
else:
l3=set()
for i in l1:
l3.add(i)
for i in l2:
l3.add(i)
if len(l3) != len(l1)+len(l2):
p... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,636,211,742 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 154 | 17,715,200 | n = int(input())
arr = list(map(int, input().split()))
even = 0
odd = 0
is_even = False
for i in arr:
if i % 2 == 1:
odd += 1
else:
even += 1
if even > odd:
is_even = True
for i in range(len(arr)):
if is_even:
if arr[i] % 2 == 1:
print(i + 1)
else:
if ar... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
arr = list(map(int, input().split()))
even = 0
odd = 0
is_even = False
for i in arr:
if i % 2 == 1:
odd += 1
else:
even += 1
if even > odd:
is_even = True
for i in range(len(arr)):
if is_even:
if arr[i] % 2 == 1:
print(i + 1)
else:
... | 3.928503 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,635,566,977 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 4,300,800 | name=input()
n=len(name)
count=0
for x in name:
if x.isupper():
count+=1
if count<=(n/2):
print(name.lower())
elif count>(n/2):
print(name.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
name=input()
n=len(name)
count=0
for x in name:
if x.isupper():
count+=1
if count<=(n/2):
print(name.lower())
elif count>(n/2):
print(name.upper())
``` | 3.961489 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,696,578,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | s1=input()
a=s1.lower()
s2=input()
b=s2.lower()
os1=0
os2=0
for i in a:
os1+= ord(i)
for i in b:
os2+= ord(i)
if os1==os2:
print(0)
if os1<os2:
print('-1')
if os2<os1:
print(1)
| Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
s1=input()
a=s1.lower()
s2=input()
b=s2.lower()
os1=0
os2=0
for i in a:
os1+= ord(i)
for i in b:
os2+= ord(i)
if os1==os2:
print(0)
if os1<os2:
print('-1')
if os2<os1:
print(1)
``` | 0 |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One ope... | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains thr... | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
... | 1,638,445,141 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 62 | 307,200 | import sys
import math
input=sys.stdin.readline
INF=int(1e9)+7
def solve(): # 123456
s=input().rstrip()
for _ in range(int(input())):
l,r,k=map(int,input().split())
l-=1
r-=1
length=r-l+1
k%=length
s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]
print(s... | Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**... | ```python
import sys
import math
input=sys.stdin.readline
INF=int(1e9)+7
def solve(): # 123456
s=input().rstrip()
for _ in range(int(input())):
l,r,k=map(int,input().split())
l-=1
r-=1
length=r-l+1
k%=length
s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]
... | 3 | |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,641,678,580 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import sys
primes = [2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37, 41, 43, 47]
count = 0
for i in primes:
sys.stdout.flush(i)
x = sys.stdin()
if x == "yes":
count += 1
if count > 1:
sys.stdout.flush("composite")
else:
sys.stdout.flush("prime")
| Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i... | ```python
import sys
primes = [2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37, 41, 43, 47]
count = 0
for i in primes:
sys.stdout.flush(i)
x = sys.stdin()
if x == "yes":
count += 1
if count > 1:
sys.stdout.flush("composite")
else:
sys.stdout.flush("prime")
``` | -1 | |
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut... | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i... | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th... | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
... | 1,565,676,503 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | R = lambda : map(int, input().split())
n,k = R()
a = 0
for _ in range(n):
h,m = R()
b = h*60+m
if _ ==0:
if b-a>=k+1:
print(0,0)
exit(0)
else:
a = b
else:
if b-a>=k*2+2:
print((a+k+1)//60,(a+k+1)%60)
exit(0)
else... | Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ... | ```python
R = lambda : map(int, input().split())
n,k = R()
a = 0
for _ in range(n):
h,m = R()
b = h*60+m
if _ ==0:
if b-a>=k+1:
print(0,0)
exit(0)
else:
a = b
else:
if b-a>=k*2+2:
print((a+k+1)//60,(a+k+1)%60)
exit(0)
... | 3 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,665,572,994 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
s = input()
invalid = 0
for x in range(N):
if s[x] == 'x',s[x+1] == 'x',s[x+2] == 'x':
ans += 1
print(ans) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
n = int(input())
s = input()
invalid = 0
for x in range(N):
if s[x] == 'x',s[x+1] == 'x',s[x+2] == 'x':
ans += 1
print(ans)
``` | -1 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,626,194,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 6,963,200 | a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
g,h,i=list(map(int,input().split()))
print(f+h//2,b,c)
print(d,c+g//2,f)
print(g,h,b+d//2)
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
g,h,i=list(map(int,input().split()))
print(f+h//2,b,c)
print(d,c+g//2,f)
print(g,h,b+d//2)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,693,811,092 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | times = int(input())
words = []
# Считывание строк и добавление их в список
for i in range(times):
a = input()
words.append(a)
# Обработка каждой строки из списка
for w in words:
length = len(w) # Получение длины строки
# Проверка наличия символов в строке и формирование новой строки
... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
times = int(input())
words = []
# Считывание строк и добавление их в список
for i in range(times):
a = input()
words.append(a)
# Обработка каждой строки из списка
for w in words:
length = len(w) # Получение длины строки
# Проверка наличия символов в строке и формирование новой ... | 0 |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some int... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
... | 1,588,184,000 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 38 | 405 | 307,200 |
entrada = input()
entrada_int = list(map(int, entrada.split(" ")))
n = entrada_int[0]
m = entrada_int[1]
soma = 0
for i in reversed(range(m)):
entrada = input()
entrada_float = list(map(float, entrada.split(" ")))
soma += entrada_float[0] * n
if entrada_float[1] > 0:
soma += entrada_float[1] ... | Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c... | ```python
entrada = input()
entrada_int = list(map(int, entrada.split(" ")))
n = entrada_int[0]
m = entrada_int[1]
soma = 0
for i in reversed(range(m)):
entrada = input()
entrada_float = list(map(float, entrada.split(" ")))
soma += entrada_float[0] * n
if entrada_float[1] > 0:
soma += entrada... | 0 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,664,172,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 26 13:50:59 2022
@author: 86158
"""
n = int(input())
list = []
for i in range(n):
list.append([int(i) for i in input().split()])
for i in range(n):
for j in range(i+1,n):
if (list[i][0]>list[j][0] and list[i][1]>list[j][1]) or (list[i][0]<lis... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 26 13:50:59 2022
@author: 86158
"""
n = int(input())
list = []
for i in range(n):
list.append([int(i) for i in input().split()])
for i in range(n):
for j in range(i+1,n):
if (list[i][0]>list[j][0] and list[i][1]>list[j][1]) or (list... | 0 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,689,446,827 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n, k, l, c, d, p, nl, np = map(int, input().split())
Drink = k * l
maxDrink = Drink // nl
lime = c*d
salt = p//np
print(min(maxDrink,lime,salt)//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n, k, l, c, d, p, nl, np = map(int, input().split())
Drink = k * l
maxDrink = Drink // nl
lime = c*d
salt = p//np
print(min(maxDrink,lime,salt)//n)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a... | The first line of the input contains two integers *n* and *q* (2<=≤<=*n*<=≤<=1<=000<=000, 1<=≤<=*q*<=≤<=2<=000<=000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that *n* is even.
Next *q* lines contain the descriptions of the commands. Each command has type... | Output *n* integers, the *i*-th of them should be equal to the index of boy the *i*-th girl is dancing with after performing all *q* moves. | [
"6 3\n1 2\n2\n1 2\n",
"2 3\n1 1\n2\n1 -2\n",
"4 2\n2\n1 3\n"
] | [
"4 3 6 5 2 1\n",
"1 2\n",
"1 4 3 2\n"
] | none | 0 | [
{
"input": "6 3\n1 2\n2\n1 2",
"output": "4 3 6 5 2 1"
},
{
"input": "2 3\n1 1\n2\n1 -2",
"output": "1 2"
},
{
"input": "4 2\n2\n1 3",
"output": "1 4 3 2"
},
{
"input": "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2",
"output": "4 3 6 5 2 1"
},
{
"input": "6 8\n1 -1\n2\n2\n1... | 1,461,521,640 | 5,940 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 4,608,000 | # You lost the game.
n,q = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
impair = 0
pair = 0
pos = 1
for i in range(q):
if Q[i][0] == 1:
d = Q[i][1]
impair += d
pair += d
if pos == 1 and d % 2:
pos = -1
elif pos == -1 and d % 2 ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in... | ```python
# You lost the game.
n,q = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
impair = 0
pair = 0
pos = 1
for i in range(q):
if Q[i][0] == 1:
d = Q[i][1]
impair += d
pair += d
if pos == 1 and d % 2:
pos = -1
elif pos == -1 ... | 0 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,666,996,980 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n,k=[int(n) for n in input().split()]
s="abcdefghijklmnopqrstuvwxyz"
p=s[0:k]
q=p*n
print(q[0:n]) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
n,k=[int(n) for n in input().split()]
s="abcdefghijklmnopqrstuvwxyz"
p=s[0:k]
q=p*n
print(q[0:n])
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,675,546,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 4,505,600 | n,p=input().split()
count=0
p3=int(p)
for i in range (int(n)):
sign,p2=input().split()
if(sign=='+'):
p3+=int(p2)
else:
if(int(p2)<p3):
p3-=int(p2)
else:
count+=1
print(str(p3)+" "+str(count))
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,p=input().split()
count=0
p3=int(p)
for i in range (int(n)):
sign,p2=input().split()
if(sign=='+'):
p3+=int(p2)
else:
if(int(p2)<p3):
p3-=int(p2)
else:
count+=1
print(str(p3)+" "+str(count))
``` | 0 | |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,082,703 | 77,803 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,632,000 | n,k = map(int,input().split())
x = tuple(map(int,input().split()))
t = x[0]
p = 1
output = 1
for i in range(len(x)-1):
if x[i+1]-x[i]>k:
output = -1
if (output!=-1):
for i in range(len(x)-1):
if (x[i]>t+k) or (x[i]==t+k):
t = x[i-1]
p = p+1
output = p
print(output) | Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
n,k = map(int,input().split())
x = tuple(map(int,input().split()))
t = x[0]
p = 1
output = 1
for i in range(len(x)-1):
if x[i+1]-x[i]>k:
output = -1
if (output!=-1):
for i in range(len(x)-1):
if (x[i]>t+k) or (x[i]==t+k):
t = x[i-1]
p = p+1
output = p
print(output)
``` | 0 | |
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. ... | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
... | 1,510,509,746 | 7,046 | Python 3 | OK | TESTS | 53 | 62 | 0 | s = sorted([int(i) for i in input().split()])
res = False
summ = sum(s)
for i in range(6):
for j in range(6):
if j == i:
continue
for k in range(6):
if k == j or k == i:
continue
if s[i] + s[j] + s[k] == summ//2:
res = Tr... | Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build ... | ```python
s = sorted([int(i) for i in input().split()])
res = False
summ = sum(s)
for i in range(6):
for j in range(6):
if j == i:
continue
for k in range(6):
if k == j or k == i:
continue
if s[i] + s[j] + s[k] == summ//2:
... | 3 | |
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr... | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO... | 1,661,484,640 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | t = int(input())
l =[0]
for i in range(1,t+1):
s =int((i*(i+1))/2)
l.append(s)
if t in l:
print("YES")
else:
print("NO")
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t... | ```python
t = int(input())
l =[0]
for i in range(1,t+1):
s =int((i*(i+1))/2)
l.append(s)
if t in l:
print("YES")
else:
print("NO")
``` | 3.977 |
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be perfo... | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espr... | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81... | 1,664,031,311 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | xC, yC, xT, yT = input().split()
xP, yP = input().split()
dX = int(xT) - int(xC)
dY = int(yT) - int(yC)
pair1 = dX/int(xP)
pair2 = dY/int(yP)
def isEven(n):
if n%2 == 0:
return True
else:
return False
if (isEven(pair1) == isEven(pair2)):
print("YES")
else:
print("NO")
... | Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with... | ```python
xC, yC, xT, yT = input().split()
xP, yP = input().split()
dX = int(xT) - int(xC)
dY = int(yT) - int(yC)
pair1 = dX/int(xP)
pair2 = dY/int(yP)
def isEven(n):
if n%2 == 0:
return True
else:
return False
if (isEven(pair1) == isEven(pair2)):
print("YES")
else:
print("NO")
... | 0 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,687,933,958 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 109 | 2,355,200 | n, a, b, c = map(int, input().split())
temp = 0
for i in range(n+1):
for j in range(n+1):
if i*a + j*b <= n:
if (n - (i*a + j*b)) % c == 0:
flag = i + j + (n - (i*a + j*b)) // c
if flag > temp and flag != 0:
temp = flag
print(tem... | 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
n, a, b, c = map(int, input().split())
temp = 0
for i in range(n+1):
for j in range(n+1):
if i*a + j*b <= n:
if (n - (i*a + j*b)) % c == 0:
flag = i + j + (n - (i*a + j*b)) // c
if flag > temp and flag != 0:
temp = flag
... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,543,914,656 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
if l[i]%2!=0:
ans+=1
print(n-ans) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
if l[i]%2!=0:
ans+=1
print(n-ans)
``` | 0 | |
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-... | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
... | 1,687,969,215 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 3,072,000 | mod=int(1e9+7)
#qm=lambda x:x%mod if x%mod>=0 else x%mod+mod
class Mx:
def __init__(self,a11,a12,a21,a22):
self.a11=a11%mod;self.a12=a12%mod
self.a21=a21%mod;self.a22=a22%mod
def __mul__(self, other):
b11 = self.a11 * other.a11 + self.a12 * other.a21
b12 = self.a11 * othe... | Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers... | ```python
mod=int(1e9+7)
#qm=lambda x:x%mod if x%mod>=0 else x%mod+mod
class Mx:
def __init__(self,a11,a12,a21,a22):
self.a11=a11%mod;self.a12=a12%mod
self.a21=a21%mod;self.a22=a22%mod
def __mul__(self, other):
b11 = self.a11 * other.a11 + self.a12 * other.a21
b12 = self.... | -1 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,694,070,921 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 307,200 | from collections import Counter
def parse(n):
fs = Counter()
his = []
for _ in n:
name, score = input().split()
score = int(score)
fs[name] += score
his.append((name, fs[name]))
return fs, his
n = range(int(input()))
fs, his = parse(n)
mx = max(fs.valu... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from collections import Counter
def parse(n):
fs = Counter()
his = []
for _ in n:
name, score = input().split()
score = int(score)
fs[name] += score
his.append((name, fs[name]))
return fs, his
n = range(int(input()))
fs, his = parse(n)
mx = m... | 0 |
113 | A | Grammar Lessons | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | A. Grammar Lessons | 5 | 256 | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of spee... | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible tha... | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | [
"petr\n",
"etis atis animatis etis atis amatis\n",
"nataliala kataliala vetra feinites\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "petr",
"output": "YES"
},
{
"input": "etis atis animatis etis atis amatis",
"output": "NO"
},
{
"input": "nataliala kataliala vetra feinites",
"output": "YES"
},
{
"input": "qweasbvflios",
"output": "YES"
},
{
"input": "lios lios petr initis qwe",
... | 1,652,614,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 4,505,600 | n = input().split()
w = 0
x=y=z=0
while w<len(n):
if n[w][-4:]=="lios" or n[w][-5:]=="liala":
x+=1
w+=1
else:
break
while w<len(n):
if n[w][-3:]=="etr" or n[w][-4:]=="etra":
y+=1
w+=1
else:
break
while w<len(n):
if n[w][-6:]=="initis" o... | Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the lang... | ```python
n = input().split()
w = 0
x=y=z=0
while w<len(n):
if n[w][-4:]=="lios" or n[w][-5:]=="liala":
x+=1
w+=1
else:
break
while w<len(n):
if n[w][-3:]=="etr" or n[w][-4:]=="etra":
y+=1
w+=1
else:
break
while w<len(n):
if n[w][-6:]==... | 0 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,804,279 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 186 | 2,355,200 | a = int(input())
counter = 0
for x in range(a):
b = str(input()).split()
c = [list(map(int, b))]
for i in c:
count = sum(i)
if count >= 2:
counter += 1
print(counter)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
a = int(input())
counter = 0
for x in range(a):
b = str(input()).split()
c = [list(map(int, b))]
for i in c:
count = sum(i)
if count >= 2:
counter += 1
print(counter)
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,637,634,550 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | def checkEquilibrium( n,matrix ):
forces = 0
i,j = 0,0
while j < 3:
while i < n:
forces += matrix[i][j]
i += 1
if not forces == 0:
return 'NO'
forces = 0
i = 0
j += 1
return 'YES'
matrix = []
n = int( input() )
... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
def checkEquilibrium( n,matrix ):
forces = 0
i,j = 0,0
while j < 3:
while i < n:
forces += matrix[i][j]
i += 1
if not forces == 0:
return 'NO'
forces = 0
i = 0
j += 1
return 'YES'
matrix = []
n = int( i... | 3.977 |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to str... | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"i... | 1,582,379,643 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | a = list(input())
while a[-1] == 0:
a.pop()
for i in range (len(a) // 2):
if a[i] != a[-1 - i]:
print ("NO")
print ("YES")
| Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from righ... | ```python
a = list(input())
while a[-1] == 0:
a.pop()
for i in range (len(a) // 2):
if a[i] != a[-1 - i]:
print ("NO")
print ("YES")
``` | 0 | |
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters e... | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "Y... | 1,630,569,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 6,963,200 | # x = input("").split() # her will input number of steps and step level
# all_step = int(x[0])
# lev_step = int(x[1])
# string = input("")
# i = 1
# while i < all_step:
# j = i
# while j <= lev_step+i:
# if string[j] == ".":
# i = j
# continue
# j += 1
# pri... | Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to t... | ```python
# x = input("").split() # her will input number of steps and step level
# all_step = int(x[0])
# lev_step = int(x[1])
# string = input("")
# i = 1
# while i < all_step:
# j = i
# while j <= lev_step+i:
# if string[j] == ".":
# i = j
# continue
# j += 1
... | 0 | |
690 | C2 | Brain Network (medium) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology ... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow.... | Print one number – the brain latency. | [
"4 3\n1 2\n1 3\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n"
] | [
"2",
"3"
] | none | 0 | [
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 2\n2 1\n3 2",
"output": "2"
},
{
"input": "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "6"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n3 5",
"outp... | 1,672,492,881 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | from collections import defaultdict,deque
nodes,edges = list(map(int,input().split()))
graph = defaultdict(list)
in_degree = defaultdict(int)
for edge in range(edges):
a,b = input().split()
graph[a].append(b)
graph[b].append(a)
in_degree[a] += 1
in_degree[b] += 1
queue = deque()
vis... | Title: Brain Network (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of... | ```python
from collections import defaultdict,deque
nodes,edges = list(map(int,input().split()))
graph = defaultdict(list)
in_degree = defaultdict(int)
for edge in range(edges):
a,b = input().split()
graph[a].append(b)
graph[b].append(a)
in_degree[a] += 1
in_degree[b] += 1
queue = de... | 0 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,693,415,706 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | k = int(input())
l = int(input())
c = 0
s = ''
while l > k:
c += 1
if k == 1 :
s = 'YES'
break
else:
l //= k
if l == k:
print('YES')
print(c)
else:
print('NO')
| Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
k = int(input())
l = int(input())
c = 0
s = ''
while l > k:
c += 1
if k == 1 :
s = 'YES'
break
else:
l //= k
if l == k:
print('YES')
print(c)
else:
print('NO')
``` | 0 | |
219 | B | Special Offer! Super Price 999 Bourles! | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, ... | The first line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=1018; 0<=≤<=*d*<=<<=*p*) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
The required number shouldn't have leading zeroes. | [
"1029 102\n",
"27191 17\n"
] | [
"999\n",
"27189\n"
] | none | 1,000 | [
{
"input": "1029 102",
"output": "999"
},
{
"input": "27191 17",
"output": "27189"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "9 0",
"output": "9"
},
{
"input": "20 1",
"output": "19"
},
{
"input": "100 23",
"output": "99"
},
{
"input... | 1,623,166,031 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 310 | 0 | p,d = map(int,input().split())
k=0
if d==0:
print(p)
exit()
x=[p]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
| Title: Special Offer! Super Price 999 Bourles!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and s... | ```python
p,d = map(int,input().split())
k=0
if d==0:
print(p)
exit()
x=[p]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
``` | 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,458,423,123 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 62 | 5,120,000 | def main():
input()
a, b = 0, -1
for c in sorted(set(map(int, input().split()))):
if a < b < c < a + 3:
print("YES")
return
a, b = b, c
print("NO")
if __name__ == '__main__':
main()
| 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 main():
input()
a, b = 0, -1
for c in sorted(set(map(int, input().split()))):
if a < b < c < a + 3:
print("YES")
return
a, b = b, c
print("NO")
if __name__ == '__main__':
main()
``` | 3 | |
988 | D | Points and Powers of Two | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any sub... | The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points.
The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points. | In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above.
In the second line print $m$ integers — the coordinates of points in the subset you have chosen.
If there are multiple answers, print any of them. | [
"6\n3 5 4 7 10 12\n",
"5\n-1 2 5 8 11\n"
] | [
"3\n7 3 5",
"1\n8\n"
] | In the first example the answer is $[7, 3, 5]$. Note, that $|7-3|=4=2^2$, $|7-5|=2=2^1$ and $|3-5|=2=2^1$. You can't find a subset having more points satisfying the required property. | 0 | [
{
"input": "6\n3 5 4 7 10 12",
"output": "3\n3 4 5 "
},
{
"input": "5\n-1 2 5 8 11",
"output": "1\n-1 "
},
{
"input": "1\n42",
"output": "1\n42 "
},
{
"input": "3\n0 -536870912 536870912",
"output": "3\n-536870912 0 536870912 "
},
{
"input": "2\n536870912 -5368709... | 1,680,185,412 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 670 | 33,894,400 | from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm, log2
from copy import deepcopy
import heapq
from sys import stdin, stdout
input = stdin.readline
def main():
n = int(input())
... | Title: Points and Powers of Two
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is a... | ```python
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm, log2
from copy import deepcopy
import heapq
from sys import stdin, stdout
input = stdin.readline
def main():
n = int(inpu... | 0 | |
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number t... | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the nu... | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
... | 1,602,415,413 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 108 | 307,200 | cnt = int(input())
main_list = []
second_list = []
main_dict = {}
x = 0
y = 0
z = 0
for i in range(cnt):
x = int(input())
main_list.append(x)
main_set = set(main_list)
if len(main_set) == 1 or len(main_set) >= 3:
print('NO')
else:
for i in main_set:
main_dict[i] = main_list.... | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (di... | ```python
cnt = int(input())
main_list = []
second_list = []
main_dict = {}
x = 0
y = 0
z = 0
for i in range(cnt):
x = int(input())
main_list.append(x)
main_set = set(main_list)
if len(main_set) == 1 or len(main_set) >= 3:
print('NO')
else:
for i in main_set:
main_dict[i] = ... | 3 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,532,738,795 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 |
enteros = ''
for i in range(1000):
enteros += str(i)
ch = input("")
print(enteros[int(ch)])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
enteros = ''
for i in range(1000):
enteros += str(i)
ch = input("")
print(enteros[int(ch)])
``` | 3 | |
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe... | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70... | 1,546,363,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 102,400 | #!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <[email protected]>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ import divi... | Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not... | ```python
#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <[email protected]>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ i... | 0 | |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,680,927,247 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 22 | 154 | 5,427,200 | n = int(input())
# print(n//2+1)
if n & 1:
for i in range(1, n//2+2):
# print(i, n-i+1, end=' ')
if (i == n-i+1):
print(i, end=' ')
else:
print(i, n-i+1, end=' ')
else:
for i in range(1, n//2+1):
print(i, n-i+1, end=' ')
| Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
n = int(input())
# print(n//2+1)
if n & 1:
for i in range(1, n//2+2):
# print(i, n-i+1, end=' ')
if (i == n-i+1):
print(i, end=' ')
else:
print(i, n-i+1, end=' ')
else:
for i in range(1, n//2+1):
print(i, n-i+1, end=' ')
``` | 3.951391 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,634,652,178 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n = int(input())
a = [int(x) for x in input().split()]
count = 0
sumA = sum(a)
ans = 0
for i in range(1, 6):
if (sumA+i)%(n+1)!=1:
ans+=1
print(ans) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
a = [int(x) for x in input().split()]
count = 0
sumA = sum(a)
ans = 0
for i in range(1, 6):
if (sumA+i)%(n+1)!=1:
ans+=1
print(ans)
``` | 3 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,645,986,430 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 156 | 4,710,400 | # n,m = map(lambda x: int(x), input().split())
# n = int(input())
import collections
n = int(input())
a=collections.defaultdict(lambda: -1)
for i in range(n):
k,d = map(lambda x: int(x), input().split())
a.setdefault(k, d+k)
col=list(a.items())
for i in col:
if a[i[1]]==i[0]:
print("Y... | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
# n,m = map(lambda x: int(x), input().split())
# n = int(input())
import collections
n = int(input())
a=collections.defaultdict(lambda: -1)
for i in range(n):
k,d = map(lambda x: int(x), input().split())
a.setdefault(k, d+k)
col=list(a.items())
for i in col:
if a[i[1]]==i[0]:
... | 3.952226 |
268 | B | Buttons | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the seque... | A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. | In a single line print the number of times Manao has to push a button in the worst-case scenario. | [
"2\n",
"3\n"
] | [
"3\n",
"7\n"
] | Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "14"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "175"
},
{
"input": "2000",
"output": "1333335000"
},
{
"input": "1747",
"ou... | 1,695,026,409 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 92 | 0 | n=int(input())
print(int((n*(n-1)*(n+1))/6+n)) | Title: Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the loc... | ```python
n=int(input())
print(int((n*(n-1)*(n+1))/6+n))
``` | 3 | |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,699,848,566 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 77 | 2,150,400 | #author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
mod = (10 ** 9) + 7
def answer():
dp = [[0 , 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1 , n + 1):
for j in range(k , 0 , -1):
if(i - j < 0):con... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
#author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
mod = (10 ** 9) + 7
def answer():
dp = [[0 , 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1 , n + 1):
for j in range(k , 0 , -1):
if(i - ... | 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,690,885,172 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 61 | 1,536,000 | from typing import List
from collections import namedtuple
import sys
class Solution:
def sereja_and_dima(self, nums: List):
result = [0, 0]
left, right = 0, len(nums) - 1
index = 0
while left <= right:
if nums[left] > nums[right]:
result[ind... | 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
from typing import List
from collections import namedtuple
import sys
class Solution:
def sereja_and_dima(self, nums: List):
result = [0, 0]
left, right = 0, len(nums) - 1
index = 0
while left <= right:
if nums[left] > nums[right]:
... | 3 | |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, ... | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro... | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{... | 1,448,984,405 | 305 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | def g(w,m,x):
return max(0.3*x,(1-m/250)*x-50*w)
m1,m2,m3,m4,m5=map(int,input().split())
w1,w2,w3,w4,w5=map(int,input().split())
h1,h2=map(int,input().split())
print(g(w1,m1,500)+g(w2,m2,1000)+g(w3,m3,1500)+g(w4,m4,2000)+g(w5,m5,2500)+h1*100-h2*50) | Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin... | ```python
def g(w,m,x):
return max(0.3*x,(1-m/250)*x-50*w)
m1,m2,m3,m4,m5=map(int,input().split())
w1,w2,w3,w4,w5=map(int,input().split())
h1,h2=map(int,input().split())
print(g(w1,m1,500)+g(w2,m2,1000)+g(w3,m3,1500)+g(w4,m4,2000)+g(w5,m5,2500)+h1*100-h2*50)
``` | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,666,698,681 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | import math
for _ in range( int(input()) ):
a = int(input())
n = (360)/(180-a)
print('YNEOS'[not math.floor(n)==n::2])
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
import math
for _ in range( int(input()) ):
a = int(input())
n = (360)/(180-a)
print('YNEOS'[not math.floor(n)==n::2])
``` | 3 | |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I ple... | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are steward... | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
... | 1,691,239,912 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | stewards_number = int(input())
stewards = set(sorted([int(x) for x in input().split()]))
print(max(len(set)-2 , 0))
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am... | ```python
stewards_number = int(input())
stewards = set(sorted([int(x) for x in input().split()]))
print(max(len(set)-2 , 0))
``` | -1 |
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.