contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | none | none | none | 0 | [
"none"
] | null | null | Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены дру... | В первой строке задано число *n* (1<=≤<=*n*<=≤<=1000) — количество ножек у стола, купленного Васей.
Во второй строке следует последовательность из 2*n* целых положительных чисел *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=100<=000) — длины частей ножек стола в произвольном порядке. | Выведите *n* строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать *n* ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них. | [
"3\n1 3 2 4 5 3\n",
"3\n1 1 1 2 2 2\n"
] | [
"1 5\n2 4\n3 3\n",
"1 2\n2 1\n1 2\n"
] | none | 0 | [
{
"input": "3\n1 3 2 4 5 3",
"output": "1 5\n2 4\n3 3"
},
{
"input": "3\n1 1 1 2 2 2",
"output": "1 2\n1 2\n1 2"
},
{
"input": "1\n3 7",
"output": "3 7"
},
{
"input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15",
"output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5... | 1,458,746,158 | 958 | Python 3 | OK | TESTS | 57 | 62 | 5,324,800 | n=int(input())
per = list(map(int, input().split()))
per.sort()
for i in range(n):
print(per[i], per[-(i+1)])
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить ... | ```python
n=int(input())
per = list(map(int, input().split()))
per.sort()
for i in range(n):
print(per[i], per[-(i+1)])
``` | 3 | |
91 | A | Newspaper Headline | PROGRAMMING | 1,500 | [
"greedy",
"strings"
] | A. Newspaper Headline | 2 | 256 | A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. After that walrus erase several letters from this string in order to get a n... | The input data contain two lines. The first line contain the heading *s*1, the second line contains the word *s*2. The lines only consist of lowercase Latin letters (1<=≤<=|*s*1|<=≤<=104,<=1<=≤<=|*s*2|<=≤<=106). | If it is impossible to get the word *s*2 in the above-described manner, print "-1" (without the quotes). Otherwise, print the least number of newspaper headings *s*1, which Fangy will need to receive the word *s*2. | [
"abc\nxyz\n",
"abcd\ndabc\n"
] | [
"-1\n",
"2\n"
] | none | 500 | [
{
"input": "abc\nxyz",
"output": "-1"
},
{
"input": "abcd\ndabc",
"output": "2"
},
{
"input": "ab\nbabaaab",
"output": "5"
},
{
"input": "ab\nbaaabba",
"output": "6"
},
{
"input": "fbaaigiihhfaahgdbddgeggjdeigfadhfddja\nhbghjgijijcdafcbgiedichdeebaddfddb",
"ou... | 1,699,642,224 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 5 | 496 | 268,390,400 | fs = list(input())
ss = list(input())
d = {}
i = 0
c = 0
index = 0
a = []
flag = 1
if set(fs) == set(ss):
for i in range(len(ss)):
for j in range(len(fs)):
n_v = fs.index(ss[i], index)
if fs[j] == ss[i] and (i == 0 or n_v > fs.index(a[-1])):
a.append(fs[j])
flag = 0
... | Title: Newspaper Headline
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order... | ```python
fs = list(input())
ss = list(input())
d = {}
i = 0
c = 0
index = 0
a = []
flag = 1
if set(fs) == set(ss):
for i in range(len(ss)):
for j in range(len(fs)):
n_v = fs.index(ss[i], index)
if fs[j] == ss[i] and (i == 0 or n_v > fs.index(a[-1])):
a.append(fs[j])
... | 0 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,496,118,168 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | if __name__ == '__main__':
n = int(input())
line = map(int, input().split())
print(2) if sum(line) % n == 0 else print(1)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
if __name__ == '__main__':
n = int(input())
line = map(int, input().split())
print(2) if sum(line) % n == 0 else print(1)
``` | 0 | |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,657,304,431 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 186 | 0 | s=input().split()
amount=int(s[0])
front=int(s[1])
behind=int(s[2])
pos=(amount-front)
if pos>1+behind:
print(behind+1)
else:
print(pos)
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
s=input().split()
amount=int(s[0])
front=int(s[1])
behind=int(s[2])
pos=(amount-front)
if pos>1+behind:
print(behind+1)
else:
print(pos)
``` | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,694,509,264 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 216 | 0 | # Even Odds Difficulty:900
n,k=map(int,input().split())
if k <= (n+1)/2:
print(2*k-1)
else:
print(2*(k-(n+1)//2)) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
# Even Odds Difficulty:900
n,k=map(int,input().split())
if k <= (n+1)/2:
print(2*k-1)
else:
print(2*(k-(n+1)//2))
``` | 3 | |
719 | B | Anatoly and Cockroaches | PROGRAMMING | 1,400 | [
"greedy"
] | null | null | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectio... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cockroaches.
The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. | Print one integer — the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. | [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first sample, Anatoly has to swap third and fourth cockroaches. He needs 1 turn to do this.
In the second sample, the optimum answer is to paint the second and the fourth cockroaches red. This requires 2 turns.
In the third sample, the colors of cockroaches in the line are alternating already, thus the answer ... | 1,000 | [
{
"input": "5\nrbbrr",
"output": "1"
},
{
"input": "5\nbbbbb",
"output": "2"
},
{
"input": "3\nrbr",
"output": "0"
},
{
"input": "13\nrbbbrbrrbrrbb",
"output": "3"
},
{
"input": "18\nrrrrrrrrrrrrrrrrrb",
"output": "8"
},
{
"input": "100\nbrbbbrrrbbrbrb... | 1,474,732,962 | 1,062 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 819,200 | def f(p):
cnt = sum(p[i] != a[i] for i in range(n))
res = 0
cur = 0
for i in range(n):
if a[i] != p[i]:
cur += 1
else:
res += cur // 2
res += cur % 2
cur = 0
return res
n = int(input())
a = [int(i == 'r') for i in input()... | Title: Anatoly and Cockroaches
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches... | ```python
def f(p):
cnt = sum(p[i] != a[i] for i in range(n))
res = 0
cur = 0
for i in range(n):
if a[i] != p[i]:
cur += 1
else:
res += cur // 2
res += cur % 2
cur = 0
return res
n = int(input())
a = [int(i == 'r') for i ... | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,583,138,140 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n = int(input()) - 1
lst = sorted(list(map(int, input().split())))
if n % 2 == 0:
print(lst[len(lst) // 2 - 1])
else:
print(lst[len(lst) // 2]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n = int(input()) - 1
lst = sorted(list(map(int, input().split())))
if n % 2 == 0:
print(lst[len(lst) // 2 - 1])
else:
print(lst[len(lst) // 2])
``` | 0 | |
471 | D | MUH and Cube Walls | PROGRAMMING | 1,800 | [
"string suffix structures",
"strings"
] | null | null | Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of di... | The first line contains two integers *n* and *w* (1<=≤<=*n*,<=*w*<=≤<=2·105) — the number of towers in the bears' and the elephant's walls correspondingly. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the heights of the towers in the bears' wall. The third line contains *w* integers *b**i* (1<=... | Print the number of segments in the bears' wall where Horace can "see an elephant". | [
"13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2\n"
] | [
"2"
] | The picture to the left shows Horace's wall from the sample, the picture to the right shows the bears' wall. The segments where Horace can "see an elephant" are in gray. | 2,000 | [
{
"input": "13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2",
"output": "2"
},
{
"input": "5 1\n8 71 1 24 2\n31",
"output": "5"
},
{
"input": "6 3\n2 2 2 2 2 2\n5 5 5",
"output": "4"
},
{
"input": "1 1\n576560149\n691846236",
"output": "1"
},
{
"input": "10 5\n5 10 8 1... | 1,679,652,222 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 155 | 35,225,600 | def diff(s) : return [s[i] - s[i - 1] for i in range(1, len(s))]
n, m = map(int, input().split())
if m > n : print(0) ; exit(0)
if m == 1 : print(n) ; exit(0)
t = diff(list(map(int, input().split())))
p = diff(list(map(int, input().split())))
w = p + [10 ** 9] + t
res = 0
pi = [0] * len(w)
for i in range (1, len(w)):
... | Title: MUH and Cube Walls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of ... | ```python
def diff(s) : return [s[i] - s[i - 1] for i in range(1, len(s))]
n, m = map(int, input().split())
if m > n : print(0) ; exit(0)
if m == 1 : print(n) ; exit(0)
t = diff(list(map(int, input().split())))
p = diff(list(map(int, input().split())))
w = p + [10 ** 9] + t
res = 0
pi = [0] * len(w)
for i in range (1, ... | 3 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,544,387,689 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | s=input()
t=input()
result=""
has_result = False
for n in range(len(s)):
gap=ord(t[n]) - ord(s[n])
if gap == 0 :
result = result + chr(ord(s[n]))
elif gap == 1 :
if n != (len(s) -1):
has_result = True
result = result + chr(ord(s[n]))
else:
if ... | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s=input()
t=input()
result=""
has_result = False
for n in range(len(s)):
gap=ord(t[n]) - ord(s[n])
if gap == 0 :
result = result + chr(ord(s[n]))
elif gap == 1 :
if n != (len(s) -1):
has_result = True
result = result + chr(ord(s[n]))
else:
... | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,685,903,854 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
if n % 2 == 0:
print(n//2)
num = n//2
for i in range(num):
print(2, end=" ")
else:
print(3)
num = (n-3)//2
for i in range(num):
print(2, end=" ") | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n = int(input())
if n % 2 == 0:
print(n//2)
num = n//2
for i in range(num):
print(2, end=" ")
else:
print(3)
num = (n-3)//2
for i in range(num):
print(2, end=" ")
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,694,364,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def solution(n):
dic = {n[i]:i+1 for i in range(len(n))}
ln = []
for i in range(len(n)):
ln.append(dic[i+1])
return ln
l=int(input())
n=list(map(int, input().split()))
res = solution(n)
res2 = ''
for i in res:
res2 += str(i)
res2 + ' '
print(res2) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
def solution(n):
dic = {n[i]:i+1 for i in range(len(n))}
ln = []
for i in range(len(n)):
ln.append(dic[i+1])
return ln
l=int(input())
n=list(map(int, input().split()))
res = solution(n)
res2 = ''
for i in res:
res2 += str(i)
res2 + ' '
print(res2)
... | 0 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,680,870,257 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 498 | 14,540,800 | n=int(input())
a=list(map(int,input().split()))
c1=a.count(1)
c2=a.count(2)
c3=a.count(3)
l=[c1,c2,c3]
l.remove(max(l))
print(sum(l))
| Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
n=int(input())
a=list(map(int,input().split()))
c1=a.count(1)
c2=a.count(2)
c3=a.count(3)
l=[c1,c2,c3]
l.remove(max(l))
print(sum(l))
``` | 3.848416 |
778 | A | String Game | PROGRAMMING | 1,700 | [
"binary search",
"greedy",
"strings"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 500 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,696,939,295 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def check():
for i in range(len_m):
if i == len_m - 1 and temp[i] != n[0]:
return False
if temp[i] == "0":
continue
xx = 0
flag = i
if temp[i] == n[0]:
xx += 1
bflag = True
while bflag:
if... | Title: String Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gi... | ```python
def check():
for i in range(len_m):
if i == len_m - 1 and temp[i] != n[0]:
return False
if temp[i] == "0":
continue
xx = 0
flag = i
if temp[i] == n[0]:
xx += 1
bflag = True
while bflag:
... | 0 | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,617,994,989 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 109 | 0 | n, s = map(int, input().split())
ft = []
for _ in range(n):
f, t = map(int, input().split())
ft.append([f, t])
ft.sort(reverse=True)
prevf, ans = s, 0
for f, t in ft:
ans += prevf - f
if ans < t:
ans = t
prevf = f
ans += ft[-1][0]
print(ans)
| Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n, s = map(int, input().split())
ft = []
for _ in range(n):
f, t = map(int, input().split())
ft.append([f, t])
ft.sort(reverse=True)
prevf, ans = s, 0
for f, t in ft:
ans += prevf - f
if ans < t:
ans = t
prevf = f
ans += ft[-1][0]
print(ans)
``` | 3 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,599,581,535 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | numbers=int(input())
lNum=[int(n) for n in input().split()]
cL,suM=[0],sum(lNum)
for i in lNum:
if i%2==0: cL+=[i]
if (suM-i)%2==0: cL+=[suM-i]
print(max(cL)) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
numbers=int(input())
lNum=[int(n) for n in input().split()]
cL,suM=[0],sum(lNum)
for i in lNum:
if i%2==0: cL+=[i]
if (suM-i)%2==0: cL+=[suM-i]
print(max(cL))
``` | 0 | |
998 | A | Balloons | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi... | The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. | If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons... | [
"3\n1 2 1\n",
"2\n5 5\n",
"1\n10\n"
] | [
"2\n1 2\n",
"-1\n",
"-1\n"
] | In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | 500 | [
{
"input": "3\n1 2 1",
"output": "1\n1"
},
{
"input": "2\n5 5",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1\n1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 9",... | 1,613,844,449 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 204,800 | import sys
n = int(sys.stdin.readline().strip())
arr = list(map(int, sys.stdin.readline().rstrip().split(" ")))
a1 = 0
a2 = 0
for i in range(len(arr)):
if i%2 == 0:
a1 += 1
else:
a2 += 1
if a1 == 0 or a2 == 0:
print(-1)
elif a1 != a2:
print(a1, end=' ')
print(a2, en... | Title: Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bou... | ```python
import sys
n = int(sys.stdin.readline().strip())
arr = list(map(int, sys.stdin.readline().rstrip().split(" ")))
a1 = 0
a2 = 0
for i in range(len(arr)):
if i%2 == 0:
a1 += 1
else:
a2 += 1
if a1 == 0 or a2 == 0:
print(-1)
elif a1 != a2:
print(a1, end=' ')
pr... | 0 | |
794 | C | Naming Company | PROGRAMMING | 1,800 | [
"games",
"greedy",
"sortings"
] | null | null | Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor ... | The first line of input contains a string *s* of length *n* (1<=≤<=*n*<=≤<=3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string *t* of length *n*. All characters of the string are lowercase English lett... | The output should contain a string of *n* lowercase English letters, denoting the company name if Oleg and Igor plays optimally. | [
"tinkoff\nzscoder\n",
"xxxxxx\nxxxxxx\n",
"ioi\nimo\n"
] | [
"fzfsirk\n",
"xxxxxx\n",
"ioi\n"
] | One way to play optimally in the first sample is as follows :
- Initially, the company name is ???????.- Oleg replaces the first question mark with 'f'. The company name becomes f??????.- Igor replaces the second question mark with 'z'. The company name becomes fz?????.- Oleg replaces the third question mark with '... | 1,750 | [
{
"input": "tinkoff\nzscoder",
"output": "fzfsirk"
},
{
"input": "xxxxxx\nxxxxxx",
"output": "xxxxxx"
},
{
"input": "ioi\nimo",
"output": "ioi"
},
{
"input": "abc\naaa",
"output": "aab"
},
{
"input": "reddit\nabcdef",
"output": "dfdeed"
},
{
"input": "... | 1,673,848,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | # modified from original but this sol is still wrong
s1 = input().strip()
s2 = input().strip()
c = len(s1)
k = ''
a = True
while len(k) < c:
if a:
k += min(s1)
s1 = s1.replace(min(s1), '', 1)
a = False
continue
k += max(s2)
s2 = s2.replace(max(s2), '', ... | Title: Naming Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this p... | ```python
# modified from original but this sol is still wrong
s1 = input().strip()
s2 = input().strip()
c = len(s1)
k = ''
a = True
while len(k) < c:
if a:
k += min(s1)
s1 = s1.replace(min(s1), '', 1)
a = False
continue
k += max(s2)
s2 = s2.replace(max... | 0 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,455,762,022 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 171 | 0 | sLine = input()
sSplit = sLine.split()
x1 = int(sSplit[0])
y1 = int(sSplit[1])
sLine = input()
sSplit = sLine.split()
x2 = int(sSplit[0])
y2 = int(sSplit[1])
d = max(abs(x2 - x1), abs(y2 - y1))
print(d)
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
sLine = input()
sSplit = sLine.split()
x1 = int(sSplit[0])
y1 = int(sSplit[1])
sLine = input()
sSplit = sLine.split()
x2 = int(sSplit[0])
y2 = int(sSplit[1])
d = max(abs(x2 - x1), abs(y2 - y1))
print(d)
``` | 3 | |
862 | B | Mahmoud and Ehab and the bipartiteness | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *... | The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105).
The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree.
It's guaranteed that the given graph is a tree. | Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. | [
"3\n1 2\n1 3\n",
"5\n1 2\n2 3\n3 4\n4 5\n"
] | [
"0\n",
"2\n"
] | Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory))
Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph)
In the first test case the only edge that can be added in such a way, that ... | 1,000 | [
{
"input": "3\n1 2\n1 3",
"output": "0"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5",
"output": "2"
},
{
"input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6",
"output": "16"
},
{
"input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4",
"output": "16"
},
{
"in... | 1,661,335,761 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
d = {}
used = [False] * (n + 1)
s, s2 = set(), set()
for _ in range(n - 1):
u, v = map(int, input().split())
if (u not in s) and (u not in s2):
if (v not in s) and (v not in s2):
s.add(v)
if v in s:
s2.add(u)
else:
if v in ... | Title: Mahmoud and Ehab and the bipartiteness
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.
A tree is a connected acyclic graph. A bipartite graph is a gra... | ```python
n = int(input())
d = {}
used = [False] * (n + 1)
s, s2 = set(), set()
for _ in range(n - 1):
u, v = map(int, input().split())
if (u not in s) and (u not in s2):
if (v not in s) and (v not in s2):
s.add(v)
if v in s:
s2.add(u)
else:
... | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,607,690,856 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | s1=input()
s2=input()
s1s=[]
s2s=[]
ct1=[]
ct2=[]
for i in s1:
s1s.append(i)
for i in s2:
s2s.append(i)
temp=0
for i in s1:
if(s1s.count(i)==s2s.count(i)):
continue
else:
temp=1
break
if(temp==0):
print("YES")
else:
print("NO")
"""
for i in s2:
... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
s1=input()
s2=input()
s1s=[]
s2s=[]
ct1=[]
ct2=[]
for i in s1:
s1s.append(i)
for i in s2:
s2s.append(i)
temp=0
for i in s1:
if(s1s.count(i)==s2s.count(i)):
continue
else:
temp=1
break
if(temp==0):
print("YES")
else:
print("NO")
"""
for i... | 0 | |
774 | C | Maximum Number | PROGRAMMING | 1,200 | [
"*special",
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. ... | The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. | Print the maximum integer which can be shown on the display of Stepan's newest device. | [
"2\n",
"3\n"
] | [
"1\n",
"7\n"
] | none | 0 | [
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "11"
},
{
"input": "5",
"output": "71"
},
{
"input": "6",
"output": "111"
},
{
"input": "85651",
"output": "711111111111111111111111111111111111111111111111... | 1,491,407,508 | 1,008 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 |
n = int(input())
ans = ''
while(n >= 2):
if (n >= 3):
ans += '7'
n-=3
else:
ans += '1'
n-=2
print(ans) | Title: Maximum Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below.
So, for example, to show the digit 3 o... | ```python
n = int(input())
ans = ''
while(n >= 2):
if (n >= 3):
ans += '7'
n-=3
else:
ans += '1'
n-=2
print(ans)
``` | 0 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,611,099 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 174,387,200 | n,l,r=input().split(" ")
n=int(n)
l=int(l)
r=int(r)
final=[]
def solution(n):
if n!=0 and n!=1:
solution(n//2)
solution(n%2)
solution(n//2)
else:
final.append(n)
solution(n)
print(final[l-1:r].count(1))
| Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
n,l,r=input().split(" ")
n=int(n)
l=int(l)
r=int(r)
final=[]
def solution(n):
if n!=0 and n!=1:
solution(n//2)
solution(n%2)
solution(n//2)
else:
final.append(n)
solution(n)
print(final[l-1:r].count(1))
``` | 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,597,756,824 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 307,200 | def solve(n,m):
ei=0
ec=0
oi=0
oc=0
for i in range(0,n):
if(m[i]%2==0):
ei=i
ec+=1
elif(m[i]%2!=0):
... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
def solve(n,m):
ei=0
ec=0
oi=0
oc=0
for i in range(0,n):
if(m[i]%2==0):
ei=i
ec+=1
elif(m[i]%2!=0):
... | -1 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,694,342 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | s=list(input())
vowel=['a','e','i','u','o','y']#将元音储存进列表
result=[]
for letter in s:#遍历string中各个字母
if letter.lower() in vowel:
pass
else:
result.append('.'+letter.lower())#将辅音存进新列表
print(''.join(result))#将新列表以字符串形式打印出来
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
s=list(input())
vowel=['a','e','i','u','o','y']#将元音储存进列表
result=[]
for letter in s:#遍历string中各个字母
if letter.lower() in vowel:
pass
else:
result.append('.'+letter.lower())#将辅音存进新列表
print(''.join(result))#将新列表以字符串形式打印出来
``` | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,698,054,686 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | l = [int(x) for x in input().split('+')]
l.sort()
print(*l,sep="+")
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
l = [int(x) for x in input().split('+')]
l.sort()
print(*l,sep="+")
``` | 3 | |
195 | A | Let's Watch Football | PROGRAMMING | 1,000 | [
"binary search",
"brute force",
"math"
] | null | null | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si... | The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=><=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T... | Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses. | [
"4 1 1\n",
"10 3 2\n",
"13 12 1\n"
] | [
"3\n",
"5\n",
"1\n"
] | In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch... | 500 | [
{
"input": "4 1 1",
"output": "3"
},
{
"input": "10 3 2",
"output": "5"
},
{
"input": "13 12 1",
"output": "1"
},
{
"input": "2 1 3",
"output": "3"
},
{
"input": "6 2 4",
"output": "8"
},
{
"input": "5 2 1",
"output": "2"
},
{
"input": "2 1... | 1,679,434,032 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | typedef long double ld;
typedef long long int lli;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define sz(s) lli(s.size())
#define all(s) begin(s), end(s)
#define print(s) cout << s << endl
#define fore(i, a, b) for(lli i = (a), TT = (b); ... | Title: Let's Watch Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ... | ```python
typedef long double ld;
typedef long long int lli;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define sz(s) lli(s.size())
#define all(s) begin(s), end(s)
#define print(s) cout << s << endl
#define fore(i, a, b) for(lli i = (a), ... | -1 | |
159 | A | Friends or Not | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that ... | The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=1000). The next *n* lines contain the messages log. The *i*-th line contains one line of the log formatted as "*A**i* *B**i* *t**i*" (without the quotes), which means that user *A**i* sent a message to user *B**i* at time *t**i* (1<=≤<=*... | In the first line print integer *k* — the number of pairs of friends. In the next *k* lines print pairs of friends as "*A**i* *B**i*" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once. | [
"4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4\n",
"1 1000\na b 0\n"
] | [
"1\npetya vasya\n",
"0\n"
] | In the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second. | 500 | [
{
"input": "4 1\nvasya petya 1\npetya vasya 2\nanya ivan 2\nivan anya 4",
"output": "1\npetya vasya"
},
{
"input": "1 1000\na b 0",
"output": "0"
},
{
"input": "2 1\na b 0\nb a 0",
"output": "0"
},
{
"input": "3 1\na b 1\nb c 2\nc d 3",
"output": "0"
},
{
"input":... | 1,419,184,471 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 124 | 0 | import sys
import math
n, dv = [int(x) for x in (sys.stdin.readline()).split()]
d = dict()
for i in range(n):
ai, bi, t = (sys.stdin.readline()).split()
if ai in d:
if bi in d[ai]:
d[ai][bi].append(int(t))
else:
d[ai][bi] = [int(t)]
else:
d[ai]... | Title: Friends or Not
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't... | ```python
import sys
import math
n, dv = [int(x) for x in (sys.stdin.readline()).split()]
d = dict()
for i in range(n):
ai, bi, t = (sys.stdin.readline()).split()
if ai in d:
if bi in d[ai]:
d[ai][bi].append(int(t))
else:
d[ai][bi] = [int(t)]
else:
... | -1 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,682,529,029 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 77 | 0 | l=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
n,k=map(int,input().split())
s="".join(l[:k])
j=n-k
for i in range(j):
if i%2==0:
s=s+s[0]
else:
s=s+s[1]
print(s) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
l=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
n,k=map(int,input().split())
s="".join(l[:k])
j=n-k
for i in range(j):
if i%2==0:
s=s+s[0]
else:
s=s+s[1]
print(s)
``` | 3 | |
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th... | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"... | 1,605,507,557 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | # https://codeforces.com/problemset/problem/426/A
n, s = map(input().split())
for i in map(int, input().split()):
if i >= s:
print("NO")
break
else:
print("YES") | Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
# https://codeforces.com/problemset/problem/426/A
n, s = map(input().split())
for i in map(int, input().split()):
if i >= s:
print("NO")
break
else:
print("YES")
``` | -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,589,667,535 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 216 | 6,963,200 | n = int(input())
l = [int(x) for x in input().split()]
l.insert(0,-1)
t = int(input())
while(t):
t -= 1
q = [int(x) for x in input().split()]
try:
l[q[0]-1] += q[1]-1
except:
pass
try:
l[q[0]+1] += l[q[0]]-q[1]
except:
pass
l[q[0]] = 0
for i in... | 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
n = int(input())
l = [int(x) for x in input().split()]
l.insert(0,-1)
t = int(input())
while(t):
t -= 1
q = [int(x) for x in input().split()]
try:
l[q[0]-1] += q[1]-1
except:
pass
try:
l[q[0]+1] += l[q[0]]-q[1]
except:
pass
l[q[0]] = 0... | 3 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,643,827,979 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | n = int(input())
data = []
for i in range(n):
I = input().split()
data.append((I[0], I[1]))
results = []
for i in data:
if i not in results:
results.append(i)
print(len(results)) | Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
n = int(input())
data = []
for i in range(n):
I = input().split()
data.append((I[0], I[1]))
results = []
for i in data:
if i not in results:
results.append(i)
print(len(results))
``` | 3.9845 |
0 | none | none | none | 0 | [
"none"
] | null | null | Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree... | The first line contains a single integer *h* (2<=≤<=*h*<=≤<=105) — the height of the tree.
The second line contains *h*<=+<=1 integers — the sequence *a*0,<=*a*1,<=...,<=*a**h* (1<=≤<=*a**i*<=≤<=2·105). The sum of all *a**i* does not exceed 2·105. It is guaranteed that there is at least one tree matching this sequence... | If there is only one tree matching this sequence, print "perfect".
Otherwise print "ambiguous" in the first line. In the second and in the third line print descriptions of two trees in the following format: in one line print integers, the *k*-th of them should be the parent of vertex *k* or be equal to zero, if the *... | [
"2\n1 1 1\n",
"2\n1 2 2\n"
] | [
"perfect\n",
"ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"
] | The only tree in the first example and the two printed trees from the second example are shown on the picture:
<img class="tex-graphics" src="https://espresso.codeforces.com/ae5d1889e09854f9d8ad6e29ab7afbe690ca4702.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 0 | [
{
"input": "2\n1 1 1",
"output": "perfect"
},
{
"input": "2\n1 2 2",
"output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 1 1 2 1 1 1 1 1",
"output": "perfect"
},
{
"input": "10\n1 1 1 ... | 1,513,702,989 | 5,289 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 61 | 5,529,600 | n = int(input())
c = list(map(int, input().split()))
f = True
for i in range(n + 1):
if i % 2 == 0 and c[i] != 1:
f = False
if f:
print('perfect')
else:
last = 0
print('ambiguous')
g = 0
for i in range(n + 1):
for j in range(c[i]):
print(g, end=' ')
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that... | ```python
n = int(input())
c = list(map(int, input().split()))
f = True
for i in range(n + 1):
if i % 2 == 0 and c[i] != 1:
f = False
if f:
print('perfect')
else:
last = 0
print('ambiguous')
g = 0
for i in range(n + 1):
for j in range(c[i]):
print(g,... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,595,886,924 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | x=input();print("YES") if"ll"in x and"helo"in"".join(list(dict.fromkeys(x)))else print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
x=input();print("YES") if"ll"in x and"helo"in"".join(list(dict.fromkeys(x)))else print("NO")
``` | 0 |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,608,362,401 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 421 | 6,656,000 | a,b=map(int,input().split())
queue=[a]
flag=0
dict={a:1}
while len(queue)>0:
if(queue[0]==b):
flag=1
break
if(queue[0]*2<=b):
queue.append(queue[0]*2)
dict[queue[0]*2]=1
if(queue[0]*10+1<=b):
queue.append(queue[0]*10+1)
dict[queue[0]*10+1]=1
... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app... | ```python
a,b=map(int,input().split())
queue=[a]
flag=0
dict={a:1}
while len(queue)>0:
if(queue[0]==b):
flag=1
break
if(queue[0]*2<=b):
queue.append(queue[0]*2)
dict[queue[0]*2]=1
if(queue[0]*10+1<=b):
queue.append(queue[0]*10+1)
dict[queue[0]*10+... | 3 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,578,919,142 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 170 | 0 |
a = input().split()
arr = input().split()
arr = list(map(int, arr))
score = 0
flag = True
while (flag):
for i in range(1, int(a[0])+1):
try:
index = arr.index(i)
except ValueError:
index = -1
if (index == -1):
flag = False
break
else:
... | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
a = input().split()
arr = input().split()
arr = list(map(int, arr))
score = 0
flag = True
while (flag):
for i in range(1, int(a[0])+1):
try:
index = arr.index(i)
except ValueError:
index = -1
if (index == -1):
flag = False
break
... | 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,687,062,472 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | x,y = input().split()
x, y = int(x), int(y)
mx = max(x,y)
o = 7-mx
if o == 1:
print("1/6")
elif o == 2:
print("1/3")
elif o == 3:
print("1/2")
elif o == 4:
print("2/3")
elif o == 5:
print("5/6")
elif o == 6:
print("1/1") | 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
x,y = input().split()
x, y = int(x), int(y)
mx = max(x,y)
o = 7-mx
if o == 1:
print("1/6")
elif o == 2:
print("1/3")
elif o == 3:
print("1/2")
elif o == 4:
print("2/3")
elif o == 5:
print("5/6")
elif o == 6:
print("1/1")
``` | 3.954 |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for ... | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use al... | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"i... | 1,555,853,694 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 0 | # ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math
# import collections
# import string
# ===================================
n, k = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
q = sorted(enumerate(q), key = l... | Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ... | ```python
# ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math
# import collections
# import string
# ===================================
n, k = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
q = sorted(enumerate(q... | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,696,304,497 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 |
b1,b2 = map(int,input().split())
y = 0
while b1 <= b2 :
b1 = 3*b1
b2 = 2*b2
y += 1
print(y) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
b1,b2 = map(int,input().split())
y = 0
while b1 <= b2 :
b1 = 3*b1
b2 = 2*b2
y += 1
print(y)
``` | 3 | |
729 | B | Spotlights | PROGRAMMING | 1,200 | [
"dp",
"implementation"
] | null | null | Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan.
The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ... | Print one integer — the number of good positions for placing the spotlight. | [
"2 4\n0 1 0 0\n1 0 1 0\n",
"4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n"
] | [
"9\n",
"20\n"
] | In the first example the following positions are good:
1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and... | 1,000 | [
{
"input": "2 4\n0 1 0 0\n1 0 1 0",
"output": "9"
},
{
"input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0",
"output": "20"
},
{
"input": "1 5\n1 1 0 0 0",
"output": "3"
},
{
"input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0",
"output": "20"
},
{
"input": "3 ... | 1,596,216,157 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 16,486,400 | a,b=map(int,input().split())
z=[[0]*(b+2)];z1=[[0]*(b+2)];x=[0]
for _ in range(1,a+1):
p=[0];p1=[0];o=0
for i,j in zip(range(1,b+1),map(int,input().split())):
p+=[z1[_-1][i]+j]
p1+=[j];o+=j
p+=[0];p1+=[0]
z1+=[p];z+=[p1]
x+=[o]
z+=[[0]*(b+2)]
z1+=[[0]*(b+2)]
s=0
for i i... | Title: Spotlights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to pl... | ```python
a,b=map(int,input().split())
z=[[0]*(b+2)];z1=[[0]*(b+2)];x=[0]
for _ in range(1,a+1):
p=[0];p1=[0];o=0
for i,j in zip(range(1,b+1),map(int,input().split())):
p+=[z1[_-1][i]+j]
p1+=[j];o+=j
p+=[0];p1+=[0]
z1+=[p];z+=[p1]
x+=[o]
z+=[[0]*(b+2)]
z1+=[[0]*(b+2)]
s=... | 0 | |
409 | H | A + B Strikes Back | PROGRAMMING | 1,500 | [
"*special",
"brute force",
"constructive algorithms",
"dsu",
"implementation"
] | null | null | A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? | The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. | Output the sum of the given integers. | [
"5 14\n",
"381 492\n"
] | [
"19\n",
"873\n"
] | none | 0 | [
{
"input": "5 14",
"output": "19"
},
{
"input": "381 492",
"output": "873"
},
{
"input": "536 298",
"output": "834"
},
{
"input": "143 522",
"output": "665"
},
{
"input": "433 126",
"output": "559"
},
{
"input": "723 350",
"output": "1073"
},
{... | 1,682,749,590 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | # LUOGU_RID: 109165219
a=int(input())
b=int(input())
print(a+b) | Title: A + B Strikes Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
Input ... | ```python
# LUOGU_RID: 109165219
a=int(input())
b=int(input())
print(a+b)
``` | -1 | |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The ... | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input":... | 1,600,945,817 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 434 | 7,884,800 | a,b=[int(i) for i in input().split()]
l=list(range(1,a+1))[::-1]
print(*l[0:b]+l[b:][::-1]) | Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutat... | ```python
a,b=[int(i) for i in input().split()]
l=list(range(1,a+1))[::-1]
print(*l[0:b]+l[b:][::-1])
``` | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,362,614 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
res = 0
for _ in range(n):
res += sum(map(int, input().split())) >= 2
print(res) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
res = 0
for _ in range(n):
res += sum(map(int, input().split())) >= 2
print(res)
``` | 3 | |
888 | C | K-Dominant Character | PROGRAMMING | 1,400 | [
"binary search",
"implementation",
"two pointers"
] | null | null | You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* such that there exists at least one *k*-dominant character. | The first line contains string *s* consisting of lowercase Latin letters (1<=≤<=|*s*|<=≤<=100000). | Print one number — the minimum value of *k* such that there exists at least one *k*-dominant character. | [
"abacaba\n",
"zzzzz\n",
"abcde\n"
] | [
"2\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "2"
},
{
"input": "zzzzz",
"output": "1"
},
{
"input": "abcde",
"output": "3"
},
{
"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab",
"output": "8"
},
{
"input": "daabcdabbab... | 1,591,085,456 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 18 | 155 | 8,294,400 | import sys,math
s=input()
n=len(s)
if len(set(list(s)))==1:
print(1)
elif len(set(list(s)))==n:
print(n-2)
else:
a=[[0] for i in range(26)]
for i in range(n):
a[ord(s[i])-97].append(i+1)
for i in range(26):
a[i].append(n)
ans=n+1
for i in range(26):
... | Title: K-Dominant Character
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of lowercase Latin letters. Character *c* is called *k*-dominant iff each substring of *s* with length at least *k* contains this character *c*.
You have to find minimum *k* s... | ```python
import sys,math
s=input()
n=len(s)
if len(set(list(s)))==1:
print(1)
elif len(set(list(s)))==n:
print(n-2)
else:
a=[[0] for i in range(26)]
for i in range(n):
a[ord(s[i])-97].append(i+1)
for i in range(26):
a[i].append(n)
ans=n+1
for i in range(26... | 0 | |
14 | B | Young Photographer | PROGRAMMING | 1,000 | [
"implementation"
] | B. Young Photographer | 2 | 64 | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at t... | The first line of the input file contains integers *n* and *x*0 (1<=≤<=*n*<=≤<=100; 0<=≤<=*x*0<=≤<=1000). The following *n* lines contain pairs of integers *a**i*,<=*b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000; *a**i*<=≠<=*b**i*). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | [
"3 3\n0 7\n14 2\n4 6\n"
] | [
"1\n"
] | none | 0 | [
{
"input": "3 3\n0 7\n14 2\n4 6",
"output": "1"
},
{
"input": "1 1\n0 10",
"output": "0"
},
{
"input": "2 2\n1 2\n3 2",
"output": "0"
},
{
"input": "3 2\n1 2\n2 3\n3 4",
"output": "-1"
},
{
"input": "2 4\n10 4\n1 5",
"output": "0"
},
{
"input": "1 10\n... | 1,645,117,939 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 154 | 0 | n,x=map(int,input().split())
MIN=-1<<60
MAX=1<<60
for i in range(n):
a,b=map(int,input().split())
MIN=max(MIN,min(a,b))
MAX=min(MAX,max(a,b))
if MIN>MAX:
print(-1)
elif MIN<=x<=MAX:
print(0)
else:
print(min(abs(MIN-x),abs(MAX-x)))
| Title: Young Photographer
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position *x*0 of a long straight racetrack and got ready to take pictures. Bu... | ```python
n,x=map(int,input().split())
MIN=-1<<60
MAX=1<<60
for i in range(n):
a,b=map(int,input().split())
MIN=max(MIN,min(a,b))
MAX=min(MAX,max(a,b))
if MIN>MAX:
print(-1)
elif MIN<=x<=MAX:
print(0)
else:
print(min(abs(MIN-x),abs(MAX-x)))
``` | 3.9615 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,599,115,327 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 307,200 | s = input()
s= s.split()
f=0
dr=0
l=0
if(int(s[0])<int(s[1])):
d=int(s[1])-int(s[0])
if(d%2!=0):
print(int(s[0])+int(d/2),end=" ")
print("0",end=" ")
print(7-int(s[1])+int(d/2))
else:
if(d==2):
print(int(s[0]), end=" ")
print("1", end=" "... | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
s = input()
s= s.split()
f=0
dr=0
l=0
if(int(s[0])<int(s[1])):
d=int(s[1])-int(s[0])
if(d%2!=0):
print(int(s[0])+int(d/2),end=" ")
print("0",end=" ")
print(7-int(s[1])+int(d/2))
else:
if(d==2):
print(int(s[0]), end=" ")
print("1... | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,562,878,052 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | #!/usr/bin/python3
s = input()
low = sum(1 for c in s if c>'Z')
up = sum(1 for c in s if c<='a')
if up > low:
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
#!/usr/bin/python3
s = input()
low = sum(1 for c in s if c>'Z')
up = sum(1 for c in s if c<='a')
if up > low:
print(s.upper())
else:
print(s.lower())
``` | 0 |
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout st... | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"... | 1,697,285,909 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 35 | 2,000 | 11,776,000 | from math import sqrt
def is_prime(n) :
if n < 2 :
return False
if n < 4 :
return True
if n % 2 ==0 or n % 3 ==0:
return False
i = 5
w = 2
while i *i <= n :
if n % i==0 :
return False
i+=w
w=6 - w
return True
... | Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an ar... | ```python
from math import sqrt
def is_prime(n) :
if n < 2 :
return False
if n < 4 :
return True
if n % 2 ==0 or n % 3 ==0:
return False
i = 5
w = 2
while i *i <= n :
if n % i==0 :
return False
i+=w
w=6 - w
retu... | 0 | |
408 | B | Garland | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie... | The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the ... | Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer. | [
"aaabbac\naabbccac\n",
"a\nz\n"
] | [
"6\n",
"-1"
] | In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
In the second test sample Vasya cannot mak... | 1,000 | [
{
"input": "aaabbac\naabbccac",
"output": "6"
},
{
"input": "a\nz",
"output": "-1"
},
{
"input": "r\nr",
"output": "1"
},
{
"input": "stnsdn\nndnndsn",
"output": "4"
},
{
"input": "yqfqfp\ntttwtqq",
"output": "-1"
},
{
"input": "zzbbrrtrtzr\ntbbtrrrzr"... | 1,621,090,220 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n = []
m = []
n[0:] = input()
m[0:] = input()
m_unique = list(set(m))
area = 0
for i in m_unique:
area += m.count(i) if m.count(i) <= n.count(i) else n.count(i)
if area == 0:
area = -1
print(area)
| Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.... | ```python
n = []
m = []
n[0:] = input()
m[0:] = input()
m_unique = list(set(m))
area = 0
for i in m_unique:
area += m.count(i) if m.count(i) <= n.count(i) else n.count(i)
if area == 0:
area = -1
print(area)
``` | 0 | |
825 | D | Suitable Replacement | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation"
] | null | null | You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=106).
The second line contains string *t* (1<=≤<=|*t*|<=≤<=106). | Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
If there are multiple strings with maximal suitability then print any of them. | [
"?aa?\nab\n",
"??b?\nza\n",
"abcd\nabacaba\n"
] | [
"baab\n",
"azbz\n",
"abcd\n"
] | In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.
In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
In the third exam... | 0 | [
{
"input": "?aa?\nab",
"output": "baab"
},
{
"input": "??b?\nza",
"output": "azbz"
},
{
"input": "abcd\nabacaba",
"output": "abcd"
},
{
"input": "mqwstphetbfrsyxuzdww\nrutseqtsbh",
"output": "mqwstphetbfrsyxuzdww"
},
{
"input": "????????????????????\nxwkxsxlrre",
... | 1,593,929,402 | 4,022 | PyPy 3 | OK | TESTS | 24 | 561 | 91,443,200 | def check(mid,ha,has,c):
need=0
for i in range(26):
need+=max(0,ha[i]*mid-has[i])
# print(mid,need)
return c>=need
ss='abcdefghijklmnopqrstuvwxyz'
s = list(input())
t = list(input())
ha=[0]*26
has=[0]*26
m=10000000000
c=0
for i in t:
ha[ord(i)-ord('a')]+=1
for i in s:
... | Title: Suitable Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped po... | ```python
def check(mid,ha,has,c):
need=0
for i in range(26):
need+=max(0,ha[i]*mid-has[i])
# print(mid,need)
return c>=need
ss='abcdefghijklmnopqrstuvwxyz'
s = list(input())
t = list(input())
ha=[0]*26
has=[0]*26
m=10000000000
c=0
for i in t:
ha[ord(i)-ord('a')]+=1
for... | 3 | |
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,651,156,615 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | import math
a,b = map(int,input().split())
print(0 if a > 1000 and b > 1000 else str(math.factorial(b) // math.factorial(a))[-1]) | 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(int,input().split())
print(0 if a > 1000 and b > 1000 else str(math.factorial(b) // math.factorial(a))[-1])
``` | 0 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,541,591,146 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 108 | 0 | a=int(input())
b=a//2
c=a-b
i=2
while i<b:
if (b/i)%1==0 and (c/i)%1==0:
b=b-1
c=c+1
else:
i=i+1
if b<=0:
break
if b<=0:
print("1 "+str(a-1))
else:
print(str(b)+" "+str(c)) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
a=int(input())
b=a//2
c=a-b
i=2
while i<b:
if (b/i)%1==0 and (c/i)%1==0:
b=b-1
c=c+1
else:
i=i+1
if b<=0:
break
if b<=0:
print("1 "+str(a-1))
else:
print(str(b)+" "+str(c))
``` | 0 | |
774 | A | Amusement Park | PROGRAMMING | 2,100 | [
"*special",
"ternary search"
] | null | null | Pupils decided to go to amusement park. Some of them were with parents. In total, *n* people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.
Tickets for group of *x* people are sold on the attraction, there should be at least one adult in each group (it is possible... | The first line contains three integers *n*, *c*1 and *c*2 (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*c*1,<=*c*2<=≤<=107) — the number of visitors and parameters for determining the ticket prices for a group.
The second line contains the string of length *n*, which consists of zeros and ones. If the *i*-th symbol of the string is... | Print the minimum price of visiting the most extreme attraction for all pupils and their parents. Each of them should roll on the attraction exactly once. | [
"3 4 1\n011\n",
"4 7 2\n1101\n"
] | [
"8\n",
"18\n"
] | In the first test one group of three people should go to the attraction. Then they have to pay 4 + 1 * (3 - 1)<sup class="upper-index">2</sup> = 8.
In the second test it is better to go to the attraction in two groups. The first group should consist of two adults (for example, the first and the second person), the sec... | 0 | [
{
"input": "3 4 1\n011",
"output": "8"
},
{
"input": "4 7 2\n1101",
"output": "18"
},
{
"input": "1 2 2\n1",
"output": "2"
},
{
"input": "2 3 10\n01",
"output": "13"
},
{
"input": "5 10 3\n11100",
"output": "35"
},
{
"input": "10 2 2\n1111101111",
... | 1,594,205,510 | 950 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 6,963,200 | import math
n,c1,c2=map(int,input().split())
s=input()
cnt=s.count('1')
if(cnt==1):
print(int(c1+c2*math.pow((n-1),2)))
else:
if(n%2):
l=int(c1+c2*math.pow((n-1),2))
r=int(2*c1+c2*math.pow(int((n+1)/2)-1,2)+c2*math.pow(int((n-1)/2)-1,2))
print(min(l,r))
else:
l=in... | Title: Amusement Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pupils decided to go to amusement park. Some of them were with parents. In total, *n* people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.
Tickets for group of *x*... | ```python
import math
n,c1,c2=map(int,input().split())
s=input()
cnt=s.count('1')
if(cnt==1):
print(int(c1+c2*math.pow((n-1),2)))
else:
if(n%2):
l=int(c1+c2*math.pow((n-1),2))
r=int(2*c1+c2*math.pow(int((n+1)/2)-1,2)+c2*math.pow(int((n-1)/2)-1,2))
print(min(l,r))
else:
... | 0 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,600,921,564 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 216 | 0 | n,k = map(int,input().split())
arr = list(map(int,input().split()))
for i in range(n):
if arr[i]<0:
arr[i] *=-1
k -=1
if k==0:
break
arr.sort()
if k//2!=0:
arr[0]*=-1
print(sum(arr)) | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
n,k = map(int,input().split())
arr = list(map(int,input().split()))
for i in range(n):
if arr[i]<0:
arr[i] *=-1
k -=1
if k==0:
break
arr.sort()
if k//2!=0:
arr[0]*=-1
print(sum(arr))
``` | 0 | |
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,676,214,623 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 92 | 0 | def solve(s):
res = s[0]
for i in range(1, len(s)):
if len(res) == 7:
return 'YES'
if res[-1] == s[i]:
res += s[i]
else:
res = s[i]
return 'NO'
print(solve(input()))
| 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
def solve(s):
res = s[0]
for i in range(1, len(s)):
if len(res) == 7:
return 'YES'
if res[-1] == s[i]:
res += s[i]
else:
res = s[i]
return 'NO'
print(solve(input()))
``` | 0 |
361 | B | Levko and Permutation | PROGRAMMING | 1,200 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g... | The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*). | In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist.
If there are multiple suitable permutations, you are allowed to print any of them. | [
"4 2\n",
"1 1\n"
] | [
"2 4 3 1",
"-1\n"
] | In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 > 1 and *gcd*(3, 3) = 3 > 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.
The second sample has no beautiful permutations. | 1,000 | [
{
"input": "4 2",
"output": "2 1 3 4 "
},
{
"input": "1 1",
"output": "-1"
},
{
"input": "7 4",
"output": "3 1 2 4 5 6 7 "
},
{
"input": "10 9",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "10000 5000",
"output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1... | 1,640,967,735 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, k = map(int, input().split())
if n == k:
print(-1)
exit()
arr = [i for i in range(2, n+1)]
arr.insert(k, 1)
print(*arr)
# 7 4
# Output
# 6 2 3 4 5 1 7
# Answer
# 3 1 2 4 5 6 7 | Title: Levko and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*.
Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb... | ```python
n, k = map(int, input().split())
if n == k:
print(-1)
exit()
arr = [i for i in range(2, n+1)]
arr.insert(k, 1)
print(*arr)
# 7 4
# Output
# 6 2 3 4 5 1 7
# Answer
# 3 1 2 4 5 6 7
``` | 0 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,682,050,594 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 140 | 1,331,200 | s = str(input())
q = int(input())
sl= []
for i in range (len(s)):
sl.append(s[i])
lis = []
for i in range(q):
c=0
g,h=0,0
a=[]
dem = 0
l,r=map(int,input().split())
for j in range(l-1,r):
c+=1
a.append(sl[j])
if sl[j]=="(":
if j!=r-1: ... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
s = str(input())
q = int(input())
sl= []
for i in range (len(s)):
sl.append(s[i])
lis = []
for i in range(q):
c=0
g,h=0,0
a=[]
dem = 0
l,r=map(int,input().split())
for j in range(l-1,r):
c+=1
a.append(sl[j])
if sl[j]=="(":
if ... | 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,659,184,920 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
n = input().split(" ")
dim1 = int(n[0])
dim2 = int(n[1])
count = 0
if dim1 * dim2 < 2 :
print(0)
else:
if dim1 == 1 and dim2 > 1 :
count = math.floor(dim2 / 2)
elif dim2 == 1 and dim1 > 1:
count = math.floor(dim1 / 2)
elif dim1 > 1 and dim2 > 1:
if dim1 % 2 == 0:
count += ((d... | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import math
n = input().split(" ")
dim1 = int(n[0])
dim2 = int(n[1])
count = 0
if dim1 * dim2 < 2 :
print(0)
else:
if dim1 == 1 and dim2 > 1 :
count = math.floor(dim2 / 2)
elif dim2 == 1 and dim1 > 1:
count = math.floor(dim1 / 2)
elif dim1 > 1 and dim2 > 1:
if dim1 % 2 == 0:
co... | 3.977 |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,568,479,003 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 280 | 0 | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
x, y, a, b = map(int, input().split())
temp_gcd = gcd(x, y)
lcm = x * y // temp_gcd
k = (b - a - 1) // lcm
if a % lcm == 0:
k += 1
if b % lcm == 0:
k += 1
print(k) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
x, y, a, b = map(int, input().split())
temp_gcd = gcd(x, y)
lcm = x * y // temp_gcd
k = (b - a - 1) // lcm
if a % lcm == 0:
k += 1
if b % lcm == 0:
k += 1
print(k)
``` | 0 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,695,430,535 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | n = int(input())
strings = []
for _ in range(n):
strings.append(input())
strings.sort(key=lambda x: (len(x), x),reverse=True)
result = ''.join(strings)
print(result)
| Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
n = int(input())
strings = []
for _ in range(n):
strings.append(input())
strings.sort(key=lambda x: (len(x), x),reverse=True)
result = ''.join(strings)
print(result)
``` | 0 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,696,422,842 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | # URL: https://codeforces.com/problemset/problem/271/A
for ans in range(int(input()) + 1, 9012):
if len(set(str(ans))) == 4:
print(ans)
break
| Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
# URL: https://codeforces.com/problemset/problem/271/A
for ans in range(int(input()) + 1, 9012):
if len(set(str(ans))) == 4:
print(ans)
break
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,508,057,752 | 3,052 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 8,601,600 | n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
print(min(l))
elif k==2:
m=l[:]
m.sort()
c=[]
for x in m:
c.append(l.index(x))
if c[-1]==0 or c[-1]==n-1:
print(m[-1])
else:
if l[0]>l[-1]:
print(l[0])
else:
print(l[-1])
else:
print(max(l)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
if k==1:
print(min(l))
elif k==2:
m=l[:]
m.sort()
c=[]
for x in m:
c.append(l.index(x))
if c[-1]==0 or c[-1]==n-1:
print(m[-1])
else:
if l[0]>l[-1]:
print(l[0])
else:
print(l[-1])
else:
print(max(l))
``` | 0 | |
742 | B | Arpa’s obvious problem and Mehrdad’s terrible solution | PROGRAMMING | 1,500 | [
"brute force",
"math",
"number theory"
] | null | null | There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad di... | First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer: the answer to the problem. | [
"2 3\n1 2\n",
"6 1\n5 1 2 3 4 1\n"
] | [
"1",
"2"
] | In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1.
In the second sample the only two pairs are *i* = 3, *j* = 4 ... | 1,000 | [
{
"input": "2 3\n1 2",
"output": "1"
},
{
"input": "6 1\n5 1 2 3 4 1",
"output": "2"
},
{
"input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423",
"output": "0"
},
{
"i... | 1,685,214,088 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 17 | 77 | 13,721,600 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
C = Counter(A)
ans =... | Title: Arpa’s obvious problem and Mehrdad’s terrible solution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indice... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
C = Counte... | 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,515,694,786 | 1,186 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 19,968,000 | def main():
t, m = map(int, input().split())
memory = [(0, m, 0)]
next_id = 1
for _ in range(t):
cmd = list(input().split())
if cmd[0] == 'defragment':
new_mem = []
rem_sz = 0
for block in memory:
if block[2] > 0:
n... | 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
def main():
t, m = map(int, input().split())
memory = [(0, m, 0)]
next_id = 1
for _ in range(t):
cmd = list(input().split())
if cmd[0] == 'defragment':
new_mem = []
rem_sz = 0
for block in memory:
if block[2] > 0:
... | 0 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,686,301,574 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | n=int(input())
ls=map(int,input().split())
print((a+b+c)/len(l)) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n=int(input())
ls=map(int,input().split())
print((a+b+c)/len(l))
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all:
- 'U': go up, (x, y) <=→<= (x, y+1); - 'D': go down, (x, y) <=→<= (x, y-1); - 'L': go l... | The first line contains two integers *a* and *b*, (<=-<=109<=≤<=*a*,<=*b*<=≤<=109). The second line contains a string *s* (1<=≤<=|*s*|<=≤<=100, *s* only contains characters 'U', 'D', 'L', 'R') — the command. | Print "Yes" if the robot will be located at (*a*,<=*b*), and "No" otherwise. | [
"2 2\nRU\n",
"1 2\nRU\n",
"-1 1000000000\nLRRLU\n",
"0 0\nD\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on.
The locations of its moves are (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → ...
So it can reach (2, 2) but not (1, 2). | 0 | [
{
"input": "2 2\nRU",
"output": "Yes"
},
{
"input": "1 2\nRU",
"output": "No"
},
{
"input": "-1 1000000000\nLRRLU",
"output": "Yes"
},
{
"input": "0 0\nD",
"output": "Yes"
},
{
"input": "0 0\nUURRDL",
"output": "Yes"
},
{
"input": "987654321 987654321\... | 1,480,322,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 204,800 | d={'U':(0,1),'D':(0,-1),'R':(1,0),'L':(-1,0)}
x,y=[int(i) for i in input().split()]
path=input()
c={}
c[0]=(0,0)
dx,dy=0,0
for i in range(len(path)):
dx,dy=dx+d[path[i]][0],dy+d[path[i]][1]
x1,y1=c[i][0]+d[path[i]][0],c[i][1]+d[path[i]][1]
c[i+1]=(x1,y1)
if (x,y) in c.values(): print('Yes')
else:... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string *s*. Each character of *s* is one move operation. There are four move operations at all:
... | ```python
d={'U':(0,1),'D':(0,-1),'R':(1,0),'L':(-1,0)}
x,y=[int(i) for i in input().split()]
path=input()
c={}
c[0]=(0,0)
dx,dy=0,0
for i in range(len(path)):
dx,dy=dx+d[path[i]][0],dy+d[path[i]][1]
x1,y1=c[i][0]+d[path[i]][0],c[i][1]+d[path[i]][1]
c[i+1]=(x1,y1)
if (x,y) in c.values(): print('Ye... | 0 | |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,549,878,787 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | import math
n=int(input())
if n%2!=0:
if (n/2)%2!=0:
print(math.floor(n/2)-2,math.ceil(n/2)+2)
else:
print(math.floor(n/2),math.ceil(n/2))
else:
if (n/2)%2!=0:
print(math.floor(n/2)-2,math.ceil(n/2)+2)
else:
print(math.floor(n/2)-1,math.ceil(n/2)+1) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
import math
n=int(input())
if n%2!=0:
if (n/2)%2!=0:
print(math.floor(n/2)-2,math.ceil(n/2)+2)
else:
print(math.floor(n/2),math.ceil(n/2))
else:
if (n/2)%2!=0:
print(math.floor(n/2)-2,math.ceil(n/2)+2)
else:
print(math.floor(n/2)-1,math.ceil(n/2)+1)
`... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,683,439,439 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 92 | 0 | n=int(input())
if n>0 and n<101:
L=[]
s=0
for i in range(n):
x=input()
L.append(x)
for i in L:
b=i.split(" ")
for j in b:
s=s+int(j)
if s==0:
print("YES")
else:
print("NO")
else:
print("Invalid number")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
if n>0 and n<101:
L=[]
s=0
for i in range(n):
x=input()
L.append(x)
for i in L:
b=i.split(" ")
for j in b:
s=s+int(j)
if s==0:
print("YES")
else:
print("NO")
else:
print("Invalid number")
... | 0 |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,673,007,215 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 46 | 0 | scoreboard = [ list(map(str,input().split())) for _ in range(int(input()))]
scoreboard.append([0,0])
for result in scoreboard[:-1]:
if (result[0] > result[1]): scoreboard[len(scoreboard)-1][0] += 1
else: scoreboard[len(scoreboard)-1][1] += 1
if (max(scoreboard[len(scoreboard)-1]) == scoreboard[len(scorebo... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
scoreboard = [ list(map(str,input().split())) for _ in range(int(input()))]
scoreboard.append([0,0])
for result in scoreboard[:-1]:
if (result[0] > result[1]): scoreboard[len(scoreboard)-1][0] += 1
else: scoreboard[len(scoreboard)-1][1] += 1
if (max(scoreboard[len(scoreboard)-1]) == scoreboard[l... | 0 | |
14 | C | Four Segments | PROGRAMMING | 1,700 | [
"brute force",
"constructive algorithms",
"geometry",
"implementation",
"math"
] | C. Four Segments | 2 | 64 | Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the progr... | The input data contain four lines. Each of these lines contains four integers *x*1, *y*1, *x*2, *y*2 (<=-<=109<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points. | Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO». | [
"1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n",
"0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0",
"output": "YES"
},
{
"input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "NO"
},
{
"input": "0 0 0 2\n2 0 0 0\n2 2 2 0\n0 2 2 2",
"output": "YES"
},
{
"input": "0 0 10 0\n0 0 10 0\n0 0 0 5\n0 0 0 -5",
"output": "NO"
... | 1,678,470,868 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | l1, l2, l3, l4=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
points=[[l1[0],l1[1]],[l1[2],l1[3]],[l2[0],l2[1]],[l2[2],l2[3]],[l3[0],l3[1]],[l3[2],l3[3]],[l4[0],l4[1]],[l4[2],l4[3]]]
#XD
point=[]
for a in points:
if a not in point:
... | Title: Four Segments
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creati... | ```python
l1, l2, l3, l4=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
points=[[l1[0],l1[1]],[l1[2],l1[3]],[l2[0],l2[1]],[l2[2],l2[3]],[l3[0],l3[1]],[l3[2],l3[3]],[l4[0],l4[1]],[l4[2],l4[3]]]
#XD
point=[]
for a in points:
if a not in poin... | 0 |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,655,995,326 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | n, m = map(int, input().split())
a = []
count = 0
for i in range(n):
a.append(input())
for i in range(n):
if 'S' in a[i]:
continue
else:
a[i] = '0'*m
count += m
for j in range(m):
in_count = 0
for i in range(n):
if a[i][j] == '.':
in_count +... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n, m = map(int, input().split())
a = []
count = 0
for i in range(n):
a.append(input())
for i in range(n):
if 'S' in a[i]:
continue
else:
a[i] = '0'*m
count += m
for j in range(m):
in_count = 0
for i in range(n):
if a[i][j] == '.':
... | 3 | |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,618,166,156 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | # https://codeforces.com/problemset/problem/221/A
# f(x):
# if 1 exit
# else:
# f(x-1)
# swap(x, x-1)
# 1, 2, 3, 4, 5, 6, 7
# 2, 3, 4, 5, 6, 7, 1
n = int(input())
print(n, end=' ')
if n>1:
num = 1
for _ in range(n-1):
print(num, end=' ')
num += 1
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
# https://codeforces.com/problemset/problem/221/A
# f(x):
# if 1 exit
# else:
# f(x-1)
# swap(x, x-1)
# 1, 2, 3, 4, 5, 6, 7
# 2, 3, 4, 5, 6, 7, 1
n = int(input())
print(n, end=' ')
if n>1:
num = 1
for _ in range(n-1):
print(num, end=' ')
num += 1
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,684,765,490 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | s=input()
if len(s)>5:
print("Yes")
else:
print("No")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s=input()
if len(s)>5:
print("Yes")
else:
print("No")
``` | 0 |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,607,177,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 307,200 | n = int(input())
a = list(map(int,input().split()))
if all(item % 2 == 0 for item in a):
print("Second")
elif all(item % 2 != 0 for item in a) and n % 2 == 0:
print("First")
elif all(item % 2 != 0 for item in a) and n % 2 != 0:
print("Second")
elif sum(a) % 2 != 0:
print("First")
elif sum(a) %... | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
n = int(input())
a = list(map(int,input().split()))
if all(item % 2 == 0 for item in a):
print("Second")
elif all(item % 2 != 0 for item in a) and n % 2 == 0:
print("First")
elif all(item % 2 != 0 for item in a) and n % 2 != 0:
print("Second")
elif sum(a) % 2 != 0:
print("First")
eli... | 0 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,675,344,348 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 614,400 | def solve():
s = input().split(':')
while len(s) != 8:
s.insert(s.index(''), '')
res = []
for block in s:
while len(block) != 4:
block = '0' + block
res.append(block)
print(':'.join(res))
for _ in range(int(input())):
solve()
##... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
def solve():
s = input().split(':')
while len(s) != 8:
s.insert(s.index(''), '')
res = []
for block in s:
while len(block) != 4:
block = '0' + block
res.append(block)
print(':'.join(res))
for _ in range(int(input())):
sol... | 0 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,656,275,204 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | num_queue=int(input())
intial_num=int(input())
i=0
sad_kid=0
in_value=['x']
while i<num_queue:
in_value.append(input())
in_value.append(input())
in_value.append(input())
if in_value[1]=="+" :
intial_num=intial_num+int(in_value[3])
elif in_value[1]=="-" and int(in_value[3])<=intial... | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
num_queue=int(input())
intial_num=int(input())
i=0
sad_kid=0
in_value=['x']
while i<num_queue:
in_value.append(input())
in_value.append(input())
in_value.append(input())
if in_value[1]=="+" :
intial_num=intial_num+int(in_value[3])
elif in_value[1]=="-" and int(in_value[3... | -1 | |
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,679,946,236 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 327 | 7,987,200 | from bisect import *
n = int(input())
a = list(map(int,input().split()))
m = int(input())
ms = list(map(int,input().split()))
cmltve = []
temp = 0
for i in a:
temp += i
cmltve.append(temp)
for i in ms:
x = bisect_left(cmltve,i) + 1
print(x)
| 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
from bisect import *
n = int(input())
a = list(map(int,input().split()))
m = int(input())
ms = list(map(int,input().split()))
cmltve = []
temp = 0
for i in a:
temp += i
cmltve.append(temp)
for i in ms:
x = bisect_left(cmltve,i) + 1
print(x)
``` | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,635,962,613 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 93 | 4,300,800 | p=int(input())
t=0
for i in range(1,p):
if p%i==0:
t+=1
print(t) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
p=int(input())
t=0
for i in range(1,p):
if p%i==0:
t+=1
print(t)
``` | 3 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,507,592,200 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | # http://codeforces.com/problemset/problem/787/A
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
vmax = max(a,b,c,d)
for i in range(vmax+1):
temp = a*i + b
print(temp)
# if ( (temp-d)%c == float(0) ):
# print(temp)
# break
# else:
# print(-1) | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
# http://codeforces.com/problemset/problem/787/A
a, b = [int(x) for x in input().split()]
c, d = [int(x) for x in input().split()]
vmax = max(a,b,c,d)
for i in range(vmax+1):
temp = a*i + b
print(temp)
# if ( (temp-d)%c == float(0) ):
# print(temp)
# break
# else:
# print(-1)
``` | 0 | |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,665,833,284 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 187 | 307,200 | from collections import defaultdict
n = int(input())
s = input()
n = len(s)
hmap = defaultdict(int)
ans = float("inf")
unique = len(set(s))
l = 0
for r in range(n):
hmap[s[r]]+=1
while l<n and len(hmap) == unique and hmap[s[l]]>0:
ans = min(ans,r-l+1)
hmap[s[l]]-=1
... | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
from collections import defaultdict
n = int(input())
s = input()
n = len(s)
hmap = defaultdict(int)
ans = float("inf")
unique = len(set(s))
l = 0
for r in range(n):
hmap[s[r]]+=1
while l<n and len(hmap) == unique and hmap[s[l]]>0:
ans = min(ans,r-l+1)
hmap[s[l]]... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,621,839,163 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 124 | 0 | # -*- coding: utf-8 -*-
"""
Created on Mon May 24 14:40:12 2021
@author: nagan
"""
a, b, n = map(int, input().split())
c = 0
ans = 9
while True:
if c % 2 == 0:
y = True
d = min(a, n)
if n < a:
ans = 1
break
for i in range(d, 0, -1):
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon May 24 14:40:12 2021
@author: nagan
"""
a, b, n = map(int, input().split())
c = 0
ans = 9
while True:
if c % 2 == 0:
y = True
d = min(a, n)
if n < a:
ans = 1
break
for i in range(d, 0, -1)... | 0 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,533,357,068 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 3,993,600 | warriorCount, totalMinutes = list(map(int,input().strip().split(" ")))
strengthList = list(map(int,input().split(" ")))
orderList = list(map(int,input().split(" ")))
def prefixSum(currList):
result = [0] * len(strengthList)
result[0] = currList[0]
for i in range(1,len(currList)):
result[i] = result[i-1] + currLis... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
warriorCount, totalMinutes = list(map(int,input().strip().split(" ")))
strengthList = list(map(int,input().split(" ")))
orderList = list(map(int,input().split(" ")))
def prefixSum(currList):
result = [0] * len(strengthList)
result[0] = currList[0]
for i in range(1,len(currList)):
result[i] = result[i-1]... | 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,579,954,416 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | x = input()
C = 0
for i in x:
if 64 < ord(i) < 91:
C = C + 1
if C > len(x) / 2:
x = x.upper()
else:
x = x.lower()
print(x) | 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
x = input()
C = 0
for i in x:
if 64 < ord(i) < 91:
C = C + 1
if C > len(x) / 2:
x = x.upper()
else:
x = x.lower()
print(x)
``` | 3.93 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,692,092,690 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 4,096,000 | import io,os
from collections import *
from math import *
from string import *
from itertools import *
from statistics import *
from fractions import *
from functools import reduce
from heapq import *
try:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
pass
#subsets here (;
d... | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
import io,os
from collections import *
from math import *
from string import *
from itertools import *
from statistics import *
from fractions import *
from functools import reduce
from heapq import *
try:
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
pass
#subsets ... | 0 | |
929 | B | Места в самолёте | PROGRAMMING | 1,300 | [
"*special",
"implementation"
] | null | null | В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
Известно, что некоторые места уже заняты пассажирами. Всего есть два вида пассажиров — статусные (те, ... | В первой строке следуют два целых числа *n* и *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10·*n*) — количество рядов мест в самолёте и количество пассажиров, которых нужно рассадить.
Далее следует описание рядов мест самолёта по одному ряду в строке. Если очередной символ равен '-', то это проход между рядами. Если очередно... | В первую строку выведите минимальное суммарное число соседей у статусных пассажиров.
Далее выведите план рассадки пассажиров, который минимизирует суммарное количество соседей у статусных пассажиров, в том же формате, что и во входных данных. Если в свободное место нужно посадить одного из *k* пассажиров, выведите стр... | [
"1 2\nSP.-SS.S-S.S\n",
"4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP\n"
] | [
"5\nSPx-SSxS-S.S\n",
"15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP\n"
] | В первом примере нужно посадить ещё двух обычных пассажиров. Для минимизации соседей у статусных пассажиров, нужно посадить первого из них на третье слева место, а второго на любое из оставшихся двух мест, так как независимо от выбора места он станет соседом двух статусных пассажиров.
Изначально, у статусного пассажи... | 1,000 | [
{
"input": "1 2\nSP.-SS.S-S.S",
"output": "5\nSPx-SSxS-S.S"
},
{
"input": "4 9\nPP.-PPPS-S.S\nPSP-PPSP-.S.\n.S.-S..P-SS.\nP.S-P.PP-PSP",
"output": "15\nPPx-PPPS-S.S\nPSP-PPSP-xSx\nxSx-SxxP-SSx\nP.S-PxPP-PSP"
},
{
"input": "3 7\n.S.-SSSP-..S\nS..-.SPP-S.P\n.S.-PPPP-PSP",
"output": "13... | 1,520,023,815 | 18,915 | PyPy 3 | OK | TESTS | 47 | 109 | 20,070,400 | n, k = map(int, input().split())
qq = []
for i in range(n):
qq.append(list(input()))
for i in range(n):
for j in range(12):
if qq[i][j] == '.' and (j == 0 or qq[i][j - 1] != 'S') and (j == 11 or qq[i][j + 1] != 'S') and k > 0:
qq[i][j] = 'x'
k -= 1
if k == 0:
... | Title: Места в самолёте
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
В самолёте есть *n* рядов мест. Если смотреть на ряды сверху, то в каждом ряду есть 3 места слева, затем проход между рядами, затем 4 центральных места, затем ещё один проход между рядами, а затем ещё 3 места справа.
... | ```python
n, k = map(int, input().split())
qq = []
for i in range(n):
qq.append(list(input()))
for i in range(n):
for j in range(12):
if qq[i][j] == '.' and (j == 0 or qq[i][j - 1] != 'S') and (j == 11 or qq[i][j + 1] != 'S') and k > 0:
qq[i][j] = 'x'
k -= 1
if k == ... | 3 | |
288 | A | Polo the Penguin and Strings | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase English letters (that is, the string's length equals *n*), exactly *k* of these letters are distinct. 1. No two neighbo... | A single line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=106,<=1<=≤<=*k*<=≤<=26) — the string's length and the number of distinct letters. | In a single line print the required string. If there isn't such string, print "-1" (without the quotes). | [
"7 4\n",
"4 7\n"
] | [
"ababacd\n",
"-1\n"
] | none | 500 | [
{
"input": "7 4",
"output": "ababacd"
},
{
"input": "4 7",
"output": "-1"
},
{
"input": "10 5",
"output": "abababacde"
},
{
"input": "47 2",
"output": "abababababababababababababababababababababababa"
},
{
"input": "10 7",
"output": "ababacdefg"
},
{
"... | 1,629,280,618 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 30,924,800 | n,k = map(int,input().split())
s=""
if(k>n or(n>1 and k==1)):
print(-1)
else:
i=0
k = max(0,k-2)
ans = n-k
st = "ab"
while(ans):
s+=st[i]
i+=1
ans-=1
if(i==2):
i=0
for i in range(99,123):
if k<=0:
break
... | Title: Polo the Penguin and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo adores strings. But most of all he adores strings of length *n*.
One day he wanted to find a string that meets the following conditions:
1. The string consists of *n* lowercase Englis... | ```python
n,k = map(int,input().split())
s=""
if(k>n or(n>1 and k==1)):
print(-1)
else:
i=0
k = max(0,k-2)
ans = n-k
st = "ab"
while(ans):
s+=st[i]
i+=1
ans-=1
if(i==2):
i=0
for i in range(99,123):
if k<=0:
br... | 0 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,699,774,046 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | s = input()
a = [int(i) for i in s.split('+')]
a.sort()
a = list(map(str,a))
print('+'.join(a)) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
s = input()
a = [int(i) for i in s.split('+')]
a.sort()
a = list(map(str,a))
print('+'.join(a))
``` | 3 | |
925 | B | Resource Distribution | PROGRAMMING | 1,700 | [
"binary search",
"implementation",
"sortings"
] | null | null | One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expressed with a single integer number $c_j$ of artificial resource units.
In order for production to work, it ... | The first line contains three integers $n$, $x_1$, $x_2$ ($2 \leq n \leq 300\,000$, $1 \leq x_1, x_2 \leq 10^9$) — the number of servers that the department may use, and resource units requirements for each of the services.
The second line contains $n$ space-separated integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq... | If it is impossible to deploy both services using the given servers, print the only word "No" (without the quotes).
Otherwise print the word "Yes" (without the quotes).
In the second line print two integers $k_1$ and $k_2$ ($1 \leq k_1, k_2 \leq n$) — the number of servers used for each of the services.
In the thir... | [
"6 8 16\n3 5 2 9 8 7\n",
"4 20 32\n21 11 11 12\n",
"4 11 32\n5 5 16 16\n",
"5 12 20\n7 8 4 11 9\n"
] | [
"Yes\n3 2\n1 2 6\n5 4",
"Yes\n1 3\n1\n2 3 4\n",
"No\n",
"No\n"
] | In the first sample test each of the servers 1, 2 and 6 will will provide $8 / 3 = 2.(6)$ resource units and each of the servers 5, 4 will provide $16 / 2 = 8$ resource units.
In the second sample test the first server will provide $20$ resource units and each of the remaining servers will provide $32 / 3 = 10.(6)$ re... | 1,000 | [
{
"input": "6 8 16\n3 5 2 9 8 7",
"output": "Yes\n4 2\n3 1 2 6\n5 4"
},
{
"input": "4 20 32\n21 11 11 12",
"output": "Yes\n1 3\n1\n2 3 4"
},
{
"input": "4 11 32\n5 5 16 16",
"output": "No"
},
{
"input": "5 12 20\n7 8 4 11 9",
"output": "No"
},
{
"input": "2 1 1\n1... | 1,654,207,609 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 748 | 42,700,800 | I = lambda:list(map(int, input().split()))
n,x1,x2 = I()
servers = I()
idx = list(range(n))
idx.sort(key = lambda i : servers[i])
def solve(a, b, rev):
j = len(idx)-1
while j >= 0 and (n-j)*servers[idx[j]] < b:
j -= 1
if j < 0:
return
i = j-1
while i >= 0 and (j-i)*serv... | Title: Resource Distribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One department of some software company has $n$ servers of different specifications. Servers are indexed with consecutive integers from $1$ to $n$. Suppose that the specifications of the $j$-th server may be expre... | ```python
I = lambda:list(map(int, input().split()))
n,x1,x2 = I()
servers = I()
idx = list(range(n))
idx.sort(key = lambda i : servers[i])
def solve(a, b, rev):
j = len(idx)-1
while j >= 0 and (n-j)*servers[idx[j]] < b:
j -= 1
if j < 0:
return
i = j-1
while i >= 0 and ... | 3 | |
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T... | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader... | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",... | 1,492,527,349 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 62 | 5,529,600 | n,k=(int(n) for n in input().split())
A=[int(n) for n in input().split()]
V=[i+1 for i in range(n)]
pos=0
elim=[]
for i in range(k):
pos=(pos+A[i])%len(V)
elim.append(V.pop(pos))
if(pos == len(V)):
pos=0
for x in elim:
print(x,end=' ')
| Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ... | ```python
n,k=(int(n) for n in input().split())
A=[int(n) for n in input().split()]
V=[i+1 for i in range(n)]
pos=0
elim=[]
for i in range(k):
pos=(pos+A[i])%len(V)
elim.append(V.pop(pos))
if(pos == len(V)):
pos=0
for x in elim:
print(x,end=' ')
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,578,214,766 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 496 | 10,752,000 | n, dist = map(int, input().split())
points = list(map(int, input().split()))
group_count = 0
tail = 0
for head in range(n) :
while points[head] - points[tail] > dist: # when the condition is not working make a step
tail += 1
# the number of points in the segment between two pointers, exclu... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n, dist = map(int, input().split())
points = list(map(int, input().split()))
group_count = 0
tail = 0
for head in range(n) :
while points[head] - points[tail] > dist: # when the condition is not working make a step
tail += 1
# the number of points in the segment between two point... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,666,407,603 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a = tuple(map(int,input().split(" ")))
n = n//a if n//a == n/a else (n//a) + 1
m = m//a if m//a == m/a else (m//a) + 1
print(n*m)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a = tuple(map(int,input().split(" ")))
n = n//a if n//a == n/a else (n//a) + 1
m = m//a if m//a == m/a else (m//a) + 1
print(n*m)
``` | 3.977 |
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,630,671,035 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 20,172,800 | def non(s):
m, l = 1, 0
for i in range(0, len(s) - 1):
if s[i] == s[i + 1]: l = 0
elif s[i + 1] == s[i - 1] and i > 0: l = 1
else: l += 1
m = max(m, l + 1)
if m == 1: return 0
else: return m
n=input()
print(non(n)) | 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
def non(s):
m, l = 1, 0
for i in range(0, len(s) - 1):
if s[i] == s[i + 1]: l = 0
elif s[i + 1] == s[i - 1] and i > 0: l = 1
else: l += 1
m = max(m, l + 1)
if m == 1: return 0
else: return m
n=input()
print(non(n))
``` | 0 | |
898 | B | Proper Nutrition | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"number theory"
] | null | null | Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly *n* bu... | First line contains single integer *n* (1<=≤<=*n*<=≤<=10<=000<=000) — amount of money, that Vasya has.
Second line contains single integer *a* (1<=≤<=*a*<=≤<=10<=000<=000) — cost of one bottle of Ber-Cola.
Third line contains single integer *b* (1<=≤<=*b*<=≤<=10<=000<=000) — cost of one Bars bar. | If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly *n* burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers *x* and *y* — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly... | [
"7\n2\n3\n",
"100\n25\n10\n",
"15\n4\n8\n",
"9960594\n2551\n2557\n"
] | [
"YES\n2 1\n",
"YES\n0 10\n",
"NO\n",
"YES\n1951 1949\n"
] | In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly *n* burles multiple ways:
- buy two bottles of Ber-Cola and five Bars bars; - buy four bottles of Ber-Cola and don't buy Bars bars; - don't buy Ber-Cola an... | 750 | [
{
"input": "7\n2\n3",
"output": "YES\n2 1"
},
{
"input": "100\n25\n10",
"output": "YES\n0 10"
},
{
"input": "15\n4\n8",
"output": "NO"
},
{
"input": "9960594\n2551\n2557",
"output": "YES\n1951 1949"
},
{
"input": "10000000\n1\n1",
"output": "YES\n0 10000000"
... | 1,561,740,618 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n, a, b = int(input()), int(input()), int(input())
f = True
if a < b:
f = False
a = max(a, b)
b = min(b, a)
t=int(n/a+1)
for i in range(t+1):
m=i*a;
if((n-m)%b==0 and n-m>=0):
print('YES')
if f:
print('{} {}'.format(i,int((n-m)/b)))
else:
print('{} {}'.format(int((n-m)/b), i))
exit()
print("NO"); | Title: Proper Nutrition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* burles. One bottle of Ber-Cola costs *a* burles and one Bars bar costs *b* burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find... | ```python
n, a, b = int(input()), int(input()), int(input())
f = True
if a < b:
f = False
a = max(a, b)
b = min(b, a)
t=int(n/a+1)
for i in range(t+1):
m=i*a;
if((n-m)%b==0 and n-m>=0):
print('YES')
if f:
print('{} {}'.format(i,int((n-m)/b)))
else:
print('{} {}'.format(int((n-m)/b), i))
exit()
prin... | 0 | |
1,007 | A | Reorder the Array | PROGRAMMING | 1,300 | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. | Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | 500 | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
... | 1,541,946,548 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n = int(input())
H = sorted(list(map(int, input().split())))
print(H)
counter = 0
used = [0] * n
for i in range(n):
for j in range(i + 1, n):
if H[j] > H[i] and not used[j]:
used[j] = 1
counter += 1
break
print(counter)
| Title: Reorder the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find t... | ```python
n = int(input())
H = sorted(list(map(int, input().split())))
print(H)
counter = 0
used = [0] * n
for i in range(n):
for j in range(i + 1, n):
if H[j] > H[i] and not used[j]:
used[j] = 1
counter += 1
break
print(counter)
``` | 0 | |
811 | A | Vladik and Courtesy | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn.
More formally, the guys take turns giving eac... | Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. | Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. | [
"1 1\n",
"7 6\n"
] | [
"Valera\n",
"Vladik\n"
] | Illustration for first test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Illustration for second test case:
<img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e... | 500 | [
{
"input": "1 1",
"output": "Valera"
},
{
"input": "7 6",
"output": "Vladik"
},
{
"input": "25 38",
"output": "Vladik"
},
{
"input": "8311 2468",
"output": "Valera"
},
{
"input": "250708 857756",
"output": "Vladik"
},
{
"input": "957985574 24997558",
... | 1,643,048,832 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | n,k=map(int,input().split())
p=n//3
q=k//2
if(n==k):
print("Valera")
elif(p<q):
print("Vladik")
else:
print("Valera") | Title: Vladik and Courtesy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vla... | ```python
n,k=map(int,input().split())
p=n//3
q=k//2
if(n==k):
print("Valera")
elif(p<q):
print("Vladik")
else:
print("Valera")
``` | 0 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,694,024,237 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | a = [4, 7]
for i in ('47'):
for j in ('47'):
a.append(int(i + j))
for t in ('47'):
for i in ('47'):
for j in ('47'):
a.append(int(i + j + t))
n = int(input())
flag = False
for i in a:
if n % i == 0:
print('YES')
flag = True
break
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
a = [4, 7]
for i in ('47'):
for j in ('47'):
a.append(int(i + j))
for t in ('47'):
for i in ('47'):
for j in ('47'):
a.append(int(i + j + t))
n = int(input())
flag = False
for i in a:
if n % i == 0:
print('YES')
flag = True
... | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,673,278,377 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | inputs = [input() for i in range(3)]
lowToHigh = ""
dictt = {'A':0, 'B':0, 'C':0}
for i in inputs:
if i[1] == "<":
i = i [::-1]
dictt[i[0]] += 1
for i in range(3):
if dictt['A'] == i:
print('A', end= '')
if dictt['B'] == i:
print('B', end= '')
if dictt['C'... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
inputs = [input() for i in range(3)]
lowToHigh = ""
dictt = {'A':0, 'B':0, 'C':0}
for i in inputs:
if i[1] == "<":
i = i [::-1]
dictt[i[0]] += 1
for i in range(3):
if dictt['A'] == i:
print('A', end= '')
if dictt['B'] == i:
print('B', end= '')
if... | 0 |
339 | B | Xenia and Ringroad | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105). The second line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*). Note that Xenia can have multiple consecutive tasks in one house. | Print a single integer — the time Xenia needs to complete all tasks.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n3 2 3\n",
"4 3\n2 3 3\n"
] | [
"6\n",
"2\n"
] | In the first test example the sequence of Xenia's moves along the ringroad looks as follows: 1 → 2 → 3 → 4 → 1 → 2 → 3. This is optimal sequence. So, she needs 6 time units. | 1,000 | [
{
"input": "4 3\n3 2 3",
"output": "6"
},
{
"input": "4 3\n2 3 3",
"output": "2"
},
{
"input": "2 2\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "100 100\n56 46 1 47 5 86 45 35 81 1 ... | 1,698,847,142 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 186 | 13,516,800 | n, m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(m-1):
if a[i] > a[i+1]:
ans += n
print(ans + (a[-1] - 1)) | Title: Xenia and Ringroad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise.
Xenia has recent... | ```python
n, m = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(m-1):
if a[i] > a[i+1]:
ans += n
print(ans + (a[-1] - 1))
``` | 3 | |
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 0<=≤<=*m*<=≤<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=≤<=*v**i*<=≤<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=≤<=*x**... | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20 + 10 + 10 +... | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
... | 1,406,201,718 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 0 | n,m = map(int,input().split())
fun = [int(x) for x in input().split()]
ans = 0
for i in range(m):
a,b=map(int,input().split())
ans+=min(fun[a-1],fun[b-1])
print (ans)
| Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but ev... | ```python
n,m = map(int,input().split())
fun = [int(x) for x in input().split()]
ans = 0
for i in range(m):
a,b=map(int,input().split())
ans+=min(fun[a-1],fun[b-1])
print (ans)
``` | 3 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,587,117,364 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,m,num,i,neg=0,pos=0,a,b;
cin>>n>>m;
while(n--)
{
cin>>num;
if (num==-1)
neg++;
else
pos++;
}
while(m--)
{
cin>>a>>b;
int x = b-a+1;
... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n,m,num,i,neg=0,pos=0,a,b;
cin>>n>>m;
while(n--)
{
cin>>num;
if (num==-1)
neg++;
else
pos++;
}
while(m--)
{
cin>>a>>b;
int x =... | -1 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,666,079,435 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Oct 18 15:50:10 2022
@author: hp
"""
a = int(input())
b = list(map(int,input().split()))
c = 0
for i in range(0,3):
c+=b[i]%2
if c>1:
for i in range(0,a):
if b[i]%2==0:
print(i+1)
else:
for i in range(0,a):
if b[i]%2=... | 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
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 18 15:50:10 2022
@author: hp
"""
a = int(input())
b = list(map(int,input().split()))
c = 0
for i in range(0,3):
c+=b[i]%2
if c>1:
for i in range(0,a):
if b[i]%2==0:
print(i+1)
else:
for i in range(0,a):
... | 3.977 |
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.