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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
225 | A | Dice Tower | PROGRAMMING | 1,100 | [
"constructive algorithms",
"greedy"
] | null | null | A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower.
The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=... | Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). | [
"3\n6\n3 2\n5 4\n2 4\n",
"3\n3\n2 6\n4 1\n5 3\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "3\n6\n3 2\n5 4\n2 4",
"output": "YES"
},
{
"input": "3\n3\n2 6\n4 1\n5 3",
"output": "NO"
},
{
"input": "1\n3\n2 1",
"output": "YES"
},
{
"input": "2\n2\n3 1\n1 5",
"output": "NO"
},
{
"input": "3\n2\n1 4\n5 3\n6 4",
"output": "NO"
},
{
"in... | 1,595,813,669 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 218 | 6,963,200 | import sys
def can_determine(top, elems, i):
if i >= len(elems):
return True
l, r = elems[i]
possible = {2, 4, 6, 1, 3, 5}
possible.remove(l)
possible.remove(r)
possible.remove(7 - l)
possible.remove(7 - r)
if 7 - top not in possible:
return False
else:
poss... | Title: Dice Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other... | ```python
import sys
def can_determine(top, elems, i):
if i >= len(elems):
return True
l, r = elems[i]
possible = {2, 4, 6, 1, 3, 5}
possible.remove(l)
possible.remove(r)
possible.remove(7 - l)
possible.remove(7 - r)
if 7 - top not in possible:
return False
else:
... | 3 | |
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, wher... | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000... | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"outp... | 1,590,970,480 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 218 | 307,200 | n, t = map(int, input().split())
li = []
for _ in range(n):
tx = tuple(map(int, input().split()))
li.append(tx)
p = 2
li.sort(key = lambda x: x[0])
for i in range(len(li)-1):
d = abs(li[i][0]-li[i+1][0])-(li[i][1]+li[i+1][1])//2
if d >= t:
p += round(d/t)
print(p) | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. I... | ```python
n, t = map(int, input().split())
li = []
for _ in range(n):
tx = tuple(map(int, input().split()))
li.append(tx)
p = 2
li.sort(key = lambda x: x[0])
for i in range(len(li)-1):
d = abs(li[i][0]-li[i+1][0])-(li[i][1]+li[i+1][1])//2
if d >= t:
p += round(d/t)
print(p)
``` | 0 |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,696,440,194 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a=input()
b=input()
c=input()
i=0
test = True
while True :
if a.count(a[i])==c.count(a[i]) and b.count(b[i])==c.count(b[i]):
i+=1
else :
test=False
break
if test :
print('YES')
else :
print ('NO') | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
a=input()
b=input()
c=input()
i=0
test = True
while True :
if a.count(a[i])==c.count(a[i]) and b.count(b[i])==c.count(b[i]):
i+=1
else :
test=False
break
if test :
print('YES')
else :
print ('NO')
``` | -1 | |
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,641,054,119 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 122 | 0 | s=int(input())
a=b=c=0
for i in range(s):
x=list(map(int,input().split()))
a += x[0]
b += x[1]
c += x[2]
if a==b==c==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
s=int(input())
a=b=c=0
for i in range(s):
x=list(map(int,input().split()))
a += x[0]
b += x[1]
c += x[2]
if a==b==c==0 :
print ('YES')
else:
print ('NO')
``` | 3.9695 |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,686,078,833 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 122 | 0 | s = input().lower()
vowels = 'aeiouy'
consonants = 'bcdfghjklmnpqrstvwxz'
for i in range(len(s) - 1, -1, -1):
if s[i] in vowels:
print('YES')
break
elif s[i] in consonants:
print('NO')
break | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s = input().lower()
vowels = 'aeiouy'
consonants = 'bcdfghjklmnpqrstvwxz'
for i in range(len(s) - 1, -1, -1):
if s[i] in vowels:
print('YES')
break
elif s[i] in consonants:
print('NO')
break
``` | 3.9695 |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,626,368,814 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 92 | 20,172,800 | # cook your dish here
n = int(input())
a=[]
for i in range(n):
s=input()
a.append(s)
flag=0
for i in range(n):
for j in range(n):
if(a[i][j] == 'o'):
if(j==0 and i>0 and i<n-1):
flag=1
break
if(j==n and i>0 and i<n-1):
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
# cook your dish here
n = int(input())
a=[]
for i in range(n):
s=input()
a.append(s)
flag=0
for i in range(n):
for j in range(n):
if(a[i][j] == 'o'):
if(j==0 and i>0 and i<n-1):
flag=1
break
if(j==n and i>0 and i<n-1)... | 0 | |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they... | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"... | 1,674,314,009 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | x1,x2,x3 = input().split()
l = [x1,x2,x3]
l.sort()
distance = int(l[2]) - int(l[1]) + (int(l[1]) - int(l[0]))
print(distance)
| Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ... | ```python
x1,x2,x3 = input().split()
l = [x1,x2,x3]
l.sort()
distance = int(l[2]) - int(l[1]) + (int(l[1]) - int(l[0]))
print(distance)
``` | 0 | |
468 | A | 24 Game | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them, let's denote them *a* and *b*, erase them from the sequence, and append to the sequence eit... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If it's possible, print "YES" in the first line. Otherwise, print "NO" (without the quotes).
If there is a way to obtain 24 as the result number, in the following *n*<=-<=1 lines print the required operations an operation per line. Each operation should be in form: "*a* *op* *b* = *c*". Where *a* and *b* are the numbe... | [
"1\n",
"8\n"
] | [
"NO\n",
"YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24\n"
] | none | 500 | [
{
"input": "1",
"output": "NO"
},
{
"input": "8",
"output": "YES\n8 * 7 = 56\n6 * 5 = 30\n3 - 4 = -1\n1 - 2 = -1\n30 - -1 = 31\n56 - 31 = 25\n25 + -1 = 24"
},
{
"input": "12",
"output": "YES\n3 * 4 = 12\n2 * 1 = 2\n12 * 2 = 24\n6 - 5 = 1\n24 * 1 = 24\n8 - 7 = 1\n24 * 1 = 24\n10 - 9 =... | 1,570,471,319 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 108 | 307,200 |
n = int(input())
if n < 4:
print('NO')
elif n == 4:
print('YES')
print('{} * {} = {}'.format(1,2,1*2))
t = 1*2
for i in range(3,4 + 1):
print('{} * {} = {}'.format(t,i,t*i))
t *= i
elif n == 5:
print('YES')
print('{} - {} = {}'.format(3,2,1))
print('{} ... | Title: 24 Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X used to play a card game called "24 Game", but recently he has found it too easy. So he invented a new game.
Initially you have a sequence of *n* integers: 1,<=2,<=...,<=*n*. In a single step, you can pick two of them... | ```python
n = int(input())
if n < 4:
print('NO')
elif n == 4:
print('YES')
print('{} * {} = {}'.format(1,2,1*2))
t = 1*2
for i in range(3,4 + 1):
print('{} * {} = {}'.format(t,i,t*i))
t *= i
elif n == 5:
print('YES')
print('{} - {} = {}'.format(3,2,1))
... | 0 | |
165 | C | Another Problem on Strings | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math",
"strings",
"two pointers"
] | null | null | A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if th... | The first line contains the single integer *k* (0<=≤<=*k*<=≤<=106). The second line contains a non-empty binary string *s*. The length of *s* does not exceed 106 characters. | Print the single number — the number of substrings of the given string, containing exactly *k* characters "1".
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"1\n1010\n",
"2\n01010\n",
"100\n01010\n"
] | [
"6\n",
"4\n",
"0\n"
] | In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".
In the second sample the sought substrings are: "101", "0101", "1010", "01010". | 1,500 | [
{
"input": "1\n1010",
"output": "6"
},
{
"input": "2\n01010",
"output": "4"
},
{
"input": "100\n01010",
"output": "0"
},
{
"input": "0\n01010",
"output": "3"
},
{
"input": "0\n0010100011",
"output": "10"
},
{
"input": "0\n10000",
"output": "10"
}... | 1,631,429,407 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 216 | 20,172,800 | k=int(input())
s=input()
l=len(s)
count=0
for i in range(l):
for j in range(l):
s1=s[i:j+1]
if(s1.count('1')==k):
count+=1
print(count) | Title: Another Problem on Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is binary, if it consists only of characters "0" and "1".
String *v* is a substring of string *w* if it has a non-zero length and can be read starting from some position in string *w*. For example, ... | ```python
k=int(input())
s=input()
l=len(s)
count=0
for i in range(l):
for j in range(l):
s1=s[i:j+1]
if(s1.count('1')==k):
count+=1
print(count)
``` | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,625,248,743 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 124 | 0 | n,m = map(int,input().split())
eq = 0
for a in range(n):
for b in range(m):
if a**2 + b == n and b**2+a == m: eq+=1
print(eq)
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n,m = map(int,input().split())
eq = 0
for a in range(n):
for b in range(m):
if a**2 + b == n and b**2+a == m: eq+=1
print(eq)
``` | 0 | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,621,932,670 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | n=int(input())
c=[]
w=[]
m=[]
r=[]
for i in range(1,n+1):
a,b=input().split()
if b=='rat':
r.append(a)
if b=='woman' or b=='child':
w.append(a)
if b=='man':
m.append(a)
if b=='captain':
c.append(a)
for i in r:
print(i)
for i in w:
print(i)
for i in m:
prin... | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
n=int(input())
c=[]
w=[]
m=[]
r=[]
for i in range(1,n+1):
a,b=input().split()
if b=='rat':
r.append(a)
if b=='woman' or b=='child':
w.append(a)
if b=='man':
m.append(a)
if b=='captain':
c.append(a)
for i in r:
print(i)
for i in w:
print(i)
for i in m... | 3.969 |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,690,237,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | x = input().split()
s1 = x[0]
s2 = x[1]
c = s2[0]
menor = ""
it = 0
ans = s1[0]
for i in range(1, len(s1)):
if s1[i] < c:
ans += s1[i]
c = s1[i]
print(ans + s2[0])
| Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
x = input().split()
s1 = x[0]
s2 = x[1]
c = s2[0]
menor = ""
it = 0
ans = s1[0]
for i in range(1, len(s1)):
if s1[i] < c:
ans += s1[i]
c = s1[i]
print(ans + s2[0])
``` | 0 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,692,068,979 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 436 | 33,075,200 | l=[]
n = input()
for i in range(int(n)):
x=input()
l.append(x)
l = list(map(lambda x: x.replace('Tetrahedron', '4'), l))
l = list(map(lambda x: x.replace('Cube', '6'), l))
l = list(map(lambda x: x.replace('Octahedron', '8'), l))
l = list(map(lambda x: x.replace('Dodecahedron', '12'), l))
l = list(map(l... | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
l=[]
n = input()
for i in range(int(n)):
x=input()
l.append(x)
l = list(map(lambda x: x.replace('Tetrahedron', '4'), l))
l = list(map(lambda x: x.replace('Cube', '6'), l))
l = list(map(lambda x: x.replace('Octahedron', '8'), l))
l = list(map(lambda x: x.replace('Dodecahedron', '12'), l))
l = ... | 3 | |
120 | J | Minimum Sum | PROGRAMMING | 1,900 | [
"divide and conquer",
"geometry",
"sortings"
] | null | null | You are given a set of *n* vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector *v**i*<==<=(*x**i*,<=*y**i*) can be transformed into one of the following four vectors:
- *v**i*1<==<=(*x**i*,<=*y**i*), - *v**i*2<==<=(<=-<=*x**i*,<=*y**i*), - *v**i*3<==<=(*x*... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105). Then *n* lines contain vectors as pairs of integers "*x**i* *y**i*" (<=-<=10000<=≤<=*x**i*,<=*y**i*<=≤<=10000), one pair per line. | Print on the first line four space-separated numbers "*i* *k*1 *j* *k*2" — the answer to the problem. If there are several variants the absolute value of whose sums is minimum, you can print any of them. | [
"5\n-7 -3\n9 0\n-8 6\n7 -8\n4 -5\n",
"5\n3 2\n-4 7\n-6 0\n-8 4\n5 1\n"
] | [
"3 2 4 2\n",
"3 4 5 4\n"
] | A sum of two vectors *v* = (*x*<sub class="lower-index">*v*</sub>, *y*<sub class="lower-index">*v*</sub>) and *u* = (*x*<sub class="lower-index">*u*</sub>, *y*<sub class="lower-index">*u*</sub>) is vector *s* = *v* + *u* = (*x*<sub class="lower-index">*v*</sub> + *x*<sub class="lower-index">*u*</sub>, *y*<sub class="lo... | 0 | [
{
"input": "5\n-7 -3\n9 0\n-8 6\n7 -8\n4 -5",
"output": "3 2 4 2"
},
{
"input": "5\n3 2\n-4 7\n-6 0\n-8 4\n5 1",
"output": "3 4 5 4"
},
{
"input": "2\n-4 -2\n-2 1",
"output": "1 4 2 3"
},
{
"input": "3\n-4 -3\n-4 -5\n-1 0",
"output": "2 4 1 1"
},
{
"input": "10\n5... | 1,600,859,925 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 404 | 2,150,400 | import numpy as np
def calc(x1, x2):
if x1[0] == x2[0] and x1[1] == x2[1]:
return 1
elif x1[0] != x2[0] and x1[1] == x2[1]:
return 2
elif x1[0] == x2[0] and x1[1] != x2[1]:
return 3
elif x1[0] != x2[0] and x1[1] != x2[1]:
return 4
inputfile = open("input.txt... | Title: Minimum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a set of *n* vectors on a plane. For each vector you are allowed to multiply any of its coordinates by -1. Thus, each vector *v**i*<==<=(*x**i*,<=*y**i*) can be transformed into one of the following four vecto... | ```python
import numpy as np
def calc(x1, x2):
if x1[0] == x2[0] and x1[1] == x2[1]:
return 1
elif x1[0] != x2[0] and x1[1] == x2[1]:
return 2
elif x1[0] == x2[0] and x1[1] != x2[1]:
return 3
elif x1[0] != x2[0] and x1[1] != x2[1]:
return 4
inputfile = open(... | -1 | |
961 | C | Chessboard | PROGRAMMING | 1,400 | [
"bitmasks",
"brute force",
"implementation"
] | null | null | Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size *n* by *n*, *n* is always odd. And what's even worse, some squares were of wrong color. *j*-th square of the *i*-th row of *k*-th piece of the board has color *a**k*... | The first line contains odd integer *n* (1<=≤<=*n*<=≤<=100) — the size of all pieces of the board.
Then 4 segments follow, each describes one piece of the board. Each consists of *n* lines of *n* characters; *j*-th one of *i*-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separat... | Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard. | [
"1\n0\n\n0\n\n1\n\n0\n",
"3\n101\n010\n101\n\n101\n000\n101\n\n010\n101\n011\n\n010\n101\n010\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "1\n0\n\n0\n\n1\n\n0",
"output": "1"
},
{
"input": "3\n101\n010\n101\n\n101\n000\n101\n\n010\n101\n011\n\n010\n101\n010",
"output": "2"
},
{
"input": "3\n000\n000\n000\n\n111\n111\n111\n\n111\n111\n111\n\n000\n000\n000",
"output": "16"
},
{
"input": "3\n101\n010\n1... | 1,563,959,688 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 280 | 3,584,000 | #Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
from itertools import permutations
#sys.stdin = open('input.txt', 'r')
MOD = 998244353
sys.setrecursionlimit(1000000)
def cost(p, r, s, n):
c = 0
for i in range(n):
for j in range(n):
if p[i][j] != r[s... | Title: Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size *n* by *n*, *n* is always odd. And what's even worse, some squares we... | ```python
#Bhargey Mehta (Junior)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
from itertools import permutations
#sys.stdin = open('input.txt', 'r')
MOD = 998244353
sys.setrecursionlimit(1000000)
def cost(p, r, s, n):
c = 0
for i in range(n):
for j in range(n):
if p[i]... | 3 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,598,408,735 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 204,800 | def solve(n,string):
left_key = []
count = 0
for i in range(2,(2*n),2):
key = string[i-2].upper()
if key != string[i-1]:
left_key.append(key)
if string[i-1] in left_key:
left_key.remove(string[i-1])
else:
count+=1
... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
def solve(n,string):
left_key = []
count = 0
for i in range(2,(2*n),2):
key = string[i-2].upper()
if key != string[i-1]:
left_key.append(key)
if string[i-1] in left_key:
left_key.remove(string[i-1])
else:
... | -1 | |
385 | C | Bear and Prime Numbers | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"implementation",
"math",
"number theory"
] | null | null | Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct.
The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ... | Print *m* integers — the answers to the queries on the order the queries appear in the input. | [
"6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n"
] | [
"9\n7\n0\n",
"0\n7\n"
] | Consider the first sample. Overall, the first sample has 3 queries.
1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7.... | 1,500 | [
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4",
"output": "9\n7\n0"
},
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123",
"output": "0\n7"
},
{
"input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792",
"output": "0\n0\n0\n0\n9\n0\n0"
},
{
"... | 1,532,106,822 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | def isprime(x):
if x==2 or x==1:
return True
elif x%2==0:
return False
else:
for i in range(3,int(pow(x,1/2))):
if x%i==0:
return False
return True
n = int(input())
a = list(map(int,input().split()))
q = int(input())
while q:
cnt=0
q-=1
s, t = ... | Title: Bear and Prime Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b... | ```python
def isprime(x):
if x==2 or x==1:
return True
elif x%2==0:
return False
else:
for i in range(3,int(pow(x,1/2))):
if x%i==0:
return False
return True
n = int(input())
a = list(map(int,input().split()))
q = int(input())
while q:
cnt=0
q-=1
... | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,665,054,048 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | a,b,c=map(int,input().split())
otv=min(a,c+b)
otv+=min(a+b,c)
otv+=min(b,a+c)
print(otv)
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a,b,c=map(int,input().split())
otv=min(a,c+b)
otv+=min(a+b,c)
otv+=min(b,a+c)
print(otv)
``` | 3 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,685,457,478 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 1,331,200 | def Lottery(n):
total_notes = 0
total_amnt = 0
while True:
if total_amnt == n:
return total_notes
elif total_amnt + 100 <= n:
total_amnt += 100
total_notes += 1
elif total_amnt + 20 <= n:
total_amnt += 20
... | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
def Lottery(n):
total_notes = 0
total_amnt = 0
while True:
if total_amnt == n:
return total_notes
elif total_amnt + 100 <= n:
total_amnt += 100
total_notes += 1
elif total_amnt + 20 <= n:
total_amnt += ... | 3 | |
616 | C | The Labyrinth | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side.
Let's call a connected component any non-extendible set of cells such ... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field.
Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells. | Print the answer as a matrix as described above. See the examples to precise the format of the output. | [
"3 3\n*.*\n.*.\n*.*\n",
"4 5\n**..*\n..***\n.*.*.\n*.*.*\n"
] | [
"3.3\n.5.\n3.3\n",
"46..3\n..732\n.6.4.\n5.4.3\n"
] | In first example, if we imagine that the central cell is empty then it will be included to component of size 5 (cross). If any of the corner cell will be empty then it will be included to component of size 3 (corner). | 0 | [
{
"input": "3 3\n*.*\n.*.\n*.*",
"output": "3.3\n.5.\n3.3"
},
{
"input": "4 5\n**..*\n..***\n.*.*.\n*.*.*",
"output": "46..3\n..732\n.6.4.\n5.4.3"
},
{
"input": "1 1\n*",
"output": "1"
},
{
"input": "1 1\n.",
"output": "."
},
{
"input": "1 10\n**********",
"ou... | 1,667,221,258 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 31 | 0 | n, m = map(int, input().split())
grid = []
for _ in range(n):
row = input()
grid.append(row)
class UnionFind:
def __init__(self):
self.parent = {}
self.rank = {}
def union(self, x, y):
findX, findY = self.find(x), self.find(y)
if findX == findY: return
... | Title: The Labyrinth
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adj... | ```python
n, m = map(int, input().split())
grid = []
for _ in range(n):
row = input()
grid.append(row)
class UnionFind:
def __init__(self):
self.parent = {}
self.rank = {}
def union(self, x, y):
findX, findY = self.find(x), self.find(y)
if findX == find... | 0 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,557,279,901 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 109 | 0 | ruler = input()
vowels = 'A E I O U Y'.split()
jump = jump_max = 1
for letter in ruler:
jump += 1
if letter in vowels:
jump = 1
if jump_max < jump:
jump_max = jump
print(jump_max)
| Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
ruler = input()
vowels = 'A E I O U Y'.split()
jump = jump_max = 1
for letter in ruler:
jump += 1
if letter in vowels:
jump = 1
if jump_max < jump:
jump_max = jump
print(jump_max)
``` | 3 | |
846 | C | Four Segments | PROGRAMMING | 1,800 | [
"brute force",
"data structures",
"dp"
] | null | null | You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* holds 0<=≤<=*l*<=≤<=*r*<=≤<=*n*. Indices in array are numbered from 0.
For example, if *a*<==<=[<... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=5000).
The second line contains *n* numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=109<=≤<=*a**i*<=≤<=109). | Choose three indices so that the value of *res* is maximal. If there are multiple answers, print any of them. | [
"3\n-1 2 3\n",
"4\n0 0 -1 0\n",
"1\n10000\n"
] | [
"0 1 3\n",
"0 0 0\n",
"1 1 1\n"
] | none | 0 | [
{
"input": "3\n-1 2 3",
"output": "0 1 3"
},
{
"input": "4\n0 0 -1 0",
"output": "0 0 0"
},
{
"input": "1\n10000",
"output": "0 0 1"
},
{
"input": "1\n-1",
"output": "0 0 0"
},
{
"input": "1\n0",
"output": "0 0 0"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0... | 1,505,225,744 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | def maxsubarr(a):
n = len(a)
ms = [0 for _ in range(n)]
l = [0 for _ in range(n)]
for i in range(n):
prevsum = ms[i-1] if i > 0 else 0
ms[i] = a[i] + (prevsum if prevsum >= 0 else 0)
previdx = l[i-1] if i > 0 else 0
l[i] = previdx if prevsum >= 0 else i
retur... | Title: Four Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers. Let *sum*(*l*,<=*r*) be the sum of all numbers on positions from *l* to *r* non-inclusive (*l*-th element is counted, *r*-th element is not counted). For indices *l* and *r* ... | ```python
def maxsubarr(a):
n = len(a)
ms = [0 for _ in range(n)]
l = [0 for _ in range(n)]
for i in range(n):
prevsum = ms[i-1] if i > 0 else 0
ms[i] = a[i] + (prevsum if prevsum >= 0 else 0)
previdx = l[i-1] if i > 0 else 0
l[i] = previdx if prevsum >= 0 else i
... | 0 | |
272 | D | Dima and Two Sequences | PROGRAMMING | 1,600 | [
"combinatorics",
"math",
"sortings"
] | null | null | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* ... | In the single line print the remainder after dividing the answer to the problem by number *m*. | [
"1\n1\n2\n7\n",
"2\n1 2\n2 3\n11\n"
] | [
"1\n",
"2\n"
] | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | 2,000 | [
{
"input": "1\n1\n2\n7",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n11",
"output": "2"
},
{
"input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5... | 1,649,929,542 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 102,400 | import collections
import math
import sys
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = collections.Counter(a + b)
m = int(input())
res = 1
def f(v):
r = 1
for i in range(1, v + 1):
r *= i... | Title: Dima and Two Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the ... | ```python
import collections
import math
import sys
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = collections.Counter(a + b)
m = int(input())
res = 1
def f(v):
r = 1
for i in range(1, v + 1):
... | 0 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,654,395,324 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 46 | 0 | if __name__ == '__main__':
n = int(input())
a = list(map(int, input().strip().split()))
INF = float("inf")
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(n):
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
if a[i] == 1 or a[i] == 3: # contest
dp[i + 1][1] =... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
if __name__ == '__main__':
n = int(input())
a = list(map(int, input().strip().split()))
INF = float("inf")
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(n):
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
if a[i] == 1 or a[i] == 3: # contest
dp[i... | 3 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,649,756,081 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | inputs = [int(num) for num in input().split()]
n = inputs[0]
m = inputs[1]
if(n<=m):
min1 = n
max1 = m
else:
min1 = m
max1 = n
squares =[]
i=0
sq=0
count=0
while(sq<=min1):
squares.append(sq)
i+=1
sq=i*i
for i in range(len(squares)-1,-1,-1):
b = min1-squares[i]
a =... | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
inputs = [int(num) for num in input().split()]
n = inputs[0]
m = inputs[1]
if(n<=m):
min1 = n
max1 = m
else:
min1 = m
max1 = n
squares =[]
i=0
sq=0
count=0
while(sq<=min1):
squares.append(sq)
i+=1
sq=i*i
for i in range(len(squares)-1,-1,-1):
b = min1-squares[i... | 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,691,070,558 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | def restore_original_song(remix):
original_song = remix.replace("WUB", " ")
original_song = original_song.strip()
original_song = " ".join(original_song.split())
return original_song
remix = input().strip()
result = restore_original_song(remix)
print(result)
| 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(remix):
original_song = remix.replace("WUB", " ")
original_song = original_song.strip()
original_song = " ".join(original_song.split())
return original_song
remix = input().strip()
result = restore_original_song(remix)
print(result)
``` | 3 | |
299 | A | Ksusha and Array | PROGRAMMING | 1,000 | [
"brute force",
"number theory",
"sortings"
] | null | null | Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! | The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements. | Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1.
If there are multiple answers, you are allowed to print any of them. | [
"3\n2 2 4\n",
"5\n2 1 3 1 6\n",
"3\n2 3 5\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 500 | [
{
"input": "3\n2 2 4",
"output": "2"
},
{
"input": "5\n2 1 3 1 6",
"output": "1"
},
{
"input": "3\n2 3 5",
"output": "-1"
},
{
"input": "1\n331358794",
"output": "331358794"
},
{
"input": "5\n506904227 214303304 136194869 838256937 183952885",
"output": "-1"
... | 1,460,650,856 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 466 | 11,059,200 | def f():
input()
a = list(map(int,input().split(' ')))
m = min(a)
for i in a:
if i % m != 0:
print(-1)
break
else:
print(m)
f() | Title: Ksusha and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers.
Her university teacher gave her a task. Find such number in the array, that ... | ```python
def f():
input()
a = list(map(int,input().split(' ')))
m = min(a)
for i in a:
if i % m != 0:
print(-1)
break
else:
print(m)
f()
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,554,362,506 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 11,264,000 | from itertools import combinations
n, d = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
print(len([combo for combo in combinations(arr, 3) if max(combo) - min(combo) <= d]))
| Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
from itertools import combinations
n, d = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
print(len([combo for combo in combinations(arr, 3) if max(combo) - min(combo) <= d]))
``` | 0 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,693,413,066 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n, x = list(map(int, input().split()))
distress = 0
for i in range(n):
d, num = input().split()
num = int(num)
if d == '+':
x += num
else:
if num <= x:
x -= num
else:
distress += 1
print(x, distress) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n, x = list(map(int, input().split()))
distress = 0
for i in range(n):
d, num = input().split()
num = int(num)
if d == '+':
x += num
else:
if num <= x:
x -= num
else:
distress += 1
print(x, distress)
``` | 3 | |
29 | E | Quarrel | PROGRAMMING | 2,400 | [
"graphs",
"shortest paths"
] | E. Quarrel | 1 | 256 | Friends Alex and Bob live in Bertown. In this town there are *n* crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number *n*.
One day Alex and Bob had a big quarrel, and they refused to see each other. It... | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=500,<=1<=≤<=*m*<=≤<=10000) — the amount of crossroads and the amount of roads. Each of the following *m* lines contains two integers — the numbers of crossroads connected by the road. It is guaranteed that no road connects a crossroads with itself and no t... | If the required routes don't exist, output -1. Otherwise, the first line should contain integer *k* — the length of shortest routes (the length of the route is the amount of roads in it). The next line should contain *k*<=+<=1 integers — Bob's route, i.e. the numbers of *k*<=+<=1 crossroads passed by Bob. The last line... | [
"2 1\n1 2\n",
"7 5\n1 2\n2 7\n7 6\n2 3\n3 4\n",
"7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5\n"
] | [
"1\n1 2 \n2 1 \n",
"-1\n",
"6\n1 2 3 4 3 2 7 \n7 6 7 2 1 5 1 \n"
] | none | 2,500 | [
{
"input": "2 1\n1 2",
"output": "1\n1 2 \n2 1 "
},
{
"input": "7 5\n1 2\n2 7\n7 6\n2 3\n3 4",
"output": "-1"
},
{
"input": "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5",
"output": "6\n1 2 3 4 3 2 7 \n7 6 7 2 1 5 1 "
},
{
"input": "6 10\n3 6\n3 5\n1 3\n2 6\n5 4\n6 4\n6 5\n5 1\n2 3\n1 2... | 1,689,416,694 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 872 | 71,475,200 | import sys
from collections import deque
readline = sys.stdin.readline
N, M = [int(w) for w in readline().split()]
city = [[] for _ in range(N + 1)]
edges = []
for _ in range(M):
u, v = [int(w) for w in readline().split()]
city[u].append(v)
city[v].append(u)
edges.append((u, v))
def gen_dists(node: in... | Title: Quarrel
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Friends Alex and Bob live in Bertown. In this town there are *n* crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads nu... | ```python
import sys
from collections import deque
readline = sys.stdin.readline
N, M = [int(w) for w in readline().split()]
city = [[] for _ in range(N + 1)]
edges = []
for _ in range(M):
u, v = [int(w) for w in readline().split()]
city[u].append(v)
city[v].append(u)
edges.append((u, v))
def gen_dist... | 3.430867 |
937 | B | Vile Grasshoppers | PROGRAMMING | 1,400 | [
"brute force",
"math",
"number theory"
] | null | null | The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh... | The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109). | Output the number of the highest suitable branch. If there are none, print -1 instead. | [
"3 6\n",
"3 4\n"
] | [
"5\n",
"-1\n"
] | In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5.
It immediately follows that there are no valid branches in second sample case. | 1,000 | [
{
"input": "3 6",
"output": "5"
},
{
"input": "3 4",
"output": "-1"
},
{
"input": "2 2",
"output": "-1"
},
{
"input": "5 50",
"output": "49"
},
{
"input": "944192806 944193066",
"output": "944192807"
},
{
"input": "1000000000 1000000000",
"output":... | 1,590,675,398 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 155 | 0 | p, y = map(int, input().split())
ans = -1
for j in range(y, p, -1):
i = 2
d = j
while i * i <= j:
if j % i == 0:
d = i
break
i += 1
if d > p:
ans = j
break
print(ans)
| Title: Vile Grasshoppers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape.
The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor... | ```python
p, y = map(int, input().split())
ans = -1
for j in range(y, p, -1):
i = 2
d = j
while i * i <= j:
if j % i == 0:
d = i
break
i += 1
if d > p:
ans = j
break
print(ans)
``` | 3 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,680,157,810 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n, l, r = map(int, input().split())
lst = [n]
while True:
x = max(lst)
if x == 1:
break
lst.remove(x)
lst.extend([x // 2, x // 2, x // 2])
if x % 2 == 1:
lst.append(1)
cnt = 0
for i in range(l - 1, r):
if lst[i] == 1:
cnt += 1
print(cnt)
| Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
n, l, r = map(int, input().split())
lst = [n]
while True:
x = max(lst)
if x == 1:
break
lst.remove(x)
lst.extend([x // 2, x // 2, x // 2])
if x % 2 == 1:
lst.append(1)
cnt = 0
for i in range(l - 1, r):
if lst[i] == 1:
cnt += 1
print(cnt)
... | 0 | |
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,692,213,220 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 155 | 6,451,200 | from queue import Queue
n, k = map(int, input().split())
array = list(map(int, input().split()))
queue = Queue()
if k > n:
print(max(array))
else:
wins = 0
champion = array[0]
for i in range(1,n):
queue.put(array[i])
while wins < k:
atual = queue.get()
if champ... | 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
from queue import Queue
n, k = map(int, input().split())
array = list(map(int, input().split()))
queue = Queue()
if k > n:
print(max(array))
else:
wins = 0
champion = array[0]
for i in range(1,n):
queue.put(array[i])
while wins < k:
atual = queue.get()
... | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,614,596,268 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 512,000 | n,k=map(int,input().split())
st=input()
s1=set(st)
occur=[]
for i in s1:
occur.append(st.count(i))
occur.sort(reverse=True)
# print(occur)
count=0
i=0
while i<n and k>0:
if k>=occur[i]:
count+=occur[i]*occur[i]
k-=occur[i]
else:
count+=k*k
k=0
i+=1
pri... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
n,k=map(int,input().split())
st=input()
s1=set(st)
occur=[]
for i in s1:
occur.append(st.count(i))
occur.sort(reverse=True)
# print(occur)
count=0
i=0
while i<n and k>0:
if k>=occur[i]:
count+=occur[i]*occur[i]
k-=occur[i]
else:
count+=k*k
k=0
... | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,697,401,032 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | input_str = input()
n, k = map(int, input_str.split())
num_odd = (n + 1) // 2
num_even = n - num_odd
if k > num_odd:
# Even integers start at position num_odd + 1
even_start = num_odd + 1
# Calculate the even number at the k position
result = 2 * (k - num_odd)
else:
# Odd integers start at positio... | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
input_str = input()
n, k = map(int, input_str.split())
num_odd = (n + 1) // 2
num_even = n - num_odd
if k > num_odd:
# Even integers start at position num_odd + 1
even_start = num_odd + 1
# Calculate the even number at the k position
result = 2 * (k - num_odd)
else:
# Odd integers start ... | 3 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100... | Print a single integer — the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,601,183,271 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | # Author: SaykaT
# Problem: 385A
# Time Created: September 27(Sunday) 2020 || 11:03:31
#>-------------------------<#
#>-------------------------<#
# Helper Functions. -> Don't cluster your code.
# Main functions. -> Write the main solution here
def solve():
n, c = map(int, input().split())
... | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
# Author: SaykaT
# Problem: 385A
# Time Created: September 27(Sunday) 2020 || 11:03:31
#>-------------------------<#
#>-------------------------<#
# Helper Functions. -> Don't cluster your code.
# Main functions. -> Write the main solution here
def solve():
n, c = map(int, input().spli... | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,620,858,668 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 61 | 6,963,200 | n = int(input())
t = [[1] * 10]
for i in range(1, 10):
t.append([1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
for i in range(1, 10):
for j in range(1, 10):
t[i][j] = t[i - 1][j] + t[i][j - 1]
print(t[n - 1][n - 1]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
t = [[1] * 10]
for i in range(1, 10):
t.append([1, 0, 0, 0, 0, 0, 0, 0, 0, 0])
for i in range(1, 10):
for j in range(1, 10):
t[i][j] = t[i - 1][j] + t[i][j - 1]
print(t[n - 1][n - 1])
``` | 3 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,586,690,809 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 307,200 | a = int(input())
b = list(map(int, input().split()))
small = []
for i in range(len(b)):
if b[i] == max(b):
print(max(b), str(sorted(small, reverse=True))[1:-1].replace(',', ''))
small.clear()
b[i] = 0
else:
small.append(b[i])
b[i] = 0
print()
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
a = int(input())
b = list(map(int, input().split()))
small = []
for i in range(len(b)):
if b[i] == max(b):
print(max(b), str(sorted(small, reverse=True))[1:-1].replace(',', ''))
small.clear()
b[i] = 0
else:
small.append(b[i])
b[i] = 0
print()
... | 0 | |
264 | B | Good Sequences | PROGRAMMING | 1,500 | [
"dp",
"number theory"
] | null | null | Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k* is called good if it satisfies the following three conditions:
- The sequence is strictly increas... | The input consists of two lines. The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of good integers. The second line contains a single-space separated list of good integers *a*1,<=*a*2,<=...,<=*a**n* in strictly increasing order (1<=≤<=*a**i*<=≤<=105; *a**i*<=<<=*a**i*<=+<=1). | Print a single integer — the length of the longest good sequence. | [
"5\n2 3 4 6 9\n",
"9\n1 2 3 5 6 7 8 9 10\n"
] | [
"4\n",
"4\n"
] | In the first example, the following sequences are examples of good sequences: [2; 4; 6; 9], [2; 4; 6], [3; 9], [6]. The length of the longest good sequence is 4. | 1,000 | [
{
"input": "5\n2 3 4 6 9",
"output": "4"
},
{
"input": "9\n1 2 3 5 6 7 8 9 10",
"output": "4"
},
{
"input": "4\n1 2 4 6",
"output": "3"
},
{
"input": "7\n1 2 3 4 7 9 10",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "8\n3 4 5 6 7 8 9... | 1,434,936,697 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 2,000 | 8,192,000 | ovmaxx = 0
prime = [True] * (10**5+5)
prime[0]=False
prime[1]=False
for i in range(2, 10**5+5):
if prime[i]:
for j in range(2*i, 10**5+5, i):
prime[j] = False
t = [i for i in range(10**5) if prime[i]]
x = int(input())
y = list(map(int, input().split(' ')))
good = [False]... | Title: Good Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks *n* integers *a*1,<=*a*2,<=...,<=*a**n* are good.
Now she is interested in good sequences. A sequence *x*1,<=*x*2,<=...,<=*x**k*... | ```python
ovmaxx = 0
prime = [True] * (10**5+5)
prime[0]=False
prime[1]=False
for i in range(2, 10**5+5):
if prime[i]:
for j in range(2*i, 10**5+5, i):
prime[j] = False
t = [i for i in range(10**5) if prime[i]]
x = int(input())
y = list(map(int, input().split(' ')))
good... | 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,535,484,388 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 342 | 409,600 | import re
s = input()
big = len(re.findall('[A-Z]', s))
lit = len(re.findall('[a-z]', s))
print(s.lower() if lit >= big else s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import re
s = input()
big = len(re.findall('[A-Z]', s))
lit = len(re.findall('[a-z]', s))
print(s.lower() if lit >= big else s.upper())
``` | 3.913737 |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,626,095,424 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 6,963,200 | n, m = map(int, input().split())
b = []
f = 1
p = 0
for i in range(n):
a = list(input())
if f == 1:
if len(set(a)) == 1:
if i == 0:
p = a[0]
else:
if p != a[0]:
f = 0
else:
f = 0
if f:
pri... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
n, m = map(int, input().split())
b = []
f = 1
p = 0
for i in range(n):
a = list(input())
if f == 1:
if len(set(a)) == 1:
if i == 0:
p = a[0]
else:
if p != a[0]:
f = 0
else:
f = 0
if f... | 0 |
140 | C | New Year Snowmen | PROGRAMMING | 1,800 | [
"binary search",
"data structures",
"greedy"
] | null | null | As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made *n* snowballs with radii equal to *r*1, *r*2, ..., *r**n*. To make a snowman, one nee... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of snowballs. The next line contains *n* integers — the balls' radii *r*1, *r*2, ..., *r**n* (1<=≤<=*r**i*<=≤<=109). The balls' radii can coincide. | Print on the first line a single number *k* — the maximum number of the snowmen. Next *k* lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print... | [
"7\n1 2 3 4 5 6 7\n",
"3\n2 2 3\n"
] | [
"2\n3 2 1\n6 5 4\n",
"0\n"
] | none | 1,500 | [
{
"input": "7\n1 2 3 4 5 6 7",
"output": "2\n7 5 3\n6 4 2"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n255317",
"output": "0"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2\n3 2 1\n3 2 1"
},
{
"input": "6\n1 2 2 2 3 3",
"output": "1\n3 2 1"
},
... | 1,384,516,959 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 748 | 14,131,200 | from collections import defaultdict
n, t = int(input()), input().split()
p = defaultdict(int)
for i in t:
p[i] += 1
if len(p) < 3: print(0)
else:
q = list(p.items())
a, b = q[0][1], q[1][1]
x, y = 0, 1
if a < b: x, y, a, b = y, x, b, a
for i in range(2, len(q)):
if q[i][1] > ... | Title: New Year Snowmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they... | ```python
from collections import defaultdict
n, t = int(input()), input().split()
p = defaultdict(int)
for i in t:
p[i] += 1
if len(p) < 3: print(0)
else:
q = list(p.items())
a, b = q[0][1], q[1][1]
x, y = 0, 1
if a < b: x, y, a, b = y, x, b, a
for i in range(2, len(q)):
if ... | 0 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,656,679,536 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int sum=a;
while(a>=b)
{
sum+=(a/b);
a/=b;
}
cout<<sum;
} | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int sum=a;
while(a>=b)
{
sum+=(a/b);
a/=b;
}
cout<<sum;
}
``` | -1 | |
245 | B | Internet Address | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol> can equal either "http" (without the quotes) or "ftp" (without the quotes), - <domain> is a no... | The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only.
It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above... | Print a single line — the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them. | [
"httpsunrux\n",
"ftphttprururu\n"
] | [
"http://sun.ru/x\n",
"ftp://http.ru/ruru\n"
] | In the second sample there are two more possible answers: "ftp://httpruru.ru" and "ftp://httpru.ru/ru". | 0 | [
{
"input": "httpsunrux",
"output": "http://sun.ru/x"
},
{
"input": "ftphttprururu",
"output": "ftp://http.ru/ruru"
},
{
"input": "httpuururrururruruurururrrrrurrurrurruruuruuu",
"output": "http://uu.ru/rrururruruurururrrrrurrurrurruruuruuu"
},
{
"input": "httpabuaruauabbaruru... | 1,685,695,800 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | s=input()
if s[0]=="h":
p="http"
s=s[4:]
else:
p="ftp"
s=s[3:]
f=s.find("ru")
host=s[:f]+".ru"
s=s[f+2:]
res=""
if len(s)>0: res="/"+s
print(p+"://"+host+res)
| Title: Internet Address
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format:
where:
- <protocol>... | ```python
s=input()
if s[0]=="h":
p="http"
s=s[4:]
else:
p="ftp"
s=s[3:]
f=s.find("ru")
host=s[:f]+".ru"
s=s[f+2:]
res=""
if len(s)>0: res="/"+s
print(p+"://"+host+res)
``` | 0 | |
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,511,081,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 5,529,600 | n = int(input())
input() #for all folks of k
for i in range(n):
a = sum([int(j)*5+15 for j in input().split()])
val = 1e18+5
ans = min(val,a)
print(ans)
| 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())
input() #for all folks of k
for i in range(n):
a = sum([int(j)*5+15 for j in input().split()])
val = 1e18+5
ans = min(val,a)
print(ans)
``` | 0 | |
495 | A | Digital Counter | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ... | The only line of input contains exactly two digits representing number *n* (0<=≤<=*n*<=≤<=99). Note that *n* may have a leading zero. | In the only line of the output print the number of good integers. | [
"89\n",
"00\n",
"73\n"
] | [
"2\n",
"4\n",
"15\n"
] | In the first sample the counter may be supposed to show 88 or 89.
In the second sample the good integers are 00, 08, 80 and 88.
In the third sample the good integers are 03, 08, 09, 33, 38, 39, 73, 78, 79, 83, 88, 89, 93, 98, 99. | 500 | [
{
"input": "89",
"output": "2"
},
{
"input": "00",
"output": "4"
},
{
"input": "73",
"output": "15"
},
{
"input": "08",
"output": "2"
},
{
"input": "26",
"output": "4"
},
{
"input": "49",
"output": "6"
},
{
"input": "88",
"output": "1"
... | 1,589,288,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 124 | 6,656,000 | v=[2,6,2,3,3,3,2,5,1,2]
r=1
for x in input():r*=v[int(x)]
print(r) | Title: Digital Counter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a numbe... | ```python
v=[2,6,2,3,3,3,2,5,1,2]
r=1
for x in input():r*=v[int(x)]
print(r)
``` | 0 | |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ... | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin... | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
... | 1,676,603,074 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 108 | 1,433,600 | import sys
abfk = list(map(int,input().split()))
faf = 2*(abfk[0]-abfk[2])
f0f = 2*abfk[2]
if abfk[1]<abfk[2]:
print(-1)
exit()
gas = abfk[1]-abfk[2]
j = 0
gases = 0
forward = True
while j<abfk[3]-1:
if(forward):
if faf>gas:
gas = abfk[1]
gases += 1
... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ... | ```python
import sys
abfk = list(map(int,input().split()))
faf = 2*(abfk[0]-abfk[2])
f0f = 2*abfk[2]
if abfk[1]<abfk[2]:
print(-1)
exit()
gas = abfk[1]-abfk[2]
j = 0
gases = 0
forward = True
while j<abfk[3]-1:
if(forward):
if faf>gas:
gas = abfk[1]
ga... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year *n* competitions will take place. During the *i*-th competition the participant must as quickly as possible complete a ride along a straight... | The first line contains three integers *n*, *r* and *v* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*r*,<=*v*<=≤<=109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively.
Next *n* lines contain the descriptions of the contests. The *i*-th line contains two integers *s**i... | Print *n* real numbers, the *i*-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=6.
Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker progr... | [
"2 1 2\n1 10\n5 9\n"
] | [
"3.849644710502\n1.106060157705\n"
] | none | 0 | [] | 1,447,072,364 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 307,200 | import math
def g(L, r):
b = 2 * r * math.pi
m = L // b
c = m * b
a = L - c
y = a / (2.0 * r)
F = lambda x: x + math.sin(x)
f = lambda x: 1 + math.cos(x)
theta = NewtonRaphson(math.pi/2, F, f, y, 10**(-7))
return 2 * r * theta + c
def NewtonRaphson(x, F, f, y, eps):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions.
He knows that this year *n* competitions will take place. During the *i*-t... | ```python
import math
def g(L, r):
b = 2 * r * math.pi
m = L // b
c = m * b
a = L - c
y = a / (2.0 * r)
F = lambda x: x + math.sin(x)
f = lambda x: 1 + math.cos(x)
theta = NewtonRaphson(math.pi/2, F, f, y, 10**(-7))
return 2 * r * theta + c
def NewtonRaphson(x, F, f,... | -1 | |
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
... | 1,516,373,089 | 589 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 46 | 5,632,000 | def check(a, b):
a = str(a) + str(b)
return a[0] == "7" or a[1] == "7" or a[2] == "7" or a[3] == "7"
def last(h, m, x):
time = h * 60 + m
time -= x
time %= 1440
m = time % 60
h = time // 60
return (h, m)
x = int(input())
cnt = 0
h, m = map(int, input().split())
while (not ch... | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the... | ```python
def check(a, b):
a = str(a) + str(b)
return a[0] == "7" or a[1] == "7" or a[2] == "7" or a[3] == "7"
def last(h, m, x):
time = h * 60 + m
time -= x
time %= 1440
m = time % 60
h = time // 60
return (h, m)
x = int(input())
cnt = 0
h, m = map(int, input().split())
whi... | -1 | |
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000... | 1,679,540,937 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | a,b = map(int,input().split())
if a==1:
if b<10: print(b,b)
else: print(-1,-1)
else:
l = [1 for i in range(a-1)]
if (b-a+1)<0:
print(-1,-1)
elif (b-a+1)==0:
l.append(0)
t = ""
for i in l: t+=str(i)
l[1],l[a-1] = l[a-1],l[1]
x = ""
... | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ... | ```python
a,b = map(int,input().split())
if a==1:
if b<10: print(b,b)
else: print(-1,-1)
else:
l = [1 for i in range(a-1)]
if (b-a+1)<0:
print(-1,-1)
elif (b-a+1)==0:
l.append(0)
t = ""
for i in l: t+=str(i)
l[1],l[a-1] = l[a-1],l[1]
x = "... | 0 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,692,377,851 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 62 | 1,638,400 | n=int(input())
s=input()
counter=0
for i in range (n):
if s[i] =="A":
counter +=1
else:
counter -=1
print((counter>0)*"Anton"+(counter<0)*"Danik"+ (counter==0)*"Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n=int(input())
s=input()
counter=0
for i in range (n):
if s[i] =="A":
counter +=1
else:
counter -=1
print((counter>0)*"Anton"+(counter<0)*"Danik"+ (counter==0)*"Friendship")
``` | 3 | |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,699,723,243 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 1,558 | 4,403,200 | line=input()
s=[0]*(len(line)+1)
for i in range(0,len(line)-1):
if line[i]==line[i+1]:
s[i+1]+=1
s[i+1]+=s[i]
m=int(input())
for _ in range(m):
l,r=map(int,input().split())
l-=1;r-=1
print(s[r]-s[l]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
line=input()
s=[0]*(len(line)+1)
for i in range(0,len(line)-1):
if line[i]==line[i+1]:
s[i+1]+=1
s[i+1]+=s[i]
m=int(input())
for _ in range(m):
l,r=map(int,input().split())
l-=1;r-=1
print(s[r]-s[l])
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,668,549,225 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 6,553,600 | n = int(input())
x = list(map(int, input().split()))
min_max = []
for i in x:
cost = []
for j in x:
if i == j:
continue
cost.append(int(((i-j)**2)**0.5))
min_max.append([min(cost),max(cost)])
for i in min_max:
print(*i) | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
x = list(map(int, input().split()))
min_max = []
for i in x:
cost = []
for j in x:
if i == j:
continue
cost.append(int(((i-j)**2)**0.5))
min_max.append([min(cost),max(cost)])
for i in min_max:
print(*i)
``` | 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,636,634,162 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 4,505,600 | n1 = int(input(''))
list =[0]
exist = 0
for i in range(0,n1):
if exist > 0:
list.insert(len(list),exist)
s = str(input(''))
l = s.split(' ')
enter = int(l[1])
exit = int(l[0])
exist = exist + enter - exit
m1 = max(list)
print(m1) | 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
n1 = int(input(''))
list =[0]
exist = 0
for i in range(0,n1):
if exist > 0:
list.insert(len(list),exist)
s = str(input(''))
l = s.split(' ')
enter = int(l[1])
exit = int(l[0])
exist = exist + enter - exit
m1 = max(list)
print(m1)
``` | -1 |
508 | B | Anton and currency you all know | PROGRAMMING | 1,300 | [
"greedy",
"math",
"strings"
] | null | null | Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.
Reliable sources have informed the financier Anton of some information about the exchange rate of... | The first line contains an odd positive integer *n* — the exchange rate of currency you all know for today. The length of number *n*'s representation is within range from 2 to 105, inclusive. The representation of *n* doesn't contain any leading zeroes. | If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print <=-<=1.
Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained fro... | [
"527\n",
"4573\n",
"1357997531\n"
] | [
"572\n",
"3574\n",
"-1\n"
] | none | 1,000 | [
{
"input": "527",
"output": "572"
},
{
"input": "4573",
"output": "3574"
},
{
"input": "1357997531",
"output": "-1"
},
{
"input": "444443",
"output": "444434"
},
{
"input": "22227",
"output": "72222"
},
{
"input": "24683",
"output": "34682"
},
... | 1,675,836,754 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 77 | 6,553,600 | def get(f): return f(input().strip())
def gets(f): return [*map(f, input().split())]
s = [*get(str)]
n = len(s)
z = int(s[-1])
m = -1
for i in range(n):
y = int(s[i])
if not y & 1:
m = i
if y < z:
s[i], s[-1] = s[-1], s[i]
print(''.join(s))
break
else:
i... | Title: Anton and currency you all know
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed... | ```python
def get(f): return f(input().strip())
def gets(f): return [*map(f, input().split())]
s = [*get(str)]
n = len(s)
z = int(s[-1])
m = -1
for i in range(n):
y = int(s[i])
if not y & 1:
m = i
if y < z:
s[i], s[-1] = s[-1], s[i]
print(''.join(s))
break
e... | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,658,737,183 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 109 | 0 | from collections import defaultdict
n,m=map(int,input().split())
an=n
pog=n
while pog>=m:
an+=pog//m
pog=pog//m+pog%m
print(an) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
from collections import defaultdict
n,m=map(int,input().split())
an=n
pog=n
while pog>=m:
an+=pog//m
pog=pog//m+pog%m
print(an)
``` | 3 | |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,621,308,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 93 | 512,000 | import re
n=input()
cn,s=0,[]
if '_' not in n:
s=(re.findall('[A-Z][^A-Z]*', n))
else:
s=n.split('_')
c=s.count("Danil");c1=s.count("Slava");c2=s.count("Ann");c3=s.count("Nikita");c4=s.count('Olya')
if (c+c1+c2+c3+c4==1):print('YES')
else:print('NO')
| Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
import re
n=input()
cn,s=0,[]
if '_' not in n:
s=(re.findall('[A-Z][^A-Z]*', n))
else:
s=n.split('_')
c=s.count("Danil");c1=s.count("Slava");c2=s.count("Ann");c3=s.count("Nikita");c4=s.count('Olya')
if (c+c1+c2+c3+c4==1):print('YES')
else:print('NO')
``` | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,689,515,886 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 124 | 0 | n = input()
a = list(map(int ,input().split()))
b = []
maximum = 0
summa = sum(a)
minimum = 0
for i in range(len(a)):
num = round(a[i] * 100 / summa)
if 50 < num:
minimum = 1
break
elif num >= maximum:
b.append(num)
maximum = num
else:
for j i... | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
n = input()
a = list(map(int ,input().split()))
b = []
maximum = 0
summa = sum(a)
minimum = 0
for i in range(len(a)):
num = round(a[i] * 100 / summa)
if 50 < num:
minimum = 1
break
elif num >= maximum:
b.append(num)
maximum = num
else:
... | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,671,907,772 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 186 | 0 | s=list(input())
x=len(s)
for i in reversed(range(x)):
if s[i].isalpha()==False:
s.remove(s[i])
if s[len(s)-1].lower() in "aeiouy":
print("YES")
else:
print("NO") | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s=list(input())
x=len(s)
for i in reversed(range(x)):
if s[i].isalpha()==False:
s.remove(s[i])
if s[len(s)-1].lower() in "aeiouy":
print("YES")
else:
print("NO")
``` | 3.9535 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,588,995,219 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 6,963,200 | while True:
try:
def soln(n, k, a):
s = i = 0
j = k
a.sort()
while i < n and j > 0:
if a[i] < 0:
s += abs(a[i])
else:
break
j -= 1
i += 1
print(s)
def read():
n, k = map(int, input().split())
a = list(map(int, input().split()))
soln(n, ... | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
while True:
try:
def soln(n, k, a):
s = i = 0
j = k
a.sort()
while i < n and j > 0:
if a[i] < 0:
s += abs(a[i])
else:
break
j -= 1
i += 1
print(s)
def read():
n, k = map(int, input().split())
a = list(map(int, input().split()))
... | 3.93253 |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ... | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,657,076,742 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | for _ in [0]*int(input()):
input();r=[*map(int,input().split())]
print(r.index(min(r))+1,r.index(max(r))+1) | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
for _ in [0]*int(input()):
input();r=[*map(int,input().split())]
print(r.index(min(r))+1,r.index(max(r))+1)
``` | -1 | |
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат и... | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=.... | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы доб... | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},... | 1,520,085,769 | 80,869 | Python 3 | OK | TESTS | 52 | 62 | 5,632,000 | n, k = map(int, input().split())
list = input().split()
g = 0
i = 0
q = 1
vel = 0
list.append(int(list[len(list)-1])+k+1)
#print(list)
flag1 = True
while flag1 == True:
flag = True
if int(list[i+q]) - int(list[i]) <=k:
while flag == True:
if int(list[i+q]) - int(list[i]) <=k... | Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
n, k = map(int, input().split())
list = input().split()
g = 0
i = 0
q = 1
vel = 0
list.append(int(list[len(list)-1])+k+1)
#print(list)
flag1 = True
while flag1 == True:
flag = True
if int(list[i+q]) - int(list[i]) <=k:
while flag == True:
if int(list[i+q]) - int(li... | 3 | |
928 | A | Login Verification | PROGRAMMING | 1,200 | [
"*special",
"strings"
] | null | null | When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds ... | The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of existing logins.
The next *n* lines describe the exi... | Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes). | [
"1_wat\n2\n2_wat\nwat_1\n",
"000\n3\n00\nooA\noOo\n",
"_i_\n3\n__i_\n_1_\nI\n",
"La0\n3\n2a0\nLa1\n1a0\n",
"abc\n1\naBc\n",
"0Lil\n2\nLIL0\n0Ril\n"
] | [
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n"
] | In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one. | 500 | [
{
"input": "1_wat\n2\n2_wat\nwat_1",
"output": "Yes"
},
{
"input": "000\n3\n00\nooA\noOo",
"output": "No"
},
{
"input": "_i_\n3\n__i_\n_1_\nI",
"output": "No"
},
{
"input": "La0\n3\n2a0\nLa1\n1a0",
"output": "No"
},
{
"input": "abc\n1\naBc",
"output": "No"
}... | 1,527,946,694 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 7,065,600 | x = input()
n = int(input())
a = []
fin = True
count = -1
for i in range(n):
a.append(input())
for i in x:
count += 1
for j in range(len(a)):
if len(x)==len(a[j]):
if ord(a[j][count]) == ord(i) + 32 or ord(a[j][count]) + 32 == ord(i):
fin = False
... | Title: Login Verification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercas... | ```python
x = input()
n = int(input())
a = []
fin = True
count = -1
for i in range(n):
a.append(input())
for i in x:
count += 1
for j in range(len(a)):
if len(x)==len(a[j]):
if ord(a[j][count]) == ord(i) + 32 or ord(a[j][count]) + 32 == ord(i):
fin = False
... | 0 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,698,128,092 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
print(k+(2*l)+m+n) | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
print(k+(2*l)+m+n)
``` | 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,674,476,609 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s=str(input())
n=len(s)
countl=0
countu=0
for i in range(0,n):
if s[i].isupper():
countu+=1
else:
countl+=1
if countu>countl:
s=s.upper()
else:
s=s.lower()
print(s)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=str(input())
n=len(s)
countl=0
countu=0
for i in range(0,n):
if s[i].isupper():
countu+=1
else:
countl+=1
if countu>countl:
s=s.upper()
else:
s=s.lower()
print(s)
``` | 3.977 |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,606,503,058 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 310 | 0 | s=input().lower().strip("?")
print("YES" if s[-1] in "aeioyu" else "NO") | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s=input().lower().strip("?")
print("YES" if s[-1] in "aeioyu" else "NO")
``` | 0 |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,621,822,607 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 592 | 69,017,600 | n=int(input())
a=list(map(int,input().split()))
m=0
for i in range(n):
if a[i]%2==1:m+=1
if int(m)> n//2:print('First')
else:print('Second') | Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
n=int(input())
a=list(map(int,input().split()))
m=0
for i in range(n):
if a[i]%2==1:m+=1
if int(m)> n//2:print('First')
else:print('Second')
``` | 0 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,592,217,353 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | n=int(input())
m=int(input())
l=[]
for i in range(n):
p=int(input())
l.append(p)
l.sort()
c=0
for i in range(m):
c=c+ abs(l[i])
print(c)
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n=int(input())
m=int(input())
l=[]
for i in range(n):
p=int(input())
l.append(p)
l.sort()
c=0
for i in range(m):
c=c+ abs(l[i])
print(c)
``` | -1 |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,597,763,429 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 31 | 280 | 2,560,000 | s, s1 = input(), input()
if len(s) != len(s1):
print("NO")
else:
cnt = 0
for i in range(len(s)):
if s[i] != s1[i]:
cnt += 1
if(cnt == 2):
print("YES")
else:
print("NO")
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
s, s1 = input(), input()
if len(s) != len(s1):
print("NO")
else:
cnt = 0
for i in range(len(s)):
if s[i] != s1[i]:
cnt += 1
if(cnt == 2):
print("YES")
else:
print("NO")
``` | 0 | |
769 | B | News About Credit | PROGRAMMING | 1,200 | [
"*special",
"greedy",
"two pointers"
] | null | null | Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send p... | The first line contains the positive integer *n* (2<=≤<=*n*<=≤<=100) — the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has th... | Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to t... | [
"4\n1 2 1 0\n",
"6\n2 0 1 3 2 0\n",
"3\n0 2 2\n"
] | [
"3\n1 2\n2 4\n2 3\n",
"6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n",
"-1\n"
] | In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit. | 1,000 | [
{
"input": "4\n1 2 1 0",
"output": "3\n1 2\n2 3\n2 4"
},
{
"input": "6\n2 0 1 3 2 0",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6"
},
{
"input": "3\n0 2 2",
"output": "-1"
},
{
"input": "2\n0 0",
"output": "-1"
},
{
"input": "2\n1 0",
"output": "1\n1 2"
},
{
... | 1,623,726,274 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
b = [0] * len(a)
if a[0] == -1:
print(-1)
else:
ans = []
b[0] = 1
r = 1
for i in range(len(a)):
left = a[i]
while left > 0 and r < len(a):
if b[r] > 0:
r += 1
else:
... | Title: News About Credit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student... | ```python
n = int(input())
a = list(map(int, input().split()))
b = [0] * len(a)
if a[0] == -1:
print(-1)
else:
ans = []
b[0] = 1
r = 1
for i in range(len(a)):
left = a[i]
while left > 0 and r < len(a):
if b[r] > 0:
r += 1
el... | 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,567,636,400 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 124 | 0 | s = input()
cur_min = 10 ** 6
d = ['B', 'u', 'l', 'b', 'a', 's', 'r']
for element in d:
if s.count(element) < cur_min:
cur_min = s.count(element)
print(cur_min)
| 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
s = input()
cur_min = 10 ** 6
d = ['B', 'u', 'l', 'b', 'a', 's', 'r']
for element in d:
if s.count(element) < cur_min:
cur_min = s.count(element)
print(cur_min)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots o... | The first line of the input consists of two integers, the number of robots *n* (2<=≤<=*n*<=≤<=100<=000) and the number of rap battles *m* ().
The next *m* lines describe the results of the rap battles in the order they took place. Each consists of two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=... | Print the minimum *k* such that the ordering of the robots by skill level is uniquely defined by the first *k* rap battles. If there exists more than one ordering that satisfies all *m* relations, output -1. | [
"4 5\n2 1\n1 3\n2 3\n4 2\n4 3\n",
"3 2\n1 2\n3 2\n"
] | [
"4\n",
"-1\n"
] | In the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.
In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles. | 0 | [
{
"input": "4 5\n2 1\n1 3\n2 3\n4 2\n4 3",
"output": "4"
},
{
"input": "3 2\n1 2\n3 2",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "5 10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5",
"outp... | 1,512,575,372 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 39,526,400 | from sys import *
f = lambda: map(int, stdin.readline().split())
n, m = f()
p = q = n
a, b = [0] * n, [0] * n
u = [[] for x in range(n)]
v = [[] for y in range(n)]
j = 0
while j < m:
x, y = f()
x -= 1
y -= 1
u[x].append(y)
v[y].append(x)
if a[x] == 0: p -= 1
if b[y] == 0: q -=... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. ... | ```python
from sys import *
f = lambda: map(int, stdin.readline().split())
n, m = f()
p = q = n
a, b = [0] * n, [0] * n
u = [[] for x in range(n)]
v = [[] for y in range(n)]
j = 0
while j < m:
x, y = f()
x -= 1
y -= 1
u[x].append(y)
v[y].append(x)
if a[x] == 0: p -= 1
if b[y] ... | 0 | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,560,351,985 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 358 | 0 | n=int(input())
a = list(map(int,input().split()))
l,m=a[1]*a[0],a[1]
for _ in range(n-1):
a = list(map(int,input().split()))
if a[1]<m:
m=a[1]
l+=a[0]*m
else:
l+=a[0]*m
print(l) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
n=int(input())
a = list(map(int,input().split()))
l,m=a[1]*a[0],a[1]
for _ in range(n-1):
a = list(map(int,input().split()))
if a[1]<m:
m=a[1]
l+=a[0]*m
else:
l+=a[0]*m
print(l)
``` | 3 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,688,377,348 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 | n=int(input())
if n>=0:
print(n)
else:
n=str(n)
m=int(n[:len(n)-1])
k=int(n[:len(n)-2]+n[-1])
if m>k:
print(m)
else:
print(k) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n=int(input())
if n>=0:
print(n)
else:
n=str(n)
m=int(n[:len(n)-1])
k=int(n[:len(n)-2]+n[-1])
if m>k:
print(m)
else:
print(k)
``` | 3 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,671,721,149 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
sch_m = 0
sch_n = 0
for i in range(n):
m, n = map(int, input().split())
if m > n:
sch_m += 1
elif m < n:
sch_n += 1
if sch_m > sch_n:
print("Mishka")
elif sch_n > sch_m:
print("Chris")
else:
print("Friendship is magic!^^")
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
sch_m = 0
sch_n = 0
for i in range(n):
m, n = map(int, input().split())
if m > n:
sch_m += 1
elif m < n:
sch_n += 1
if sch_m > sch_n:
print("Mishka")
elif sch_n > sch_m:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 | |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,666,794,212 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 122 | 0 | n = int(input())
arr = [int(k) for k in input().split()]
obj = {}
for i, el in enumerate(arr):
if el not in obj:
obj[el] = []
obj[el].append(i)
res = []
for k in obj:
if len(obj[k]) == 1:
res.append([el, 0])
else:
diff = obj[k][1] - obj[k][0]
cur_in =... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n = int(input())
arr = [int(k) for k in input().split()]
obj = {}
for i, el in enumerate(arr):
if el not in obj:
obj[el] = []
obj[el].append(i)
res = []
for k in obj:
if len(obj[k]) == 1:
res.append([el, 0])
else:
diff = obj[k][1] - obj[k][0]
... | 0 | |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,609,152,830 | 2,147,483,647 | PyPy 3 | OK | TESTS | 119 | 187 | 1,945,600 |
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
from heapq import heappop , heappush
from bisect import *
from collections imp... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
from heapq import heappop , heappush
from bisect import *
from colle... | 3 | |
475 | D | CGCDSSQ | PROGRAMMING | 2,000 | [
"brute force",
"data structures",
"math"
] | null | null | Given a sequence of integers *a*1,<=...,<=*a**n* and *q* queries *x*1,<=...,<=*x**q* on it. For each query *x**i* you have to count the number of pairs (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=*n* and *gcd*(*a**l*,<=*a**l*<=+<=1,<=...,<=*a**r*)<==<=*x**i*.
is a greatest common divisor of *v*1,<=*v*2,<=...,<=*v**n*... | The first line of the input contains integer *n*, (1<=≤<=*n*<=≤<=105), denoting the length of the sequence. The next line contains *n* space separated integers *a*1,<=...,<=*a**n*, (1<=≤<=*a**i*<=≤<=109).
The third line of the input contains integer *q*, (1<=≤<=*q*<=≤<=3<=×<=105), denoting the number of queries. Then ... | For each query print the result in a separate line. | [
"3\n2 6 3\n5\n1\n2\n3\n4\n6\n",
"7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000\n"
] | [
"1\n2\n2\n0\n1\n",
"14\n0\n2\n2\n2\n0\n2\n2\n1\n1\n"
] | none | 2,000 | [
{
"input": "3\n2 6 3\n5\n1\n2\n3\n4\n6",
"output": "1\n2\n2\n0\n1"
},
{
"input": "7\n10 20 3 15 1000 60 16\n10\n1\n2\n3\n4\n5\n6\n10\n20\n60\n1000",
"output": "14\n0\n2\n2\n2\n0\n2\n2\n1\n1"
},
{
"input": "10\n2 2 4 3 2 4 4 2 4 2\n104\n3\n3\n1\n4\n1\n1\n4\n1\n1\n3\n1\n1\n4\n1\n1\n1\n4\n3... | 1,413,454,748 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
const int N = 100010;
int n, m;
int arr[N];
int tree[4 * N];
map<int, ll> mp;
int gcd(int a, int b) {
while (b != 0) {
int c = a;
a = b;
b = c % b;
}
... | Title: CGCDSSQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given a sequence of integers *a*1,<=...,<=*a**n* and *q* queries *x*1,<=...,<=*x**q* on it. For each query *x**i* you have to count the number of pairs (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=*n* and *gcd*(*a**l*,<=*a**l*<=... | ```python
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
const int N = 100010;
int n, m;
int arr[N];
int tree[4 * N];
map<int, ll> mp;
int gcd(int a, int b) {
while (b != 0) {
int c = a;
a = b;
b = c %... | -1 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,698,206,358 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 716 | 13,824,000 | n, m = map(int,input().split())
a = list(map(int, input().split()))
ans = []
num = []
mx = 0
for i in range(n):
ans.append(0)
mx = max(mx, a[i])
ans.append(0)
for i in range(mx + 2):
num.append(False)
for j in range(n):
if num[a[n - 1 - j]]:
ans[n - 1 - j] = ans[n - j]
cont... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
n, m = map(int,input().split())
a = list(map(int, input().split()))
ans = []
num = []
mx = 0
for i in range(n):
ans.append(0)
mx = max(mx, a[i])
ans.append(0)
for i in range(mx + 2):
num.append(False)
for j in range(n):
if num[a[n - 1 - j]]:
ans[n - 1 - j] = ans[n - j]
... | 3 | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,454,845,549 | 2,147,483,647 | Python 3 | OK | TESTS | 82 | 62 | 0 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
litr =0
cen = b-c
if n>=a or n>=b:
if cen < a and n>=c:
litr = (n-c)//(b-c)
n-=litr*(b-c)
litr += n//a
print(litr)
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
litr =0
cen = b-c
if n>=a or n>=b:
if cen < a and n>=c:
litr = (n-c)//(b-c)
n-=litr*(b-c)
litr += n//a
print(litr)
``` | 3 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,660,460,540 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n=int(input())
h=input()
t=input()
c=0
l=['0','1','2','3','4','5','6','7','8','9']
for i in range(n):
c+=min(abs(l.index(h[i])-l.index(t[i])),10-abs(l.index(h[i])-l.index(t[i])))
print(c) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n=int(input())
h=input()
t=input()
c=0
l=['0','1','2','3','4','5','6','7','8','9']
for i in range(n):
c+=min(abs(l.index(h[i])-l.index(t[i])),10-abs(l.index(h[i])-l.index(t[i])))
print(c)
``` | 0 | |
591 | B | Rebranding | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slog... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=200<=000) — the length of the initial name and the number of designers hired, respectively.
The second line consists of *n* lowercase English letters and represents the original name of the corporation.
Next *m* lines contain the descr... | Print the new name of the corporation. | [
"6 1\npolice\np m\n",
"11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n"
] | [
"molice\n",
"cdcbcdcfcdc\n"
] | In the second sample the name of the corporation consecutively changes as follows:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c7648432f7138ca53234357d7e08d1d119166055.png" style="max-width: 100.0%;max-height: 100.0%;"/>
<img align="middle" class="tex-formula" src="https://espresso.co... | 1,000 | [
{
"input": "6 1\npolice\np m",
"output": "molice"
},
{
"input": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b",
"output": "cdcbcdcfcdc"
},
{
"input": "1 1\nf\nz h",
"output": "f"
},
{
"input": "1 1\na\na b",
"output": "b"
},
{
"input": "10 10\nlellelleel\ne l\n... | 1,504,616,325 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 0 | def rebranding():
n_m = input().split()
n = int(n_m[0])
m = int(n_m[1])
brand_name = input()
for _ in range(0, m):
x_y = input().split()
x = x_y[0]
y = x_y[1]
for i, letter in enumerate(brand_name):
if letter == x:
brand_name = brand_name[:i] + y + brand_name[i+1:]
if letter == y:... | Title: Rebranding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The name of one small but proud corporation consists of *n* lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand ... | ```python
def rebranding():
n_m = input().split()
n = int(n_m[0])
m = int(n_m[1])
brand_name = input()
for _ in range(0, m):
x_y = input().split()
x = x_y[0]
y = x_y[1]
for i, letter in enumerate(brand_name):
if letter == x:
brand_name = brand_name[:i] + y + brand_name[i+1:]
if le... | 0 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,512,689,931 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | import numpy as np
n=int(input())
j=0
lis=[]
for x in range (n+1):
k=0
s=str(x)
for i in range (len(s)):
k=k+int(s[i])
if n==x+k:
j=j+1;
lis.append(x)
l=sorted(lis)
print(j)
for x in lis:
print(x)
| Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
import numpy as np
n=int(input())
j=0
lis=[]
for x in range (n+1):
k=0
s=str(x)
for i in range (len(s)):
k=k+int(s[i])
if n==x+k:
j=j+1;
lis.append(x)
l=sorted(lis)
print(j)
for x in lis:
print(x)
``` | -1 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,674,323,168 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n, m = list(map(int, input().strip().split()))
s = 0
x = 1
c = n % 10
if c != m:
s += 1
c * x
x += 1
if c == m:
print(s)
if c == m:
print("1")
if c == 0:
s += 1
print(s) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
n, m = list(map(int, input().strip().split()))
s = 0
x = 1
c = n % 10
if c != m:
s += 1
c * x
x += 1
if c == m:
print(s)
if c == m:
print("1")
if c == 0:
s += 1
print(s)
``` | 0 | |
878 | A | Short Program | PROGRAMMING | 1,600 | [
"bitmasks",
"constructive algorithms"
] | null | null | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023. | Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input. | [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n"
] | [
"2\n| 3\n^ 2\n",
"1\n& 1\n",
"0\n"
] | You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the ... | 500 | [
{
"input": "3\n| 3\n^ 2\n| 1",
"output": "2\n| 3\n^ 2"
},
{
"input": "3\n& 1\n& 3\n& 5",
"output": "1\n& 1"
},
{
"input": "3\n^ 1\n^ 2\n^ 3",
"output": "0"
},
{
"input": "2\n| 999\n^ 689",
"output": "2\n| 999\n^ 689"
},
{
"input": "3\n& 242\n^ 506\n^ 522",
"ou... | 1,670,493,863 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | import sys
input = sys.stdin.readline
n = int(input())
d = [[] for _ in range(3)]
a = {'|':0, '&':1, '^':2}
for i in range(n):
s = input()[:-1].split()
d[a[s[0]]].append(int(s[1]))
ew = []
for i in range(3):
if len(d[i]) != 0:
c = d[i][0]
for j in range(1, len(d[i])):
... | Title: Short Program
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitw... | ```python
import sys
input = sys.stdin.readline
n = int(input())
d = [[] for _ in range(3)]
a = {'|':0, '&':1, '^':2}
for i in range(n):
s = input()[:-1].split()
d[a[s[0]]].append(int(s[1]))
ew = []
for i in range(3):
if len(d[i]) != 0:
c = d[i][0]
for j in range(1, len(d[i])):... | 0 | |
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,673,253,415 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | x1,y1,x2,y2=map(int, input().split())
if (x1==y1 and x2==y2):#0011 or 0011
print(x1,x2,y2,y1)
elif((x1==y1==x2 and x1!= y2)): #0001
print(y2,y2,y2,x1)
elif((y2==y1==x2 and x1!= y2)): #1000
print(x1,x1,x1,y2)
elif((x1==y1==y2 and x2!= y2)): #0010
print(x2,x2,x2,y1)
elif((x1==y2==x2 and y1!= y2))... | 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
x1,y1,x2,y2=map(int, input().split())
if (x1==y1 and x2==y2):#0011 or 0011
print(x1,x2,y2,y1)
elif((x1==y1==x2 and x1!= y2)): #0001
print(y2,y2,y2,x1)
elif((y2==y1==x2 and x1!= y2)): #1000
print(x1,x1,x1,y2)
elif((x1==y1==y2 and x2!= y2)): #0010
print(x2,x2,x2,y1)
elif((x1==y2==x2 and... | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,667,290,124 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
loc = []
leng = []
for i in range(n):
trees = list(map(int, input().split()))
loc.append(trees[0])
leng.append(trees[1])
street = [0] * (loc[-1])
for ll in loc:
street[ll - 1] = 1
answer = 2
for ii in range(n - 1):
if ii != 0 and loc[ii] - leng[ii] >= 0:
... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
n = int(input())
loc = []
leng = []
for i in range(n):
trees = list(map(int, input().split()))
loc.append(trees[0])
leng.append(trees[1])
street = [0] * (loc[-1])
for ll in loc:
street[ll - 1] = 1
answer = 2
for ii in range(n - 1):
if ii != 0 and loc[ii] - leng[ii] >=... | 0 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,655,494,489 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 154 | 409,600 | from queue import Queue as Q
n = int(input())
v = [[] for i in range(n)]
r = []
for i in range(n):
t = int(input())
if t != -1:
v[t-1].append(i)
else:
r.append(i)
q = Q()
for i in r:
q.put((i, 1))
ans = 1
while not q.empty():
new = q.get()
ans = max(ans, new[1])
for i in v[ne... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
from queue import Queue as Q
n = int(input())
v = [[] for i in range(n)]
r = []
for i in range(n):
t = int(input())
if t != -1:
v[t-1].append(i)
else:
r.append(i)
q = Q()
for i in r:
q.put((i, 1))
ans = 1
while not q.empty():
new = q.get()
ans = max(ans, new[1])
for... | 3 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,595,591,757 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,860,800 | def split(word):
return list(word)
def nCr(n, r):
return (fact(n) / (fact(r)
* fact(n - r)))
def fact(n):
res = 1
for i in range(2, n+1):
res = res * i
return res
n=int(input())
r=dict()
c=0
a=[]
for i in range(n):
a.ap... | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
def split(word):
return list(word)
def nCr(n, r):
return (fact(n) / (fact(r)
* fact(n - r)))
def fact(n):
res = 1
for i in range(2, n+1):
res = res * i
return res
n=int(input())
r=dict()
c=0
a=[]
for i in range(n):... | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,620,389,670 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | a , b = map(int,input().split())
print(a*b//2)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a , b = map(int,input().split())
print(a*b//2)
``` | 3.956411 |
7 | B | Memory Manager | PROGRAMMING | 1,600 | [
"implementation"
] | B. Memory Manager | 1 | 64 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | The first line of the input data contains two positive integers *t* and *m* (1<=≤<=*t*<=≤<=100;1<=≤<=*m*<=≤<=100), where *t* — the amount of operations given to the memory manager for processing, and *m* — the available memory size in bytes. Then there follow *t* lines where the operations themselves are given. The fir... | Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return inte... | [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
] | [
"1\n2\nNULL\n3\n"
] | none | 0 | [
{
"input": "6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6",
"output": "1\n2\nNULL\n3"
},
{
"input": "6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1",
"output": "NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT"
},
{
"input": "14 100\nalloc 99\nalloc... | 1,628,412,553 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 186 | 20,172,800 | t, m = map(int, input().split())
Memory = []
AllocNum = 0
for _ in range(t):
operation = input()
if operation[0] == 'a':
operate, n = operation.split()
n = int(n)
if Memory == []:
if m >= n:
AllocNum += 1
Memory.append([0, n, All... | Title: Memory Manager
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first relea... | ```python
t, m = map(int, input().split())
Memory = []
AllocNum = 0
for _ in range(t):
operation = input()
if operation[0] == 'a':
operate, n = operation.split()
n = int(n)
if Memory == []:
if m >= n:
AllocNum += 1
Memory.append(... | 0 |
246 | C | Beauty Pageant | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"greedy"
] | null | null | General Payne has a battalion of *n* soldiers. The soldiers' beauty contest is coming up, it will last for *k* days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
All soldiers in the battalion have different beauty that is represented by a positive integer. The v... | The first line contains two integers *n*, *k* (1<=≤<=*n*<=≤<=50; 1<=≤<=*k*<=≤<= ) — the number of soldiers and the number of days in the pageant, correspondingly. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=107) — the beauties of the battalion soldiers.
It is guarante... | Print *k* lines: in the *i*-th line print the description of the detachment that will participate in the pageant on the *i*-th day. The description consists of integer *c**i* (1<=≤<=*c**i*<=≤<=*n*) — the number of soldiers in the detachment on the *i*-th day of the pageant and *c**i* distinct integers *p*1,<=*i*,<=*p*2... | [
"3 3\n1 2 3\n",
"2 1\n7 12\n"
] | [
"1 1\n1 2\n2 3 2\n",
"1 12 \n"
] | none | 1,500 | [
{
"input": "3 3\n1 2 3",
"output": "1 1\n1 2\n2 3 2"
},
{
"input": "2 1\n7 12",
"output": "1 12 "
},
{
"input": "1 1\n1000",
"output": "1 1000 "
},
{
"input": "5 8\n10 3 8 31 20",
"output": "1 31 \n1 20 \n1 10 \n1 8 \n1 3 \n2 31 20 \n2 31 10 \n2 31 8 "
},
{
"input... | 1,654,340,858 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 218 | 7,372,800 | n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
for i in range(n+1):
if k==0:
break
small=arr[:n-i]
big=arr[n-i:]
for s in small:
print(len(big)+1," ".join(str(x) for x in big),s)
k-=1
if k==0:
break | Title: Beauty Pageant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
General Payne has a battalion of *n* soldiers. The soldiers' beauty contest is coming up, it will last for *k* days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants.
... | ```python
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
for i in range(n+1):
if k==0:
break
small=arr[:n-i]
big=arr[n-i:]
for s in small:
print(len(big)+1," ".join(str(x) for x in big),s)
k-=1
if k==0:
break
``` | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,607,530,264 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 312 | 0 | def f(s):
res = []
sp = s.split(":")
if not sp[0]:
sp[0] = "0"
if not sp[-1]:
sp[-1] = "0"
for b in sp:
if b:
res.append("{:0>4}".format(b))
if not b:
res.extend(("0000" for i in range(8 - len(sp) + 1)))
return(":".join(res))
... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
def f(s):
res = []
sp = s.split(":")
if not sp[0]:
sp[0] = "0"
if not sp[-1]:
sp[-1] = "0"
for b in sp:
if b:
res.append("{:0>4}".format(b))
if not b:
res.extend(("0000" for i in range(8 - len(sp) + 1)))
return(":".joi... | 3 | |
652 | B | z-sort | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=><=1.
For example the arrays [1,2,1,2] and [1,1,1,1] are *z*-sorted while the array [1,2... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array *a*.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | If it's possible to make the array *a* *z*-sorted print *n* space separated integers *a**i* — the elements after *z*-sort. Otherwise print the only word "Impossible". | [
"4\n1 2 2 1\n",
"5\n1 3 2 2 5\n"
] | [
"1 2 1 2\n",
"1 5 2 3 2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 1",
"output": "1 2 1 2"
},
{
"input": "5\n1 3 2 2 5",
"output": "1 5 2 3 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1 ... | 1,459,944,388 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 62 | 5,120,000 | n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = [0] * n
j = 0
for i in range(n//2):
b[j] = a[i]
b[j+1] = a[-1-i]
j += 2
if n%2:
b[j] = a[n//2]
for x in b:
print(x, end=' ')
print()
| Title: z-sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A student of *z*-school found a kind of sorting called *z*-sort. The array *a* with *n* elements are *z*-sorted if two conditions hold:
1. *a**i*<=≥<=*a**i*<=-<=1 for all even *i*, 1. *a**i*<=≤<=*a**i*<=-<=1 for all odd *i*<=... | ```python
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
b = [0] * n
j = 0
for i in range(n//2):
b[j] = a[i]
b[j+1] = a[-1-i]
j += 2
if n%2:
b[j] = a[n//2]
for x in b:
print(x, end=' ')
print()
``` | 3 | |
190 | B | Surrounded | PROGRAMMING | 1,800 | [
"geometry"
] | null | null | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround... | The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=≤<=104; 1<=≤<=*r**i*<=≤<=104) — the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is gua... | Print a single real number — the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6. | [
"0 0 1\n6 0 3\n",
"-10 10 3\n10 -10 3\n"
] | [
"1.000000000000000",
"11.142135623730951"
] | The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2, 0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0, 0). | 1,000 | [
{
"input": "0 0 1\n6 0 3",
"output": "1.000000000000000"
},
{
"input": "-10 10 3\n10 -10 3",
"output": "11.142135623730951"
},
{
"input": "2 1 3\n8 9 5",
"output": "1.000000000000000"
},
{
"input": "0 0 1\n-10 -10 9",
"output": "2.071067811865475"
},
{
"input": "1... | 1,608,116,312 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 140 | 0 | import math
x1,y1,r1=map(int,input().split())
x2,y2,r2=map(int,input().split())
a=[]
m=(y2-y1)/(x2-x1)
c=x1+(r1/math.sqrt(m**2+1))
d=y1+((r1*m)/math.sqrt(m**2+1))
a.append([c,d])
c=x1-(r1/math.sqrt(m**2+1))
d=y1-((r1*m)/math.sqrt(m**2+1))
a.append([c,d])
b=[]
c=x2+(r2/math.sqrt(m**2+1))
d=y2+((r2*m)/math.s... | Title: Surrounded
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal — their both cities are surrounded! The... | ```python
import math
x1,y1,r1=map(int,input().split())
x2,y2,r2=map(int,input().split())
a=[]
m=(y2-y1)/(x2-x1)
c=x1+(r1/math.sqrt(m**2+1))
d=y1+((r1*m)/math.sqrt(m**2+1))
a.append([c,d])
c=x1-(r1/math.sqrt(m**2+1))
d=y1-((r1*m)/math.sqrt(m**2+1))
a.append([c,d])
b=[]
c=x2+(r2/math.sqrt(m**2+1))
d=y2+((r2... | 0 | |
65 | A | Harry Potter and Three Spells | PROGRAMMING | 1,800 | [
"implementation",
"math"
] | A. Harry Potter and Three Spells | 2 | 256 | A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams o... | The first line contains 6 integers *a*, *b*, *c*, *d*, *e*, *f* (0<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*,<=*f*<=≤<=1000). | Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione". | [
"100 200 250 150 200 250\n",
"100 50 50 200 200 100\n",
"100 10 200 20 300 30\n",
"0 0 0 0 0 0\n",
"1 1 0 1 1 1\n",
"1 0 1 2 1 2\n",
"100 1 100 1 0 1\n"
] | [
"Ron\n",
"Hermione\n",
"Hermione\n",
"Hermione\n",
"Ron\n",
"Hermione\n",
"Ron\n"
] | Consider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 gram... | 500 | [
{
"input": "100 200 250 150 200 250",
"output": "Ron"
},
{
"input": "100 50 50 200 200 100",
"output": "Hermione"
},
{
"input": "100 10 200 20 300 30",
"output": "Hermione"
},
{
"input": "0 0 0 0 0 0",
"output": "Hermione"
},
{
"input": "1 1 0 1 1 1",
"output"... | 1,614,271,114 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 154 | 0 | a, b, c, d, e, f = [int(i) for i in input().split()]
if b == 0 or d == 0 or f == 0:
print('Hermione')
elif a == 0 or c == 0 or e == 0:
print('Ron')
else:
fa = (f * b * d) / (c * e)
print('Ron' if a < fa else 'Hermione')
| Title: Harry Potter and Three Spells
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a... | ```python
a, b, c, d, e, f = [int(i) for i in input().split()]
if b == 0 or d == 0 or f == 0:
print('Hermione')
elif a == 0 or c == 0 or e == 0:
print('Ron')
else:
fa = (f * b * d) / (c * e)
print('Ron' if a < fa else 'Hermione')
``` | 0 |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,691,426,846 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 62 | 0 | # ██████╗
# ███ ███═█████╗
# ████████╗ ██████╗ ████████╗ ████ █████ ████╗
# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║
# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝
# ██╔═══╝ ██║ ██... | 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
# ██████╗
# ███ ███═█████╗
# ████████╗ ██████╗ ████████╗ ████ █████ ████╗
# ██╔═════╝ ██╔═══██╗ ██╔═════╝ ████ █ ███║
# ██████╗ ██║ ╚═╝ ██████╗ ████ ████╔╝
# ██╔═══╝ ... | 3 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,565,367,621 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n=int(input())
a,b=0,0
while(n>0):
d=n%10
b+=1
if(d==4 or d==7):
a+=1
n//=10
if(a==4 or a==7 or a==b):
print("YES")
else:
print("NO") | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
n=int(input())
a,b=0,0
while(n>0):
d=n%10
b+=1
if(d==4 or d==7):
a+=1
n//=10
if(a==4 or a==7 or a==b):
print("YES")
else:
print("NO")
``` | 0 |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,698,252,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
solo = a.count(1)
equipoDos = a.count(2)
equipos = min(solo, equipoDos)
solo -= equipos
equipoDos -= equipos
equipos += equipoDos // 3
equipoDos %= 3
if equipoDos == 1 and solo >= 2:
equipos += 1
solo -= 2
if equipoDos == 2 and solo >= 1:
equipos += ... | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
a = list(map(int, input().split()))
solo = a.count(1)
equipoDos = a.count(2)
equipos = min(solo, equipoDos)
solo -= equipos
equipoDos -= equipos
equipos += equipoDos // 3
equipoDos %= 3
if equipoDos == 1 and solo >= 2:
equipos += 1
solo -= 2
if equipoDos == 2 and solo >= 1:
e... | 0 | |
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Nold... | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 ... | 1,680,343,638 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | def is_prime(num):
sq = int(math.sqrt(num))
for j in range(2, sq + 1):
if num % j == 0:
return False
return True
n, p = map(int,input().split())
lst = []
dic = {}
cnt = 0
for i in range(2, n + 1):
if is_prime(i):
lst += [i]
dic[i] = 1
for k in range(0, l... | Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a prob... | ```python
def is_prime(num):
sq = int(math.sqrt(num))
for j in range(2, sq + 1):
if num % j == 0:
return False
return True
n, p = map(int,input().split())
lst = []
dic = {}
cnt = 0
for i in range(2, n + 1):
if is_prime(i):
lst += [i]
dic[i] = 1
for k in ... | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.