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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,600,793,031 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 280 | 409,600 | from collections import *
print(sorted(Counter([*open(0)][1:]).items(), key=lambda x: x[1])[::-1][0][0]) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
from collections import *
print(sorted(Counter([*open(0)][1:]).items(), key=lambda x: x[1])[::-1][0][0])
``` | 3.929237 |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,587,764,897 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 218 | 0 | n=int(input())
l=list(map(int,input().split()))
s=list(set(l))
s.sort()
if len(s)>=2:
print(s[1])
else:
print("NO")
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
l=list(map(int,input().split()))
s=list(set(l))
s.sort()
if len(s)>=2:
print(s[1])
else:
print("NO")
``` | 3.9455 |
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,663,696,838 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | t = int(input("Enter here: "))
x =0
y =0
z =0
for i in range(t):#You can also take t as an input here directly
a = list(map(int, input().split()))
x += a[0]
y += a[1]
z += a[2]
if x == 0 and y ==0 and z == 0:
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
t = int(input("Enter here: "))
x =0
y =0
z =0
for i in range(t):#You can also take t as an input here directly
a = list(map(int, input().split()))
x += a[0]
y += a[1]
z += a[2]
if x == 0 and y ==0 and z == 0:
print("YES")
else:
print("NO")
``` | 0 |
825 | B | Five-In-a-Row | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i... | You are given matrix 10<=×<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed th... | Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. | [
"XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X",
"output": "NO"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.",
"output": "N... | 1,671,948,841 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | a=[]
jauap='NO'
v=''
d=''
for i in range(10):
s=input()
if 'X' in s and len(s[s.index('X'):s.rindex('X')])>=5 and s[s.index('X'):s.rindex('X')].count('O')==0:
jauap='YES'
exit()
a.append(s)
for i in range(10):
for j in range(10):
if j==0:
v+=a[i][j]
... | Title: Five-In-a-Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=×<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some t... | ```python
a=[]
jauap='NO'
v=''
d=''
for i in range(10):
s=input()
if 'X' in s and len(s[s.index('X'):s.rindex('X')])>=5 and s[s.index('X'):s.rindex('X')].count('O')==0:
jauap='YES'
exit()
a.append(s)
for i in range(10):
for j in range(10):
if j==0:
v+=... | 0 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,666,302,046 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 25,088,000 | print((1378**(int(input())))%10) | Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
print((1378**(int(input())))%10)
``` | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,638,274,519 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 0 | s = input()
vowels = ['a', 'e', 'i', 'o', 'u']
cards_to_turn = 0
for w in s:
if (w in vowels): cards_to_turn += 1
elif (w.isnumeric() and int(w) % 2 != 0): cards_to_turn += 1
print(cards_to_turn)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s = input()
vowels = ['a', 'e', 'i', 'o', 'u']
cards_to_turn = 0
for w in s:
if (w in vowels): cards_to_turn += 1
elif (w.isnumeric() and int(w) % 2 != 0): cards_to_turn += 1
print(cards_to_turn)
``` | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,693,201,434 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | def is_lucky(number):
# Function to check if a number is lucky (contains only 4 and 7)
while number > 0:
digit = number % 10
if digit != 4 and digit != 7:
return False
number //= 10
return True
def is_almost_lucky(n):
# Function to check if a number is almo... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def is_lucky(number):
# Function to check if a number is lucky (contains only 4 and 7)
while number > 0:
digit = number % 10
if digit != 4 and digit != 7:
return False
number //= 10
return True
def is_almost_lucky(n):
# Function to check if a numb... | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=≤<=*n*<=≤<=100000) — the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,673,028,060 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
# Initialize an array to store the colors of the jewelry
colors = [0] * (n + 1)
# Color for each prime number
color = 1
# Loop through the jewelry prices
for i in range(2, n + 1):
# If the jewelry price is prime, assign a new color
if colors[i] == 0:
colors[i] = color
color ... | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
n = int(input())
# Initialize an array to store the colors of the jewelry
colors = [0] * (n + 1)
# Color for each prime number
color = 1
# Loop through the jewelry prices
for i in range(2, n + 1):
# If the jewelry price is prime, assign a new color
if colors[i] == 0:
colors[i] = color
... | 0 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,632,210,310 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 93 | 20,172,800 | import math
u,i=map(int,input().split())
e=min(u,i)
print(math.factorial(e)) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
u,i=map(int,input().split())
e=min(u,i)
print(math.factorial(e))
``` | 3 | |
523 | A | Rotate, Flip and Zoom | PROGRAMMING | 1,200 | [
"*special",
"implementation"
] | null | null | Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ... | The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as ... | Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. | [
"3 2\n.*.\n.*.\n",
"9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*\n"
] | [
"....\n....\n****\n****\n....\n....\n",
"********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......*****... | none | 500 | [
{
"input": "3 2\n.*.\n.*.",
"output": "....\n....\n****\n****\n....\n...."
},
{
"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**....... | 1,654,176,471 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | m,n=map(int,raw_input().split())
for v in zip(*[raw_input() for _ in range(n)]):
s=''.join(c*2 for c in v)
print s
print s | Title: Rotate, Flip and Zoom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally... | ```python
m,n=map(int,raw_input().split())
for v in zip(*[raw_input() for _ in range(n)]):
s=''.join(c*2 for c in v)
print s
print s
``` | -1 | |
35 | C | Fire Again | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"shortest paths"
] | C. Fire Again | 2 | 64 | After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing... | The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers.
The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning... | Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. | [
"3 3\n1\n2 2\n",
"3 3\n1\n1 1\n",
"3 3\n2\n1 1 3 3\n"
] | [
"1 1\n",
"3 3\n",
"2 2"
] | none | 1,500 | [
{
"input": "3 3\n1\n2 2",
"output": "1 1"
},
{
"input": "3 3\n1\n1 1",
"output": "3 3"
},
{
"input": "3 3\n2\n1 1 3 3",
"output": "1 3"
},
{
"input": "1 1\n1\n1 1",
"output": "1 1"
},
{
"input": "2 2\n1\n2 2",
"output": "1 1"
},
{
"input": "2 2\n2\n1 1... | 1,623,785,131 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 154 | 512,000 | '''
___ ____
____ _____ _____/ (_)_ ______ ____ _____/ / /_ __ ______ ___ __
/ __ `/ __ `/ __ / / / / / __ \/ __ `/ __ / __ \/ / / / __ `/ / / /
/ /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ /
\__,_/\__,_/\__,_/_/\__,_/ .__... | Title: Fire Again
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th... | ```python
'''
___ ____
____ _____ _____/ (_)_ ______ ____ _____/ / /_ __ ______ ___ __
/ __ `/ __ `/ __ / / / / / __ \/ __ `/ __ / __ \/ / / / __ `/ / / /
/ /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ /
\__,_/\__,_/\__,_/_/... | 0 |
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
... | 1,691,592,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # LUOGU_RID: 119972118
ss = [input() for i in range(3)]
s = "".join(ss)
x, o, p = s.count("X"), s.count("O"), s.count(".")
if o > x or x > o + 1:
print("illegal") | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ... | ```python
# LUOGU_RID: 119972118
ss = [input() for i in range(3)]
s = "".join(ss)
x, o, p = s.count("X"), s.count("O"), s.count(".")
if o > x or x > o + 1:
print("illegal")
``` | 0 |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,489,545,591 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 4,505,600 | nn = int(input())
k = int(input())
n = str(nn)
#m = input().split() #list
#[a, b, c] = [int(x) for x in input().split()]
zeros = 0
dls = 0
i = len(n) - 1
while zeros < k:
if (i == -1):
print(len(n) - 1)
break
if n[i] == '0':
zeros += 1
else:
dls ... | Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
nn = int(input())
k = int(input())
n = str(nn)
#m = input().split() #list
#[a, b, c] = [int(x) for x in input().split()]
zeros = 0
dls = 0
i = len(n) - 1
while zeros < k:
if (i == -1):
print(len(n) - 1)
break
if n[i] == '0':
zeros += 1
else:
... | -1 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,628,205,805 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 6,963,200 | a,b = map(int, input().split())
mat = []
for i in range(0,a):
x = input()
mat.append([])
for j in range(0,b):
if x[j] != '-':
if (i % 2 == 0 and j % 2 == 0) or (i % 2 == 1 and j % 2 == 1):
mat[i].append('B')
else:
mat[i].append('W... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
a,b = map(int, input().split())
mat = []
for i in range(0,a):
x = input()
mat.append([])
for j in range(0,b):
if x[j] != '-':
if (i % 2 == 0 and j % 2 == 0) or (i % 2 == 1 and j % 2 == 1):
mat[i].append('B')
else:
mat[i]... | 3 | |
124 | B | Permutations | PROGRAMMING | 1,400 | [
"brute force",
"combinatorics",
"implementation"
] | null | null | You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers. | The first line contains integers *n* and *k* — the number and digit capacity of numbers correspondingly (1<=≤<=*n*,<=*k*<=≤<=8). Next *n* lines contain *k*-digit positive integers. Leading zeroes are allowed both in the initial integers and the integers resulting from the rearranging of digits. | Print a single number: the minimally possible difference between the largest and the smallest number after the digits are rearranged in all integers by the same rule. | [
"6 4\n5237\n2753\n7523\n5723\n5327\n2537\n",
"3 3\n010\n909\n012\n",
"7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156\n"
] | [
"2700\n",
"3\n",
"20522\n"
] | In the first sample, if we rearrange the digits in numbers as (3,1,4,2), then the 2-nd and the 4-th numbers will equal 5237 and 2537 correspondingly (they will be maximum and minimum for such order of digits).
In the second sample, if we swap the second digits and the first ones, we get integers 100, 99 and 102. | 1,000 | [
{
"input": "6 4\n5237\n2753\n7523\n5723\n5327\n2537",
"output": "2700"
},
{
"input": "3 3\n010\n909\n012",
"output": "3"
},
{
"input": "7 5\n50808\n36603\n37198\n44911\n29994\n42543\n50156",
"output": "20522"
},
{
"input": "5 5\n61374\n74304\n41924\n46010\n09118",
"output... | 1,688,796,440 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 5,017,600 | from itertools import permutations
n, k = map(int, input().split())
a = []
for _ in range(n):
a.append(list(input()))
s = ''.join([str(x) for x in range(k)])
prm = list(permutations(s))
inf = int(1e9)
min_delta = inf
for p in prm:
min_val = inf
max_val = 0
for x in a:
num ... | Title: Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* *k*-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all int... | ```python
from itertools import permutations
n, k = map(int, input().split())
a = []
for _ in range(n):
a.append(list(input()))
s = ''.join([str(x) for x in range(k)])
prm = list(permutations(s))
inf = int(1e9)
min_delta = inf
for p in prm:
min_val = inf
max_val = 0
for x in a:
... | 0 | |
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 ... | 1,698,151,587 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 11,059,200 | n, m=map(int, input().split())
a=map(int,input().split())
# lijst_a=list(a)
new_lijst=[]
output=0
pre_test_var=0
for i, var in enumerate(a):
#print(var)
if i==0:
pre_test_var=var
elif var >= pre_test_var:
pre_test_var=var
else:
while var < pre_test_var:
... | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recent... | ```python
n, m=map(int, input().split())
a=map(int,input().split())
# lijst_a=list(a)
new_lijst=[]
output=0
pre_test_var=0
for i, var in enumerate(a):
#print(var)
if i==0:
pre_test_var=var
elif var >= pre_test_var:
pre_test_var=var
else:
while var < pre_test_var:
... | 0 | |
171 | D | Broken checker | PROGRAMMING | 1,300 | [
"*special",
"brute force"
] | null | null | "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy. | The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index. | The only line of the output contains an integer between 1 and 3, inclusive. | [] | [] | This problem has no samples, since there so few test cases. | 0 | [
{
"input": "3",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "3"
},
{
"input": "5",
"output": "1"
}
] | 1,561,462,990 | 2,147,483,647 | Python 3 | OK | TESTS | 5 | 216 | 0 | print((int(input())%5)%3+1) | Title: Broken checker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No,... | ```python
print((int(input())%5)%3+1)
``` | 3 | |
721 | B | Passwords | PROGRAMMING | 1,100 | [
"implementation",
"math",
"sortings",
"strings"
] | null | null | Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitr... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next *n* lines contains passwords, one per line — pairwise distinct non-empty strings consisting of ... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | [
"5 2\ncba\nabc\nbb1\nabC\nABC\nabc\n",
"4 100\n11\n22\n1\n2\n22\n"
] | [
"1 15\n",
"3 4\n"
] | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | 1,000 | [
{
"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc",
"output": "1 15"
},
{
"input": "4 100\n11\n22\n1\n2\n22",
"output": "3 4"
},
{
"input": "1 1\na1\na1",
"output": "1 1"
},
{
"input": "1 100\na1\na1",
"output": "1 1"
},
{
"input": "2 1\nabc\nAbc\nAbc",
"output": ... | 1,569,593,427 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 139 | 0 | #https://codeforces.com/problemset/problem/90/B
'''
Comment
'''
if __name__ == "__main__":
n, k = map(int, input().split())
leng = [0 for _ in range(105)]
for _ in range(n):
line = str(input())
leng[len(line)] += 1
line = str(input());
acPass = len(line)
summ = ... | Title: Passwords
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya is managed to enter his favourite site Codehorses. Vanya uses *n* distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords... | ```python
#https://codeforces.com/problemset/problem/90/B
'''
Comment
'''
if __name__ == "__main__":
n, k = map(int, input().split())
leng = [0 for _ in range(105)]
for _ in range(n):
line = str(input())
leng[len(line)] += 1
line = str(input());
acPass = len(line)
... | 0 | |
965 | B | Battleship | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arka... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the size of the field and the size of the ship.
The next $n$ lines contain the field. Each line contains $n$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship). | Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship.
If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell. | [
"4 3\n#..#\n#.#.\n....\n.###\n",
"10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#\n",
"19 6\n##..............###\n#......#####.....##\n.....#########.....\n....###########....\n...#############...\n..###############..\n.###############... | [
"3 2\n",
"6 1\n",
"1 8\n"
] | The picture below shows the three possible locations of the ship that contain the cell $(3, 2)$ in the first sample. | 1,000 | [
{
"input": "4 3\n#..#\n#.#.\n....\n.###",
"output": "3 2"
},
{
"input": "10 4\n#....##...\n.#...#....\n..#..#..#.\n...#.#....\n.#..##.#..\n.....#...#\n...#.##...\n.#...#.#..\n.....#..#.\n...#.#...#",
"output": "6 1"
},
{
"input": "19 6\n##..............###\n#......#####.....##\n.....####... | 1,526,139,590 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 77 | 7,065,600 | d=dict()
def func(ch,i,n,d,k):
c=0
for j in range(n):
if ch[j]==".":
c+=1
if (ch[j]=="." and j==n-1) or ch[j]!=".":
if c>=k:
for f in range(c-k+1):
for h in range(j+1-c+f+1,j+1-c+f+1+k)... | Title: Battleship
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady is playing Battleship. The rules of this game aren't really important.
There is a field of $n \times n$ cells. There should be exactly one $k$-decker on the field, i. e. a ship that is $k$ cells long oriented either ... | ```python
d=dict()
def func(ch,i,n,d,k):
c=0
for j in range(n):
if ch[j]==".":
c+=1
if (ch[j]=="." and j==n-1) or ch[j]!=".":
if c>=k:
for f in range(c-k+1):
for h in range(j+1-c+f+1,j+... | 0 | |
592 | B | The Monster and the Squirrel | PROGRAMMING | 1,100 | [
"math"
] | null | null | Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other v... | The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari. | Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after. | [
"5\n",
"3\n"
] | [
"9\n",
"1\n"
] | One of the possible solutions for the first sample is shown on the picture above. | 1,000 | [
{
"input": "5",
"output": "9"
},
{
"input": "3",
"output": "1"
},
{
"input": "54321",
"output": "2950553761"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "16"
},
{
"input": "7",
"output": "25"
},
{
"input": "8",
"output... | 1,470,346,984 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 62 | 4,608,000 | n = int(input()) - 2
print(n * n) | Title: The Monster and the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=... | ```python
n = int(input()) - 2
print(n * n)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,669,118,051 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | k=input()
p=input()
rev=k[::-1]
if rev==p:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
k=input()
p=input()
rev=k[::-1]
if rev==p:
print('YES')
else:
print('NO')
``` | 3.977 |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,663,988,665 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | from sys import exit
n=int(input())
s=list(map(int,input().split()))
z=[]
for i in range(n):
if n==1:
print(1)
exit()
else:
c=0
x=s[i]
if i ==0:
for j in range(n):
if s[j]<=x:
c+=1
x=s[j]
if j==n-1:
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
from sys import exit
n=int(input())
s=list(map(int,input().split()))
z=[]
for i in range(n):
if n==1:
print(1)
exit()
else:
c=0
x=s[i]
if i ==0:
for j in range(n):
if s[j]<=x:
c+=1
x=s[j]
if j==... | 0 |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,628,935,154 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 6,758,400 | n = int(input())
s = input().split()
mx = 0
for w in s:
c = 0
for x in w:
if x.isupper():
c += 1
if c > mx:
mx = c
print(mx) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
n = int(input())
s = input().split()
mx = 0
for w in s:
c = 0
for x in w:
if x.isupper():
c += 1
if c > mx:
mx = c
print(mx)
``` | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,646,807 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | w=input()
if w%2=0 and w>2:
print("YES)
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w=input()
if w%2=0 and w>2:
print("YES)
else:
print("NO")
``` | -1 |
760 | A | Petr and a calendar | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture:
Petr wants to ... | The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). | Print single integer: the number of columns the table should have. | [
"1 7\n",
"1 1\n",
"11 6\n"
] | [
"6\n",
"5\n",
"5\n"
] | The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough. | 500 | [
{
"input": "1 7",
"output": "6"
},
{
"input": "1 1",
"output": "5"
},
{
"input": "11 6",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "2 1",
"output": "4"
},
{
"input": "8 6",
"output": "6"
},
{
"input": "1 1",
"output... | 1,485,109,429 | 529 | Python 3 | OK | TESTS | 104 | 77 | 4,608,000 | m, d = list(map(int, input().split()))
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
import math
day = days[m-1]
print(math.ceil((day + d-1)/7))
| Title: Petr and a calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells... | ```python
m, d = list(map(int, input().split()))
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
import math
day = days[m-1]
print(math.ceil((day + d-1)/7))
``` | 3 | |
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"in... | 1,646,193,544 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | s=input()
lens=len(s)
sum=0
for i in range(lens):
for j in range(lens):
if s[i]=s[j]:
sum+=1
print(sum) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbo... | ```python
s=input()
lens=len(s)
sum=0
for i in range(lens):
for j in range(lens):
if s[i]=s[j]:
sum+=1
print(sum)
``` | -1 |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,683,322,163 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | x=list(map(int,input().split()))
y=list(map(int,input().split()))
ls=[]
for i in range(len(y)):
lss=[y[i]]
k=0
while len(lss)!=x[0]:
for j in range(len(y)):
if i==j:
continue
elif abs(y[i]-y[j])==k:
lss.append(y[j])
k+=1
... | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
x=list(map(int,input().split()))
y=list(map(int,input().split()))
ls=[]
for i in range(len(y)):
lss=[y[i]]
k=0
while len(lss)!=x[0]:
for j in range(len(y)):
if i==j:
continue
elif abs(y[i]-y[j])==k:
lss.append(y[j])
... | 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,696,094,974 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n=int(input())
ans=0
for i in range(n):
x=input()
nb_1=int(x[0])
nb_2=int(x[2])
nb_3=int(x[4])
sm=nb_3+nb_2+nb_1
if sm >=2:
ans=ans+1
print(ans) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n=int(input())
ans=0
for i in range(n):
x=input()
nb_1=int(x[0])
nb_2=int(x[2])
nb_3=int(x[4])
sm=nb_3+nb_2+nb_1
if sm >=2:
ans=ans+1
print(ans)
``` | 3 | |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,492,359,255 | 2,355 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 61 | 5,529,600 | x = input().strip()
y = input().strip()
def main():
for i in range(len(x)):
if x[i] == y[i]:
print(x[i],end="")
elif x[i] < y[i]:
print(-1)
return
else:
print(y[i], end="")
if __name__ == "__main__":
main() | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
x = input().strip()
y = input().strip()
def main():
for i in range(len(x)):
if x[i] == y[i]:
print(x[i],end="")
elif x[i] < y[i]:
print(-1)
return
else:
print(y[i], end="")
if __name__ == "__main__":
main()
``` | 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,676,768,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | n = int(input())
q =set()
a=[]
b=[]
for i in range(n):
x, y = [int(x) for x in input().split()]
q.add(x)
q.add(y)
a.append(x)
b.append(y)
sa=[]
sa.extend(a)
sa.sort(reverse=True)
if len(q)==n and a != sa:
print('unrated')
elif len(q)>n:
print('rated')
else:
print(... | 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
n = int(input())
q =set()
a=[]
b=[]
for i in range(n):
x, y = [int(x) for x in input().split()]
q.add(x)
q.add(y)
a.append(x)
b.append(y)
sa=[]
sa.extend(a)
sa.sort(reverse=True)
if len(q)==n and a != sa:
print('unrated')
elif len(q)>n:
print('rated')
else:
... | 0 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,667,708,227 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | l1=[int(i) for i in input().split()]
l2=[int(i) for i in input().split()]
l3=[int(i) for i in input().split()]
s1=[1,1,1]
s2=[1,1,1]
s3=[1,1,1]
for j in range(3):
if l1[j]%2!=0:
if j==0:
s1[0]=1-s1[0]
s1[1]=1-s1[1]
s2[0]=1-s2[0]
elif j==1:
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
l1=[int(i) for i in input().split()]
l2=[int(i) for i in input().split()]
l3=[int(i) for i in input().split()]
s1=[1,1,1]
s2=[1,1,1]
s3=[1,1,1]
for j in range(3):
if l1[j]%2!=0:
if j==0:
s1[0]=1-s1[0]
s1[1]=1-s1[1]
s2[0]=1-s2[0]
elif j==1:
... | 3 | |
994 | B | Knights of a Polygonal Table | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"sortings"
] | null | null | Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. However, even such a knight will torment his conscience, so he can kill no mo... | The first line contains two integers $n$ and $k$ $(1 \le n \le 10^5, 0 \le k \le \min(n-1,10))$ — the number of knights and the number $k$ from the statement.
The second line contains $n$ integers $p_1, p_2 ,\ldots,p_n$ $(1 \le p_i \le 10^9)$ — powers of the knights. All $p_i$ are distinct.
The third line contains $n... | Print $n$ integers — the maximum number of coins each knight can have it only he kills other knights. | [
"4 2\n4 5 9 7\n1 2 11 33\n",
"5 1\n1 2 3 4 5\n1 2 3 4 5\n",
"1 0\n2\n3\n"
] | [
"1 3 46 36 ",
"1 3 5 7 9 ",
"3 "
] | Consider the first example.
- The first knight is the weakest, so he can't kill anyone. That leaves him with the only coin he initially has. - The second knight can kill the first knight and add his coin to his own two. - The third knight is the strongest, but he can't kill more than $k = 2$ other knights. It is o... | 1,000 | [
{
"input": "4 2\n4 5 9 7\n1 2 11 33",
"output": "1 3 46 36 "
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 3 5 7 9 "
},
{
"input": "1 0\n2\n3",
"output": "3 "
},
{
"input": "7 1\n2 3 4 5 7 8 9\n0 3 7 9 5 8 9",
"output": "0 3 10 16 14 17 18 "
},
{
"input"... | 1,529,581,528 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | n,m=input().split()
n=int(n)
m=int(m)
l=input().split()
l=[int(i) for i in l]
k=input().split()
k=[int(i) for i in k]
dict={i:j for (i,j) in zip(l,k)}
coins=[]
keys=dict.keys()
keys=sorted(keys)
for i in range(len(keys)):
coins.append(dict[keys[i]])
if(i>0):
for j in range(m):
... | Title: Knights of a Polygonal Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power ... | ```python
n,m=input().split()
n=int(n)
m=int(m)
l=input().split()
l=[int(i) for i in l]
k=input().split()
k=[int(i) for i in k]
dict={i:j for (i,j) in zip(l,k)}
coins=[]
keys=dict.keys()
keys=sorted(keys)
for i in range(len(keys)):
coins.append(dict[keys[i]])
if(i>0):
for j in range(m)... | 0 | |
182 | D | Common Divisors | PROGRAMMING | 1,400 | [
"brute force",
"hashing",
"implementation",
"math",
"strings"
] | null | null | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam... | The first input line contains a non-empty string *s*1.
The second input line contains a non-empty string *s*2.
Lengths of strings *s*1 and *s*2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters. | Print the number of common divisors of strings *s*1 and *s*2. | [
"abcdabcd\nabcdabcdabcdabcd\n",
"aaa\naa\n"
] | [
"2\n",
"1\n"
] | In first sample the common divisors are strings "abcd" and "abcdabcd".
In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa". | 1,000 | [
{
"input": "abcdabcd\nabcdabcdabcdabcd",
"output": "2"
},
{
"input": "aaa\naa",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa",
"output": "4"
},
{
"input": "a\nb",
... | 1,689,448,509 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689448509.142863")# 1689448509.142883 | Title: Common Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive ... | ```python
print("_RANDOM_GUESS_1689448509.142863")# 1689448509.142883
``` | 0 | |
383 | A | Milking cows | PROGRAMMING | 1,600 | [
"data structures",
"greedy"
] | null | null | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. | Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1",
"3"
] | In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost. | 500 | [
{
"input": "4\n0 0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "3"
},
{
"input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0",
"output": "416"
},
{
"input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ... | 1,390,233,360 | 1,560 | Python 3 | OK | TESTS | 42 | 265 | 6,860,800 | import sys
n=int(input())
L=list(map(int,sys.stdin.readline().split()))
z=L.count(0)
if(z==n or z==0):
print(0)
Zeros=[0]*n
Zeros[n-1]+=1-L[n-1]
for i in range(n-2,-1,-1):
Zeros[i]=Zeros[i+1]
if(L[i]==0):
Zeros[i]+=1
else:
Zeros=[0]*n
Zeros[n-1]+=1-L... | Title: Milking cows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub... | ```python
import sys
n=int(input())
L=list(map(int,sys.stdin.readline().split()))
z=L.count(0)
if(z==n or z==0):
print(0)
Zeros=[0]*n
Zeros[n-1]+=1-L[n-1]
for i in range(n-2,-1,-1):
Zeros[i]=Zeros[i+1]
if(L[i]==0):
Zeros[i]+=1
else:
Zeros=[0]*n
Zeros... | 3 | |
560 | A | Currency System in Geraldion | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of ea... | The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion.
The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. | Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. | [
"5\n1 2 3 4 5\n"
] | [
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837",
"output": "-1"
},
{
"input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264",
"o... | 1,477,936,700 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 77 | 0 | n = input()
banknotes = [int(x) for x in input().split()]
print('-1') if 1 in banknotes else print('1') | Title: Currency System in Geraldion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cann... | ```python
n = input()
banknotes = [int(x) for x in input().split()]
print('-1') if 1 in banknotes else print('1')
``` | 3 | |
514 | C | Watto and Mechanism | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"hashing",
"string suffix structures",
"strings"
] | null | null | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the ... | The first line contains two non-negative numbers *n* and *m* (0<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of the initial strings and the number of queries, respectively.
Next follow *n* non-empty strings that are uploaded to the memory of the mechanism.
Next follow *m* non-empty strings that are the querie... | For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes). | [
"2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"
] | [
"YES\nNO\nNO\n"
] | none | 2,000 | [
{
"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac",
"output": "YES\nNO\nNO"
},
{
"input": "1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb",
"output": "NO\nNO\nNO\nNO\nYES"
},
{
"input": "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb",
"output": "YE... | 1,676,015,492 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 343 | 46,694,400 | # Use two hashes to avoid collisions
import sys
input = sys.stdin.readline
MAXN = 6 * 10 ** 5
MOD = 10 ** 9 + 7
base = [5, 7]
# hash stuff
pw = [[1] * MAXN for i in range(2)]
for j in range(2):
for i in range(1, MAXN):
pw[j][i] = pw[j][i - 1] * base[j] % MOD
def hash_s(s: str):
hsh... | Title: Watto and Mechanism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism sh... | ```python
# Use two hashes to avoid collisions
import sys
input = sys.stdin.readline
MAXN = 6 * 10 ** 5
MOD = 10 ** 9 + 7
base = [5, 7]
# hash stuff
pw = [[1] * MAXN for i in range(2)]
for j in range(2):
for i in range(1, MAXN):
pw[j][i] = pw[j][i - 1] * base[j] % MOD
def hash_s(s: str)... | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,697,576,970 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | s=input()
curr=chr('a')
sum=0
for i in s:
sum+=min(chr(i)-curr,26-(chr(i)-curr))
curr=chr(i)
print(sum) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
s=input()
curr=chr('a')
sum=0
for i in s:
sum+=min(chr(i)-curr,26-(chr(i)-curr))
curr=chr(i)
print(sum)
``` | -1 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,615,977,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | n=int(input())
nums=list(map(int,input().split()))
nums.sort()
stack=[]
flag=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if nums[i]<nums[j]<nums[k] and nums[j]%nums[i]==0 and nums[k]%nums[j]==0:
stack.append(nums[i])
stack.append(n... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
n=int(input())
nums=list(map(int,input().split()))
nums.sort()
stack=[]
flag=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if nums[i]<nums[j]<nums[k] and nums[j]%nums[i]==0 and nums[k]%nums[j]==0:
stack.append(nums[i])
stac... | 0 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,539,710,386 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 0 | n=int(input())
s=sum(map(int, input().split()))
for i in range(n,0,-1):
if s%i==0:
print(i)
exit() | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n=int(input())
s=sum(map(int, input().split()))
for i in range(n,0,-1):
if s%i==0:
print(i)
exit()
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,592,815,620 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 2,252,800 | d1,d2,d3 = map(int, input().split())
print(min(2*d1+2*d2),min(d1+d2+d3)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3 = map(int, input().split())
print(min(2*d1+2*d2),min(d1+d2+d3))
``` | -1 | |
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,696,499,871 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | for _ in range(int(input())):
inp=input()
if len(inp)<=10:
print(inp)
else:
s=""
s+=inp[0]
s+=str(len(inp)-2)
s+=inp[-1]
print(s)
| 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
for _ in range(int(input())):
inp=input()
if len(inp)<=10:
print(inp)
else:
s=""
s+=inp[0]
s+=str(len(inp)-2)
s+=inp[-1]
print(s)
``` | 3.977 |
633 | C | Spy Syndrome 2 | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the ciphe... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered wh... | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | 1,500 | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaa... | 1,456,511,623 | 4,723 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 170 | 921,600 | dp = dict()
def solve(index,cur_word,temp,n):
if cur_word in dp:
if not dp[cur_word]:
return False
else:
return temp + dp[cur_word]
if cur_word in d:
w = d[cur_word]
else:
w = -1
if index == n:
if w != -1:
return temp + [w]
... | Title: Spy Syndrome 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observati... | ```python
dp = dict()
def solve(index,cur_word,temp,n):
if cur_word in dp:
if not dp[cur_word]:
return False
else:
return temp + dp[cur_word]
if cur_word in d:
w = d[cur_word]
else:
w = -1
if index == n:
if w != -1:
return temp... | -1 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=≤<=*V**i*<=≤<=100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,038,416 | 516 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
int main(){
int V1,V2,V3,C1,C2,C3,Vm;
scanf ("%d%d%d%d",&V1,&V2,&V3,&Vm);
C3 = max(Vm,V3);
C2 = V2;
C1 = V1;
if (V3 <= C3 && 2*V3 >= C3 && 2*Vm >= C3 && Vm <= C3){
printf ("%d\n%d\n%d\n",C1,C2,C3);
}else{
printf ("-... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
#include <bits/stdc++.h>
using namespace std;
int main(){
int V1,V2,V3,C1,C2,C3,Vm;
scanf ("%d%d%d%d",&V1,&V2,&V3,&Vm);
C3 = max(Vm,V3);
C2 = V2;
C1 = V1;
if (V3 <= C3 && 2*V3 >= C3 && 2*Vm >= C3 && Vm <= C3){
printf ("%d\n%d\n%d\n",C1,C2,C3);
}else{
... | -1 | |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,618,949,676 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 186 | 0 | min_val = float("inf")
max_val = float("-inf")
min_idx = max_idx = 0
idx = 1
for _ in range(int(input())):
x, y = map(int, input().split())
if x == min_val and y == max_val:
pass
elif x <= min_val and y >= max_val:
min_idx = max_idx = idx
elif x < min_val:
min_... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
min_val = float("inf")
max_val = float("-inf")
min_idx = max_idx = 0
idx = 1
for _ in range(int(input())):
x, y = map(int, input().split())
if x == min_val and y == max_val:
pass
elif x <= min_val and y >= max_val:
min_idx = max_idx = idx
elif x < min_val:
... | 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,684,276,322 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 77 | 0 | def prime(n):
if n == 1 or n == 2 :
return True
else:
p = int(n**(1/2))+1
for i in range(2,p):
if n%i == 0:
return False
return True
n = int(input())
i = 3
while prime(i) or prime(n-i) :
i +=1
print(i,n-i) | 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
def prime(n):
if n == 1 or n == 2 :
return True
else:
p = int(n**(1/2))+1
for i in range(2,p):
if n%i == 0:
return False
return True
n = int(input())
i = 3
while prime(i) or prime(n-i) :
i +=1
pri... | 3 | |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,672,850,081 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 19 | 156 | 11,468,800 | N, m = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
state = list(map(int, input().split()))
ones_sum = 0
curr_sum = 0
for i in range(len(state)):
if state[i] == 1:
ones_sum += arr[i]
elif i < m:
curr_sum += arr[i]
ans = 0
for i in range(m, len(state)):... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
N, m = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
state = list(map(int, input().split()))
ones_sum = 0
curr_sum = 0
for i in range(len(state)):
if state[i] == 1:
ones_sum += arr[i]
elif i < m:
curr_sum += arr[i]
ans = 0
for i in range(m, le... | 0 | |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,611,390,166 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 77 | 0 |
n,d = map(int,input().split())
a=list(map(int,input().split()))
if d < (sum(a) + (len(a)-1)*10):
print(-1)
else:
x=(d-sum(a))//5
print(x)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n,d = map(int,input().split())
a=list(map(int,input().split()))
if d < (sum(a) + (len(a)-1)*10):
print(-1)
else:
x=(d-sum(a))//5
print(x)
``` | 3 | |
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,642,775,411 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 0 | for _ in range(int(input())):
a = int(input())
print("YES") if 360%(180-a)==0 else print("NO") | 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
for _ in range(int(input())):
a = int(input())
print("YES") if 360%(180-a)==0 else print("NO")
``` | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,504,004,645 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 62 | 0 | ticket = [int(x) for x in input()]
fst = ticket[:3]
sec = ticket[3:]
diff = abs(sum(fst) - sum(sec))
if diff == 0:
print(0)
elif diff < 0:
if 9 - min(fst) >= diff or max(sec) >= diff:
print(1)
elif 18 - (sum(fst) - max(fst)) >= diff or sum(sec) - min(sec) >= diff:
print(2)
els... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
ticket = [int(x) for x in input()]
fst = ticket[:3]
sec = ticket[3:]
diff = abs(sum(fst) - sum(sec))
if diff == 0:
print(0)
elif diff < 0:
if 9 - min(fst) >= diff or max(sec) >= diff:
print(1)
elif 18 - (sum(fst) - max(fst)) >= diff or sum(sec) - min(sec) >= diff:
print(2... | 0 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,624,189,115 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 93 | 3,174,400 | def equal_s(s):
l = len(s)
mid = len(s)//2
if l % 2 == 0:
l = s[:mid]
else:
l = s[:mid+1]
r = s[mid:]
return l, r
a = input().strip()
b = input().strip()
a1, a2 = equal_s(a)
b1, b2 = equal_s(b)
a1, a2, b1, b2 = sorted(a1), sorted(a2), sorted(b1), sorted(b2)
... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def equal_s(s):
l = len(s)
mid = len(s)//2
if l % 2 == 0:
l = s[:mid]
else:
l = s[:mid+1]
r = s[mid:]
return l, r
a = input().strip()
b = input().strip()
a1, a2 = equal_s(a)
b1, b2 = equal_s(b)
a1, a2, b1, b2 = sorted(a1), sorted(a2), sorted(b1), so... | 0 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,585,882,049 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 109 | 0 | s = input().replace('7', '1').replace('4', '0')
n = 0
for i in range(1, len(s)):
n += 2**i
print(n + int(s, 2) + 1) | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
s = input().replace('7', '1').replace('4', '0')
n = 0
for i in range(1, len(s)):
n += 2**i
print(n + int(s, 2) + 1)
``` | 3 | |
5 | D | Follow Traffic Rules | PROGRAMMING | 2,100 | [
"implementation",
"math"
] | D. Follow Traffic Rules | 1 | 64 | Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the ro... | The first line of the input file contains two integer numbers *a* and *v* (1<=≤<=*a*,<=*v*<=≤<=10000). The second line contains three integer numbers *l*, *d* and *w* (2<=≤<=*l*<=≤<=10000; 1<=≤<=*d*<=<<=*l*; 1<=≤<=*w*<=≤<=10000). | Print the answer with at least five digits after the decimal point. | [
"1 1\n2 1 3\n",
"5 70\n200 170 40\n"
] | [
"2.500000000000\n",
"8.965874696353\n"
] | none | 0 | [
{
"input": "1 1\n2 1 3",
"output": "2.500000000000"
},
{
"input": "5 70\n200 170 40",
"output": "8.965874696353"
},
{
"input": "6 80\n100 50 10",
"output": "7.312347829731"
},
{
"input": "7 80\n100 50 50",
"output": "5.345224838248"
},
{
"input": "8 80\n100 50 199... | 1,677,552,009 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | import math
# Ввод данных
a, v = map(int, input().split())
l, d, w = map(int, input().split())
# Расстояние, на котором нужно двигаться с ограничением скорости
x = d
# Расстояние, на котором можно двигаться с максимальной скоростью
y = l - d
# Время, потраченное на разгон автомобиля до максимальной скорости
t1 = v ... | Title: Follow Traffic Rules
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. T... | ```python
import math
# Ввод данных
a, v = map(int, input().split())
l, d, w = map(int, input().split())
# Расстояние, на котором нужно двигаться с ограничением скорости
x = d
# Расстояние, на котором можно двигаться с максимальной скоростью
y = l - d
# Время, потраченное на разгон автомобиля до максимальной скорос... | 0 |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,509,793,830 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 61 | 0 | st = input()
ans = "no"
k_0 = 0
if int(st) < 1000000:
ans = "no"
for e in st:
if e == "0":
k_0+=1
if k_0 == 6:
ans = "yes"
break
print(ans) | Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
st = input()
ans = "no"
k_0 = 0
if int(st) < 1000000:
ans = "no"
for e in st:
if e == "0":
k_0+=1
if k_0 == 6:
ans = "yes"
break
print(ans)
``` | 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,680,014,440 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | #문제가 제대로 이해는 안됐지만.. 합성수로 나타내라는 조건하에
#8을 기준으로 잡는 풀이방법
x=int(input())
a=8+x%2
b=x-a
print(a,b)
| 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
#문제가 제대로 이해는 안됐지만.. 합성수로 나타내라는 조건하에
#8을 기준으로 잡는 풀이방법
x=int(input())
a=8+x%2
b=x-a
print(a,b)
``` | 3 | |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything ... | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth ... | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is... | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca... | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input... | 1,671,287,217 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 46 | 0 | import math
d, h, v, e = map(int, input().split())
drink_s = (4 * v) / (math.pi * (d**2))
if drink_s > e:
print("YES")
result = (h / (drink_s - e))
print(round(result, 12))
else:
print("NO") | Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, cont... | ```python
import math
d, h, v, e = map(int, input().split())
drink_s = (4 * v) / (math.pi * (d**2))
if drink_s > e:
print("YES")
result = (h / (drink_s - e))
print(round(result, 12))
else:
print("NO")
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,669,116,016 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | k=input()
cl=0
cu=0
for i in k:
if i.islower():
cl=cl+1
if i.isupper():
cu=cu+1
if cl>cu:
print(k.lower())
if cl<cu:
print(k.upper())
if cl==cu:
print(k.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
k=input()
cl=0
cu=0
for i in k:
if i.islower():
cl=cl+1
if i.isupper():
cu=cu+1
if cl>cu:
print(k.lower())
if cl<cu:
print(k.upper())
if cl==cu:
print(k.lower())
``` | 3.977 |
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,683,672,028 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | """
contest= https://codeforces.com/contest/731/problem/A
date= Thursday, May 11, 2023
Verdict =
"""
w='a'+input()
x=0
for i in range(len(w)-1):
tem_1= abs((ord(w[i])%ord('a') ) -(ord(w[i+1])%ord('a') ))
tem_2= abs(tem_1-26)
x+= min (tem_1 , tem_2 )
print(x) | 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
"""
contest= https://codeforces.com/contest/731/problem/A
date= Thursday, May 11, 2023
Verdict =
"""
w='a'+input()
x=0
for i in range(len(w)-1):
tem_1= abs((ord(w[i])%ord('a') ) -(ord(w[i+1])%ord('a') ))
tem_2= abs(tem_1-26)
x+= min (tem_1 , tem_2 )
print(x)
``` | 3 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,620,819,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,860,800 | n = int(input())
h = input().split(" ")
current_energy = 0
current_pylon = 0
money_paid = 0
for i in range(0,n-1):
diff = int(h[current_pylon]) - int(h[current_pylon + 1])
if diff >= 0:
current_energy += diff
current_pylon = current_pylon + 1
else: #diff < 0 : ... | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n = int(input())
h = input().split(" ")
current_energy = 0
current_pylon = 0
money_paid = 0
for i in range(0,n-1):
diff = int(h[current_pylon]) - int(h[current_pylon + 1])
if diff >= 0:
current_energy += diff
current_pylon = current_pylon + 1
else: #d... | 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,521,630,572 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 7,065,600 | n=int(input())
isPrime=[True for i in range(n+1)]
for i in range(2, n+1):
if isPrime[i]:
for j in range(2*i, n+1, i):
isPrime[j]=False
x=2
y=0
while x<n:
if isPrime[x]:
y+=1
x+=1
print(y)
| 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
n=int(input())
isPrime=[True for i in range(n+1)]
for i in range(2, n+1):
if isPrime[i]:
for j in range(2*i, n+1, i):
isPrime[j]=False
x=2
y=0
while x<n:
if isPrime[x]:
y+=1
x+=1
print(y)
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,529,478,596 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | a,b=map(int,input().split())
x = a^b
n = ""
while x > 0:
y = str(x % 2)
n = y + n
x = int(x / 2)
print (n) | 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=map(int,input().split())
x = a^b
n = ""
while x > 0:
y = str(x % 2)
n = y + n
x = int(x / 2)
print (n)
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be.
... | The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. | If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes).
Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k... | [
"helloworld\nehoolwlroz\n",
"hastalavistababy\nhastalavistababy\n",
"merrychristmas\nchristmasmerry\n"
] | [
"3\nh e\nl o\nd z\n",
"0\n",
"-1\n"
] | none | 0 | [
{
"input": "helloworld\nehoolwlroz",
"output": "3\nh e\nl o\nd z"
},
{
"input": "hastalavistababy\nhastalavistababy",
"output": "0"
},
{
"input": "merrychristmas\nchristmasmerry",
"output": "-1"
},
{
"input": "kusyvdgccw\nkusyvdgccw",
"output": "0"
},
{
"input": "... | 1,482,697,114 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from sys import *
s=input()
sf=input()
pair=dict()
abet="abcdefghijklmnopqrstuvwxyz"
for i range(len(s)):
if not pair.get(s[i]) and not pair.get(sf[i]):
pair[s[i]]=sf[i]
pair[sf[i]]=s[i]
else if pair[s[i]]!=sf[i] or pair[sf[i]]!=s[i]:
print(-1)
exit(0)
ans=[]
for i... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, ... | ```python
from sys import *
s=input()
sf=input()
pair=dict()
abet="abcdefghijklmnopqrstuvwxyz"
for i range(len(s)):
if not pair.get(s[i]) and not pair.get(sf[i]):
pair[s[i]]=sf[i]
pair[sf[i]]=s[i]
else if pair[s[i]]!=sf[i] or pair[sf[i]]!=s[i]:
print(-1)
exit(0)
ans... | -1 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,589,968,385 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 140 | 0 | n, m = map(int, input().split())
if m < 1:
print('No')
elif m == 1:
if n == 0: print('YES')
else: print('No')
else:
n -= m-1
#print(n)
if n >= 0 and n%2 == 0:
print('Yes')
else:
print('No') | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
n, m = map(int, input().split())
if m < 1:
print('No')
elif m == 1:
if n == 0: print('YES')
else: print('No')
else:
n -= m-1
#print(n)
if n >= 0 and n%2 == 0:
print('Yes')
else:
print('No')
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,626,638,321 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,656,000 | q = input()
for i in range(len(q), -1, -1):
if q[i].isalpha():
print("YES" if q[i] in ("A", "I", "E", "O", "U", "Y") else "NO")
break | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
q = input()
for i in range(len(q), -1, -1):
if q[i].isalpha():
print("YES" if q[i] in ("A", "I", "E", "O", "U", "Y") else "NO")
break
``` | -1 |
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,586,781,575 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
e=o=0
for i in range(0,n):
if(a[i]%2==0):
b.append(a[i])
e+=1
else:
c.append(a[i])
o+=1
if(o==1):
print(a.index(c[0])+1)
else:
print(a.index(b[0])+1) | 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())
a=list(map(int,input().split()))
b=[]
c=[]
e=o=0
for i in range(0,n):
if(a[i]%2==0):
b.append(a[i])
e+=1
else:
c.append(a[i])
o+=1
if(o==1):
print(a.index(c[0])+1)
else:
print(a.index(b[0])+1)
``` | 3.944928 |
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,509,690,684 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | n,m,k=map(int,input().split())
c=[0]*m
for i in range(n):
a=input()
for j in range(m):
c[j]+=a[j]=='Y'
print(sum(c[i]>=k for i in range(m)))#kitten | Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a li... | ```python
n,m,k=map(int,input().split())
c=[0]*m
for i in range(n):
a=input()
for j in range(m):
c[j]+=a[j]=='Y'
print(sum(c[i]>=k for i in range(m)))#kitten
``` | 3 | |
550 | C | Divisibility by Eight | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"math"
] | null | null | You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no... | The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits. | Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any ... | [
"3454\n",
"10\n",
"111111\n"
] | [
"YES\n344\n",
"YES\n0\n",
"NO\n"
] | none | 1,000 | [
{
"input": "3454",
"output": "YES\n344"
},
{
"input": "10",
"output": "YES\n0"
},
{
"input": "111111",
"output": "NO"
},
{
"input": "8996988892",
"output": "YES\n8"
},
{
"input": "5555555555",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
... | 1,697,739,747 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 93 | 0 | s = input()
if s.count('0') > 0:
print('YES')
print(0)
exit(0)
if s.count('8') > 0:
print('YES')
print(8)
exit(0)
for i in range(len(s)):
for j in range(i + 1, len(s)):
for k in range(j + 1, len(s)):
x = int(s[i] + s[j] + s[k])
if x % 8 == 0:
... | Title: Divisibility by Eight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of t... | ```python
s = input()
if s.count('0') > 0:
print('YES')
print(0)
exit(0)
if s.count('8') > 0:
print('YES')
print(8)
exit(0)
for i in range(len(s)):
for j in range(i + 1, len(s)):
for k in range(j + 1, len(s)):
x = int(s[i] + s[j] + s[k])
if x % ... | 3 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,583,296,564 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,964 | 307,200 | n=int(input())
cnt=0
x=0
for r in range(4,n+1):
v=r
cnt=0
for i in range(2,v-1):
if(v%i==0):
k=0
for j in range(2,i-1):
if(i%j==0):
k+=1
if(k==0):
cnt+=1
if(cnt==2):
x+=1
print(x)
| Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n=int(input())
cnt=0
x=0
for r in range(4,n+1):
v=r
cnt=0
for i in range(2,v-1):
if(v%i==0):
k=0
for j in range(2,i-1):
if(i%j==0):
k+=1
if(k==0):
cnt+=1
if(cnt==2):
x+=1
print(x)
``` | 3.508428 |
1,009 | B | Minimum Ternary String | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).
For e... | The first line of the input contains the string $s$ consisting only of characters '0', '1' and '2', its length is between $1$ and $10^5$ (inclusive). | Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero). | [
"100210\n",
"11222121\n",
"20\n"
] | [
"001120\n",
"11112222\n",
"20\n"
] | none | 0 | [
{
"input": "100210",
"output": "001120"
},
{
"input": "11222121",
"output": "11112222"
},
{
"input": "20",
"output": "20"
},
{
"input": "1002",
"output": "0012"
},
{
"input": "10",
"output": "01"
},
{
"input": "000021",
"output": "000012"
},
{
... | 1,617,375,746 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 2,867,200 | s=input()[::-1]
while '12' in s:
s1=s.replace('12','21')
s=s1[:]
while '01' in s:
s1=s.replace('01','10')
s=s1[:]
print(s[::-1])
| Title: Minimum Ternary String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').
You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) ... | ```python
s=input()[::-1]
while '12' in s:
s1=s.replace('12','21')
s=s1[:]
while '01' in s:
s1=s.replace('01','10')
s=s1[:]
print(s[::-1])
``` | 0 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,570,089,940 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | from math import sqrt
n,k=map(int,input().split())
x=[]
y=[]
for i in range(1,int(sqrt(n))+1):
if n%i==0 and n//i!=i:
x.append(i)
y.append(n//i)
y.sort()
k-=1
if k>=len(x)+len(y):
print(-1)
elif k<len(x):
print(x[k])
else:
print(y[k-len(x)]) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
from math import sqrt
n,k=map(int,input().split())
x=[]
y=[]
for i in range(1,int(sqrt(n))+1):
if n%i==0 and n//i!=i:
x.append(i)
y.append(n//i)
y.sort()
k-=1
if k>=len(x)+len(y):
print(-1)
elif k<len(x):
print(x[k])
else:
print(y[k-len(x)])
``` | 0 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,589,370,317 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 156 | 20,172,800 | a=int(input())
p=0
for j in range(len(str(a)),1,-1):
if j==len(str(a)):
p+= (a-int((j-1)*'9'))*j
else:
p+= (int('9'*j)-int('9'*(j-1)))*j
if a>9:
print(p+9)
else:
print(a)
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
a=int(input())
p=0
for j in range(len(str(a)),1,-1):
if j==len(str(a)):
p+= (a-int((j-1)*'9'))*j
else:
p+= (int('9'*j)-int('9'*(j-1)))*j
if a>9:
print(p+9)
else:
print(a)
``` | 3 | |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,623,913,931 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 6 | 202 | 11,980,800 | dx = [-1,0,0,1,-1,-1,1,1]
dy = [0,-1,1,0,-1,1,-1,1]
k = 0
def check(arr,visited, x, y):
if x < 0 or y < 0 or y >= m or x >= n: return False
if arr[x][y] == "#": return False
if visited[x][y]: return False
return True
def dfs(arr, visited, x, y, path):
visited[x][y] = True
if a... | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
dx = [-1,0,0,1,-1,-1,1,1]
dy = [0,-1,1,0,-1,1,-1,1]
k = 0
def check(arr,visited, x, y):
if x < 0 or y < 0 or y >= m or x >= n: return False
if arr[x][y] == "#": return False
if visited[x][y]: return False
return True
def dfs(arr, visited, x, y, path):
visited[x][y] = True... | -1 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,659,454,036 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n1,n2=map(int,input().split())
l1=[0]*n1;l2=[1]*n2
if n1-n2>1 or n2>n1*2+2:
print (-1);exit()
if n2>n1*2:print(('110'*n1)+'1'*((n2-n1*2)));exit()
if n2==n1*2:print(('110'*n1)+'1'*((n2-n1)-n1));exit()
if n1==n2:print('10'*n1);exit()
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
n1,n2=map(int,input().split())
l1=[0]*n1;l2=[1]*n2
if n1-n2>1 or n2>n1*2+2:
print (-1);exit()
if n2>n1*2:print(('110'*n1)+'1'*((n2-n1*2)));exit()
if n2==n1*2:print(('110'*n1)+'1'*((n2-n1)-n1));exit()
if n1==n2:print('10'*n1);exit()
``` | 0 | |
641 | F | Little Artem and 2-SAT | PROGRAMMING | 3,000 | [] | null | null | Little Artem is a very smart programmer. He knows many different difficult algorithms. Recently he has mastered in 2-SAT one.
In computer science, 2-satisfiability (abbreviated as 2-SAT) is the special case of the problem of determining whether a conjunction (logical AND) of disjunctions (logical OR) have a solution, ... | The first line of the input contains three integers *n*, *m*1 and *m*2 (1<=≤<=*n*<=≤<=1000, 1<=≤<=*m*1,<=*m*2<=≤<=*n*2) — the number of variables, the number of disjunctions in the first formula and the number of disjunctions in the second formula, respectively.
Next *m*1 lines contains the description of 2-SAT formul... | If both formulas share the same set of solutions, output a single word "SIMILAR" (without quotes). Otherwise output exactly *n* integers *x**i* () — any set of values *x* such that *f*(*x*)<=≠<=*g*(*x*). | [
"2 1 1\n1 2\n1 2\n",
"2 1 1\n1 2\n1 -2\n"
] | [
"SIMILAR\n",
"0 0 \n"
] | First sample has two equal formulas, so they are similar by definition.
In second sample if we compute first function with *x*<sub class="lower-index">1</sub> = 0 and *x*<sub class="lower-index">2</sub> = 0 we get the result 0, because <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/82cbca... | 3,000 | [] | 1,689,420,975 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689420975.2080457")# 1689420975.2080696 | Title: Little Artem and 2-SAT
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem is a very smart programmer. He knows many different difficult algorithms. Recently he has mastered in 2-SAT one.
In computer science, 2-satisfiability (abbreviated as 2-SAT) is the special case of t... | ```python
print("_RANDOM_GUESS_1689420975.2080457")# 1689420975.2080696
``` | 0 | |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,590,474,434 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | s=input()
if len(s) < 4: print(0)
else:
a=0
for i in range(len(s)):
d=s.find("bear", i)
if d>=0: a+=len(s)-d-3
print(a) | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
s=input()
if len(s) < 4: print(0)
else:
a=0
for i in range(len(s)):
d=s.find("bear", i)
if d>=0: a+=len(s)-d-3
print(a)
``` | 3 | |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,614,867,906 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 78 | 2,150,400 | import math
def printDivisors(n):
i = 1
l=[]
c=0
while i <= math.sqrt(n):
if (n % i == 0):
if (n / i == i):
l.append(i)
c+=1
else:
l.append(i)
l.append(n//i)
c+=2
i = i +... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
import math
def printDivisors(n):
i = 1
l=[]
c=0
while i <= math.sqrt(n):
if (n % i == 0):
if (n / i == i):
l.append(i)
c+=1
else:
l.append(i)
l.append(n//i)
c+=2
... | -1 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,687,956,061 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 140 | 18,534,400 | n, m = map(int, input().split())
a = set(map(int, input().split()))
types = set()
curr_type= 1
while m > 0 and curr_type < 10 ** 9:
if curr_type not in a:
if m - curr_type >= 0:
m = m - curr_type
types.add(curr_type)
else:
break
curr_type += 1
prin... | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
n, m = map(int, input().split())
a = set(map(int, input().split()))
types = set()
curr_type= 1
while m > 0 and curr_type < 10 ** 9:
if curr_type not in a:
if m - curr_type >= 0:
m = m - curr_type
types.add(curr_type)
else:
break
curr_type ... | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,623,177,629 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 39 | 310 | 0 | n,m = map(int,input().split())
arr=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
for i in range(len(arr)):
if arr[i]>n:
if arr[i]==m:
# print(arr[i])
print("YES")
break
else:
print("NO")
break | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,m = map(int,input().split())
arr=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]
for i in range(len(arr)):
if arr[i]>n:
if arr[i]==m:
# print(arr[i])
print("YES")
break
else:
print("NO")
break
``` | 0 |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,641,299,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | ''' #1
n = int(input())
lst = [int(i) for i in input().split()]
max_res = lst[0]
min_res = lst[0]
k = 0
for i in range(len(lst)):
if lst[i] > max_res:
k += 1
max_res = lst[i]
if lst[i] < min_res:
k += 1
min_res = lst[i]
print(k)
#2
n = int(input())
lst = ... | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
''' #1
n = int(input())
lst = [int(i) for i in input().split()]
max_res = lst[0]
min_res = lst[0]
k = 0
for i in range(len(lst)):
if lst[i] > max_res:
k += 1
max_res = lst[i]
if lst[i] < min_res:
k += 1
min_res = lst[i]
print(k)
#2
n = int(input(... | 0 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,667,597,257 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
using namespace std;
int main() {
string v;
cin >> v;
for (int i=0; i<v.size() ; i++){
// cout << "i="<<i<< endl;
// cout << v[i] << endl;
// cout << v[i+1] << endl;
// cout << v[i+2] << endl;
if (v[i]=='1'){
//cout << "inside if"<<endl;
... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
#include <iostream>
#include <vector>
using namespace std;
int main() {
string v;
cin >> v;
for (int i=0; i<v.size() ; i++){
// cout << "i="<<i<< endl;
// cout << v[i] << endl;
// cout << v[i+1] << endl;
// cout << v[i+2] << endl;
if (v[i]=='1'){
//cout << "inside if... | -1 | |
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,632,813,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 6,963,200 | t = int(input())
ans = []
ret = 0
for i in range(t):
a = int(input())
for j in range(int(2 / (180 / a - 1) - 1), int(2 / (180 / a - 1) + 2), 1):
if 180 * j / (j + 2) == a:
ret = 1
if ret == 1:
ans.append("YES")
else:
ans.append("NO")
for i in ans:
print(i)
| 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
t = int(input())
ans = []
ret = 0
for i in range(t):
a = int(input())
for j in range(int(2 / (180 / a - 1) - 1), int(2 / (180 / a - 1) + 2), 1):
if 180 * j / (j + 2) == a:
ret = 1
if ret == 1:
ans.append("YES")
else:
ans.append("NO")
for i in ans:
print(... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,660,399,738 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n,m,a=list(map(int,input().strip().split()))
count=0
if n%a==0:
count=count+n//a
else:
count=count+n//a+1
if m%a==0:
count=count+m//a
else:
count=count+m//a+1
print(count)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=list(map(int,input().strip().split()))
count=0
if n%a==0:
count=count+n//a
else:
count=count+n//a+1
if m%a==0:
count=count+m//a
else:
count=count+m//a+1
print(count)
``` | 0 |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,674,659,978 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 9,830,400 | n=int(input())
l1=[int(i)for i in input().split()]
b=max(l1)-min(l1)
c=0
for i in range(len(l1)):
for j in range(i+1,len(l1)):
if(abs(l1[i]-l1[j])==b):
c+=1
print(b,c) | Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
n=int(input())
l1=[int(i)for i in input().split()]
b=max(l1)-min(l1)
c=0
for i in range(len(l1)):
for j in range(i+1,len(l1)):
if(abs(l1[i]-l1[j])==b):
c+=1
print(b,c)
``` | 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,564,040,065 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 0 | n = int(input())
t = []
for i in range(n):
a, b = map(int, input().split())
if a - b != 0:
print('rated')
exit()
else:
t.append(a)
if min(t) != a:
print('unrated')
exit()
print('maybe')
# CodeForcesian
# ♥
# سرمایه گذاری بر روی دانش ... | 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
n = int(input())
t = []
for i in range(n):
a, b = map(int, input().split())
if a - b != 0:
print('rated')
exit()
else:
t.append(a)
if min(t) != a:
print('unrated')
exit()
print('maybe')
# CodeForcesian
# ♥
# سرمایه گذاری بر... | 0 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,526,108,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 78 | 7,065,600 | '''input
370330636048898430 61721772674816405 6
'''
def gcd(a, b):
if(a%b==0):
return b
else:
return gcd(b, a%b)
t, w, b = map(int, input().split())
mini = min(w, b)
g = gcd(b, w)
lcm = (w*b)/g
cnt = t//lcm
n = mini*cnt
last = lcm*cnt
n += min(mini, t-last+1)
n -= 1
p = in... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
'''input
370330636048898430 61721772674816405 6
'''
def gcd(a, b):
if(a%b==0):
return b
else:
return gcd(b, a%b)
t, w, b = map(int, input().split())
mini = min(w, b)
g = gcd(b, w)
lcm = (w*b)/g
cnt = t//lcm
n = mini*cnt
last = lcm*cnt
n += min(mini, t-last+1)
n -=... | 0 | |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=50,<=1<=≤<=*c*<=≤<=1000) — the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=1000,<=*p**i*<=<<=*p**i*<=+<=1) — initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50 - *c*·10 = 50 - 2·10 = 30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,594,316,280 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 6,963,200 | a,b=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
l,y=[],[]
x,q,w,o= 0,0,0,0
for e in m :
x = x+e
l.append(x)
for i in range(len(l)):
q = q+max(0,n[i]-b*l[i])
n=n[::-1]
m=m[::-1]
for p in m :
w=w+p
y.append(w)
for r in range(len(y)):
o = o+max(0,n[r]-b*... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
a,b=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
l,y=[],[]
x,q,w,o= 0,0,0,0
for e in m :
x = x+e
l.append(x)
for i in range(len(l)):
q = q+max(0,n[i]-b*l[i])
n=n[::-1]
m=m[::-1]
for p in m :
w=w+p
y.append(w)
for r in range(len(y)):
o = o+max... | 3 | |
1,009 | A | Game Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$.
Games in the shop are ordered from left to right, Maxim tries to buy ... | The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet.
The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game.
The third line of the inp... | Print a single integer — the number of games Maxim will buy. | [
"5 4\n2 4 5 2 4\n5 3 4 6\n",
"5 2\n20 40 50 20 40\n19 20\n",
"6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n"
] | [
"3\n",
"0\n",
"4\n"
] | The first example is described in the problem statement.
In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.
In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti... | 0 | [
{
"input": "5 4\n2 4 5 2 4\n5 3 4 6",
"output": "3"
},
{
"input": "5 2\n20 40 50 20 40\n19 20",
"output": "0"
},
{
"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000",
"output": "4"
},
{
"input": "5 1\n1 1 1 1 1\n5",
"output": "1"
},
{
"input": "5 1\n10 1 1 1 1\n... | 1,557,326,258 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 78 | 0 | n,m = map(int, input().split())
mat = list(map(int, input().split()))
sat = list(map(int, input().split()))
i,j = 0,0
res = 0
while i<n:
if mat[i]<=sat[j]:
res+=1
j+=1
i+=1
print(res)
| Title: Game Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$.
Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ... | ```python
n,m = map(int, input().split())
mat = list(map(int, input().split()))
sat = list(map(int, input().split()))
i,j = 0,0
res = 0
while i<n:
if mat[i]<=sat[j]:
res+=1
j+=1
i+=1
print(res)
``` | -1 | |
11 | C | How Many Squares? | PROGRAMMING | 2,200 | [
"implementation"
] | C. How Many Squares? | 2 | 64 | You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2<=×<=2. We are only interested in two types of squares:
1. squares with each side parallel to a side of the matrix; 1. squares with each side... | The first line contains integer *t* (1<=≤<=*t*<=≤<=10000), where *t* is the number of test cases in the input. Then test cases follow. Each case starts with a line containing integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=250), where *n* is the number of rows and *m* is the number of columns. The following *n* lines contain... | You should output exactly *t* lines, with the answer to the *i*-th test case on the *i*-th line. | [
"2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000\n",
"1\n12 11\n11111111111\n10000000001\n10111111101\n10100000101\n10101100101\n10101100101\n101000... | [
"1\n2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n8 8\n00010001\n00101000\n01000100\n10000010\n01000100\n00101000\n11010011\n11000011\n10 10\n1111111000\n1000001000\n1011001000\n1011001010\n1000001101\n1001001010\n1010101000\n1001001000\n1000001000\n1111111000",
"output": "1\n2"
},
{
"input": "1\n12 11\n11111111111\n10000000001\n1011... | 1,557,378,806 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | print('I have no idea...') | Title: How Many Squares?
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a 0-1 rectangular matrix. What is the number of squares in it? A square is a solid square frame (border) with linewidth equal to 1. A square should be at least 2<=×<=2. We are only interested in two types of ... | ```python
print('I have no idea...')
``` | 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,698,496,217 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
array=[]
for i in range(n):
array1=list(map(int,input().split(" ",1)))
array.append(array1)
array=sorted(array,key=lambda x:x[0])
m=0
for m in range(n-1):
if array[m][1]<array[m+1][1]:
m=1
print('Happy Alex')
break
if m==0:
print('Poor Alex') | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
n=int(input())
array=[]
for i in range(n):
array1=list(map(int,input().split(" ",1)))
array.append(array1)
array=sorted(array,key=lambda x:x[0])
m=0
for m in range(n-1):
if array[m][1]<array[m+1][1]:
m=1
print('Happy Alex')
break
if m==0:
print('Poor Alex')... | 0 | |
306 | A | Candies | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *... | The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends. | Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value. | [
"12 3\n",
"15 4\n",
"18 7\n"
] | [
"4 4 4 ",
"3 4 4 4 ",
"2 2 2 3 3 3 3 "
] | Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces. | 500 | [
{
"input": "12 4",
"output": "3 3 3 3 "
},
{
"input": "15 6",
"output": "2 2 2 3 3 3 "
},
{
"input": "18 8",
"output": "2 2 2 2 2 2 3 3 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "2 1",
"output": "2 "
},
{
"input": "100 1",
"output": "100 ... | 1,602,620,461 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 280 | 0 |
s = input()
s2 = s.split(' ')
n = int(s2[0])
m = int(s2[1])
lst = []
f = n // m
for i in range(m):
lst.append(f)
k = 0
for i in lst:
k += i
while k < n:
for j in range(len(lst)):
lst[j] += 1
k += 1
if not k < n:
break
for item in lst[::-1]:
... | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ... | ```python
s = input()
s2 = s.split(' ')
n = int(s2[0])
m = int(s2[1])
lst = []
f = n // m
for i in range(m):
lst.append(f)
k = 0
for i in lst:
k += i
while k < n:
for j in range(len(lst)):
lst[j] += 1
k += 1
if not k < n:
break
for item in l... | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,509,463,440 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 0 | from sys import stdin, stdout
def main():
sec_day = 86400
n, t = map(int, stdin.readline().split())
cnt = 0
for cur in stdin.readline().split():
cur = int(cur)
t -= sec_day - cur
cnt += 1
if t <= 0:
stdout.write(str(cnt))
break
if _... | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
from sys import stdin, stdout
def main():
sec_day = 86400
n, t = map(int, stdin.readline().split())
cnt = 0
for cur in stdin.readline().split():
cur = int(cur)
t -= sec_day - cur
cnt += 1
if t <= 0:
stdout.write(str(cnt))
bre... | 3 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,531,908,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | n, p, k = list(map(int,input().split()))
if(p - k > 1):
print("<< ",end="")
for i in range(k):
if(p - k + i >= 1):
print(p - k + i,end=" ")
print("(",end="")
print(p,end=") ")
for i in range(k):
if(p + i + 1 <= n):
print(p + i + 1,end=" ")
if(p + k + 1 < n):
print(">>... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
n, p, k = list(map(int,input().split()))
if(p - k > 1):
print("<< ",end="")
for i in range(k):
if(p - k + i >= 1):
print(p - k + i,end=" ")
print("(",end="")
print(p,end=") ")
for i in range(k):
if(p + i + 1 <= n):
print(p + i + 1,end=" ")
if(p + k + 1 < n):
... | 0 | |
999 | D | Equalize the Remainders | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"implementation"
] | null | null | You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's calculate $c_r$ ($0 \le r \le m-1)$ — the number of elements havin... | The first line of input contains two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le n$). It is guaranteed that $m$ is a divisor of $n$.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), the elements of the array. | In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $0$ to $m - 1$, the number of elements of the array having this remainder equals $\frac{n}{m}$.
In the second line, print any array satisfying the condition and can be obtained f... | [
"6 3\n3 2 0 6 10 12\n",
"4 2\n0 1 2 3\n"
] | [
"3\n3 2 0 7 10 14 \n",
"0\n0 1 2 3 \n"
] | none | 0 | [
{
"input": "6 3\n3 2 0 6 10 12",
"output": "3\n3 2 0 7 10 14 "
},
{
"input": "4 2\n0 1 2 3",
"output": "0\n0 1 2 3 "
},
{
"input": "1 1\n1000000000",
"output": "0\n1000000000 "
},
{
"input": "6 3\n3 2 0 6 10 11",
"output": "1\n3 2 0 7 10 11 "
},
{
"input": "100 25... | 1,643,081,442 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 3,000 | 28,569,600 | """
-*- coding: utf-8 -*-
Created on Sat Jan 22 18:33:32 2022
@author: Tausif Khan Arnob
"""
n, m = map(int, input().split())
a = [*map(int, input().split())]
li = [[] for i in range(m)]
k, s = n//m, 0
for i, val in enumerate(a):
li[val%m].append(i)
for i in range(2*m):
if len(li[i%m]) > k:
... | Title: Equalize the Remainders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$... | ```python
"""
-*- coding: utf-8 -*-
Created on Sat Jan 22 18:33:32 2022
@author: Tausif Khan Arnob
"""
n, m = map(int, input().split())
a = [*map(int, input().split())]
li = [[] for i in range(m)]
k, s = n//m, 0
for i, val in enumerate(a):
li[val%m].append(i)
for i in range(2*m):
if len(li[i%m... | 0 | |
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,589,557,245 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 6,656,000 | #https://codeforces.com/problemset/problem/832/A
inp = input()
inp = inp.split(" ")
numbers = []
for number in inp:
numbers.append(int(number))
Sasha = numbers[1]
Lena = numbers[0]-numbers[1]
if Sasha > Lena:
print ("YES")
else:
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
#https://codeforces.com/problemset/problem/832/A
inp = input()
inp = inp.split(" ")
numbers = []
for number in inp:
numbers.append(int(number))
Sasha = numbers[1]
Lena = numbers[0]-numbers[1]
if Sasha > Lena:
print ("YES")
else:
print ("NO")
``` | 0 | |
495 | B | Modular Equations | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and... | In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. | If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . | [
"21 5\n",
"9435152 272\n",
"10 10\n"
] | [
"2\n",
"282\n",
"infinity\n"
] | In the first sample the answers of the Modular Equation are 8 and 16 since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/6f5ff39ebd209bf990adaf91f4b82f9687097224.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "21 5",
"output": "2"
},
{
"input": "9435152 272",
"output": "282"
},
{
"input": "10 10",
"output": "infinity"
},
{
"input": "0 1000000000",
"output": "0"
},
{
"input": "11 2",
"output": "2"
},
{
"input": "1 0",
"output": "1"
},
{
... | 1,580,317,252 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 | a,b = list(map(int , input().split()))
if(a<b): print(0)
else:
if a==b:
print('infinity')
elif a>b:
cnt =0
for i in range(1,int((a-b)**0.5)+1):
if(a-b)%i==0:
if(i>b): cnt+=1
if(a-b)/i > b and i*i != (a-b) : cnt+=1
p... | Title: Modular Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed'... | ```python
a,b = list(map(int , input().split()))
if(a<b): print(0)
else:
if a==b:
print('infinity')
elif a>b:
cnt =0
for i in range(1,int((a-b)**0.5)+1):
if(a-b)%i==0:
if(i>b): cnt+=1
if(a-b)/i > b and i*i != (a-b) : cnt+=1
... | 3 | |
932 | B | Recursive Queries | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"dfs and similar"
] | null | null | Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x* between *l* and *r* inclusive, such that *g*(*x*)<==<=*k*. | The first line of the input contains an integer *Q* (1<=≤<=*Q*<=≤<=2<=×<=105) representing the number of queries.
*Q* lines follow, each of which contains 3 integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=106,<=1<=≤<=*k*<=≤<=9). | For each query, print a single line containing the answer for that query. | [
"4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n",
"4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n"
] | [
"1\n4\n0\n8\n",
"3\n1\n1\n5\n"
] | In the first example:
- *g*(33) = 9 as *g*(33) = *g*(3 × 3) = *g*(9) = 9 - *g*(47) = *g*(48) = *g*(60) = *g*(61) = 6 - There are no such integers between 47 and 55. - *g*(4) = *g*(14) = *g*(22) = *g*(27) = *g*(39) = *g*(40) = *g*(41) = *g*(58) = 4 | 1,000 | [
{
"input": "4\n22 73 9\n45 64 6\n47 55 7\n2 62 4",
"output": "1\n4\n0\n8"
},
{
"input": "4\n82 94 6\n56 67 4\n28 59 9\n39 74 4",
"output": "3\n1\n1\n5"
}
] | 1,585,461,521 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 74,649,600 | def func(num):
ans = 1
while True:
for i in str(num):
if i!='0':
ans = ans*(int(i))
if ans<10:
break
else:
num = ans
ans = 1
return ans
N = 10**6+1
mat = [[0 for i in range(N)]for j in range(10)]
for i in r... | Title: Recursive Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let us define two functions *f* and *g* on positive integer numbers.
You need to process *Q* queries. In each query, you will be given three integers *l*, *r* and *k*. You need to print the number of integers *x*... | ```python
def func(num):
ans = 1
while True:
for i in str(num):
if i!='0':
ans = ans*(int(i))
if ans<10:
break
else:
num = ans
ans = 1
return ans
N = 10**6+1
mat = [[0 for i in range(N)]for j in range(10)]
... | 0 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,688,837,533 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 12,390,400 | n=int(input())
lst=list(map(int,input().split()))
final=[]
for i in range(n):
a=lst[i]
for j in lst:
if a!=j:
p=abs(a-j)
final.append(p)
print(min(final),max(final))
final.clear()
| Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n=int(input())
lst=list(map(int,input().split()))
final=[]
for i in range(n):
a=lst[i]
for j in lst:
if a!=j:
p=abs(a-j)
final.append(p)
print(min(final),max(final))
final.clear()
``` | 0 | |
545 | A | Toy Cars | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are *n* toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turne... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cars.
Each of the next *n* lines contains *n* space-separated integers that determine matrix *A*.
It is guaranteed that on the main diagonal there are <=-<=1, and <=-<=1 doesn't appear anywhere else in the matrix.
It is guaranteed that the inpu... | Print the number of good cars and in the next line print their space-separated indices in the increasing order. | [
"3\n-1 0 0\n0 -1 1\n0 2 -1\n",
"4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1\n"
] | [
"2\n1 3 ",
"0\n"
] | none | 500 | [
{
"input": "3\n-1 0 0\n0 -1 1\n0 2 -1",
"output": "2\n1 3 "
},
{
"input": "4\n-1 3 3 3\n3 -1 3 3\n3 3 -1 3\n3 3 3 -1",
"output": "0"
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n-1 0\n0 -1",
"output": "2\n1 2 "
},
{
"input": "2\n-1 1\n2 -1",
"out... | 1,674,501,798 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 77 | 2,048,000 | # -*- coding: utf-8 -*-
"""
Created on Mon Jan 23 16:09:09 2023
@author: Lenovo
"""
n = int(input())
m = []
ind = []
for i in range(n):
m.append(list(map(int,input().split())))
for i in m:
if 1 not in i and 3 not in i:
ind.append(m.index(i)+1)
for j in range(n):
x = 0
for ... | Title: Toy Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph.
There are *n* toy cars. Each pair coll... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 23 16:09:09 2023
@author: Lenovo
"""
n = int(input())
m = []
ind = []
for i in range(n):
m.append(list(map(int,input().split())))
for i in m:
if 1 not in i and 3 not in i:
ind.append(m.index(i)+1)
for j in range(n):
x = 0... | 3 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,691,341,606 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | test_cases, k = map(int, input().split())
counter = 0
for _ in range(test_cases):
num = input()
temp = [i for i in range(0, k+1)]
temp = ''.join(str(n) for n in temp)
if temp == ''.join(sorted(num)): counter += 1
print(counter) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
test_cases, k = map(int, input().split())
counter = 0
for _ in range(test_cases):
num = input()
temp = [i for i in range(0, k+1)]
temp = ''.join(str(n) for n in temp)
if temp == ''.join(sorted(num)): counter += 1
print(counter)
``` | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,698,155,448 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = input ()
n = int (n)
text = input ()
danik = 0
anton = 0
for in range (n)
if text (i) =("D"):
danik = danik + 1
else:
anton = anton + 1
if anton == danik:
print(friend ship)
elif anton>danik
print(anton)
else:
print("danik")
| Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n = input ()
n = int (n)
text = input ()
danik = 0
anton = 0
for in range (n)
if text (i) =("D"):
danik = danik + 1
else:
anton = anton + 1
if anton == danik:
print(friend ship)
elif anton>danik
print(anton)
else:
print("danik")
``` | -1 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,631,160,472 | 472 | PyPy 3 | OK | TESTS | 10 | 93 | 20,172,800 | n,k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr_set = set()
ans_list = []
for index, num in enumerate(arr):
if not num in arr_set:
arr_set.add(num)
ans_list.append(index+1)
if k > len(arr_set):
print('NO')
else:
print('YES')
for i in ran... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n,k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr_set = set()
ans_list = []
for index, num in enumerate(arr):
if not num in arr_set:
arr_set.add(num)
ans_list.append(index+1)
if k > len(arr_set):
print('NO')
else:
print('YES')
fo... | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.