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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,660,934,469 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | class OneDimensionalJapaneseCrossword:
def __init__(self):
self.lastChar = 'W'
self.groups = []
def addChar(self, char):
if char == 'B':
if self.lastChar == 'W':
self.groups.append(1)
else:
self.groups[-1] += 1
self.las... | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
class OneDimensionalJapaneseCrossword:
def __init__(self):
self.lastChar = 'W'
self.groups = []
def addChar(self, char):
if char == 'B':
if self.lastChar == 'W':
self.groups.append(1)
else:
self.groups[-1] += 1
... | 3 | |
549 | H | Degenerate Matrix | PROGRAMMING | 2,100 | [
"binary search",
"math"
] | null | null | The determinant of a matrix 2<=×<=2 is defined as follows:
A matrix is called degenerate if its determinant is equal to zero.
The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements.
You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is min... | The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*.
The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*. | Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. | [
"1 2\n3 4\n",
"1 0\n0 1\n"
] | [
"0.2000000000\n",
"0.5000000000\n"
] | In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a0... | 1,500 | [
{
"input": "1 2\n3 4",
"output": "0.2000000000"
},
{
"input": "1 0\n0 1",
"output": "0.5000000000"
},
{
"input": "1000000000 0\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "8205 9482\n11 -63",
"output": "35.0198432832"
},
{
"input": "0 0\n0 0",
... | 1,435,555,094 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 62 | 0 | a,b=map(int,input().split())
c,d=map(int,input().split())
x=max(abs(a+b+c+d),abs(a+b-c-d),abs(a-b+c-d),abs(a-b-c+d))
print(abs((a*d-b*c)/x)) | Title: Degenerate Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The determinant of a matrix 2<=×<=2 is defined as follows:
A matrix is called degenerate if its determinant is equal to zero.
The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its eleme... | ```python
a,b=map(int,input().split())
c,d=map(int,input().split())
x=max(abs(a+b+c+d),abs(a+b-c-d),abs(a-b+c-d),abs(a-b-c+d))
print(abs((a*d-b*c)/x))
``` | -1 | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,521,366,602 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 7,065,600 | input()
t_array = list(map(int, input().split()))
b_array = list(map(int, input().split()))
t_array.sort()
b_array.sort()
print(t_array[-2]*b_array[-1])
| Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
input()
t_array = list(map(int, input().split()))
b_array = list(map(int, input().split()))
t_array.sort()
b_array.sort()
print(t_array[-2]*b_array[-1])
``` | 0 | |
630 | C | Lucky Numbers | PROGRAMMING | 1,100 | [
"combinatorics",
"math"
] | null | null | The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. | The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. | Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. | [
"2\n"
] | [
"6"
] | none | 0 | [
{
"input": "2",
"output": "6"
},
{
"input": "1",
"output": "2"
},
{
"input": "3",
"output": "14"
},
{
"input": "5",
"output": "62"
},
{
"input": "12",
"output": "8190"
},
{
"input": "34",
"output": "34359738366"
},
{
"input": "43",
"out... | 1,695,455,692 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | cnt = 0
for i in range(1,int(input())+1):
cnt += 2**i
print(cnt)
# Sat Sep 23 2023 10:26:19 GMT+0300 (Moscow Standard Time)
| Title: Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers.
Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building o... | ```python
cnt = 0
for i in range(1,int(input())+1):
cnt += 2**i
print(cnt)
# Sat Sep 23 2023 10:26:19 GMT+0300 (Moscow Standard Time)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,670,752,560 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a, b = int(input()), int(input())
print(min(a, b), '', (a - min(a, b) + b - min(a, b))//2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = int(input()), int(input())
print(min(a, b), '', (a - min(a, b) + b - min(a, b))//2)
``` | -1 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,454,534,641 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 420 | 20,992,000 | n = int(input())
xs = sorted(map(int, input().split()))
r = 0
for i, x in enumerate(xs, start=1):
r += x * (i + 1 if i < n else i)
print(r)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
n = int(input())
xs = sorted(map(int, input().split()))
r = 0
for i, x in enumerate(xs, start=1):
r += x * (i + 1 if i < n else i)
print(r)
``` | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,679,446,472 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 106 | 93 | 21,504,000 | # -*- coding: utf-8 -*-
def solve():
n = int(input())
a = list(map(int, input().split(' ')))
sum = 0
for i in range(n): sum += a[i]
sum = (sum + 1) // 2
cur = 0
for i in range(n):
cur += a[i]
if (cur >= sum):
print(i + 1)
return
def main... | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
# -*- coding: utf-8 -*-
def solve():
n = int(input())
a = list(map(int, input().split(' ')))
sum = 0
for i in range(n): sum += a[i]
sum = (sum + 1) // 2
cur = 0
for i in range(n):
cur += a[i]
if (cur >= sum):
print(i + 1)
return
... | 3 | |
672 | B | Different is Good | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"strings"
] | null | null | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*.
The second line contains the string *s* of length *n* consisting of only lowercase English letters. | If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | [
"2\naa\n",
"4\nkoko\n",
"5\nmurat\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | 1,000 | [
{
"input": "2\naa",
"output": "1"
},
{
"input": "4\nkoko",
"output": "2"
},
{
"input": "5\nmurat",
"output": "0"
},
{
"input": "6\nacbead",
"output": "1"
},
{
"input": "7\ncdaadad",
"output": "4"
},
{
"input": "25\npeoaicnbisdocqofsqdpgobpn",
"outp... | 1,677,135,290 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | a=int(input())
b=input()
c=abs(len(set(b))-len(b))
print(c if c < 100000 else -1) | Title: Different is Good
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are di... | ```python
a=int(input())
b=input()
c=abs(len(set(b))-len(b))
print(c if c < 100000 else -1)
``` | 0 | |
99 | B | Help Chef Gerasim | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | B. Help Chef Gerasim | 0 | 256 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup... | The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from... | [
"5\n270\n250\n250\n230\n250\n",
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n249\n230\n250\n"
] | [
"20 ml. from cup #4 to cup #1.\n",
"Exemplary pages.\n",
"Unrecoverable configuration.\n"
] | none | 1,000 | [
{
"input": "5\n270\n250\n250\n230\n250",
"output": "20 ml. from cup #4 to cup #1."
},
{
"input": "5\n250\n250\n250\n250\n250",
"output": "Exemplary pages."
},
{
"input": "5\n270\n250\n249\n230\n250",
"output": "Unrecoverable configuration."
},
{
"input": "4\n200\n190\n210\n20... | 1,600,366,233 | 2,147,483,647 | Python 3 | OK | TESTS | 200 | 109 | 307,200 | n=int(input())
l=[]
for i in range(n):
l.append(int(input()))
a=set(l)
if(len(a)==1):
print("Exemplary pages.")
else:
m=min(l)
n=max(l)
r=(n-m)//2
q=l.index(n)
w=l.index(m)
l[q]-=r
l[w]+=r
b=set(l)
if(len(b)==1):
print(str(r)+" ml. from cup #"+str(w+1... | Title: Help Chef Gerasim
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim ... | ```python
n=int(input())
l=[]
for i in range(n):
l.append(int(input()))
a=set(l)
if(len(a)==1):
print("Exemplary pages.")
else:
m=min(l)
n=max(l)
r=(n-m)//2
q=l.index(n)
w=l.index(m)
l[q]-=r
l[w]+=r
b=set(l)
if(len(b)==1):
print(str(r)+" ml. from cup ... | 3 |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,696,587,239 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 77 | 0 | a = int(input())
d = []
for i in range(a):
n = input()
d.append(n)
k = 0
for j in d:
if "++" in j:
k+=1
else:
k-=1
print(k)
| Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
a = int(input())
d = []
for i in range(a):
n = input()
d.append(n)
k = 0
for j in d:
if "++" in j:
k+=1
else:
k-=1
print(k)
``` | 3 | |
343 | B | Alternating Current | PROGRAMMING | 1,600 | [
"data structures",
"greedy",
"implementation"
] | null | null | Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it a proper glance and started experimenting right away. After a while Mike observed that the wires ended u... | The single line of the input contains a sequence of characters "+" and "-" of length *n* (1<=≤<=*n*<=≤<=100000). The *i*-th (1<=≤<=*i*<=≤<=*n*) position of the sequence contains the character "+", if on the *i*-th step from the wall the "plus" wire runs above the "minus" wire, and the character "-" otherwise. | Print either "Yes" (without the quotes) if the wires can be untangled or "No" (without the quotes) if the wires cannot be untangled. | [
"-++-\n",
"+-\n",
"++\n",
"-\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"No\n"
] | The first testcase corresponds to the picture in the statement. To untangle the wires, one can first move the "plus" wire lower, thus eliminating the two crosses in the middle, and then draw it under the "minus" wire, eliminating also the remaining two crosses.
In the second testcase the "plus" wire makes one full rev... | 1,000 | [
{
"input": "-++-",
"output": "Yes"
},
{
"input": "+-",
"output": "No"
},
{
"input": "++",
"output": "Yes"
},
{
"input": "-",
"output": "No"
},
{
"input": "+-+-",
"output": "No"
},
{
"input": "-+-",
"output": "No"
},
{
"input": "-++-+--+",
... | 1,694,751,706 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <stack>
#include <string>
using namespace std;
#define ll long long
#define llu unsigned long long
#define lld long double
#define endl "\n"
#define ENDL "\n"
#define SYSTEM_ON ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define SYSTEM_OFF return (0);
int main(voi... | Title: Alternating Current
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires without giving it... | ```python
#include <iostream>
#include <stack>
#include <string>
using namespace std;
#define ll long long
#define llu unsigned long long
#define lld long double
#define endl "\n"
#define ENDL "\n"
#define SYSTEM_ON ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define SYSTEM_OFF return (0);
in... | -1 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,697,435,251 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | s = input()
l = []
p = []
for i in range(len(s)):
if s[i].isalpha():
l.append(s[i])
for q in range(len(l)):
if l[q] not in p:
p.append(l[q])
print(len(p)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
l = []
p = []
for i in range(len(s)):
if s[i].isalpha():
l.append(s[i])
for q in range(len(l)):
if l[q] not in p:
p.append(l[q])
print(len(p))
``` | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,532,072,574 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 1,496 | 26,931,200 | # @author: guoyc
# @date: 2018/7/20
s = input()
N = len(s)
# dp = [0] * (N + 1)
#
# ml = 0
# cnt = 1
#
# for i in range(1, N):
# if s[i] == '(':
# continue
# if s[i - 1] == '(':
# dp[i] = 2 + dp[i - 2]
# elif (i - 1) - dp[i - 1] >= 0:
# if s[(i - 1) - dp[i - 1]] == '(':
# ... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
# @author: guoyc
# @date: 2018/7/20
s = input()
N = len(s)
# dp = [0] * (N + 1)
#
# ml = 0
# cnt = 1
#
# for i in range(1, N):
# if s[i] == '(':
# continue
# if s[i - 1] == '(':
# dp[i] = 2 + dp[i - 2]
# elif (i - 1) - dp[i - 1] >= 0:
# if s[(i - 1) - dp[i - 1]] == '(':
... | 3.575837 |
999 | C | Alphabetic Removals | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite... | The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove.
The second line contains the string $s$ consisting of $n$ lowercase Latin letters. | Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times.
If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). | [
"15 3\ncccaabababaccbc\n",
"15 9\ncccaabababaccbc\n",
"1 1\nu\n"
] | [
"cccbbabaccbc\n",
"cccccc\n",
""
] | none | 0 | [
{
"input": "15 3\ncccaabababaccbc",
"output": "cccbbabaccbc"
},
{
"input": "15 9\ncccaabababaccbc",
"output": "cccccc"
},
{
"input": "5 2\nzyzyx",
"output": "zzy"
},
{
"input": "4 3\nhack",
"output": "k"
},
{
"input": "4 3\nzzzz",
"output": "z"
},
{
"i... | 1,635,436,770 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 11,571,200 | n,k=map(int,input().split())
s=list(input())
for i in range(k):
b=sorted(s)
s.pop(s.index(b[0]))
print(''.join(s))
| Title: Alphabetic Removals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times:
- if there is... | ```python
n,k=map(int,input().split())
s=list(input())
for i in range(k):
b=sorted(s)
s.pop(s.index(b[0]))
print(''.join(s))
``` | 0 | |
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! deno... | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso... | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
... | 1,597,363,160 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 1,000 | 1,740,800 | import math
a, b = map(float, input().split())
first_numbers = math.factorial(b)
second_number = math.factorial(a)
result = (first_numbers / second_number) % 10
print(int(result)) | Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like... | ```python
import math
a, b = map(float, input().split())
first_numbers = math.factorial(b)
second_number = math.factorial(a)
result = (first_numbers / second_number) % 10
print(int(result))
``` | 0 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,135,536 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 13,516,800 | # LUOGU_RID: 131353811
a,b=map(int,input().split());c=input().split();d=[0]*a;e={}
for i in range(a):e[c[i]]=i
for i in e:
for j in range(e[i]+1):d[j]+=1
for i in range(b):print(d[int(input())-1]) | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
# LUOGU_RID: 131353811
a,b=map(int,input().split());c=input().split();d=[0]*a;e={}
for i in range(a):e[c[i]]=i
for i in e:
for j in range(e[i]+1):d[j]+=1
for i in range(b):print(d[int(input())-1])
``` | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,693,470,024 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | str_input = input()
data_list = str_input.split()
x_list = []
for data in data_list:
x_list.append(int(data))
x_list.sort()
min_x = min(x_list)
for i in range(0, len(x_list)):
x_list[i] -= min_x
max_x = max(x_list)
distance_list = []
for x in range(0, max_x + 1):
distance = abs(x_list[0]... | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
str_input = input()
data_list = str_input.split()
x_list = []
for data in data_list:
x_list.append(int(data))
x_list.sort()
min_x = min(x_list)
for i in range(0, len(x_list)):
x_list[i] -= min_x
max_x = max(x_list)
distance_list = []
for x in range(0, max_x + 1):
distance = abs... | 3 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,525,525,304 | 704 | Python 3 | WRONG_ANSWER | TESTS | 4 | 78 | 7,065,600 |
R = lambda: map(int, input().split())
k, n, s, p = R()
num=0
num=int((((n-1)/s+1)*k-1)/p+1)
print(num) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
R = lambda: map(int, input().split())
k, n, s, p = R()
num=0
num=int((((n-1)/s+1)*k-1)/p+1)
print(num)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,633,336,987 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | #a,b=map(int,input().split())
#print(a*b//2)
from math import *
print(round(exp(sum(map(lambda x:log(int(x)),input().split()))))//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
#a,b=map(int,input().split())
#print(a*b//2)
from math import *
print(round(exp(sum(map(lambda x:log(int(x)),input().split()))))//2)
``` | 3.956411 |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 ... | 1,638,222,764 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | a = list(map(int, input().split()))
mat = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
done = 0
if a[1] % 2 != 0:
print('No')
done = 1
b = [a[0] % a[1]]
c = a[0] % a[1]
while 1 and done == 0:
while c < a[1]:
c *= 2
if c % a[1] in b and c % a[... | Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac... | ```python
a = list(map(int, input().split()))
mat = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
done = 0
if a[1] % 2 != 0:
print('No')
done = 1
b = [a[0] % a[1]]
c = a[0] % a[1]
while 1 and done == 0:
while c < a[1]:
c *= 2
if c % a[1] in b ... | 0 | |
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want... | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
... | 1,623,910,356 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 124 | 1,331,200 | n = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
... | Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has... | ```python
n = int(input())
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divis... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть звезда).
Новое издание карты звёздного неба будет напечатано на квадратных листах, поэто... | В первой строке входных данных записаны два числа *n* и *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — количество строк и столбцов на карте звездного неба.
В следующих *n* строках задано по *m* символов. Каждый символ — это либо «.» (пустой участок неба), либо «*» (звезда).
Гарантируется, что на небе есть хотя бы одна звезда. | Выведите одно число — минимально возможную сторону квадрата, которым можно накрыть все звезды. | [
"4 4\n....\n..*.\n...*\n..**\n",
"1 3\n*.*\n",
"2 1\n.\n*\n"
] | [
"3\n",
"3\n",
"1\n"
] | Один из возможных ответов на первый тестовый пример:
Один из возможных ответов на второй тестовый пример (обратите внимание, что покрывающий квадрат выходит за пределы карты звездного неба):
Ответ на третий тестовый пример: | 0 | [
{
"input": "4 4\n....\n..*.\n...*\n..**",
"output": "3"
},
{
"input": "1 3\n*.*",
"output": "3"
},
{
"input": "2 1\n.\n*",
"output": "1"
},
{
"input": "1 1\n*",
"output": "1"
},
{
"input": "1 2\n.*",
"output": "1"
},
{
"input": "1 2\n*.",
"output":... | 1,458,969,191 | 169,991 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 4,608,000 | def squareSide():
n, m = [int(_) for _ in input().strip().split(" ")]
starMap = []
for _ in range(n):
starMap.append(input())
def verticalMax():
up = 0
down = 0
for x in range(len(starMap)):
if "*" in starMap[x]:
up = x+1
break... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Карта звёздного неба представляет собой прямоугольное поле, состоящее из *n* строк по *m* символов в каждой строке. Каждый символ — это либо «.» (означает пустой участок неба), либо «*» (означает то, что в этом месте на небе есть ... | ```python
def squareSide():
n, m = [int(_) for _ in input().strip().split(" ")]
starMap = []
for _ in range(n):
starMap.append(input())
def verticalMax():
up = 0
down = 0
for x in range(len(starMap)):
if "*" in starMap[x]:
up = x+1
... | 0 | |
628 | C | Bear and String Distance | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of di... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters. | If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that . | [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n"
] | [
"roar",
"db\n",
"-1\n"
] | none | 0 | [
{
"input": "4 26\nbear",
"output": "zcar"
},
{
"input": "2 7\naf",
"output": "hf"
},
{
"input": "3 1000\nhey",
"output": "-1"
},
{
"input": "5 50\nkzsij",
"output": "zaiij"
},
{
"input": "5 500\nvsdxg",
"output": "-1"
},
{
"input": "1 0\na",
"outpu... | 1,522,014,303 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 7,065,600 | [n,k] = input().split(" ")
s = input()
ss = ''
n = int(n)
k = int(k)
MaxD = [[0,0]]*n
SumMaxD = 0
for i in list(range(0,n)):
xl = -97 + ord(s[i])
xh = 122 - ord(s[i])
if(xl > xh):
if(xl<k):
ss =ss + chr(ord(s[i]) - xl)
k = k - xl
else:
ss ... | Title: Bear and String Distance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions ... | ```python
[n,k] = input().split(" ")
s = input()
ss = ''
n = int(n)
k = int(k)
MaxD = [[0,0]]*n
SumMaxD = 0
for i in list(range(0,n)):
xl = -97 + ord(s[i])
xh = 122 - ord(s[i])
if(xl > xh):
if(xl<k):
ss =ss + chr(ord(s[i]) - xl)
k = k - xl
else:
... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,561,562,679 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | u=0
s=0
word=input()
word=list(word)
for letter in word:
if letter.islower():
s=s+1
else:
u=u+1
word=str(word)
if u>s:
word=word.upper()
else:
word=word.lower()
print(word) | 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
u=0
s=0
word=input()
word=list(word)
for letter in word:
if letter.islower():
s=s+1
else:
u=u+1
word=str(word)
if u>s:
word=word.upper()
else:
word=word.lower()
print(word)
``` | 0 |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,695,165,873 | 2,147,483,647 | Python 3 | OK | TESTS | 133 | 46 | 0 | word = str(input())
reverse_word = word[::-1]
if reverse_word == word:
first_char = word[0]
single_letter = True
for char in word:
if char != first_char:
single_letter = False
if single_letter:
print(0)
else:
print(len(word) - 1)
else:
print(len(word))
... | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
word = str(input())
reverse_word = word[::-1]
if reverse_word == word:
first_char = word[0]
single_letter = True
for char in word:
if char != first_char:
single_letter = False
if single_letter:
print(0)
else:
print(len(word) - 1)
else:
print(len(w... | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,691,499,618 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | c=input()
l="0000000"
m="1111111"
if (l in c) or ( m in c) :
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
c=input()
l="0000000"
m="1111111"
if (l in c) or ( m in c) :
print("YES")
else:
print("NO")
``` | 3.977 |
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY... | 1,694,463,720 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 921,600 | import string
lower = list(string.ascii_lowercase)
n=int(input())
st=int()
flag=True
if len(st)<26:
flag=False
print("NO")
if flag:
for alpha in lower:
if alpha not in st:
print("No")
flag=False
break
if flag:
print("YES") | Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
... | ```python
import string
lower = list(string.ascii_lowercase)
n=int(input())
st=int()
flag=True
if len(st)<26:
flag=False
print("NO")
if flag:
for alpha in lower:
if alpha not in st:
print("No")
flag=False
break
if flag:
print("YES")
``` | -1 | |
877 | D | Olya and Energy Drinks | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or littered with cans.
Olya drank a lot of energy drink, so now she can run *k* meters per second. Each second she... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the sizes of the room and Olya's speed.
Then *n* lines follow containing *m* characters each, the *i*-th of them contains on *j*-th position "#", if the cell (*i*,<=*j*) is littered with cans, and "." otherwise.
The last line c... | Print a single integer — the minimum time it will take Olya to get from (*x*1,<=*y*1) to (*x*2,<=*y*2).
If it's impossible to get from (*x*1,<=*y*1) to (*x*2,<=*y*2), print -1. | [
"3 4 4\n....\n###.\n....\n1 1 3 1\n",
"3 4 1\n....\n###.\n....\n1 1 3 1\n",
"2 2 1\n.#\n#.\n1 1 2 2\n"
] | [
"3",
"8",
"-1"
] | In the first sample Olya should run 3 meters to the right in the first second, 2 meters down in the second second and 3 meters to the left in the third second.
In second sample Olya should run to the right for 3 seconds, then down for 2 seconds and then to the left for 3 seconds.
Olya does not recommend drinking ener... | 2,000 | [
{
"input": "3 4 4\n....\n###.\n....\n1 1 3 1",
"output": "3"
},
{
"input": "3 4 1\n....\n###.\n....\n1 1 3 1",
"output": "8"
},
{
"input": "2 2 1\n.#\n#.\n1 1 2 2",
"output": "-1"
},
{
"input": "10 10 1\n##########\n#.........\n#.#######.\n#.#.....#.\n#.#.###.#.\n#.#.#.#.#.\n... | 1,611,099,155 | 3,755 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 670 | 62,156,800 | import sys
from collections import deque
input=sys.stdin.readline
n,m,k=map(int,input().split())
grid=[]
grid1=[]
grid2=[]
leftyes=[]
rightyes=[]
upyes=[]
downyes=[]
for i in range(n):
grid.append(input())
grid1.append([-1]*m)
grid2.append([0]*m)
leftyes.append([0]*m)
rightyes.append([0]*m)
... | Title: Olya and Energy Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olya loves energy drinks. She loves them so much that her room is full of empty cans from energy drinks.
Formally, her room can be represented as a field of *n*<=×<=*m* cells, each cell of which is empty or litt... | ```python
import sys
from collections import deque
input=sys.stdin.readline
n,m,k=map(int,input().split())
grid=[]
grid1=[]
grid2=[]
leftyes=[]
rightyes=[]
upyes=[]
downyes=[]
for i in range(n):
grid.append(input())
grid1.append([-1]*m)
grid2.append([0]*m)
leftyes.append([0]*m)
rightyes.append... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,620,487,229 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | length, width = map(int, input().split())
print(length * width // 2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
length, width = map(int, input().split())
print(length * width // 2)
``` | 3.956411 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,672,973,728 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | n, p = int(input()), sorted((int(p), i + 1) for i, p in enumerate(input().split()))
res = p[-1][1], p[-2][0]
print(*res)
| Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
n, p = int(input()), sorted((int(p), i + 1) for i, p in enumerate(input().split()))
res = p[-1][1], p[-2][0]
print(*res)
``` | 3 | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,682,706,344 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 14 | 982 | 18,534,400 | ent1, ent2, ent3 = map(int, input().split())
campo = [list(input().strip()) for _ in range(ent1)]
matriz = [[0]*ent2 for _ in range(ent1)]
passouX = [[False]*ent2 for _ in range(ent1)]
passouY = [[False]*ent2 for _ in range(ent1)]
def buscaProfundidadeAtualiza(a, b, c, d):
# verifica se o ponto já foi visitad... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
ent1, ent2, ent3 = map(int, input().split())
campo = [list(input().strip()) for _ in range(ent1)]
matriz = [[0]*ent2 for _ in range(ent1)]
passouX = [[False]*ent2 for _ in range(ent1)]
passouY = [[False]*ent2 for _ in range(ent1)]
def buscaProfundidadeAtualiza(a, b, c, d):
# verifica se o ponto já f... | -1 | |
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with... | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If per... | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n99... | 1,535,000,883 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 109 | 0 | # Made By Mostafa_Khaled
bot = True
k=int(input())*2
s=''.join(input() for _ in range(4))
if max(s.count(c) for c in '0123456789')>k:
print ('NO')
else:
print('YES')
# Made By Mostafa_Khaled | Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preff... | ```python
# Made By Mostafa_Khaled
bot = True
k=int(input())*2
s=''.join(input() for _ in range(4))
if max(s.count(c) for c in '0123456789')>k:
print ('NO')
else:
print('YES')
# Made By Mostafa_Khaled
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ... | The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order.
The first line contains the coordinates of the square with sides parallel to the ... | Print "Yes" if squares intersect, otherwise print "No".
You can print each letter in any case (upper or lower). | [
"0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n",
"0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n",
"6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the second square lies entirely within the first square, so they do intersect.
In the second sample squares do not have any points in common.
Here are images corresponding to the samples: | 0 | [
{
"input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1",
"output": "NO"
},
{
"input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7",
"output": "YES"
},
{
"input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8",
"output": "YES"
},
... | 1,529,175,746 | 8,846 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 77 | 0 | def area(x1,y1,x2,y2,x3,y3):
return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2)
def check(A,x,y,x1,y1,x2,y2,x3,y3,x4,y4):
A1 = area(x, y, x1, y1, x2, y2)
A2 = area(x, y, x2, y2, x3, y3)
A3 = area(x, y, x3, y3, x4, y4)
A4 = area(x, y, x1, y1, x4, y4)
return (A == A1 + A2 + ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.
The interior of the square is considered to be pa... | ```python
def area(x1,y1,x2,y2,x3,y3):
return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2)
def check(A,x,y,x1,y1,x2,y2,x3,y3,x4,y4):
A1 = area(x, y, x1, y1, x2, y2)
A2 = area(x, y, x2, y2, x3, y3)
A3 = area(x, y, x3, y3, x4, y4)
A4 = area(x, y, x1, y1, x4, y4)
return (A == ... | 0 | |
743 | A | Vladik and flights | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u... | The first line contains three integers *n*, *a*, and *b* (1<=≤<=*n*<=≤<=105, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length *n*, which consists only of characters... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | [
"4 1 4\n1010\n",
"5 5 2\n10110\n"
] | [
"1",
"0"
] | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | 500 | [
{
"input": "4 1 4\n1010",
"output": "1"
},
{
"input": "5 5 2\n10110",
"output": "0"
},
{
"input": "10 9 5\n1011111001",
"output": "1"
},
{
"input": "7 3 7\n1110111",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 3 3\n100101101... | 1,621,609,755 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 0 | n,m,k=map(int,input().split())
p=input()
if p[m-1] == p[k-1]:
print(0)
else:
if p[m-1]=='0' and p[k-1]=='1':
print(8)
p=p[m-1:k]
for i in p:
if i=='1':
l=p.index(i)+1
break
b=l-1
p=list(p)
p.reverse()
... | Title: Vladik and flights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o... | ```python
n,m,k=map(int,input().split())
p=input()
if p[m-1] == p[k-1]:
print(0)
else:
if p[m-1]=='0' and p[k-1]=='1':
print(8)
p=p[m-1:k]
for i in p:
if i=='1':
l=p.index(i)+1
break
b=l-1
p=list(p)
p.rever... | -1 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,689,105,995 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 218 | 0 | wire_count = int(input())
wires = [x for x in map(int, input().split())]
wires.insert(0,0)
for _ in range(int(input())):
wire, bird = map(int, input().split())
left_remaining_birds = (0 + bird) - 1
right_remaining_birds = wires[wire] - bird
if wire == len(wires)-1:
wires[wire] = 0
wires[... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
wire_count = int(input())
wires = [x for x in map(int, input().split())]
wires.insert(0,0)
for _ in range(int(input())):
wire, bird = map(int, input().split())
left_remaining_birds = (0 + bird) - 1
right_remaining_birds = wires[wire] - bird
if wire == len(wires)-1:
wires[wire] = 0
... | 3 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,603,129,105 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 109 | 307,200 | # -*- coding: utf-8 -*-
"""
Created on Mon Oct 19 22:22:28 2020
@author: Dark Soul
"""
[n,k1,k2]=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
diff=[0]*n
for i in range(n):
diff[i]=abs(a[i]-b[i])
diff.sort(reverse=True)
bodla=k1+k2
while(k1):
... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 19 22:22:28 2020
@author: Dark Soul
"""
[n,k1,k2]=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
diff=[0]*n
for i in range(n):
diff[i]=abs(a[i]-b[i])
diff.sort(reverse=True)
bodla=k1+k2
while(... | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,600,456,268 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 748 | 8,806,400 | s=input()
def summer(s):
mst=list(s)
sm=0
for i in range(len(mst)):
sm=sm+int(mst[i])
return str(sm)
cn=0
while(int(s)>9):
s=summer(s)
cn=cn+1
print(cn) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
s=input()
def summer(s):
mst=list(s)
sm=0
for i in range(len(mst)):
sm=sm+int(mst[i])
return str(sm)
cn=0
while(int(s)>9):
s=summer(s)
cn=cn+1
print(cn)
``` | 3.797154 |
996 | B | World Cup | PROGRAMMING | 1,300 | [
"binary search",
"math"
] | null | null | Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen uses the following strategy to enter the fan zone:
- Initially he s... | The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen. | Print a single integer — the number of entrance that Allen will use. | [
"4\n2 3 2 0\n",
"2\n10 10\n",
"6\n5 2 6 5 7 4\n"
] | [
"3\n",
"1\n",
"6\n"
] | In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.
In the second example the number of people... | 1,000 | [
{
"input": "4\n2 3 2 0",
"output": "3"
},
{
"input": "2\n10 10",
"output": "1"
},
{
"input": "6\n5 2 6 5 7 4",
"output": "6"
},
{
"input": "2\n483544186 940350702",
"output": "1"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3",
"output": "7"
},
{
"input": "10\... | 1,694,235,989 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 36 | 93 | 13,619,200 | # -*- coding:utf-8 -*-
# author : utoppia
# description : solutions for codeforces
# updated at : 2023-09-08 22:05:41
# -----------------------------------------------------
# File Name : $%file%$
# Language : Python
# ----------------------------------------------------
def read_int():
return int(inpu... | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zo... | ```python
# -*- coding:utf-8 -*-
# author : utoppia
# description : solutions for codeforces
# updated at : 2023-09-08 22:05:41
# -----------------------------------------------------
# File Name : $%file%$
# Language : Python
# ----------------------------------------------------
def read_int():
retur... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,609,304,043 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s = input()
lst = [a for a in s]
lower = upper = 0
for i in lst:
if i.islower():
lower+=1
else:
upper+=1
if upper>lower:
print(s.upper())
else:
print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
lst = [a for a in s]
lower = upper = 0
for i in lst:
if i.islower():
lower+=1
else:
upper+=1
if upper>lower:
print(s.upper())
else:
print(s.lower())
``` | 3.9455 |
376 | A | Lever | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar is a segment on the *Ox* axis between points 0 and |*s*|<=-<=1.
The decoding of the lever d... | The first line contains the lever description as a non-empty string *s* (3<=≤<=|*s*|<=≤<=106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.
To solve the p... | Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance. | [
"=^==\n",
"9===^==1\n",
"2==^7==\n",
"41^52==\n"
] | [
"balance\n",
"left\n",
"right\n",
"balance\n"
] | As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.
The pictures to the examples: | 500 | [
{
"input": "=^==",
"output": "balance"
},
{
"input": "9===^==1",
"output": "left"
},
{
"input": "2==^7==",
"output": "right"
},
{
"input": "41^52==",
"output": "balance"
},
{
"input": "=^2=4=1===1=",
"output": "right"
},
{
"input": "9=6===5==3=9=1=1^7=... | 1,606,478,984 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 233 | 7,270,400 | s=input().split('^')
ans1=0
ans2=0
lefto=s[0]
righto=s[1]
for j in range(0,len(lefto)):
if(lefto[j]=='='):
continue
else:
ans1+=int(lefto[j])*(len(lefto)-j)
for j in range(0,len(righto)):
if(righto[j]=='='):
continue
else:
ans2+=int(righto[j])*(j+1)
if(ans1... | Title: Lever
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a description of a lever as string *s*. We'll represent the string length as record |*s*|, then the lever looks as a horizontal bar with weights of length |*s*|<=-<=1 with exactly one pivot. We will assume that the bar i... | ```python
s=input().split('^')
ans1=0
ans2=0
lefto=s[0]
righto=s[1]
for j in range(0,len(lefto)):
if(lefto[j]=='='):
continue
else:
ans1+=int(lefto[j])*(len(lefto)-j)
for j in range(0,len(righto)):
if(righto[j]=='='):
continue
else:
ans2+=int(righto[j])*(j+1... | 3 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,606,914,545 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 155 | 0 | l=int(input())
p=int(input())
q=int(input())
ans=round(((l*p)/(p+q)),8)
print(ans) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l=int(input())
p=int(input())
q=int(input())
ans=round(((l*p)/(p+q)),8)
print(ans)
``` | 3 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,679,519,000 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | from math import sqrt
def generate_subsequences(s, memo=[]):
if len(s) == 1:
memo.append(s)
return [s]
else:
first_letter = s[0]
smaller_subs = generate_subsequences(s[1:]).copy()
for subs in smaller_subs:
memo.append(first_letter + subs)
... | Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
from math import sqrt
def generate_subsequences(s, memo=[]):
if len(s) == 1:
memo.append(s)
return [s]
else:
first_letter = s[0]
smaller_subs = generate_subsequences(s[1:]).copy()
for subs in smaller_subs:
memo.append(first_letter + subs... | 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,674,413,677 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 592 | 77,414,400 | a=input().split()
a=list(map(int,a))
b=a[0]-a[1]
l=[0 for c in range(b)]
cont=0
for c in range(int(b**(1/2))):
k=b%(c+1)
if k!=0:
continue
elif (c+1)>a[1]:
cont+=2
elif b/(c+1)>a[1]:
cont+=1
if b==0:
print('infinity')
else:
print(cont)
| 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=input().split()
a=list(map(int,a))
b=a[0]-a[1]
l=[0 for c in range(b)]
cont=0
for c in range(int(b**(1/2))):
k=b%(c+1)
if k!=0:
continue
elif (c+1)>a[1]:
cont+=2
elif b/(c+1)>a[1]:
cont+=1
if b==0:
print('infinity')
else:
print(cont)
``` | -1 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,695,659,208 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | x1,x2,x3=map(int,input().split())
list1=[x1,x2,x3]
list1.sort()
dis=(list1[1]-list1[0])+(list1[2]-list1[1])
print(dis) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x1,x2,x3=map(int,input().split())
list1=[x1,x2,x3]
list1.sort()
dis=(list1[1]-list1[0])+(list1[2]-list1[1])
print(dis)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,510,958,690 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 154 | 102,400 | from collections import Counter
def main():
n = int(input().strip())
i = 0
scores = Counter()
max_score = 0
max_score_guy = None
while i < n:
name, score = input().strip().split(' ')
score = int(score)
scores[name] += score
if max_score < scores[name]:
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from collections import Counter
def main():
n = int(input().strip())
i = 0
scores = Counter()
max_score = 0
max_score_guy = None
while i < n:
name, score = input().strip().split(' ')
score = int(score)
scores[name] += score
if max_score < scores[name... | 0 |
722 | C | Destroying Array | PROGRAMMING | 1,600 | [
"data structures",
"dsu"
] | null | null | You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed.
After each element is destroyed you have to find o... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. | Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. | [
"4\n1 3 2 5\n3 4 1 2\n",
"5\n1 2 3 4 5\n4 2 3 5 1\n",
"8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n"
] | [
"5\n4\n3\n0\n",
"6\n5\n5\n1\n0\n",
"18\n16\n11\n8\n8\n6\n6\n0\n"
] | Consider the first sample:
1. Third element is destroyed. Array is now 1 3 * 5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3 * * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now * 3 * * . Segme... | 1,000 | [
{
"input": "4\n1 3 2 5\n3 4 1 2",
"output": "5\n4\n3\n0"
},
{
"input": "5\n1 2 3 4 5\n4 2 3 5 1",
"output": "6\n5\n5\n1\n0"
},
{
"input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6",
"output": "18\n16\n11\n8\n8\n6\n6\n0"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8"... | 1,555,193,125 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 1,228,800 | h=int(input())
list1=[*map(int,input().split())]
destroy=[*map(int,input().split())]
for i in range(h):
for j in range(h):
list1[destroy[j] - 1] = -1
sums=[]
x=0
y=0
for k in range(h):
while list1[x]!=-1 :
y+=list1[x]
... | Title: Destroying Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defin... | ```python
h=int(input())
list1=[*map(int,input().split())]
destroy=[*map(int,input().split())]
for i in range(h):
for j in range(h):
list1[destroy[j] - 1] = -1
sums=[]
x=0
y=0
for k in range(h):
while list1[x]!=-1 :
y+=list1[x]
... | 0 | |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | The input contains of a single integer *n* (0<=≤<=*n*<=<<=109) — the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input... | 1,612,366,595 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 38 | 2,000 | 2,355,200 | import math
def fibonacci(n):
if math.sqrt(5*n*n+4)%1==0 or math.sqrt(5*n*n-4)%1==0:
return True
return False
n = int(input())
if n==0:
print(0,0,0)
elif n==1:
print(1,0,0)
elif n==2:
print(1,1,0)
else:
for i in range(n-1,-1,-1):
if fibonacci(i):
k=i
... | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let'... | ```python
import math
def fibonacci(n):
if math.sqrt(5*n*n+4)%1==0 or math.sqrt(5*n*n-4)%1==0:
return True
return False
n = int(input())
if n==0:
print(0,0,0)
elif n==1:
print(1,0,0)
elif n==2:
print(1,1,0)
else:
for i in range(n-1,-1,-1):
if fibonacci(i):
... | 0 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,533,647,216 | 2,456 | Python 3 | OK | TESTS | 18 | 124 | 0 | n,m,s,k=list(map(int,input().split()))
for mnoj in range(1,10001):
if s*mnoj>=m:
pl=mnoj
break
amount=pl*n
add=amount%k
if add==0:
print(amount//k)
else:
add=k-add
amount+=add
print(amount//k) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
n,m,s,k=list(map(int,input().split()))
for mnoj in range(1,10001):
if s*mnoj>=m:
pl=mnoj
break
amount=pl*n
add=amount%k
if add==0:
print(amount//k)
else:
add=k-add
amount+=add
print(amount//k)
``` | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,699,966,644 | 444 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | n = int(input())
Lx = [int(i) for i in input().split(" ")]
Ly = [int(i) for i in input().split(" ")]
for i in range(1,n+1):
if not (i in Lx or Ly):
print("Oh, my keyboard!")
exit()
print("I become the guy.") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
Lx = [int(i) for i in input().split(" ")]
Ly = [int(i) for i in input().split(" ")]
for i in range(1,n+1):
if not (i in Lx or Ly):
print("Oh, my keyboard!")
exit()
print("I become the guy.")
``` | 0 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,609,329,785 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | s = input().strip()
N = int(input())
ans = s
found = -1
for i in range(N):
j = input().strip()
if j.startswith(s):
print(j)
if found==-1:
ans = j
found=1
if ans > j:
ans = j
print(ans) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s = input().strip()
N = int(input())
ans = s
found = -1
for i in range(N):
j = input().strip()
if j.startswith(s):
print(j)
if found==-1:
ans = j
found=1
if ans > j:
ans = j
print(ans)
``` | 0 |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,667,411,267 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | a = int(input())
b = [int(i) for i in input().split()]
c = set(b)
d = list(c)
maxi = 0
for i in range(len(d)):
cur = b.count(d[i])
if cur > maxi:
maxi = cur
print(maxi, len(c))
| Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
a = int(input())
b = [int(i) for i in input().split()]
c = set(b)
d = list(c)
maxi = 0
for i in range(len(d)):
cur = b.count(d[i])
if cur > maxi:
maxi = cur
print(maxi, len(c))
``` | 3.977 |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,571,477,638 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | x=int(input())
y=int(input())
a=abs(x-y)
b=a//2
if a%2==0:
c=b*(b+1)
else :
c=(b*(b+1)//2)+((m+1)*(m+2)//2)
print(c) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
x=int(input())
y=int(input())
a=abs(x-y)
b=a//2
if a%2==0:
c=b*(b+1)
else :
c=(b*(b+1)//2)+((m+1)*(m+2)//2)
print(c)
``` | -1 | |
722 | B | Verse Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guarant... | If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | 500 | [
{
"input": "3\n2 2 3\nintel\ncode\nch allenge",
"output": "YES"
},
{
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz",
"output": "NO"
},
{
"input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageo... | 1,478,891,757 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 62 | 0 | def main():
from sys import stdin, stdout
# stdin = open("input.txt", "r")
inp = stdin.readlines()
n = int(inp[0])
versePattern = iter(map(int, inp[1].split()))
ans = True
for line in inp[2:]:
vowelCnt = 0
for x in line:
if x in "aeiouy":
vowelCnt += 1
if vowelCnt != nex... | Title: Verse Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary num... | ```python
def main():
from sys import stdin, stdout
# stdin = open("input.txt", "r")
inp = stdin.readlines()
n = int(inp[0])
versePattern = iter(map(int, inp[1].split()))
ans = True
for line in inp[2:]:
vowelCnt = 0
for x in line:
if x in "aeiouy":
vowelCnt += 1
if vowel... | 3 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,562,861,411 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n=int(input())
mat = []
mat.append('x'*(n+1))
for i in range(n):
mat.append('x'+input()+'x')
output = "YES"
for i in range(1,n):
if output == "NO":
break
for j in range(n):
s=0
if mat[i][j+1] == 'o':
s+=1
if mat[i][j-1] == 'o':
s+=1
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n=int(input())
mat = []
mat.append('x'*(n+1))
for i in range(n):
mat.append('x'+input()+'x')
output = "YES"
for i in range(1,n):
if output == "NO":
break
for j in range(n):
s=0
if mat[i][j+1] == 'o':
s+=1
if mat[i][j-1] == 'o':
... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,443,539,448 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 0 | n = int(input())
a = list(map(int, input().split()))
even = 0
lastE = -1
odd = 0
lastO = -1
for i in range(n):
if a[i] % 2:
odd += 1
lastO = i
else:
even += 1
lastE = i
if odd == 1:
print(lastO + 1)
else:
print(lastE + 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()))
even = 0
lastE = -1
odd = 0
lastO = -1
for i in range(n):
if a[i] % 2:
odd += 1
lastO = i
else:
even += 1
lastE = i
if odd == 1:
print(lastO + 1)
else:
print(lastE + 1)
``` | 3.9615 |
626 | C | Block Towers | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"math",
"number theory"
] | null | null | Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use pieces made of three blocks.
The students don’t want to use too many blocks, but they also want to be ... | The first line of the input contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=1<=000<=000, *n*<=+<=*m*<=><=0) — the number of students using two-block pieces and the number of students using three-block pieces, respectively. | Print a single integer, denoting the minimum possible height of the tallest tower. | [
"1 3\n",
"3 2\n",
"5 0\n"
] | [
"9\n",
"8\n",
"10\n"
] | In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
In the second case, the students can make towers of heights 2, 4, and 8 with two-block pieces and tower... | 1,000 | [
{
"input": "1 3",
"output": "9"
},
{
"input": "3 2",
"output": "8"
},
{
"input": "5 0",
"output": "10"
},
{
"input": "4 2",
"output": "9"
},
{
"input": "0 1000000",
"output": "3000000"
},
{
"input": "1000000 1",
"output": "2000000"
},
{
"in... | 1,616,402,976 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | n, m = input().split()
n = int(n)
m = int(m)
res_n = n * 2
res_m = m * 3
tmp_height = 0
while(tmp_height < min(res_n, res_m)):
tmp_height += 6
tmpresn = res_n + 2
tmpresm = res_m + 3
if max(tmpresn, res_m) > max(res_n, tmpresm):
res_m = tmpresm
else:
res_n = tmpresn
print(max(... | Title: Block Towers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. *n* of the students use pieces made of two blocks and *m* of the students use piece... | ```python
n, m = input().split()
n = int(n)
m = int(m)
res_n = n * 2
res_m = m * 3
tmp_height = 0
while(tmp_height < min(res_n, res_m)):
tmp_height += 6
tmpresn = res_n + 2
tmpresm = res_m + 3
if max(tmpresn, res_m) > max(res_n, tmpresm):
res_m = tmpresm
else:
res_n = tmpresn
... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,637,610,170 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | s=input()
count=0
for i in s:
if count==0 and i=='h':
count+=1
elif count==1 and i=='e':
count+=1
elif count==2 and i=='l':
count+=1
elif count==3 and i=='l':
count+=1
elif count==4 and i=='o':
count+=1
if count==5:
print('YES')
else:
p... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
count=0
for i in s:
if count==0 and i=='h':
count+=1
elif count==1 and i=='e':
count+=1
elif count==2 and i=='l':
count+=1
elif count==3 and i=='l':
count+=1
elif count==4 and i=='o':
count+=1
if count==5:
print('YES')
el... | 3.969 |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,580,704,040 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | n=int(input())
l=list(map(int, input().split()))
l2=[]
for x in l:
if x not in l2 and x!=0:
l2.append(x)
print(len(l2)) | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
n=int(input())
l=list(map(int, input().split()))
l2=[]
for x in l:
if x not in l2 and x!=0:
l2.append(x)
print(len(l2))
``` | 3 | |
797 | A | k-Factorization | PROGRAMMING | 1,100 | [
"implementation",
"math",
"number theory"
] | null | null | Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20). | If it's impossible to find the representation of *n* as a product of *k* numbers, print -1.
Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. | [
"100000 2\n",
"100000 20\n",
"1024 5\n"
] | [
"2 50000 \n",
"-1\n",
"2 64 2 2 2 \n"
] | none | 0 | [
{
"input": "100000 2",
"output": "2 50000 "
},
{
"input": "100000 20",
"output": "-1"
},
{
"input": "1024 5",
"output": "2 64 2 2 2 "
},
{
"input": "100000 10",
"output": "2 2 2 2 2 5 5 5 5 5 "
},
{
"input": "99999 3",
"output": "3 813 41 "
},
{
"input... | 1,667,299,836 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 166 | 62 | 1,331,200 | def findPrimeFactors(n):
ans=[]
i=2
while(i<=(n+1)):
while(n%i==0):
ans.append(i)
n=n//i
i+=1
return ans
n,k=map(int,input().split())
l=findPrimeFactors(n)
if(len(l)<k):
print(-1)
e... | Title: k-Factorization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
Input Specification:
The first line contains two int... | ```python
def findPrimeFactors(n):
ans=[]
i=2
while(i<=(n+1)):
while(n%i==0):
ans.append(i)
n=n//i
i+=1
return ans
n,k=map(int,input().split())
l=findPrimeFactors(n)
if(len(l)<k):
pr... | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,587,022,899 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | y, w = map(int, input().split())
if y%w==0:
y = y//w
if w%y==0:
w = w//y
print(w,"/",y) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
y, w = map(int, input().split())
if y%w==0:
y = y//w
if w%y==0:
w = w//y
print(w,"/",y)
``` | 0 |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,620,457,894 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 14,438,400 | n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
Vasya=0
Petya=0
for i in b:
for j in a:
Vasya+=1
if i==j:
break
c=a[::-1]
for k in c:
Petya+=1
if i==k:
break
print(str(Vasya)+" "... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
a = list(map(int,input().split()))
m = int(input())
b = list(map(int,input().split()))
Vasya=0
Petya=0
for i in b:
for j in a:
Vasya+=1
if i==j:
break
c=a[::-1]
for k in c:
Petya+=1
if i==k:
break
print(str(... | 0 | |
245 | E | Mishap in Club | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. | Print the sought minimum number of people | [
"+-+-+\n",
"---"
] | [
"1\n",
"3"
] | none | 0 | [
{
"input": "+-+-+",
"output": "1"
},
{
"input": "---",
"output": "3"
},
{
"input": "-",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "---",
"output": "3"
},
{
"input": "----",
"output": "4"
},
{
"input": "---+",
"output... | 1,614,319,723 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | #Problem N
line = input()
enter = 0
leave = 0
for i in line:
if i == '+':
enter += 1
if leave > 0:
leave -= 1
if i == '-':
leave += 1
if enter > 0:
enter -= 1
print(enter + leave)
| Title: Mishap in Club
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitor... | ```python
#Problem N
line = input()
enter = 0
leave = 0
for i in line:
if i == '+':
enter += 1
if leave > 0:
leave -= 1
if i == '-':
leave += 1
if enter > 0:
enter -= 1
print(enter + leave)
``` | 3 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,539,691,568 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n = int(input())
m = int(input())
n = n % 6
a = []
if n == 0:
a = [0,1,2]
elif n == 1:
a = [1,0,2]
elif n == 2:
a = [1,2,0]
elif n == 3:
a = [2,1,0]
elif n == 4:
a = [2,0,1]
elif n == 5:
a = [0,2,1]
for i in [0,1,2]:
if a[i] == m:
print(i) | Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
n = int(input())
m = int(input())
n = n % 6
a = []
if n == 0:
a = [0,1,2]
elif n == 1:
a = [1,0,2]
elif n == 2:
a = [1,2,0]
elif n == 3:
a = [2,1,0]
elif n == 4:
a = [2,0,1]
elif n == 5:
a = [0,2,1]
for i in [0,1,2]:
if a[i] == m:
print(i)
``` | 0 | |
328 | A | IQ Test | PROGRAMMING | 1,800 | [
"implementation"
] | null | null | Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence *a*1, *a*1<=+<=*d*, *a*1<=+<=2*d*, ..., *a*1<=+<=(*n*<=-<=1)*d*, where *a*1 ... | The first line contains exactly four integer numbers between 1 and 1000, inclusively. | Print the required number. If the given sequence is arithmetic progression, print the next progression element. Similarly, if the given sequence is geometric progression, print the next progression element.
Print 42 if the given sequence is not an arithmetic or geometric progression. | [
"836 624 412 200\n",
"1 334 667 1000\n"
] | [
"-12\n",
"1333\n"
] | This problem contains very weak pretests! | 500 | [
{
"input": "836 624 412 200",
"output": "-12"
},
{
"input": "1 334 667 1000",
"output": "1333"
},
{
"input": "501 451 400 350",
"output": "42"
},
{
"input": "836 624 412 200",
"output": "-12"
},
{
"input": "1 334 667 1000",
"output": "1333"
},
{
"input... | 1,612,685,584 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,150,400 | def test_geometric(in_list):
geometric = True
for nr in in_list:
if nr == 0:
return False
else:
quotient = in_list[1] / in_list[0]
current_nr = in_list[0]
for nr in in_list[1:]:
if nr / current_nr != quotient:
geometric = Fals... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progressi... | ```python
def test_geometric(in_list):
geometric = True
for nr in in_list:
if nr == 0:
return False
else:
quotient = in_list[1] / in_list[0]
current_nr = in_list[0]
for nr in in_list[1:]:
if nr / current_nr != quotient:
geomet... | -1 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,413,058,492 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | n = 0
t = 0
while True:
#try:
l = input()
if len(l) == 0 : break
if l[0] == '+':
n += 1
elif l[0] == '-':
n -= 1
else:
t += n*len((l.split(':')[1]))
#except:
#break
print(t) | Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
n = 0
t = 0
while True:
#try:
l = input()
if len(l) == 0 : break
if l[0] == '+':
n += 1
elif l[0] == '-':
n -= 1
else:
t += n*len((l.split(':')[1]))
#except:
#break
print(t)
``` | -1 |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,526,795,808 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 93 | 0 | arr=list(map(int,input().split()))
if arr.count(1)>=1 or arr.count(2)>=2 or arr.count(3)>=3 or (arr.count(4)==2 and arr.count(2)==1):
print("YES")
else:
print("NO") | Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
arr=list(map(int,input().split()))
if arr.count(1)>=1 or arr.count(2)>=2 or arr.count(3)>=3 or (arr.count(4)==2 and arr.count(2)==1):
print("YES")
else:
print("NO")
``` | 3 | |
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,450,263,293 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 216 | 0 | n=int(input())
inp=input().split()
for i in range(n):inp[i]=int(inp[i])
if inp[0]%2+inp[1]%2+inp[2]%2>=2:
for i in range(n):
if inp[i]%2==0:print (i+1)
else:
for i in range(n):
if inp[i]%2==1:print (i+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())
inp=input().split()
for i in range(n):inp[i]=int(inp[i])
if inp[0]%2+inp[1]%2+inp[2]%2>=2:
for i in range(n):
if inp[i]%2==0:print (i+1)
else:
for i in range(n):
if inp[i]%2==1:print (i+1)
``` | 3.946 |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,671,961,121 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | def check_palindrome(mytxt):
n = len(mytxt)
count =0
for i in range(len(mytxt)//2):
if mytxt[i] != mytxt[n-1]:
count = count+1
n = n-1
return count
mytxt = input()
a = check_palindrome(mytxt)
if a==1:
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
def check_palindrome(mytxt):
n = len(mytxt)
count =0
for i in range(len(mytxt)//2):
if mytxt[i] != mytxt[n-1]:
count = count+1
n = n-1
return count
mytxt = input()
a = check_palindrome(mytxt)
if a==1:
print("YES")
else:
print("NO")
``` | 0 | |
37 | C | Old Berland Language | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"trees"
] | C. Old Berland Language | 2 | 256 | Berland scientists know that the Old Berland language had exactly *n* words. Those words had lengths of *l*1,<=*l*2,<=...,<=*l**n* letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each ... | The first line contains one integer *N* (1<=≤<=*N*<=≤<=1000) — the number of words in Old Berland language. The second line contains *N* space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. | If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next *N* lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. | [
"3\n1 2 3\n",
"3\n1 1 1\n"
] | [
"YES\n0\n10\n110\n",
"NO\n"
] | none | 1,500 | [
{
"input": "3\n1 2 3",
"output": "YES\n0\n10\n110"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "10\n4 4 4 4 4 4 4 4 4 4",
"output": "YES\n0000\n0001\n0010\n0011\n0100\n0101\n0110\n0111\n1000\n1001"
},
{
"input": "20\n6 7 7 7 7 6 7 7 7 7 7 7 7 7 7 7 7 7 6 7",
"o... | 1,547,316,748 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 248 | 3,584,000 | class Node:
def __init__(self):
self.endWord = False
self.children = {}
def withC(root, num, s, changed):
if root.endWord == True:
return ''
if num == 0:
root.endWord = True
if changed == False:
return ''
return s
for c in ['0', '1']:
if c not in root.chi... | Title: Old Berland Language
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Berland scientists know that the Old Berland language had exactly *n* words. Those words had lengths of *l*1,<=*l*2,<=...,<=*l**n* letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke qui... | ```python
class Node:
def __init__(self):
self.endWord = False
self.children = {}
def withC(root, num, s, changed):
if root.endWord == True:
return ''
if num == 0:
root.endWord = True
if changed == False:
return ''
return s
for c in ['0', '1']:
if c not i... | -1 |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,482,141,495 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 74 | 62 | 4,608,000 | n = int(input())
s = str(input())
if n % 4 != 0:
print("===")
exit()
div = n // 4
a, g, c, t = 0, 0, 0, 0
for i in range(n):
if any([a>div, g>div, c>div, t>div]):
print("===")
exit()
else:
cur = s[i]
if cur == 'A':
a += 1
elif cur ... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
n = int(input())
s = str(input())
if n % 4 != 0:
print("===")
exit()
div = n // 4
a, g, c, t = 0, 0, 0, 0
for i in range(n):
if any([a>div, g>div, c>div, t>div]):
print("===")
exit()
else:
cur = s[i]
if cur == 'A':
a += 1
... | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,616,762,378 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 248 | 1,740,800 | from math import inf
n = int(input())
rounds = []
for i in range(n):
a,b = input().split()
rounds.append([a,int(b)])
tot_scores = {}
for i in range(n):
move = rounds[i]
tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1]
m = -inf
for player in tot_scores:
m = max(m, tot_scores[play... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from math import inf
n = int(input())
rounds = []
for i in range(n):
a,b = input().split()
rounds.append([a,int(b)])
tot_scores = {}
for i in range(n):
move = rounds[i]
tot_scores[move[0]] = tot_scores.get(move[0],0) + move[1]
m = -inf
for player in tot_scores:
m = max(m, tot_s... | 3.86303 |
985 | B | Switches and Lamps | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps.
The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise.
It is guar... | Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. | [
"4 5\n10101\n01000\n00111\n10000\n",
"4 5\n10100\n01000\n00110\n00101\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "4 5\n10101\n01000\n00111\n10000",
"output": "YES"
},
{
"input": "4 5\n10100\n01000\n00110\n00101",
"output": "NO"
},
{
"input": "1 5\n11111",
"output": "NO"
},
{
"input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1",
"output": "YES"
},
{
"input": "1 1\n1",
... | 1,600,387,237 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 670 | 25,804,800 | n,m=map(int,input().split())
ar=[]
for i in range(n):
ar.append(list(map(int,list(input()))))
br=[0]*m
for i in range(n):
for j in range(m):
br[j]+=ar[i][j]
flag=False
for i in range(n):
f1=True
for j in range(m):
if(ar[i][j]==1 and br[j]==1):
f1=False
... | Title: Switches and Lamps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th... | ```python
n,m=map(int,input().split())
ar=[]
for i in range(n):
ar.append(list(map(int,list(input()))))
br=[0]*m
for i in range(n):
for j in range(m):
br[j]+=ar[i][j]
flag=False
for i in range(n):
f1=True
for j in range(m):
if(ar[i][j]==1 and br[j]==1):
f1=False
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give i... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500<=000,<=0<=≤<=*k*<=≤<=109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement.
The second line contains *n* integers, the *i*-th of them is *c**i* (1<=≤<=*c**i*<=≤<=109) — initial wealth of the *i... | Print a single line containing the difference between richest and poorest peoples wealth. | [
"4 1\n1 1 4 2\n",
"3 1\n2 2 2\n"
] | [
"2\n",
"0\n"
] | Lets look at how wealth changes through day in the first sample.
1. [1, 1, 4, 2] 1. [2, 1, 3, 2] or [1, 2, 3, 2]
So the answer is 3 - 1 = 2
In second sample wealth will remain the same for each person. | 0 | [
{
"input": "4 1\n1 1 4 2",
"output": "2"
},
{
"input": "3 1\n2 2 2",
"output": "0"
},
{
"input": "10 20\n6 4 7 10 4 5 5 3 7 10",
"output": "1"
},
{
"input": "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2",
"output": "2"
},
{
"input": "2 0\n182 ... | 1,663,580,871 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 51,609,600 | no_of_citizens, days_left_for_retirement = map(int, input().split())
wealth = list(map(int, input().split()))
if sum(wealth) == wealth[0]*no_of_citizens:
print(0)
else:
while days_left_for_retirement:
wealth[wealth.index(max(wealth))] -= 1
wealth[wealth.index(min(wealth))] += 1
d... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, ... | ```python
no_of_citizens, days_left_for_retirement = map(int, input().split())
wealth = list(map(int, input().split()))
if sum(wealth) == wealth[0]*no_of_citizens:
print(0)
else:
while days_left_for_retirement:
wealth[wealth.index(max(wealth))] -= 1
wealth[wealth.index(min(wealth))] += 1
... | 0 | |
862 | C | Mahmoud and Ehab and the xor | PROGRAMMING | 1,900 | [
"constructive algorithms"
] | null | null | Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to replenish his beautiful collection of sets.
Dr. Evil has his favorite evil integer *x*. He asks Mahmoud and Ehab to... | The only line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105, 0<=≤<=*x*<=≤<=105) — the number of elements in the set and the desired bitwise-xor, respectively. | If there is no such set, print "NO" (without quotes).
Otherwise, on the first line print "YES" (without quotes) and on the second line print *n* distinct integers, denoting the elements in the set is any order. If there are multiple solutions you can print any of them. | [
"5 5\n",
"3 6\n"
] | [
"YES\n1 2 4 5 7",
"YES\n1 2 5"
] | You can read more about the bitwise-xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR)
For the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb8ccd05d3a7a41eff93c98f79d158cf85e702f9.png" style="max-w... | 1,500 | [
{
"input": "5 5",
"output": "YES\n1 2 131072 131078 0 "
},
{
"input": "3 6",
"output": "YES\n131072 131078 0 "
},
{
"input": "3 0",
"output": "YES\n393216 131072 262144"
},
{
"input": "1 0",
"output": "YES\n0"
},
{
"input": "3 3",
"output": "YES\n131072 131075... | 1,506,723,641 | 6,041 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | arr=list(map(int,input().strip().split(' ')))
n,x=arr[0],arr[1]
if(n==1):
print(x)
elif(n==2):
if(x%2==1):
ans=x-1
else:
ans=x+1
alist=[1,ans]
elif(n==3):
alist=[1,2]
alist.append(3^x)
else:
i=0
ans=0
alist=[]
while(len(alist)<n-2):
ans=a... | Title: Mahmoud and Ehab and the xor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set to re... | ```python
arr=list(map(int,input().strip().split(' ')))
n,x=arr[0],arr[1]
if(n==1):
print(x)
elif(n==2):
if(x%2==1):
ans=x-1
else:
ans=x+1
alist=[1,ans]
elif(n==3):
alist=[1,2]
alist.append(3^x)
else:
i=0
ans=0
alist=[]
while(len(alist)<n-2):
... | -1 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,600,334,900 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 155 | 0 | char_list = [char for char in input()]
q_before = [0] * len(char_list)
q_before[0] = 1 if char_list[0] == 'Q' else 0
for i in range(1, len(char_list)):
q_before[i] = q_before[i-1]
if char_list[i] == 'Q':
q_before[i] += 1
qa_before = [0] * len(char_list)
for i in range(1, len(char_list)):
qa_before[i] = qa_before... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
char_list = [char for char in input()]
q_before = [0] * len(char_list)
q_before[0] = 1 if char_list[0] == 'Q' else 0
for i in range(1, len(char_list)):
q_before[i] = q_before[i-1]
if char_list[i] == 'Q':
q_before[i] += 1
qa_before = [0] * len(char_list)
for i in range(1, len(char_list)):
qa_before[i] =... | 3 | |
769 | A | Year of University Entrance | PROGRAMMING | 800 | [
"*special",
"implementation",
"sortings"
] | null | null | There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university.
Each of students joins the group of his course and joins all groups f... | The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member.
It is guaranteed tha... | Print the year of Igor's university entrance. | [
"3\n2014 2016 2015\n",
"1\n2050\n"
] | [
"2015\n",
"2050\n"
] | In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016.
In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance. | 500 | [
{
"input": "3\n2014 2016 2015",
"output": "2015"
},
{
"input": "1\n2050",
"output": "2050"
},
{
"input": "1\n2010",
"output": "2010"
},
{
"input": "1\n2011",
"output": "2011"
},
{
"input": "3\n2010 2011 2012",
"output": "2011"
},
{
"input": "3\n2049 20... | 1,488,630,502 | 1,702 | Python 3 | OK | TESTS | 45 | 62 | 4,608,000 | """ Created by Shahen Kosyan on 3/4/17 """
if __name__ == "__main__":
n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
print(arr[len(arr) // 2])
| Title: Year of University Entrance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond... | ```python
""" Created by Shahen Kosyan on 3/4/17 """
if __name__ == "__main__":
n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
print(arr[len(arr) // 2])
``` | 3 | |
88 | A | Chord | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | A. Chord | 2 | 256 | Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | The only line contains 3 space-separated notes in the above-given notation. | Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. | [
"C E G\n",
"C# B F\n",
"A B H\n"
] | [
"major\n",
"minor\n",
"strange\n"
] | none | 500 | [
{
"input": "C E G",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A B H",
"output": "strange"
},
{
"input": "G H E",
"output": "minor"
},
{
"input": "D# B G",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"... | 1,631,408,371 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 248 | 20,172,800 | def nm(a):
s = list(map(lambda i:a.index(i),input().split()))
for i in range(3):
s.sort()
x,y = abs(s[0] - s[1]),abs(s[1] - s[2])
if [x,y] == [4,3]:
return 'major'
elif [x,y] == [3,4]:
return 'minor'
s[0] += 12
return 'strange'
print... | Title: Chord
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and b... | ```python
def nm(a):
s = list(map(lambda i:a.index(i),input().split()))
for i in range(3):
s.sort()
x,y = abs(s[0] - s[1]),abs(s[1] - s[2])
if [x,y] == [4,3]:
return 'major'
elif [x,y] == [3,4]:
return 'minor'
s[0] += 12
return 'stran... | 3.900425 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,535,048,225 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 0 | l,r=map(int,input().split());
if l&1==1: l+=1;
if l+2>r: print(-1);
else: print(l,l+1,l+2);
# Made By Mostafa_Khaled | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l,r=map(int,input().split());
if l&1==1: l+=1;
if l+2>r: print(-1);
else: print(l,l+1,l+2);
# Made By Mostafa_Khaled
``` | 3 | |
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other ... | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if ... | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.pn... | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
... | 1,607,666,477 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 109 | 0 | d,L,v1,v2=map(int,input().split())
t=(L-d)/(v1+v2)
print('{0:.9f}'.format(t)) | Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a strai... | ```python
d,L,v1,v2=map(int,input().split())
t=(L-d)/(v1+v2)
print('{0:.9f}'.format(t))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | D. Falling Anvils | 2 | 256 | For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who ... | The first line contains integer *t* (1<=≤<=*t*<=≤<=10000) — amount of testcases.
Each of the following *t* lines contain two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=106).
Pretests contain all the tests with 0<=<<=*a*<=<<=10,<=0<=≤<=*b*<=<<=10. | Print *t* lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed 10<=-<=6. | [
"2\n4 2\n1 2\n"
] | [
"0.6250000000\n0.5312500000\n"
] | none | 0 | [] | 1,541,945,725 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 1 | 404 | 1,024,000 |
def calArea(a, b):
if a <= 4 * b:
return a * min(b, a / 4) / 2
return b * b * 2 + (a - 4 * b) * b
for _ in range(int(input())):
a, b = map(int, input().split())
print("{:.8f}".format(calArea(a, b) / (2 * a * b) + 0.5))
| Title: none
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.
Anvils come in different sizes and shapes. ... | ```python
def calArea(a, b):
if a <= 4 * b:
return a * min(b, a / 4) / 2
return b * b * 2 + (a - 4 * b) * b
for _ in range(int(input())):
a, b = map(int, input().split())
print("{:.8f}".format(calArea(a, b) / (2 * a * b) + 0.5))
``` | -1 |
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, th... | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/c... | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWW... | 1,662,899,187 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | ij = input()
lst = []
for a in ij.split('\n'):
lst.append(list(a))
k = 0
for j in range(8):
if lst[0][j] == "B":
k += 1
if k == 8:
k = 1
if k == 1:
for i in range(1, 8):
if lst[i][0] == "B":
k += 1
else:
for i in range(8):
if lst[i][0] == "... | Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de... | ```python
ij = input()
lst = []
for a in ij.split('\n'):
lst.append(list(a))
k = 0
for j in range(8):
if lst[0][j] == "B":
k += 1
if k == 8:
k = 1
if k == 1:
for i in range(1, 8):
if lst[i][0] == "B":
k += 1
else:
for i in range(8):
if lst[... | -1 |
88 | A | Chord | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | A. Chord | 2 | 256 | Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | The only line contains 3 space-separated notes in the above-given notation. | Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. | [
"C E G\n",
"C# B F\n",
"A B H\n"
] | [
"major\n",
"minor\n",
"strange\n"
] | none | 500 | [
{
"input": "C E G",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A B H",
"output": "strange"
},
{
"input": "G H E",
"output": "minor"
},
{
"input": "D# B G",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"... | 1,564,336,445 | 2,147,483,647 | Python 3 | OK | TESTS | 75 | 248 | 0 | acords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
lst = sorted(acords.index(x) for x in input().split())
dif = (lst[1] - lst[0], lst[2] - lst[1])
if dif in ((4, 3), (3, 5), (5, 4)):
print('major')
elif dif in ((3, 4), (4, 5), (5, 3)):
print('minor')
else:
print('strange')
| Title: Chord
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and b... | ```python
acords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
lst = sorted(acords.index(x) for x in input().split())
dif = (lst[1] - lst[0], lst[2] - lst[1])
if dif in ((4, 3), (3, 5), (5, 4)):
print('major')
elif dif in ((3, 4), (4, 5), (5, 3)):
print('minor')
else:
print('str... | 3.938 |
120 | B | Quiz League | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 ... | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | [
"5 5\n0 1 0 1 0\n",
"2 1\n1 1\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "5 5\n0 1 0 1 0",
"output": "2"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "3 2\n1 0 0",
"output": "1"
},
{
"input": "3 3\n0 1 0",
"output": "2"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "6 3\n0 0 1 1 0 1",
"output":... | 1,586,351,394 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n,k = map(int,input().split())
l = list(map(int,input().split()))
k = k - 1
while(1):
if(l[k] == 0):
k = k + 1
k = k % n
if(l[k] == 1):
break
print(k+1)
| Title: Quiz League
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a quest... | ```python
n,k = map(int,input().split())
l = list(map(int,input().split()))
k = k - 1
while(1):
if(l[k] == 0):
k = k + 1
k = k % n
if(l[k] == 1):
break
print(k+1)
``` | -1 | |
843 | A | Sorting by Subsequences | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu",
"implementation",
"math",
"sortings"
] | null | null | You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order.
Sorting integers in a sub... | The first line of input data contains integer *n* (1<=≤<=*n*<=≤<=105) — the length of the sequence.
The second line of input data contains *n* different integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of the sequence. It is guaranteed that all elements of the sequence are distinct. | In the first line print the maximum number of subsequences *k*, which the original sequence can be split into while fulfilling the requirements.
In the next *k* lines print the description of subsequences in the following format: the number of elements in subsequence *c**i* (0<=<<=*c**i*<=≤<=*n*), then *c**i* integ... | [
"6\n3 2 1 6 5 4\n",
"6\n83 -75 -49 11 37 62\n"
] | [
"4\n2 1 3\n1 2\n2 4 6\n1 5\n",
"1\n6 1 2 3 4 5 6\n"
] | In the first sample output:
After sorting the first subsequence we will get sequence 1 2 3 6 5 4.
Sorting the second subsequence changes nothing.
After sorting the third subsequence we will get sequence 1 2 3 4 5 6.
Sorting the last subsequence changes nothing. | 500 | [
{
"input": "6\n3 2 1 6 5 4",
"output": "4\n2 1 3\n1 2\n2 4 6\n1 5"
},
{
"input": "6\n83 -75 -49 11 37 62",
"output": "1\n6 1 2 3 4 5 6"
},
{
"input": "1\n1",
"output": "1\n1 1"
},
{
"input": "2\n1 2",
"output": "2\n1 1\n1 2"
},
{
"input": "2\n2 1",
"output": "... | 1,503,593,046 | 546 | Python 3 | OK | TESTS | 71 | 857 | 19,251,200 | n = int(input())
a = list(map(int, input().split()))
x = sorted([(a[i], i) for i in range(n)])
cycles = []
was = [False for i in range(n)]
for i in range(n):
if was[i]:
continue
cur = i
cyc = []
while not was[cur]:
was[cur] = True
cyc.append(cur + 1)
cur = x[cur][1]
... | Title: Sorting by Subsequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a*1,<=*a*2,<=...,<=*a**n* consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of the... | ```python
n = int(input())
a = list(map(int, input().split()))
x = sorted([(a[i], i) for i in range(n)])
cycles = []
was = [False for i in range(n)]
for i in range(n):
if was[i]:
continue
cur = i
cyc = []
while not was[cur]:
was[cur] = True
cyc.append(cur + 1)
cur = x[... | 3 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,673,354,182 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 0 | n,m,c=input().split()
n=int(n)
m=int(m)
mat=[""]*n
for i in range(n):
mat[i]=input()
ans=set()
for i in range(n):
for j in range(m):
if mat[i][j]==c:
for x,y in (i-1,j),(i+1,j),(i,j-1),(i,j+1):
if x in range(n) and y in range(m) and mat[x][y]!='.':
... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
n,m,c=input().split()
n=int(n)
m=int(m)
mat=[""]*n
for i in range(n):
mat[i]=input()
ans=set()
for i in range(n):
for j in range(m):
if mat[i][j]==c:
for x,y in (i-1,j),(i+1,j),(i,j-1),(i,j+1):
if x in range(n) and y in range(m) and mat[x][y]!='.':
... | 3.98075 |
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,663,707,893 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 124 | 24,268,800 | from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
mx,mn=max(arr),min(arr)
f=Counter(arr)
print(mx-mn,f.get(mx)*f.get(mn)) | 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
from collections import Counter
n=int(input())
arr=list(map(int,input().split()))
mx,mn=max(arr),min(arr)
f=Counter(arr)
print(mx-mn,f.get(mx)*f.get(mn))
``` | 0 | |
954 | A | Diagonal Walking | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. | Print the minimum possible length of the sequence of moves after all replacements are done. | [
"5\nRUURU\n",
"17\nUUURRRRRUUURURUUU\n"
] | [
"3\n",
"13\n"
] | In the first test the shortened sequence of moves may be DUD (its length is 3).
In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13). | 0 | [
{
"input": "5\nRUURU",
"output": "3"
},
{
"input": "17\nUUURRRRRUUURURUUU",
"output": "13"
},
{
"input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
"output": "100"
},
{
"input": "100\nRRURRUUUURURRRURRRRURRRRRR... | 1,637,777,138 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | a=int(input())
b=input()
c=b.replace("RU","D")
d=c.replace("UR","D")
print(len(d))
| Title: Diagonal Walking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence movi... | ```python
a=int(input())
b=input()
c=b.replace("RU","D")
d=c.replace("UR","D")
print(len(d))
``` | 0 | |
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,493,517,034 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 171 | 13,926,400 | t,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
pos=0
buys=[]
i=1
while True:
if pos<t and i==x[pos]:
pos+=1
else:
if i>m:break
else:
m-=i
buys.append(i)
i+=1
print(len(buys))
print(' '.join(list(map(str,buys))))
| 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
t,m=map(int,input().split())
x=sorted(list(map(int,input().split())))
pos=0
buys=[]
i=1
while True:
if pos<t and i==x[pos]:
pos+=1
else:
if i>m:break
else:
m-=i
buys.append(i)
i+=1
print(len(buys))
print(' '.join(list(map(str,b... | 3 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,689,990,743 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 904 | 14,643,200 | n = int(input())
ls = list(map(int,input().split()))
q = int(input())
la = list(map(int,input().split()))
for i in range(1,len(ls)):
ls[i] = ls[i]+ls[i-1]
for i in range(len(la)):
low = 0
high = len(ls)
flag= True
while low<=high:
mid = (low+high)//2
if ls[mid]<la[i]:
low = mid+1
elif mid == 0 and ls[mid]... | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
n = int(input())
ls = list(map(int,input().split()))
q = int(input())
la = list(map(int,input().split()))
for i in range(1,len(ls)):
ls[i] = ls[i]+ls[i-1]
for i in range(len(la)):
low = 0
high = len(ls)
flag= True
while low<=high:
mid = (low+high)//2
if ls[mid]<la[i]:
low = mid+1
elif mid == 0 a... | 3 | |
557 | C | Arthur and Table | PROGRAMMING | 1,900 | [
"brute force",
"data structures",
"dp",
"greedy",
"math",
"sortings"
] | null | null | Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arthur decided to make the table stable and remove some legs. For each of them Arthur determined number *d... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=105) — the initial number of legs in the table Arthur bought.
The second line of the input contains a sequence of *n* integers *l**i* (1<=≤<=*l**i*<=≤<=105), where *l**i* is equal to the length of the *i*-th leg of the table.
The third line of the input ... | Print a single integer — the minimum number of energy units that Arthur needs to spend in order to make the table stable. | [
"2\n1 5\n3 2\n",
"3\n2 4 4\n1 1 1\n",
"6\n2 2 1 1 3 3\n4 3 5 5 2 1\n"
] | [
"2\n",
"0\n",
"8\n"
] | none | 1,500 | [
{
"input": "2\n1 5\n3 2",
"output": "2"
},
{
"input": "3\n2 4 4\n1 1 1",
"output": "0"
},
{
"input": "6\n2 2 1 1 3 3\n4 3 5 5 2 1",
"output": "8"
},
{
"input": "10\n20 1 15 17 11 2 15 3 16 3\n129 114 183 94 169 16 18 104 49 146",
"output": "652"
},
{
"input": "10\... | 1,580,278,694 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 685 | 13,312,000 | MAX_D = 201
n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
legs = sorted(list(zip(l, d)))
d_suffix = [legs[0][1]]
for i in range(1, n):
d_suffix.append(d_suffix[-1] + legs[i][1])
ans = d_suffix[-1]
cnt = {}
left = 0
right = 0
while left < n:
while right < n and legs[... | Title: Arthur and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable.
In total the table Arthur bought has *n* legs, the length of the *i*-th leg is *l**i*.
Arth... | ```python
MAX_D = 201
n = int(input())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
legs = sorted(list(zip(l, d)))
d_suffix = [legs[0][1]]
for i in range(1, n):
d_suffix.append(d_suffix[-1] + legs[i][1])
ans = d_suffix[-1]
cnt = {}
left = 0
right = 0
while left < n:
while right < n... | 3 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,495,523,510 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | import math
n,k=map(int,input().split())
marks=list(map(int,input().split()))
count=0
for j in marks:
count+=j
avg=count/n
if math.floor(avg+1/2)==k:
print(0)
else:
num=1
while(math.floor(avg+1/2)!=k):
avg=(avg*(n+num-1)+k)/(n+num)
num+=1
print(num-1) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
import math
n,k=map(int,input().split())
marks=list(map(int,input().split()))
count=0
for j in marks:
count+=j
avg=count/n
if math.floor(avg+1/2)==k:
print(0)
else:
num=1
while(math.floor(avg+1/2)!=k):
avg=(avg*(n+num-1)+k)/(n+num)
num+=1
print(num-1)
``... | 0 | |
7 | B | Memory Manager | PROGRAMMING | 1,600 | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The fir... | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return inte... | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | 0 | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc... | 1,641,422,376 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 92 | 0 | # Codeforces Beta Round #7
# B. Memory Manager
t, m = map(int, input().split())
# Store memory as a string, where 0 means free and 1 means occupied. This
# allows us to search for free memory by finding the first index of "00..0"
mem = "0" * m
alloc_counter = 0
# Map of index -> (start, size) of used memory blocks
... | Title: Memory Manager
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first relea... | ```python
# Codeforces Beta Round #7
# B. Memory Manager
t, m = map(int, input().split())
# Store memory as a string, where 0 means free and 1 means occupied. This
# allows us to search for free memory by finding the first index of "00..0"
mem = "0" * m
alloc_counter = 0
# Map of index -> (start, size) of used memo... | 3.954 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,689,443,388 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 154 | 0 | import math
def readint():
return int(input())
def readarray(typ):
return list(map(typ, input().split()))
n, m = readarray(int)
tvs = readarray(int)
tvs.sort()
i = 0
bellar = 0
while m > 0 and tvs[i] < 0:
bellar -= tvs[i]
i += 1
m -= 1
print(bellar) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
import math
def readint():
return int(input())
def readarray(typ):
return list(map(typ, input().split()))
n, m = readarray(int)
tvs = readarray(int)
tvs.sort()
i = 0
bellar = 0
while m > 0 and tvs[i] < 0:
bellar -= tvs[i]
i += 1
m -= 1
print(bellar)
``` | 3.9615 |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,694,937,250 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n, m = map(int, input().split())
# n = number of steps
# can climb 1 or 2 steps each move
# m = number of moves to be a multiple of
# The minimal number of moves, being a multiple of m.
min_steps = n // 2 + n % 2
max_steps = n
closest_multiple = ((min_steps + m - 1) // m) * m
found = False
if min_steps < c... | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
n, m = map(int, input().split())
# n = number of steps
# can climb 1 or 2 steps each move
# m = number of moves to be a multiple of
# The minimal number of moves, being a multiple of m.
min_steps = n // 2 + n % 2
max_steps = n
closest_multiple = ((min_steps + m - 1) // m) * m
found = False
if min... | 0 | |
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 ... | 1,679,772,709 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
letters = input().split()
n = n + 1
x = 0
letters_list = [int(n) for n in letters]
for n in letters_list:
if n == 0:
x += 1
print(x)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soo... | ```python
n = int(input())
letters = input().split()
n = n + 1
x = 0
letters_list = [int(n) for n in letters]
for n in letters_list:
if n == 0:
x += 1
print(x)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,693,512,248 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 31 | 0 | n= int(input())
for i in range(n):
# TODO: write code...
word = input()
if(len(word)>10):
print(word[0],(len(word)-2),word[len(word)-1],sep="")
else:
print(word) | 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
n= int(input())
for i in range(n):
# TODO: write code...
word = input()
if(len(word)>10):
print(word[0],(len(word)-2),word[len(word)-1],sep="")
else:
print(word)
``` | 3.9845 |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,563,865,976 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 139 | 0 | a, b = map(str, input().split())
print(a, b, sep=' ')
n = int(input())
for i in range(n):
c, d = map(str, input().split())
if c == a:
a = d
if c == b:
b = d
print(a, b, sep=' ')
# CodeForcesian
# ♥
# زبل
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
a, b = map(str, input().split())
print(a, b, sep=' ')
n = int(input())
for i in range(n):
c, d = map(str, input().split())
if c == a:
a = d
if c == b:
b = d
print(a, b, sep=' ')
# CodeForcesian
# ♥
# زبل
``` | 3 | |
765 | C | Table Tennis Game 2 | PROGRAMMING | 1,200 | [
"math"
] | null | null | Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins.
Across all the sets Misha scored *a* poi... | The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=><=0). | If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets. | [
"11 11 5\n",
"11 2 3\n"
] | [
"1\n",
"-1\n"
] | Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem. | 1,250 | [
{
"input": "11 11 5",
"output": "1"
},
{
"input": "11 2 3",
"output": "-1"
},
{
"input": "1 5 9",
"output": "14"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "1 1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 3 5",
"output": "... | 1,680,288,593 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, k; cin >> k >> a >> b;
if (a + b < k){
cout << "-1\n";
return 0;
}
int x = a/k, y = b/k;
if (y == 0 && a % k){
cout << "-1\n";
return 0;
}
if (x == 0 && b % k){
cout << "-1\... | Title: Table Tennis Game 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor... | ```python
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, k; cin >> k >> a >> b;
if (a + b < k){
cout << "-1\n";
return 0;
}
int x = a/k, y = b/k;
if (y == 0 && a % k){
cout << "-1\n";
return 0;
}
if (x == 0 && b % k){
co... | -1 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,607,250,095 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | [m,n] = list(map(int,for i in input().split()))
out = (m//2)*n + (n//2)*(m%2)
print(out)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
[m,n] = list(map(int,for i in input().split()))
out = (m//2)*n + (n//2)*(m%2)
print(out)
``` | -1 |
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,127,621 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 140 | 0 | a, b, c=map(int, input().split())
if(a+b+c<=2*(a+b) and a+b+c<=2*(b+c) and a+b+c<=2*(a+c)):
print(a+b+c)
elif(2*(a+b)<=2*(b+c) and 2*(a+b)<=2*(a+c)):
print(2*(a+b))
elif(2*(b+c)<=2*(a+c)):
print(2*(b+c))
else:
print(2*(a+c))
| 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
a, b, c=map(int, input().split())
if(a+b+c<=2*(a+b) and a+b+c<=2*(b+c) and a+b+c<=2*(a+c)):
print(a+b+c)
elif(2*(a+b)<=2*(b+c) and 2*(a+b)<=2*(a+c)):
print(2*(a+b))
elif(2*(b+c)<=2*(a+c)):
print(2*(b+c))
else:
print(2*(a+c))
``` | 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.