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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
305 | C | Ivan and Powers of Two | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece of paper. Now he wonders, what minimum number of integers of form 2*b* (*b*<=≥<=0) need to be added to the pi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second input line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·109). It is guaranteed that *a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*. | Print a single integer — the answer to the problem. | [
"4\n0 1 1 1\n",
"1\n3\n"
] | [
"0\n",
"3\n"
] | In the first sample you do not need to add anything, the sum of numbers already equals 2<sup class="upper-index">3</sup> - 1 = 7.
In the second sample you need to add numbers 2<sup class="upper-index">0</sup>, 2<sup class="upper-index">1</sup>, 2<sup class="upper-index">2</sup>. | 1,500 | [
{
"input": "4\n0 1 1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n2000000000",
"output": "2000000000"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... | 1,584,644,912 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 202 | 9,728,000 | n = int(input())
seq = [int(x) for x in input().split()]
def inseri(s, n):
if n in s:
s.remove(n)
inseri(s, n+1)
else:
s.add(n)
s = set()
for i in seq:
inseri(s, i)
m = max(s)
print(m-len(s)+1) | Title: Ivan and Powers of Two
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has got an array of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2*a*1,<=2*a*2,<=...,<=2*a**n* on a piece o... | ```python
n = int(input())
seq = [int(x) for x in input().split()]
def inseri(s, n):
if n in s:
s.remove(n)
inseri(s, n+1)
else:
s.add(n)
s = set()
for i in seq:
inseri(s, i)
m = max(s)
print(m-len(s)+1)
``` | 3 | |
90 | A | Cableway | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | A. Cableway | 2 | 256 | A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them ... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=><=0, it means that the group consists of at least one student. | Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. | [
"1 3 2\n",
"3 2 1\n"
] | [
"34",
"33"
] | Let's analyze the first sample.
At the moment of time 0 a red cablecar comes and one student from the *r* group get on it and ascends to the top at the moment of time 30.
At the moment of time 1 a green cablecar arrives and two students from the *g* group get on it; they get to the top at the moment of time 31.
At t... | 500 | [
{
"input": "1 3 2",
"output": "34"
},
{
"input": "3 2 1",
"output": "33"
},
{
"input": "3 5 2",
"output": "37"
},
{
"input": "10 10 10",
"output": "44"
},
{
"input": "29 7 24",
"output": "72"
},
{
"input": "28 94 13",
"output": "169"
},
{
"... | 1,669,916,712 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | r, g , b = map(int, input().split())
i = 0
t =30 * max((r// 2), (g//2), (b//2))
while not( (r <=0) and (g <=0) and (b <=0)):
if i % 3 == 0 and r > 0:
r -= 2
elif i % 3 == 1 and g > 0:
g -= 2
elif i % 3 == 2 and b > 0:
b -= 2
#print(r, g, b, i)
if (r <=0) and (g <... | Title: Cableway
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway.
A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cabl... | ```python
r, g , b = map(int, input().split())
i = 0
t =30 * max((r// 2), (g//2), (b//2))
while not( (r <=0) and (g <=0) and (b <=0)):
if i % 3 == 0 and r > 0:
r -= 2
elif i % 3 == 1 and g > 0:
g -= 2
elif i % 3 == 2 and b > 0:
b -= 2
#print(r, g, b, i)
if (r <=0... | 0 |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,689,529,423 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | n, l = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dis = 0
for i in range(n):
if i == 0:
dis = max(dis, a[i] * 2)
else:
dis = max(dis, a[i] - a[i - 1])
dis = max(dis, (l - a[i]) * 2)
print('{:.9f}'.format(dis/2))
| Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
n, l = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dis = 0
for i in range(n):
if i == 0:
dis = max(dis, a[i] * 2)
else:
dis = max(dis, a[i] - a[i - 1])
dis = max(dis, (l - a[i]) * 2)
print('{:.9f}'.format(dis/2))
``` | 3 | |
690 | A1 | Collective Mindsets (easy) | PROGRAMMING | 1,100 | [] | null | null | Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
... | The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). | Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{... | 1,651,582,773 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | int n
n=input()
if n%2:
print(n//2+1)
else:
print(n//2)
| Title: Collective Mindsets (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get ... | ```python
int n
n=input()
if n%2:
print(n//2+1)
else:
print(n//2)
``` | -1 | ||
0 | none | none | none | 0 | [
"none"
] | null | null | You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you cannot sell shares when y... | Input begins with an integer *N* (2<=≤<=*N*<=≤<=3·105), the number of days.
Following this is a line with exactly *N* integers *p*1,<=*p*2,<=...,<=*p**N* (1<=≤<=*p**i*<=≤<=106). The price of one share of stock on the *i*-th day is given by *p**i*. | Print the maximum amount of money you can end up with at the end of *N* days. | [
"9\n10 5 4 7 9 12 6 2 10\n",
"20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4\n"
] | [
"20\n",
"41\n"
] | In the first example, buy a share at 5, buy another at 4, sell one at 9 and another at 12. Then buy at 2 and sell at 10. The total profit is - 5 - 4 + 9 + 12 - 2 + 10 = 20. | 0 | [
{
"input": "9\n10 5 4 7 9 12 6 2 10",
"output": "20"
},
{
"input": "20\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4",
"output": "41"
},
{
"input": "20\n9 29 8 9 13 4 14 27 16 11 27 14 4 29 23 17 3 9 30 19",
"output": "147"
},
{
"input": "100\n411 642 560 340 276 440 515 519 182 3... | 1,690,501,350 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690501350.905548")# 1690501350.9055672 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can perfectly predict the price of a certain stock for the next *N* days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell ... | ```python
print("_RANDOM_GUESS_1690501350.905548")# 1690501350.9055672
``` | 0 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,688,728,057 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | s1, s2, s3, s4 = map(int, input().split(' '))
horseshoes = len(set([s1, s2, s3, s4]))
additional = 4 - horseshoes
print(additional)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
s1, s2, s3, s4 = map(int, input().split(' '))
horseshoes = len(set([s1, s2, s3, s4]))
additional = 4 - horseshoes
print(additional)
``` | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,604,884,834 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 1,325 | 1,638,400 | def solve(w1, w2):
lenw1 = len(w1)
lenw2 = len(w2)
if w1 == w2:
return True
if lenw1 != lenw2 or lenw1 % 2 == 1 or lenw2 % 2 == 1:
return False
return equivalent(w1, w2)
def equivalent(w1, w2):
a = int(len(w1)/2)
b = int(len(w2)/2)
a1, a2 = w1[:a], w1[a:]
b1, b2 = w2... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
def solve(w1, w2):
lenw1 = len(w1)
lenw2 = len(w2)
if w1 == w2:
return True
if lenw1 != lenw2 or lenw1 % 2 == 1 or lenw2 % 2 == 1:
return False
return equivalent(w1, w2)
def equivalent(w1, w2):
a = int(len(w1)/2)
b = int(len(w2)/2)
a1, a2 = w1[:a], w1[a:]
b... | 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,588,708,374 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 |
s = input()
q = "hello"
p = 0
for i in range(len(s)):
if (s[i] == q[p]):
p += 1
if p == 5:
print("YES")
break
if p < 5:
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()
q = "hello"
p = 0
for i in range(len(s)):
if (s[i] == q[p]):
p += 1
if p == 5:
print("YES")
break
if p < 5:
print("NO")
``` | 3.9455 |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,687,384,085 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # solving too long words
def get_inputs():
n = int(input())
input_list = [0] * n
for i in range(n):
input_list[i] = input()
return input_list
def decode(word):
first = word[0]
last = word[-1]
mid_count = len(word[1:-1])
return print(f'{first}{mi... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
# solving too long words
def get_inputs():
n = int(input())
input_list = [0] * n
for i in range(n):
input_list[i] = input()
return input_list
def decode(word):
first = word[0]
last = word[-1]
mid_count = len(word[1:-1])
return print(f'... | 3.977 |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,624,040,938 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 248 | 0 | n,m = map(int,input().split())
l = list(map(int,input().split()))
l1 = l[:]
l2 = l[:]
s = 0
s1 = 0
for i in range(n):
z = max(l1)
s+=z
index = l1.index(z)
l1[index] -= 1
for i in range(n):
z = min(l2)
if z == 0:
index = l2.index(z)
l2[index] = 1000000000000
... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m = map(int,input().split())
l = list(map(int,input().split()))
l1 = l[:]
l2 = l[:]
s = 0
s1 = 0
for i in range(n):
z = max(l1)
s+=z
index = l1.index(z)
l1[index] -= 1
for i in range(n):
z = min(l2)
if z == 0:
index = l2.index(z)
l2[index] = 10000000000... | 3 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,675,361,267 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | n = int(input())
l = list(map(int, input().split()))
i = 0
j = n-1
saida = 0
si,sf = L[i],L[j]
while i < j:
if si > sf:
j -= 1
sf = sf + L[j]
elif si < sf:
i += 1
si = si + L[i]
else:
saida = si
i += 1
j -= 1
si = si + L[i]
sf = sf + L[... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n = int(input())
l = list(map(int, input().split()))
i = 0
j = n-1
saida = 0
si,sf = L[i],L[j]
while i < j:
if si > sf:
j -= 1
sf = sf + L[j]
elif si < sf:
i += 1
si = si + L[i]
else:
saida = si
i += 1
j -= 1
si = si + L[i]
sf... | -1 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,556,219,154 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | n,m=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
a.sort()
j=0
for i in range(m):
if j not in a:
j=j+3
if j in a:
j=j-3+2
if j in a:
print("NO")
exit()
print("YES")
# print(a) | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
n,m=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
a.sort()
j=0
for i in range(m):
if j not in a:
j=j+3
if j in a:
j=j-3+2
if j in a:
print("NO")
exit()
print("YES")
# print(a)
``` | 0 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,591,002,791 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 202 | 8,908,800 | n,c = input().split()
n = int(n)
c = int(c)
x = [int(x) for x in input().split()]
words = 0
for i in range(len(x)):
if i == 0:
words += 1
continue
if x[i] - x[i-1] <= c:
words += 1
else:
words = 1
print(words) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
n,c = input().split()
n = int(n)
c = int(c)
x = [int(x) for x in input().split()]
words = 0
for i in range(len(x)):
if i == 0:
words += 1
continue
if x[i] - x[i-1] <= c:
words += 1
else:
words = 1
print(words)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,689,774,105 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | def restore_original_song(s):
word = s.split("WUB")
original_song = " ".join(filter(None, words))
return original_song
s = input().strip()
original_song = restore_original_song(s)
print(original_song) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
def restore_original_song(s):
word = s.split("WUB")
original_song = " ".join(filter(None, words))
return original_song
s = input().strip()
original_song = restore_original_song(s)
print(original_song)
``` | -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,646,542,790 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 409,600 | import string
n,k = map(int,input().split())
ans = string.ascii_lowercase
a = ans[:k]
if len(a) < n:
x = n - len(a)
if x > len(a):
while (x >= len(a)):
a += a[0]
a += a[0]
else:
a += ans[:x]
print(a)
| 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
import string
n,k = map(int,input().split())
ans = string.ascii_lowercase
a = ans[:k]
if len(a) < n:
x = n - len(a)
if x > len(a):
while (x >= len(a)):
a += a[0]
a += a[0]
else:
a += ans[:x]
print(a)
``` | 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,676,403,240 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 92 | 0 | x = input()
if len(x) <= 4:
word = x.upper()
print(word)
elif x == x.upper():
print(x)
elif len(x) > 4:
word = x.lower()
print(word)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
x = input()
if len(x) <= 4:
word = x.upper()
print(word)
elif x == x.upper():
print(x)
elif len(x) > 4:
word = x.lower()
print(word)
``` | 0 |
939 | B | Hamster Farm | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters.
Dima can buy boxes at a factory. The factory ... | The first line contains two integers *N* and *K* (0<=≤<=*N*<=≤<=1018, 1<=≤<=*K*<=≤<=105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces.
The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≤<=*a**i*<=≤<=1018 for all *i*) — the capaciti... | Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input.
If there are many correct answers, output any of them. | [
"19 3\n5 4 10\n",
"28 3\n5 6 30\n"
] | [
"2 4\n",
"1 5\n"
] | none | 1,000 | [
{
"input": "19 3\n5 4 10",
"output": "2 4"
},
{
"input": "28 3\n5 6 30",
"output": "1 5"
},
{
"input": "1 1\n1",
"output": "1 1"
},
{
"input": "0 2\n2 3",
"output": "1 0"
},
{
"input": "30 4\n4 5 5 4",
"output": "2 6"
},
{
"input": "120 7\n109 92 38 38... | 1,615,312,347 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 140 | 10,342,400 | arr=input().split()
n=int(arr[0])
k=int(arr[1])
arr1=list(map(int,input().split()))
mx=(0,10**18)
for i in range(k):
if n%arr1[i]<mx[1]:
mx=(i,n%arr1[i])
print(mx[0]+1,n//arr1[mx[0]]) | Title: Hamster Farm
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's wh... | ```python
arr=input().split()
n=int(arr[0])
k=int(arr[1])
arr1=list(map(int,input().split()))
mx=(0,10**18)
for i in range(k):
if n%arr1[i]<mx[1]:
mx=(i,n%arr1[i])
print(mx[0]+1,n//arr1[mx[0]])
``` | 3 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,694,180,502 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 11,161,600 | n = int(input())
g=1
a=[]
for i in range(n):
x=input()
a.append(x)
if(i>0 and a[i-1]!=a[i]):
g+=1
print(g)
| Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
g=1
a=[]
for i in range(n):
x=input()
a.append(x)
if(i>0 and a[i-1]!=a[i]):
g+=1
print(g)
``` | 0 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,585,155,025 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 280 | 10,444,800 | n=int(input())
s= str(input())
if n==1:
print(s)
else:
s=s.replace(" ","")
s=s[::-1]
i=0
c=0
while c==0:
if s.count(s[0])!=len(s):
s=s.replace(s[0],"")
else:
c=1
print(s[0])
| Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
n=int(input())
s= str(input())
if n==1:
print(s)
else:
s=s.replace(" ","")
s=s[::-1]
i=0
c=0
while c==0:
if s.count(s[0])!=len(s):
s=s.replace(s[0],"")
else:
c=1
print(s[0])
``` | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,598,855,906 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 265 | 24,678,400 | n = int(input())
a = list(map(int,input().split()))
x = 0
y = 0
l = 0
r = len(a)-1
ans = 0
while l<=r:
if x<=y:
x+=a[l]
l+=1
else:
y+=a[r]
r-=1
if x==y:
ans=max(ans,x)
print(ans) | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
n = int(input())
a = list(map(int,input().split()))
x = 0
y = 0
l = 0
r = len(a)-1
ans = 0
while l<=r:
if x<=y:
x+=a[l]
l+=1
else:
y+=a[r]
r-=1
if x==y:
ans=max(ans,x)
print(ans)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,674,111,927 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | R=lambda:map(int,input().split())
a,b,c=R()
x=1
y=0
z=2
ans1=x+abs(a-x)//3+abs(b-x)//3+abs(c-x)//3
ans2=y+abs(a-y)//3+abs(b-y)//3+abs(c-y)//3
ans3=z+abs(a-z)//3+abs(b-z)//3+abs(c-z)//3
print(max(ans1,max(ans3,ans2)) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
R=lambda:map(int,input().split())
a,b,c=R()
x=1
y=0
z=2
ans1=x+abs(a-x)//3+abs(b-x)//3+abs(c-x)//3
ans2=y+abs(a-y)//3+abs(b-y)//3+abs(c-y)//3
ans3=z+abs(a-z)//3+abs(b-z)//3+abs(c-z)//3
print(max(ans1,max(ans3,ans2))
``` | -1 | |
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,681,242,142 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | a, b = map(int, input().split())
if b - a >= 5:
print("0")
else:
sum = 1
for i in range(a + 1, b + 1):
sum *= (i % 10)
print(sum % 10) | 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
a, b = map(int, input().split())
if b - a >= 5:
print("0")
else:
sum = 1
for i in range(a + 1, b + 1):
sum *= (i % 10)
print(sum % 10)
``` | 3 | |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da... | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI... | 1,685,558,419 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 92 | 0 | count = 0
t=int(input())
for j in range(0,t):
s=input()
try:
if int(s)<18:
count+=1
except:
lis=[ "ABSINTH", 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
if s in lis:
count+=1
print(count) | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
count = 0
t=int(input())
for j in range(0,t):
s=input()
try:
if int(s)<18:
count+=1
except:
lis=[ "ABSINTH", 'BEER', 'BRANDY', 'CHAMPAGNE', 'GIN', 'RUM', 'SAKE', 'TEQUILA', 'VODKA', 'WHISKEY', 'WINE']
if s in lis:
count+=1
print(count)
``` | 3.977 |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=≤<=*j*<=≤<=*n*, 1<=≤<=*i*<=≤<=*m*, 0<=≤<=*a**ij*<=≤<=109) denotes ... | Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,560,100,273 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 109 | 102,400 | n,m=map(int,input().split())
c=[0]*n
for i in range (m):
l=list(map(int,input().split()))
c[l.index(max(l))]+=1
print(c.index(max(c))+1) | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
n,m=map(int,input().split())
c=[0]*n
for i in range (m):
l=list(map(int,input().split()))
c[l.index(max(l))]+=1
print(c.index(max(c))+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,696,703,740 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n=int(input())
m=0
for i in range(n):
a,b,c=map(int,input().split())
s=a+b+c
if s>=2:
m+=1
print(m)
| 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())
m=0
for i in range(n):
a,b,c=map(int,input().split())
s=a+b+c
if s>=2:
m+=1
print(m)
``` | 3 | |
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,676,644,372 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | a=int(input())
b=[int(i)for i in input().split()]
c=[1]+[0 for i in range(a)]
for i in range(1,sum(b)+1): c[i%a]+=1
print(max(c)-min(c)+a) | 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
a=int(input())
b=[int(i)for i in input().split()]
c=[1]+[0 for i in range(a)]
for i in range(1,sum(b)+1): c[i%a]+=1
print(max(c)-min(c)+a)
``` | 0 | |
757 | A | Gotta Catch Em' All! | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas... | Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*.
The string *s* contains lowercase and uppercase English letters, i.e. . | Output a single integer, the answer to the problem. | [
"Bulbbasaur\n",
"F\n",
"aBddulbasaurrgndgbualdBdsagaurrgndbb\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first case, you could pick: Bulbbasaur.
In the second case, there is no way to pick even a single Bulbasaur.
In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur". | 500 | [
{
"input": "Bulbbasaur",
"output": "1"
},
{
"input": "F",
"output": "0"
},
{
"input": "aBddulbasaurrgndgbualdBdsagaurrgndbb",
"output": "2"
},
{
"input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr",
"output": "5"
},
{
"input": "BBBBBBB... | 1,614,610,030 | 2,147,483,647 | Python 3 | OK | TESTS | 107 | 62 | 307,200 | i=input()
print(min(i.count("B"),i.count("u")//2,i.count("l"),i.count("a")//2,i.count("s"),i.count("r"),i.count("b"))) | Title: Gotta Catch Em' All!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess... | ```python
i=input()
print(min(i.count("B"),i.count("u")//2,i.count("l"),i.count("a")//2,i.count("s"),i.count("r"),i.count("b")))
``` | 3 | |
858 | E | Tests Renumeration | PROGRAMMING | 2,200 | [
"greedy",
"implementation"
] | null | null | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of files with tests.
*n* lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the *i*-th file contains an example test, and "0" if it contains a re... | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | [
"5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"2\n1 0\n2 1\n",
"5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n"
] | [
"4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"3\nmove 1 3\nmove 2 1\nmove 3 2",
"5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3\n"
] | none | 2,500 | [
{
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"
},
{
"input": "2\n1 0\n2 1",
"output": "3\nmove 1 odt0m5\nmove 2 1\nmove odt0m5 2"
},
{
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0",
"output": "5\nmove 1 5\nmove 11 1\nmov... | 1,507,537,377 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 409,600 | n = int(input())
spis_edinic = []
spis_nylei = []
res = [-1] * (n + 2)
schet_edinic = 0
comands = []
for i in range(n):
test, example = list(input().split())
example = int(example)
if example == 1:
schet_edinic += 1
if test.isdigit() and 0 < int(test) <= n and int(test[0]) != 0:
... | Title: Tests Renumeration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data i... | ```python
n = int(input())
spis_edinic = []
spis_nylei = []
res = [-1] * (n + 2)
schet_edinic = 0
comands = []
for i in range(n):
test, example = list(input().split())
example = int(example)
if example == 1:
schet_edinic += 1
if test.isdigit() and 0 < int(test) <= n and int(test[0]) !... | 0 | |
384 | B | Multitasking | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"sortings",
"two pointers"
] | null | null | Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort *n* arrays simultaneously, each array consisting of *m* integers.
Iahub can choose a pair of distinct indices *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*). Then in each array the values at positions *i* and *j* are swapped ... | The first line contains three integers *n* (1<=≤<=<=*n*<=≤<=1000), *m* (1<=≤<=*m*<=≤<=<=100) and *k*. Integer *k* is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line *i* of the next *n* lines contains *m* integers separated by a space, representing the... | On the first line of the output print an integer *p*, the size of the array (*p* can be at most ). Each of the next *p* lines must contain two distinct integers *i* and *j* (1<=≤<=*i*,<=*j*<=≤<=*m*,<=*i*<=≠<=*j*), representing the chosen indices.
If there are multiple correct answers, you can print any. | [
"2 5 0\n1 3 2 5 4\n1 4 3 2 5\n",
"3 2 1\n1 2\n2 3\n3 4\n"
] | [
"3\n2 4\n2 3\n4 5\n",
"1\n2 1\n"
] | Consider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5]. | 1,000 | [
{
"input": "2 5 0\n1 3 2 5 4\n1 4 3 2 5",
"output": "3\n2 4\n2 3\n4 5"
},
{
"input": "3 2 1\n1 2\n2 3\n3 4",
"output": "1\n2 1"
},
{
"input": "2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591",
"output": "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 ... | 1,665,516,084 | 624 | PyPy 3-64 | OK | TESTS | 31 | 92 | 3,481,600 | import sys
input = sys.stdin.buffer.readline
def process(n, m, k, A):
if k==0:
sys.stdout.write(f'{m*(m-1)//2}\n')
for smaller in range(1, m+1):
for larger in range(smaller+1, m+1):
sys.stdout.write(f'{smaller} {larger}\n')
return
else:
sy... | Title: Multitasking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort *n* arrays simultaneously, each array consisting of *m* integers.
Iahub can choose a pair of distinct indices *i* and *j* (1<=≤<=*i*... | ```python
import sys
input = sys.stdin.buffer.readline
def process(n, m, k, A):
if k==0:
sys.stdout.write(f'{m*(m-1)//2}\n')
for smaller in range(1, m+1):
for larger in range(smaller+1, m+1):
sys.stdout.write(f'{smaller} {larger}\n')
return
else:
... | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,680,255,434 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n=int(input())
a=[]
for i in range(n):
k=input()
a.append(k)
d={}
for i in a:
if i not in d:
d[i]=1
if i in d:
d[i]+=1
di=max(zip(d.values(),d.keys()))[1]
print(di)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n=int(input())
a=[]
for i in range(n):
k=input()
a.append(k)
d={}
for i in a:
if i not in d:
d[i]=1
if i in d:
d[i]+=1
di=max(zip(d.values(),d.keys()))[1]
print(di)
``` | 3.977 |
369 | C | Valera and Elections | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other district. Let's enumerate all districts in some way by integers from 1 to *n*, inclusive. Furthermore, fo... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of districts in the city.
Then *n*<=-<=1 lines follow. Each line contains the description of a city road as three positive integers *x**i*, *y**i*, *t**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, 1<=≤<=*t**i*<=≤<=2) — the districts connected by the *... | In the first line print a single non-negative number *k* — the minimum size of the required subset of candidates. Then on the second line print *k* space-separated integers *a*1,<=*a*2,<=... *a**k* — the numbers of the candidates that form the required subset. If there are multiple solutions, you are allowed to print a... | [
"5\n1 2 2\n2 3 2\n3 4 2\n4 5 2\n",
"5\n1 2 1\n2 3 2\n2 4 1\n4 5 1\n",
"5\n1 2 2\n1 3 2\n1 4 2\n1 5 2\n"
] | [
"1\n5 \n",
"1\n3 \n",
"4\n5 4 3 2 \n"
] | none | 1,500 | [
{
"input": "5\n1 2 2\n2 3 2\n3 4 2\n4 5 2",
"output": "1\n5 "
},
{
"input": "5\n1 2 1\n2 3 2\n2 4 1\n4 5 1",
"output": "1\n3 "
},
{
"input": "5\n1 2 2\n1 3 2\n1 4 2\n1 5 2",
"output": "4\n5 4 3 2 "
},
{
"input": "5\n1 5 1\n5 4 2\n4 3 1\n3 2 2",
"output": "1\n2 "
},
{
... | 1,576,860,272 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 358 | 16,588,800 | import sys
import math
from collections import defaultdict
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
class Graph:
def __init__(self):
self.graph = defaul... | Title: Valera and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city Valera lives in is going to hold elections to the city Parliament.
The city has *n* districts and *n*<=-<=1 bidirectional roads. We know that from any district there is a path along the roads to any other... | ```python
import sys
import math
from collections import defaultdict
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
class Graph:
def __init__(self):
self.grap... | 0 | |
803 | B | Distances to Zero | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109). | Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*. | [
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 1 2 3 4\n",
"7\n5 6 0 1 -2 3 4\n"
] | [
"2 1 0 1 0 0 1 2 3 ",
"0 1 2 3 4 ",
"2 1 0 1 2 3 4 "
] | none | 0 | [
{
"input": "9\n2 1 0 3 0 0 3 2 4",
"output": "2 1 0 1 0 0 1 2 3 "
},
{
"input": "5\n0 1 2 3 4",
"output": "0 1 2 3 4 "
},
{
"input": "7\n5 6 0 1 -2 3 4",
"output": "2 1 0 1 2 3 4 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
... | 1,559,761,005 | 6,705 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 78 | 0 | def booleana(index_zero, my_index,n):
minimo = n+10
if len(index_zero) >= 3:
for i in range(1, len(index_zero)-1):
if n >= my_index[i-1] and n <= my_index[i+1]:
d1 = abs(n-my_index[i-1])
d2 = abs(n-my_index[i+1])
menor_p = min(d1,d2)
... | Title: Distances to Zero
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the give... | ```python
def booleana(index_zero, my_index,n):
minimo = n+10
if len(index_zero) >= 3:
for i in range(1, len(index_zero)-1):
if n >= my_index[i-1] and n <= my_index[i+1]:
d1 = abs(n-my_index[i-1])
d2 = abs(n-my_index[i+1])
menor_p = min(... | -1 | |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,631,986,804 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 77 | 6,758,400 | n = int(input())
t = n%10
if t <= 5:
print(n - t)
else:
print((n//10 + 1)*10)
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n = int(input())
t = n%10
if t <= 5:
print(n - t)
else:
print((n//10 + 1)*10)
``` | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,659,062,799 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 16 | 62 | 0 | n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in a:
t -= (86400-i)
ans += 1
if t<=0:
break
print(ans) | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n,t = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in a:
t -= (86400-i)
ans += 1
if t<=0:
break
print(ans)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,621,258,528 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | def main():
s = input()
t = input()
t_p = ''.join([s[- i - 1] for i in range(len(s))])
if t == t_p:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main() | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
def main():
s = input()
t = input()
t_p = ''.join([s[- i - 1] for i in range(len(s))])
if t == t_p:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
``` | 3.969 |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=≤<=*n*<=≤<=100) — the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,570,517,722 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | n=int(input())
q=input()
s=list(q)
x=(s.count('S'))
y=(s.count('F'))
if y>x and x!=0:
print("YES")
elif y>x and x==0:
print("NO")
elif x==y:
if s[0]=="S":
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n=int(input())
q=input()
s=list(q)
x=(s.count('S'))
y=(s.count('F'))
if y>x and x!=0:
print("YES")
elif y>x and x==0:
print("NO")
elif x==y:
if s[0]=="S":
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,673,878,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def task_2():
text = input()
n = len(text)
count = 0
for i in range(n):
if text[i] == 'Q':
for j in range(i, n):
if text[j] == 'A':
for k in range(j, n):
if text[k] == 'Q':
count += 1
print(c... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
def task_2():
text = input()
n = len(text)
count = 0
for i in range(n):
if text[i] == 'Q':
for j in range(i, n):
if text[j] == 'A':
for k in range(j, n):
if text[k] == 'Q':
count += 1
... | 0 | |
977 | C | Less or Equal | PROGRAMMING | 1,200 | [
"sortings"
] | null | null | You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are less than or equal to $x$.
Note that the sequence can contain equal elements.
If there is no suc... | The first line of the input contains integer numbers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $0 \le k \le n$). The second line of the input contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the sequence itself. | Print any integer number $x$ from range $[1; 10^9]$ such that exactly $k$ elements of given sequence is less or equal to $x$.
If there is no such $x$, print "-1" (without quotes). | [
"7 4\n3 7 5 1 10 3 20\n",
"7 2\n3 7 5 1 10 3 20\n"
] | [
"6",
"-1\n"
] | In the first example $5$ is also a valid answer because the elements with indices $[1, 3, 4, 6]$ is less than or equal to $5$ and obviously less than or equal to $6$.
In the second example you cannot choose any number that only $2$ elements of the given sequence will be less than or equal to this number because $3$ el... | 0 | [
{
"input": "7 4\n3 7 5 1 10 3 20",
"output": "5"
},
{
"input": "7 2\n3 7 5 1 10 3 20",
"output": "-1"
},
{
"input": "1 0\n1",
"output": "-1"
},
{
"input": "1 0\n2",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1000000000"
},
{
"input": "3 ... | 1,696,673,121 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,k=map(int,input().split())
a=sorted(map(int,input().split()))
if k==0:
print(a[0]-1)
elif k==n:
print(a[-1])
else:
if a[k-1]==a[k]:print(-1)
else:print(a[k-1])
| Title: Less or Equal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of integers of length $n$ and integer number $k$. You should print any integer number $x$ in the range of $[1; 10^9]$ (i.e. $1 \le x \le 10^9$) such that exactly $k$ elements of given sequence are... | ```python
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
if k==0:
print(a[0]-1)
elif k==n:
print(a[-1])
else:
if a[k-1]==a[k]:print(-1)
else:print(a[k-1])
``` | 0 | |
1,004 | B | Sonya and Exhibition | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation",
"math"
] | null | null | Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul... | The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively.
Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive. | Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily.
If there are multiple answers, print any. | [
"5 3\n1 3\n2 4\n2 5\n",
"6 3\n5 6\n1 4\n4 6\n"
] | [
"01100",
"110010"
] | In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions;
- in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ... | 1,000 | [
{
"input": "5 3\n1 3\n2 4\n2 5",
"output": "01010"
},
{
"input": "6 3\n5 6\n1 4\n4 6",
"output": "010101"
},
{
"input": "10 4\n3 3\n1 6\n9 9\n10 10",
"output": "0101010101"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "1000 10\n3 998\n2 1000\n1 999\n2 100... | 1,622,214,190 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 140 | 2,764,800 | import sys
import os
n,m=list(map(int,input().split()))
while m:
a,b=list(map(int,input().split()))
m-=1
for i in range(n):
if i%2==0:
print("0",end="")
else:
print("1",end="")
print("")
| Title: Sonya and Exhibition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are $n$ flowers in a row in the ... | ```python
import sys
import os
n,m=list(map(int,input().split()))
while m:
a,b=list(map(int,input().split()))
m-=1
for i in range(n):
if i%2==0:
print("0",end="")
else:
print("1",end="")
print("")
``` | 3 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,683,481,500 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n,k = (input().split())
k = int(k)
n = list(range(1,int(n)+1))
p_list = list((input().split()))
p_list = [int(i) for i in p_list]
if k >= len(p_list)-1 :
print(max(p_list))
else :
c_win = 1
winer = 0
m = max(p_list)
for i in p_list:
if i or i+1 == m :
print(m)
... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
n,k = (input().split())
k = int(k)
n = list(range(1,int(n)+1))
p_list = list((input().split()))
p_list = [int(i) for i in p_list]
if k >= len(p_list)-1 :
print(max(p_list))
else :
c_win = 1
winer = 0
m = max(p_list)
for i in p_list:
if i or i+1 == m :
prin... | 0 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,692,617,958 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n=int(input())
h=int(input())
the_list=list(map(int,input()))
w=0
for i in the_list:
w+=1
if i > h :
w+=1
print(w) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n=int(input())
h=int(input())
the_list=list(map(int,input()))
w=0
for i in the_list:
w+=1
if i > h :
w+=1
print(w)
``` | -1 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,529,490,074 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 93 | 204,800 | flag = False
a,b,n = (int(i) for i in input().split())
for i in range(10):
c = a*10 + i;
if(c%b == 0):
flag = 1
break
if(flag):
print(c,'0' * (n-1),sep = '')
else:
print(-1) | Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
flag = False
a,b,n = (int(i) for i in input().split())
for i in range(10):
c = a*10 + i;
if(c%b == 0):
flag = 1
break
if(flag):
print(c,'0' * (n-1),sep = '')
else:
print(-1)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,694,071,369 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
for i in range(n):
text = input()
if len(text) > 10:
print(f'{text[0]}'+ str(len(text)-2)+ f'{text[-1]}')
else:
print(text) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input())
for i in range(n):
text = input()
if len(text) > 10:
print(f'{text[0]}'+ str(len(text)-2)+ f'{text[-1]}')
else:
print(text)
``` | 3.977 |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,700,049,546 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | def func(x1,y1,x2,y2):
if(x1 == x2):
print(1000-x1," ",y1," ",1000-x2," ",y2)
return
if(y1 == y2):
print(x1," ",1000-y1," ",x2," ",1000-y2)
return
else:
print(x1," ",y2," ",x2," ",y1)
return
l1 = list(map(int, input().split()))
fu... | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
def func(x1,y1,x2,y2):
if(x1 == x2):
print(1000-x1," ",y1," ",1000-x2," ",y2)
return
if(y1 == y2):
print(x1," ",1000-y1," ",x2," ",1000-y2)
return
else:
print(x1," ",y2," ",x2," ",y1)
return
l1 = list(map(int, input().spl... | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,645,466,799 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 77 | 0 | a,b = map(int,input().split())
c = 0
for i in range(a):
s=0
x=input()
for i in range(b+1):
if str(i) in x:
s+=1
if s==b+1:
c+=1
print(c) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
a,b = map(int,input().split())
c = 0
for i in range(a):
s=0
x=input()
for i in range(b+1):
if str(i) in x:
s+=1
if s==b+1:
c+=1
print(c)
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,579,678,397 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 307,200 | import math
n , m = map(int,input().split())
def isprime(x) :
if x < 2 or (x % 2 == 0) :
return False
if x == 2 or x == 3 :
return True
for i in range(3, int(math.sqrt(x))+1 , 2) :
if x % i == 0 :
return False
return True
if isprime(m) :
res ... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
import math
n , m = map(int,input().split())
def isprime(x) :
if x < 2 or (x % 2 == 0) :
return False
if x == 2 or x == 3 :
return True
for i in range(3, int(math.sqrt(x))+1 , 2) :
if x % i == 0 :
return False
return True
if isprime(m) :... | 3.944928 |
0 | none | none | none | 0 | [
"none"
] | null | null | Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog... | The first line of input contains a single integer *n* (0<=≤<=*n*<=≤<=20).
The second line of input contains 2*n* space-separated integers *a*[1],<=*a*[2],<=...,<=*a*[2*n*] (1<=≤<=*a*[*i*]<=≤<=109), the initial array.
The third line of input contains a single integer *m* (1<=≤<=*m*<=≤<=106).
The fourth line of inpu... | Output *m* lines. In the *i*-th line print the answer (the number of inversions) for the *i*-th query. | [
"2\n2 1 4 3\n4\n1 2 0 2\n",
"1\n1 2\n3\n0 1 1\n"
] | [
"0\n6\n6\n0\n",
"0\n1\n0\n"
] | If we reverse an array *x*[1], *x*[2], ..., *x*[*n*] it becomes new array *y*[1], *y*[2], ..., *y*[*n*], where *y*[*i*] = *x*[*n* - *i* + 1] for each *i*.
The number of inversions of an array *x*[1], *x*[2], ..., *x*[*n*] is the number of pairs of indices *i*, *j* such that: *i* < *j* and *x*[*i*] > *x*[*j*]. | 0 | [] | 1,689,258,667 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689258667.089409")# 1689258667.0894248 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given ... | ```python
print("_RANDOM_GUESS_1689258667.089409")# 1689258667.0894248
``` | 0 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,625,269,870 | 2,147,483,647 | PyPy 3 | OK | TESTS | 128 | 140 | 1,331,200 | def fun(x,y):
final=0
for i in range(1,x+1):
if i%5==y:
final+=1
return final
n,m=map(int,input().split())
ans=0
ans+=fun(n,0)*fun(m,0)
ans+=fun(n,1)*fun(m,4)
ans+=fun(n,2)*fun(m,3)
ans+=fun(n,3)*fun(m,2)
ans+=fun(n,4)*fun(m,1)
print(ans) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
def fun(x,y):
final=0
for i in range(1,x+1):
if i%5==y:
final+=1
return final
n,m=map(int,input().split())
ans=0
ans+=fun(n,0)*fun(m,0)
ans+=fun(n,1)*fun(m,4)
ans+=fun(n,2)*fun(m,3)
ans+=fun(n,3)*fun(m,2)
ans+=fun(n,4)*fun(m,1)
print(ans)
``` | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,695,006,194 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | from math import *
u=int(input())
que=[ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
i=0
j=0
while True:
if j>=u:
break
j+=5*2**i
i+=1
k=5*(2**(i-1)-1)
l=int((u-k)/2**(i-1)-0.0001)
print(que[l])
| Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
from math import *
u=int(input())
que=[ "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
i=0
j=0
while True:
if j>=u:
break
j+=5*2**i
i+=1
k=5*(2**(i-1)-1)
l=int((u-k)/2**(i-1)-0.0001)
print(que[l])
``` | 3.969 |
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunate... | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed progra... | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal so... | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20... | 1,671,002,868 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 186 | 7,987,200 | n,m=map(int,input().split())
nums=[0]+[int(x) for x in input().split()]+[m]
x=[]
for i in range(n+1):
x.append(nums[i+1]-nums[i])
flag=[True,False][n%2]
tot=0
for i in range(n+1):
if i%2==0:
tot+=x[i]
dark=0
light=0
mx=0
nums.reverse()
if flag:
x.reverse()
for i in range(n+1):
... | Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows y... | ```python
n,m=map(int,input().split())
nums=[0]+[int(x) for x in input().split()]+[m]
x=[]
for i in range(n+1):
x.append(nums[i+1]-nums[i])
flag=[True,False][n%2]
tot=0
for i in range(n+1):
if i%2==0:
tot+=x[i]
dark=0
light=0
mx=0
nums.reverse()
if flag:
x.reverse()
for i in rang... | 3 | |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,684,226,623 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 46 | 0 | n = int(input())
my_list1 = sorted([int(i) for i in input().split()])
m = int(input())
my_list2 = sorted([int(i) for i in input().split()])
result = 0
for j in range(len(my_list1)):
for i in range(len(my_list2)):
if abs(my_list1[j] - my_list2[i]) <= 1:
result += 1
my_l... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
n = int(input())
my_list1 = sorted([int(i) for i in input().split()])
m = int(input())
my_list2 = sorted([int(i) for i in input().split()])
result = 0
for j in range(len(my_list1)):
for i in range(len(my_list2)):
if abs(my_list1[j] - my_list2[i]) <= 1:
result += 1
... | 3 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,679,156,399 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 2,560,000 | n = input()
n = int(n)
x = int(1378**n)
print(x%10)
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n = input()
n = int(n)
x = int(1378**n)
print(x%10)
``` | 0 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,585,461,916 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 204,800 | n, p, k = map(int, input().split())
if p - k > 1:
print("<<", end = ' ')
for i in range(k, 0, -1):
if p - i <= 0:
continue
print(p - i, end = ' ')
print('(' + str(p) + ')', end = ' ')
for i in range(1, k + 1):
if p + i > n:
break
print(p + i, end = ' ')
if p + k < n:
print(">>") | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
n, p, k = map(int, input().split())
if p - k > 1:
print("<<", end = ' ')
for i in range(k, 0, -1):
if p - i <= 0:
continue
print(p - i, end = ' ')
print('(' + str(p) + ')', end = ' ')
for i in range(1, k + 1):
if p + i > n:
break
print(p + i, end = ' ')
if p + k < n:
print(">>")
``` | 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,598,367,729 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | y = input()
u = 0
l = 0
for i in y:
if i.isupper()== True:
u += 1
else:
l += 1
if u > l:
print(y.upper())
else:
print(y.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
y = input()
u = 0
l = 0
for i in y:
if i.isupper()== True:
u += 1
else:
l += 1
if u > l:
print(y.upper())
else:
print(y.lower())
``` | 3.9455 |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,595,774,177 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 280 | 20,172,800 | n = int(input())
x = list(map(int, input().split()))
odd = 0
even = 0
for i in range(n):
if(x[i]%2==0):
even+=1
else:
odd+=1
if(odd%2==0):
print(even)
elif(odd%2!=0):
print(odd)
else:
print("0") | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
x = list(map(int, input().split()))
odd = 0
even = 0
for i in range(n):
if(x[i]%2==0):
even+=1
else:
odd+=1
if(odd%2==0):
print(even)
elif(odd%2!=0):
print(odd)
else:
print("0")
``` | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,695,019,408 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 0 | n = int(input())
counter = 0
s = 1
while True:
if s == 1:
if n - 1 >= 0:
counter += 1
n -= 1
s = 2
else:
break
if s == 2:
if n - 2 >= 0:
counter += 1
n -= 2
s = 1
else:
... | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n = int(input())
counter = 0
s = 1
while True:
if s == 1:
if n - 1 >= 0:
counter += 1
n -= 1
s = 2
else:
break
if s == 2:
if n - 2 >= 0:
counter += 1
n -= 2
s = 1
else:
... | 0 | |
863 | C | 1-2-3 | PROGRAMMING | 1,800 | [
"graphs",
"implementation"
] | null | null | Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is interested if Bob is better at playing different games than the previous model, "Alice".
... | The first line contains three numbers *k*, *a*, *b* (1<=≤<=*k*<=≤<=1018, 1<=≤<=*a*,<=*b*<=≤<=3).
Then 3 lines follow, *i*-th of them containing 3 numbers *A**i*,<=1, *A**i*,<=2, *A**i*,<=3, where *A**i*,<=*j* represents Alice's choice in the game if Alice chose *i* in previous game and Bob chose *j* (1<=≤<=*A**i*,<=*... | Print two numbers. First of them has to be equal to the number of points Alice will have, and second of them must be Bob's score after *k* games. | [
"10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2\n",
"8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3\n",
"5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2\n"
] | [
"1 9\n",
"5 2\n",
"0 0\n"
] | In the second example game goes like this:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e21b6e200707470571d69c9946ace6b56f5279b.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The fourth and the seventh game are won by Bob, the first game is draw and the rest are won by Alice. | 0 | [
{
"input": "10 2 1\n1 1 1\n1 1 1\n1 1 1\n2 2 2\n2 2 2\n2 2 2",
"output": "1 9"
},
{
"input": "8 1 1\n2 2 1\n3 3 1\n3 1 3\n1 1 1\n2 1 1\n1 2 3",
"output": "5 2"
},
{
"input": "5 1 1\n1 2 2\n2 2 2\n2 2 2\n1 2 2\n2 2 2\n2 2 2",
"output": "0 0"
},
{
"input": "1 1 1\n3 3 1\n1 1 1\... | 1,662,506,864 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def hod(a,b,z,ans):
q,w,x,y=a[z[0]-1][z[1]-1],b[z[0]-1][z[1]-1],z[0],z[1]
if (x>y) or (x==1 and y==3):
ans[0]+=1
else:
if x!=y:
ans[1]+=1
return [q,w]
k,a,b=map(int,input().split())
z=[]
for _ in range(3):
z.append(list(map(int,input().split()... | Title: 1-2-3
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is working for the company that constructs robots. Ilya writes programs for entertainment robots, and his current project is "Bob", a new-generation game robot. Ilya's boss wants to know his progress so far. Especially he is... | ```python
def hod(a,b,z,ans):
q,w,x,y=a[z[0]-1][z[1]-1],b[z[0]-1][z[1]-1],z[0],z[1]
if (x>y) or (x==1 and y==3):
ans[0]+=1
else:
if x!=y:
ans[1]+=1
return [q,w]
k,a,b=map(int,input().split())
z=[]
for _ in range(3):
z.append(list(map(int,input... | 0 | |
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,483,002,969 | 669 | Python 3 | OK | TESTS | 49 | 62 | 4,608,000 | n = int(input()) - 1
ans = [1]
while n > ans[-1]:
n -= ans[-1] + 1
ans.append(ans[-1] + 1)
ans[-1] += n
print(len(ans))
print(*ans) | Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n = int(input()) - 1
ans = [1]
while n > ans[-1]:
n -= ans[-1] + 1
ans.append(ans[-1] + 1)
ans[-1] += n
print(len(ans))
print(*ans)
``` | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,459,673,359 | 859 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 3,000 | 5,529,600 | __author__ = 'Alexandret'
chats_amount = int(input())
chats_order = list()
for i in range(chats_amount):
uid = input()
if uid in chats_order:
chats_order.remove(uid)
chats_order.insert(0, uid)
print('\n'.join(chats_order)) | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
__author__ = 'Alexandret'
chats_amount = int(input())
chats_order = list()
for i in range(chats_amount):
uid = input()
if uid in chats_order:
chats_order.remove(uid)
chats_order.insert(0, uid)
print('\n'.join(chats_order))
``` | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,682,963,001 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n=int(input())
a=list(map(int,input().split()))
x,y=0,0
i=0
while(len(a)>0):
if(i%2==0):
if(a[0]>a[-1]):
x=x+a[0]
a=a[1:]
else:
x=x+a[-1]
a.pop()
i=i+1
else:
if(a[0]>a[-1]):
y=y+a[0]
a=a[1:]
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n=int(input())
a=list(map(int,input().split()))
x,y=0,0
i=0
while(len(a)>0):
if(i%2==0):
if(a[0]>a[-1]):
x=x+a[0]
a=a[1:]
else:
x=x+a[-1]
a.pop()
i=i+1
else:
if(a[0]>a[-1]):
y=y+a[0]
... | 3 | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,514,393,840 | 1,340 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 62 | 5,529,600 | n = int(input())
count = 1
count1 = 0
ind = 0
for i in range(n):
a = input()
if a == "s" and ind == 0:
count *= (count1 + 1)
elif a == "f":
ind += 1
if ind == 1:
count *= (count1 + 1)
count1 += 1
elif a == "s" and ind > 0:
ind = 0
print(count) | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
n = int(input())
count = 1
count1 = 0
ind = 0
for i in range(n):
a = input()
if a == "s" and ind == 0:
count *= (count1 + 1)
elif a == "f":
ind += 1
if ind == 1:
count *= (count1 + 1)
count1 += 1
elif a == "s" and ind > 0:
ind = 0
print(count)
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,694,610,072 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # -*- coding: utf-8 -*-
"""
Created on Wed Sep 13 20:22:47 2023
@author: 雷雨松
"""
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
s=a//c
if(a%c!=0):
s+=1
t=b//c
if(b%c!=0):
t+=1
print(s*t) | 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
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 13 20:22:47 2023
@author: 雷雨松
"""
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
s=a//c
if(a%c!=0):
s+=1
t=b//c
if(b%c!=0):
t+=1
print(s*t)
``` | 3.977 |
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,663,840,146 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | ROWS,COLS = map(int,input().split())
grid = []
for _ in range(ROWS):
grid.append(list(input()))
rcount = 0
ccount = 0
for r in range(ROWS):
for c in range(COLS):
if grid[r][c]=="S":
rcount+=1
break
for c in range(COLS):
for r in range(ROWS):
... | 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
ROWS,COLS = map(int,input().split())
grid = []
for _ in range(ROWS):
grid.append(list(input()))
rcount = 0
ccount = 0
for r in range(ROWS):
for c in range(COLS):
if grid[r][c]=="S":
rcount+=1
break
for c in range(COLS):
for r in range(R... | 3 | |
496 | C | Removing Columns | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table
we obtain the table:
A table is called... | The first line contains two integers — *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Next *n* lines contain *m* small English letters each — the characters of the table. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | [
"1 10\ncodeforces\n",
"4 4\ncase\ncare\ntest\ncode\n",
"5 4\ncode\nforc\nesco\ndefo\nrces\n"
] | [
"0\n",
"2\n",
"4\n"
] | In the first sample the table is already good.
In the second sample you may remove the first and third column.
In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).
Let strings *s* and *t* have equal length. Then, *s* is lexicographica... | 1,750 | [
{
"input": "1 10\ncodeforces",
"output": "0"
},
{
"input": "4 4\ncase\ncare\ntest\ncode",
"output": "2"
},
{
"input": "5 4\ncode\nforc\nesco\ndefo\nrces",
"output": "4"
},
{
"input": "2 2\nfb\nye",
"output": "0"
},
{
"input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrz... | 1,574,777,974 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 140 | 1,433,600 | n, m = map(int, input().split())
s = list(input() for _ in range(n))
res, t = 0, [0] * n
for i in range(m):
for j in range(n-1):
if not t[j] and s[j][i] > s[j+1][i]:
res += 1
break
else:
for j in range(n-1):
t[j] = t[j] or s[j][i] < s[j+1][i]
print... | Title: Removing Columns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an *n*<=×<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For e... | ```python
n, m = map(int, input().split())
s = list(input() for _ in range(n))
res, t = 0, [0] * n
for i in range(m):
for j in range(n-1):
if not t[j] and s[j][i] > s[j+1][i]:
res += 1
break
else:
for j in range(n-1):
t[j] = t[j] or s[j][i] < s[j+1]... | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,581,172,820 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 16,896,000 | input()
socks_in_package = [int(i) for i in input().split()]
socks_on_table, max_socks_on_table = set(), 0
for sock in socks_in_package:
socks_on_table ^= {sock}
if len(socks_on_table) > max_socks_on_table:
max_socks_on_table = len(socks_on_table)
print(max_socks_on_table)
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
input()
socks_in_package = [int(i) for i in input().split()]
socks_on_table, max_socks_on_table = set(), 0
for sock in socks_in_package:
socks_on_table ^= {sock}
if len(socks_on_table) > max_socks_on_table:
max_socks_on_table = len(socks_on_table)
print(max_socks_on_table)
``` | 0 | |
460 | B | Little Dima and Equation | PROGRAMMING | 1,500 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi... | The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000). | Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109. | [
"3 2 8\n",
"1 2 -18\n",
"2 2 -1\n"
] | [
"3\n10 2008 13726 ",
"0\n",
"4\n1 31 337 967 "
] | none | 1,000 | [
{
"input": "3 2 8",
"output": "3\n10 2008 13726 "
},
{
"input": "1 2 -18",
"output": "0"
},
{
"input": "2 2 -1",
"output": "4\n1 31 337 967 "
},
{
"input": "1 1 0",
"output": "9\n1 2 3 4 5 6 7 8 9 "
},
{
"input": "1 37 963",
"output": "16\n1000 1111 1222 1333 ... | 1,682,962,004 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | import sys
input = lambda: sys.stdin.readline().rstrip()
a,b,c = map(int, input().split())
ans = []
for i in range(1,82):
x = b*(i**a)+c
t = x
cnt = 0
while t>0:
cnt+=t%10
t//=10
if cnt==i:
ans.append(x)
print(len(ans))
if ans:
print(*ans) | Title: Little Dima and Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions *x* (0<=<<=*x*<=<<=109) of the equation:
w... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
a,b,c = map(int, input().split())
ans = []
for i in range(1,82):
x = b*(i**a)+c
t = x
cnt = 0
while t>0:
cnt+=t%10
t//=10
if cnt==i:
ans.append(x)
print(len(ans))
if ans:
print(*... | 0 | |
234 | C | Weather | PROGRAMMING | 1,300 | [
"dp",
"implementation"
] | null | null | Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a ther... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single space... | Print a single integer — the answer to the given task. | [
"4\n-1 1 -2 1\n",
"5\n0 -1 1 2 -5\n"
] | [
"1\n",
"2\n"
] | Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number. | 0 | [
{
"input": "4\n-1 1 -2 1",
"output": "1"
},
{
"input": "5\n0 -1 1 2 -5",
"output": "2"
},
{
"input": "6\n0 0 0 0 0 0",
"output": "6"
},
{
"input": "6\n-1 -2 -3 -4 5 6",
"output": "0"
},
{
"input": "8\n1 2 -1 0 10 2 12 13",
"output": "3"
},
{
"input": "... | 1,621,633,055 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 342 | 10,444,800 | file = open("input.txt", "r")
lines = [line.strip() for line in file]
file.close()
number_strings = lines[1].split()
numbers_msm = [int(msm) for msm in number_strings]
zeroes = [x <= 0 for x in numbers_msm]
x = sum(zeroes)
count = len(numbers_msm)
numbers_msm.pop()
for num in numbers_msm:
x += (num > 0) - (num <... | Title: Weather
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to ... | ```python
file = open("input.txt", "r")
lines = [line.strip() for line in file]
file.close()
number_strings = lines[1].split()
numbers_msm = [int(msm) for msm in number_strings]
zeroes = [x <= 0 for x in numbers_msm]
x = sum(zeroes)
count = len(numbers_msm)
numbers_msm.pop()
for num in numbers_msm:
x += (num > 0... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,692,977,422 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def can_divide(n) :
if n > 2 and n%2 == 0 :
return "YES"
return "NO"
n = int(input())
ans = can_divide(n)
print(ans) | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def can_divide(n) :
if n > 2 and n%2 == 0 :
return "YES"
return "NO"
n = int(input())
ans = can_divide(n)
print(ans)
``` | 3.954 |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,587,499,346 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | #B. Bear and Strings
s = input()
ans = 0
for i in range(len(s)) :
part = s [i : ]
if 'bear' in part :
ans += len(part) - (part.index('bear') + 3 )
print(ans)
| Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
#B. Bear and Strings
s = input()
ans = 0
for i in range(len(s)) :
part = s [i : ]
if 'bear' in part :
ans += len(part) - (part.index('bear') + 3 )
print(ans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. More formally:
Let *a*0,<=*a*1,<=...,<=*a**n* denote the coefficients, so . Then, a polynomi... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=200<=000,<=1<=≤<=*k*<=≤<=109) — the degree of the polynomial and the limit for absolute values of coefficients.
The second line contains *n*<=+<=1 integers *a*0,<=*a*1,<=...,<=*a**n* (|*a**i*|<=≤<=*k*,<=*a**n*<=≠<=0) — describing a valid polynomial . It's... | Print the number of ways to change one coefficient to get a valid polynomial *Q* that *Q*(2)<==<=0. | [
"3 1000000000\n10 -9 -3 5\n",
"3 12\n10 -9 -3 5\n",
"2 20\n14 -7 19\n"
] | [
"3\n",
"2\n",
"0\n"
] | In the first sample, we are given a polynomial *P*(*x*) = 10 - 9*x* - 3*x*<sup class="upper-index">2</sup> + 5*x*<sup class="upper-index">3</sup>.
Limak can change one coefficient in three ways:
1. He can set *a*<sub class="lower-index">0</sub> = - 10. Then he would get *Q*(*x*) = - 10 - 9*x* - 3*x*<sup class="upp... | 0 | [] | 1,692,368,381 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | from itertools import repeat
def main():
n, k = map(int, input().split())
a = list(map(int, input().split())) + [10] * (n + 1)
r = [0] * (n + 50)
c = 0
l = n + 100
for i, x in enumerate(a):
c += x
if c >= 0:
c, r[i] = divmod(c, 2)
else:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He doesn't have many toys and thus he often plays with polynomials.
He considers a polynomial valid if its degree is *n* and its coefficients are integers not exceeding *k* by the absolute value. Mor... | ```python
from itertools import repeat
def main():
n, k = map(int, input().split())
a = list(map(int, input().split())) + [10] * (n + 1)
r = [0] * (n + 50)
c = 0
l = n + 100
for i, x in enumerate(a):
c += x
if c >= 0:
c, r[i] = divmod(c, 2)
else:
... | 0 | |
518 | C | Anya and Smartphone | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen contains *k* icons. The icons from the first to the *k*-th one are located on the first screen, from the (*k*<... | The first line of the input contains three numbers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105) — the number of applications that Anya has on her smartphone, the number of applications that will be launched and the number of icons that are located on the same screen.
The next line contains *n* integers, permutation... | Print a single number — the number of gestures that Anya needs to make to launch all the applications in the desired order. | [
"8 3 3\n1 2 3 4 5 6 7 8\n7 8 1\n",
"5 4 2\n3 1 5 2 4\n4 4 4 4\n"
] | [
"7\n",
"8\n"
] | In the first test the initial configuration looks like (123)(456)(78), that is, the first screen contains icons of applications 1, 2, 3, the second screen contains icons 4, 5, 6, the third screen contains icons 7, 8.
After application 7 is launched, we get the new arrangement of the icons — (123)(457)(68). To launch ... | 1,500 | [
{
"input": "8 3 3\n1 2 3 4 5 6 7 8\n7 8 1",
"output": "7"
},
{
"input": "5 4 2\n3 1 5 2 4\n4 4 4 4",
"output": "8"
},
{
"input": "10 10 3\n1 2 3 4 5 6 7 8 9 10\n2 3 4 5 6 7 8 9 10 1",
"output": "25"
},
{
"input": "10 12 3\n6 1 2 9 3 10 8 5 7 4\n3 9 9 4 8 2 3 8 10 8 3 4",
... | 1,604,781,379 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 358 | 11,776,000 | import sys
r=sys.stdin.readline
n,m,k=map(int,r().split())
screen=list(map(int,r().split()))
gesture=0
arr=[-1]*n
for i in range(n):
screen[i]-=1
arr[screen[i]]=i
for i in list(map(int,r().split())):
i-=1
pos = arr[i]
gesture+=pos//k+1
if pos !=0:
tmp=screen[pos-1]
... | Title: Anya and Smartphone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anya has bought a new smartphone that uses Berdroid operating system. The smartphone menu has exactly *n* applications, each application has its own icon. The icons are located on different screens, one screen conta... | ```python
import sys
r=sys.stdin.readline
n,m,k=map(int,r().split())
screen=list(map(int,r().split()))
gesture=0
arr=[-1]*n
for i in range(n):
screen[i]-=1
arr[screen[i]]=i
for i in list(map(int,r().split())):
i-=1
pos = arr[i]
gesture+=pos//k+1
if pos !=0:
tmp=screen[pos-1... | 3 | |
370 | A | Rook, Bishop and King | PROGRAMMING | 1,100 | [
"graphs",
"math",
"shortest paths"
] | null | null | Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of... | The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb... | Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. | [
"4 3 1 6\n",
"5 5 5 6\n"
] | [
"2 1 3\n",
"1 0 1\n"
] | none | 500 | [
{
"input": "4 3 1 6",
"output": "2 1 3"
},
{
"input": "5 5 5 6",
"output": "1 0 1"
},
{
"input": "1 1 8 8",
"output": "2 1 7"
},
{
"input": "1 1 8 1",
"output": "1 0 7"
},
{
"input": "1 1 1 8",
"output": "1 0 7"
},
{
"input": "8 1 1 1",
"output": "... | 1,586,297,995 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 155 | 307,200 | import sys
line = sys.stdin.readline().split()
r1, c1, r2, c2 = int(line[0]), int(line[1]), int(line[2]), int(line[3])
rook, bishop, king = 0, 0, 0
if r1 != r2 and c1 != c2:
rook = 2
else:
rook = 1
if abs(r1 - r2) == abs(c1 - c2):
bishop = 1
elif abs(r1 - r2) % 2 == abs(c1 - c2) % 2:
bishop = 2
else... | Title: Rook, Bishop and King
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=... | ```python
import sys
line = sys.stdin.readline().split()
r1, c1, r2, c2 = int(line[0]), int(line[1]), int(line[2]), int(line[3])
rook, bishop, king = 0, 0, 0
if r1 != r2 and c1 != c2:
rook = 2
else:
rook = 1
if abs(r1 - r2) == abs(c1 - c2):
bishop = 1
elif abs(r1 - r2) % 2 == abs(c1 - c2) % 2:
bisho... | 3 | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,451,491,402 | 3,502 | PyPy 3 | OK | TESTS | 38 | 109 | 0 | x = input("").split(' ')
if (x[2]=='month'):
f = int(x[0])
days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
cnt = 0
for g in days:
if (g >= f):
cnt+=1
print(cnt)
else:
f = int(x[0])
if (f == 6):
print(53)
elif (f == 7):
print(52)
elif (f == 5):
print(53)
elif (f == 4):
pr... | Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
x = input("").split(' ')
if (x[2]=='month'):
f = int(x[0])
days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
cnt = 0
for g in days:
if (g >= f):
cnt+=1
print(cnt)
else:
f = int(x[0])
if (f == 6):
print(53)
elif (f == 7):
print(52)
elif (f == 5):
print(53)
elif (f ==... | 3 | |
460 | A | Vasya and Socks | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la... | The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. | Print a single integer — the answer to the problem. | [
"2 2\n",
"9 3\n"
] | [
"3\n",
"13\n"
] | In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two.
In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on... | 500 | [
{
"input": "2 2",
"output": "3"
},
{
"input": "9 3",
"output": "13"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "1 99",
"output": "1"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "10 2",
"outp... | 1,655,293,360 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n,m=map(int,input().split())
count=n
while n>=m:
count+=(n/m)
n=((n/m)+(n%m))
print(int(count)) | Title: Vasya and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th... | ```python
n,m=map(int,input().split())
count=n
while n>=m:
count+=(n/m)
n=((n/m)+(n%m))
print(int(count))
``` | 0 | |
717 | C | Potions Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class teacher, professor Snipe ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of tasks. The next *n* lines contain exactly one integer number *a**i* (1<=≤<=*a**i*<=≤<=100<=000) — both the difficulty of the initial task and the laziness of the *i*-th students. | Print the minimum total time to finish all tasks modulo 10<=007. | [
"2\n1\n3\n"
] | [
"6\n"
] | In the first sample, if the students switch their tasks, they will be able to finish them in 3 + 3 = 6 time units. | 0 | [
{
"input": "2\n1\n3",
"output": "6"
}
] | 1,621,513,772 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 108 | 2,457,600 | # link: https://codeforces.com/problemset/problem/717/C
from sys import stdin, stdout
if __name__ == "__main__":
n = int(stdin.readline())
difficulties = [0] * (n)
for i in range(n):
difficulties[i] = int(stdin.readline())
difficulties.sort()
start = 0
end = n-1
result ... | Title: Potions Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun ... | ```python
# link: https://codeforces.com/problemset/problem/717/C
from sys import stdin, stdout
if __name__ == "__main__":
n = int(stdin.readline())
difficulties = [0] * (n)
for i in range(n):
difficulties[i] = int(stdin.readline())
difficulties.sort()
start = 0
end = n-1
... | 0 | |
727 | C | Guess the Array | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have init... | none | none | [
"5\n \n9\n \n7\n \n9\n \n11\n \n6\n "
] | [
"? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5"
] | The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-inde... | 1,500 | [
{
"input": "5\n4 6 1 5 5",
"output": "5 out of 5"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "4\n100 1 100 1",
"output": "4 out of 4"
},
{
"input": "10\n9 5 10 7 4 4 8 5 10 5",
"output": "10 out of 10"
},
{
"input": "3\n1 1 1",
"output": "3... | 1,602,358,191 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 390 | 5,529,600 | def ask (i, j):
print ("?", i, j)
resp = int(input())
return resp
n = int(input())
arr = {}
a = int(ask(1, 2))
b = int(ask(1, 3))
c = int(ask(2, 3))
arr[1] = int((a+b-c)/2)
arr[2] = int(a - arr[1])
arr[3] = int(b - arr[1])
for i in range(4, n+1):
arr[i] = int(ask(i-1, i) - arr[i-1])
print("!", *a... | Title: Guess the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In th... | ```python
def ask (i, j):
print ("?", i, j)
resp = int(input())
return resp
n = int(input())
arr = {}
a = int(ask(1, 2))
b = int(ask(1, 3))
c = int(ask(2, 3))
arr[1] = int((a+b-c)/2)
arr[2] = int(a - arr[1])
arr[3] = int(b - arr[1])
for i in range(4, n+1):
arr[i] = int(ask(i-1, i) - arr[i-1])
pri... | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,621,582,088 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 0 | input()
*b, = map(int, input().split())#magic
#print(b[1])
#print(type(b))
a = sorted(b, key = b.count)
#print(a)
print(a.count(a[-1]), len(set(a))) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
input()
*b, = map(int, input().split())#magic
#print(b[1])
#print(type(b))
a = sorted(b, key = b.count)
#print(a)
print(a.count(a[-1]), len(set(a)))
``` | 3.969 |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,675,671,226 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | # LUOGU_RID: 101572685
n1, n2, k1, k2 = map(int, input().split())
print(n1 > n2 and 'First' or 'Second') | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
# LUOGU_RID: 101572685
n1, n2, k1, k2 = map(int, input().split())
print(n1 > n2 and 'First' or 'Second')
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,654,707,668 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | # krito = int(input())
# number_of_dragon = int(input())
# dragons_power = []
# bonus = []
# flag = False
# for x in range(number_of_dragon):
# dragons_power.append(int(input()))
# bonus.append(int(input()))
# for x in range(number_of_dragon):
# if(krito>dragons_power[x]):
# krito = krito+ bo... | 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
# krito = int(input())
# number_of_dragon = int(input())
# dragons_power = []
# bonus = []
# flag = False
# for x in range(number_of_dragon):
# dragons_power.append(int(input()))
# bonus.append(int(input()))
# for x in range(number_of_dragon):
# if(krito>dragons_power[x]):
# krito =... | -1 | |
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,514,044,562 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 5,529,600 | n=int(input())
if n%2:
print((n-1)//2,(n+1)//2)
else:
print((n-2)//2,(n+2)//2) | 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
n=int(input())
if n%2:
print((n-1)//2,(n+1)//2)
else:
print((n-2)//2,(n+2)//2)
``` | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,615,916,706 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 218 | 1,843,200 | a=input()
c=0
while(len(a)>1):
c+=1
s=0
for i in range(len(a)):
s+=int(a[i])
a=str(s)
print(c)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
a=input()
c=0
while(len(a)>1):
c+=1
s=0
for i in range(len(a)):
s+=int(a[i])
a=str(s)
print(c)
``` | 3.942183 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,608,010,998 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 140 | 0 | from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst=lambda:list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr():
n,d=lst()
s=input()
dp=[float('inf')]*n
dp[0]=0
for i in range(1,n):
if s[i]=='0':continue
for j in range(i-1,max(-1,i-d-1),-1):
... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
from sys import stdin,stdout
nmbr=lambda:int(stdin.readline())
lst=lambda:list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr():
n,d=lst()
s=input()
dp=[float('inf')]*n
dp[0]=0
for i in range(1,n):
if s[i]=='0':continue
for j in range(i-1,max(-1,i-d-1)... | 3 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,571,389,641 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 109 | 0 | h,k=[int(i) for i in input().split()]
if ((h//k)%2!=0):
print('yes')
if ((h//k)%2==0):
print('no') | Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
h,k=[int(i) for i in input().split()]
if ((h//k)%2!=0):
print('yes')
if ((h//k)%2==0):
print('no')
``` | 3 | |
611 | B | New Year and Old Property | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510<==<=111110111112. Note that he doesn't care about the number of zeros in the decimal representation.
Lim... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=1018) — the first year and the last year in Limak's interval respectively. | Print one integer – the number of years Limak will count in his chosen interval. | [
"5 10\n",
"2015 2015\n",
"100 105\n",
"72057594000000000 72057595000000000\n"
] | [
"2\n",
"1\n",
"0\n",
"26\n"
] | In the first sample Limak's interval contains numbers 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub>, 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub>, 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub>, 8<sub class="lower-index">10</sub> = 1000<su... | 750 | [
{
"input": "5 10",
"output": "2"
},
{
"input": "2015 2015",
"output": "1"
},
{
"input": "100 105",
"output": "0"
},
{
"input": "72057594000000000 72057595000000000",
"output": "26"
},
{
"input": "1 100",
"output": "16"
},
{
"input": "100000000000000000... | 1,545,723,191 | 2,147,483,647 | Python 3 | OK | TESTS | 103 | 171 | 512,000 | import re
a, b= map(lambda x : bin(int(x))[2:], input().split())
cal = lambda x : (len(x) - 2) * (len(x) - 1) // 2
numa = cal(a)
for i in a:
if i != "1":
break
numa += 1
numb = cal(b)
for i in b:
if i != "1":
break
numb += 1
print(numb - numa + (1 if len(re.findall("0", b)) ... | Title: New Year and Old Property
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2... | ```python
import re
a, b= map(lambda x : bin(int(x))[2:], input().split())
cal = lambda x : (len(x) - 2) * (len(x) - 1) // 2
numa = cal(a)
for i in a:
if i != "1":
break
numa += 1
numb = cal(b)
for i in b:
if i != "1":
break
numb += 1
print(numb - numa + (1 if len(re.findall... | 3 | |
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he... | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 6... | 1,629,195,098 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 218 | 16,179,200 | n, p, q, r = list(map(int, input().split()))
arr = list(map(int, input().split()))
def maxFind(arr, n):
ans = -100000000000
prefixMax = [0]*n
suffixMax = [0]*n
prefixMax[0] = p*arr[0]
suffixMax[n-1] = r*arr[n-1]
for i in range(1, n):
prefixMax[i] = max(prefixMax[... | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed i... | ```python
n, p, q, r = list(map(int, input().split()))
arr = list(map(int, input().split()))
def maxFind(arr, n):
ans = -100000000000
prefixMax = [0]*n
suffixMax = [0]*n
prefixMax[0] = p*arr[0]
suffixMax[n-1] = r*arr[n-1]
for i in range(1, n):
prefixMax[i] = max(... | 0 | |
958 | A2 | Death Stars (medium) | PROGRAMMING | 2,000 | [
"hashing",
"strings"
] | null | null | The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she knows that both maps are correct, and indeed show the map of the so... | The first line of the input contains two space-separated integers *N* and *M* (1<=≤<=*N*<=≤<=2000, 1<=≤<=*M*<=≤<=200, *M*<=≤<=*N*). The next *N* lines each contain *M* lower-case Latin characters (a-z), denoting the first map. Different characters correspond to different cosmic object types. The next *M* lines each con... | The only line of the output should contain two space-separated integers *i* and *j*, denoting that the section of size *M*<=×<=*M* in the first map that starts at the *i*-th row is equal to the section of the second map that starts at the *j*-th column. Rows and columns are numbered starting from 1.
If there are sever... | [
"10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n"
] | [
"4 6\n"
] | The 5-by-5 grid for the first test case looks like this: | 0 | [
{
"input": "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo",
"output": "4 6"
},
{
"input": "1 1\ng\ng",
"output": "1 1"
}
] | 1,523,703,225 | 13,725 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,500 | 107,110,400 | from re import finditer
from collections import defaultdict
N, M = map(int, input().split())
m1 = []
m2 = []
m1s = defaultdict(list)
for i, n in enumerate(range(N)):
line = input()
m1.append(line)
m1s[line].append(i)
m1s = dict(m1s)
s1 = ''.join(m1)
for m in range(M):
m2.append(input())
def cal():
... | Title: Death Stars (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got r... | ```python
from re import finditer
from collections import defaultdict
N, M = map(int, input().split())
m1 = []
m2 = []
m1s = defaultdict(list)
for i, n in enumerate(range(N)):
line = input()
m1.append(line)
m1s[line].append(i)
m1s = dict(m1s)
s1 = ''.join(m1)
for m in range(M):
m2.append(input())
de... | 0 | |
475 | C | Kamal-ol-molk's Painting | PROGRAMMING | 2,100 | [
"brute force",
"constructive algorithms",
"greedy"
] | null | null | Rumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting.
Consider the painting as a *n*<=×<=*m* rectangular grid. At the beginning an *x*<=×<=*y* rectangular brush is placed somewhere in the frame, with edges parallel to the frame, (1<=≤<=*x*... | The first line of input contains two integers *n* and *m*, (1<=≤<=*n*,<=*m*<=≤<=1000), denoting the height and width of the painting.
The next *n* lines contain the painting. Each line has *m* characters. Character 'X' denotes an altered cell, otherwise it's showed by '.'. There will be at least one altered cell in th... | Print the minimum area of the brush in a line, if the painting is possibly altered, otherwise print <=-<=1. | [
"4 4\nXX..\nXX..\nXXXX\nXXXX\n",
"4 4\n....\n.XXX\n.XXX\n....\n",
"4 5\nXXXX.\nXXXX.\n.XX..\n.XX..\n"
] | [
"4\n",
"2\n",
"-1\n"
] | none | 1,500 | [
{
"input": "4 4\nXX..\nXX..\nXXXX\nXXXX",
"output": "4"
},
{
"input": "4 5\nXXXX.\nXXXX.\n.XX..\n.XX..",
"output": "-1"
},
{
"input": "5 6\n.XXX..\n.XXXX.\n.XXXX.\n..XXX.\n..XXX.",
"output": "6"
},
{
"input": "5 6\n.XXXX.\n.XXXXX\n...XXX\n...XXX\n...XXX",
"output": "-1"
... | 1,413,733,760 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 1,536,000 | #input
n,m=map(int,input().split())
painting=[str(input()) for i in range(n)]
#variables
start=[]
end=[n-1,m-1]
area=0
truearea=0
arealist=[]
#main
for i in range(n):
for j in range(m):
if painting[i][j]=='X':
if len(start)==0:
start=[i,j]
truearea+=1
for i in range(start[0],n... | Title: Kamal-ol-molk's Painting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Rumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting.
Consider the painting as a *n*<=×<=*m* rectangular grid. At the beginning a... | ```python
#input
n,m=map(int,input().split())
painting=[str(input()) for i in range(n)]
#variables
start=[]
end=[n-1,m-1]
area=0
truearea=0
arealist=[]
#main
for i in range(n):
for j in range(m):
if painting[i][j]=='X':
if len(start)==0:
start=[i,j]
truearea+=1
for i in range(... | 0 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,557,743,921 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 0 | a,b = map(int,input().split())
d = {}
k = 0
for i in range(b):
p = int(input())
if p%a in d:
k = 1
print(i+1)
break
else:
d[p%a] = p
if k == 0 and i == b - 1:
print(-1) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
a,b = map(int,input().split())
d = {}
k = 0
for i in range(b):
p = int(input())
if p%a in d:
k = 1
print(i+1)
break
else:
d[p%a] = p
if k == 0 and i == b - 1:
print(-1)
``` | 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,583,525,707 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 307,200 | a,b=map(int,input().split())
c=max(a,b)
d=7-c
if(d%6==0):
print(d//6,end="")
print('/',end="")
print(6//6)
elif(d%3==0):
print(d//3,end="")
print('/',end="")
print(6//3)
elif(d%2==0):
print(d//2,end="")
print('/',end="")
print(6//2) | 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
a,b=map(int,input().split())
c=max(a,b)
d=7-c
if(d%6==0):
print(d//6,end="")
print('/',end="")
print(6//6)
elif(d%3==0):
print(d//3,end="")
print('/',end="")
print(6//3)
elif(d%2==0):
print(d//2,end="")
print('/',end="")
print(6//2)
``` | 0 |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,623,238,022 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 280 | 0 | n=int(input())
l=list(map(int,input().split()))
s=0
for i in range(len(l)):
s=s+l[i]+((l[i]-1)*i)
print(s) | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
n=int(input())
l=list(map(int,input().split()))
s=0
for i in range(len(l)):
s=s+l[i]+((l[i]-1)*i)
print(s)
``` | 3.93 |
489 | B | BerSU Ball | PROGRAMMING | 1,200 | [
"dfs and similar",
"dp",
"graph matchings",
"greedy",
"sortings",
"two pointers"
] | null | null | The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in eac... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of boys. The second line contains sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is the *i*-th boy's dancing skill.
Similarly, the third line contains an integer *m* (1<=≤<=*m*<=≤<=100) — the number of girls. The fourth l... | Print a single number — the required maximum possible number of pairs. | [
"4\n1 4 6 2\n5\n5 1 5 7 9\n",
"4\n1 2 3 4\n4\n10 11 12 13\n",
"5\n1 1 1 1 1\n3\n1 2 3\n"
] | [
"3\n",
"0\n",
"2\n"
] | none | 1,000 | [
{
"input": "4\n1 4 6 2\n5\n5 1 5 7 9",
"output": "3"
},
{
"input": "4\n1 2 3 4\n4\n10 11 12 13",
"output": "0"
},
{
"input": "5\n1 1 1 1 1\n3\n1 2 3",
"output": "2"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 10\n1\n9",
"output": "1"
},
{... | 1,678,037,471 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 62 | 0 | n = int(input())
li1 = sorted(list(map(int, input().split())))
m = int(input())
li2 = sorted(list(map(int, input().split())))
counter = 0
i = 0
while i < n and li1 and li2:
if (li1[i] - 1) in li2:
counter += 1
li2.remove(li1[i] - 1)
li1.remove(li1[i])
elif li1[i] in li2:
... | Title: BerSU Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! *n* boys and *m* girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.
We know that several boy... | ```python
n = int(input())
li1 = sorted(list(map(int, input().split())))
m = int(input())
li2 = sorted(list(map(int, input().split())))
counter = 0
i = 0
while i < n and li1 and li2:
if (li1[i] - 1) in li2:
counter += 1
li2.remove(li1[i] - 1)
li1.remove(li1[i])
elif li1[i] in ... | 3 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,615,208,053 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 93 | 0 | a=input()
b=a[:a.find('|')]
c=a[a.find('|')+1:]
d=input()
if (len(b)+len(c)+len(d))%2==0 and abs(len(b)-len(c))<=len(d):
if len(b)>len(c):
e=len(b)-len(c)
c+=d[:e]+d[e:(len(d)-e)//2+e]
b+=d[(len(d)-e)//2+e:]
else:
e=len(c)-len(b)
b+=d[:e]+d[e:(len(d)-e)//2+e]
... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
a=input()
b=a[:a.find('|')]
c=a[a.find('|')+1:]
d=input()
if (len(b)+len(c)+len(d))%2==0 and abs(len(b)-len(c))<=len(d):
if len(b)>len(c):
e=len(b)-len(c)
c+=d[:e]+d[e:(len(d)-e)//2+e]
b+=d[(len(d)-e)//2+e:]
else:
e=len(c)-len(b)
b+=d[:e]+d[e:(len(d)-... | 3 | |
588 | B | Duff in Love | PROGRAMMING | 1,300 | [
"math"
] | null | null | Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want... | The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012). | Print the answer in one line. | [
"10\n",
"12\n"
] | [
"10\n",
"6\n"
] | In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.
In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely. | 1,000 | [
{
"input": "10",
"output": "10"
},
{
"input": "12",
"output": "6"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "4",
"output": "2"
},
{
"input": "8",
"output": "2"
},
{
"input": "3",
"output": "3"
},
... | 1,648,877,953 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | n=int(input())
a=[]
for i in range(1,int(pow(n,0.5)+1),1):
if n%i==0:
if n/i==i:
a.append(i)
else:
a.append(i)
a.append(int(n/i))
a.sort()
a.reverse()
k=-1
for i in range(0,len(a),1):
z=0
for j in range(2,int(pow(n,0,5))+1,1):
if a[i... | Title: Duff in Love
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=><=1 such that *a*2 is a divisor of *x*.
Malek has a number store! In his store, he has... | ```python
n=int(input())
a=[]
for i in range(1,int(pow(n,0.5)+1),1):
if n%i==0:
if n/i==i:
a.append(i)
else:
a.append(i)
a.append(int(n/i))
a.sort()
a.reverse()
k=-1
for i in range(0,len(a),1):
z=0
for j in range(2,int(pow(n,0,5))+1,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,593,147,559 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 6,656,000 | n = int(input())
sa = sb = sc =0
for i in range(n):
a , b , c = map(int , input().split())
sa = sa + a
sb = sb + b
sc = sc + c
if(sa==0 and sb == 0 and sc ==0):
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
sa = sb = sc =0
for i in range(n):
a , b , c = map(int , input().split())
sa = sa + a
sb = sb + b
sc = sc + c
if(sa==0 and sb == 0 and sc ==0):
print("YES")
else:
print("NO")
``` | 3.933102 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,590,892,197 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,048,000 | def elepe(n):
s = ""
flag = True
for i in range(n):
if n[i] == "1":
s += '1'
if n[i] == "0":
s += n[i+1:]
return s
return s[1:]
print(elepe(input())) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
def elepe(n):
s = ""
flag = True
for i in range(n):
if n[i] == "1":
s += '1'
if n[i] == "0":
s += n[i+1:]
return s
return s[1:]
print(elepe(input()))
``` | -1 | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,696,997,635 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | import sys
input = sys.stdin.readline
s, n = map(int, input().split())
list_dragon = []
list_bonus = []
for _ in range(n):
x, y = map(int, input().split())
tuple_dragon = (x,y)
list_dragon.append(tuple_dragon)
list_dragon.sort(key=lambda x: x[0])
for i in list_dragon:
if s > i[0]:
s += i[1]
... | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
import sys
input = sys.stdin.readline
s, n = map(int, input().split())
list_dragon = []
list_bonus = []
for _ in range(n):
x, y = map(int, input().split())
tuple_dragon = (x,y)
list_dragon.append(tuple_dragon)
list_dragon.sort(key=lambda x: x[0])
for i in list_dragon:
if s > i[0]:
s +... | 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,437,746,911 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | s = input()
h = "hello"
it = 0
for ch in s:
if it == len(h):
break
if ch == h[it]:
it += 1
if it == len(h):
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()
h = "hello"
it = 0
for ch in s:
if it == len(h):
break
if ch == h[it]:
it += 1
if it == len(h):
print("YES")
else:
print("NO")
``` | 3.938 |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,396,163,027 | 227 | Python 3 | OK | TESTS | 20 | 62 | 204,800 | n = int(input())
k = map(int, input().split())
times = []
for i in range(n):
people = list(map(int, input().split()))
time = len(people) * 15
for p in people:
time += p*5
times.append(time)
print(min(times)) | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
n = int(input())
k = map(int, input().split())
times = []
for i in range(n):
people = list(map(int, input().split()))
time = len(people) * 15
for p in people:
time += p*5
times.append(time)
print(min(times))
``` | 3 | |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,516,791,219 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 62 | 5,632,000 | k1,k2,k3=map(int,input().split())
if (k1==2 and k2==2) or (k3==2 and k2==2) or (k1==2 and k3==2):
print("YES")
elif k1==k2==k3==3:
print("YES")
elif k1==1 or k2==1 or k3==1:
print("YES")
elif (k1==2 and k2==4 and k3==4) or (k2==2 and k1==4 and k3==4) or (k1==4 and k2==4 and k3==2):
print("YES")
else:
... | Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
k1,k2,k3=map(int,input().split())
if (k1==2 and k2==2) or (k3==2 and k2==2) or (k1==2 and k3==2):
print("YES")
elif k1==k2==k3==3:
print("YES")
elif k1==1 or k2==1 or k3==1:
print("YES")
elif (k1==2 and k2==4 and k3==4) or (k2==2 and k1==4 and k3==4) or (k1==4 and k2==4 and k3==2):
print("YES"... | 3 | |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,682,870,402 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
l = []
for _ in range(n):
a, b = map(int, input().split())
l.append((a,b))
mins = list(filter(lambda x: x[0] == min(l, key=lambda x:x[0])[0], l))
a, b = max(mins, key=lambda x:x[-1])
print(m/b*a) | Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
l = []
for _ in range(n):
a, b = map(int, input().split())
l.append((a,b))
mins = list(filter(lambda x: x[0] == min(l, key=lambda x:x[0])[0], l))
a, b = max(mins, key=lambda x:x[-1])
print(m/b*a)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.