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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
48 | A | Rock-paper-scissors | PROGRAMMING | 900 | [
"implementation",
"schedules"
] | A. Rock-paper-scissors | 2 | 256 | Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obvio... | The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. | Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". | [
"rock\nrock\nrock\n",
"paper\nrock\nrock\n",
"scissors\nrock\nrock\n",
"scissors\npaper\nrock\n"
] | [
"?\n",
"F\n",
"?\n",
"?\n"
] | none | 0 | [
{
"input": "rock\nrock\nrock",
"output": "?"
},
{
"input": "paper\nrock\nrock",
"output": "F"
},
{
"input": "scissors\nrock\nrock",
"output": "?"
},
{
"input": "scissors\npaper\nrock",
"output": "?"
},
{
"input": "paper\npaper\nrock",
"output": "?"
},
{
... | 1,551,119,283 | 2,147,483,647 | PyPy 3 | OK | TESTS | 27 | 278 | 0 | F=str(input())
M=str(input())
S=str(input())
if ((F=='scissors' and M==S=='paper') or (F=='paper' and M==S=='rock') or (F=='rock' and M==S=='scissors')):
print('F')
elif ((S=='scissors' and M==F=='paper') or (S=='paper' and M==F=='rock') or (S=='rock' and M==F=='scissors')):
print('S')
elif ((M == 'sciss... | Title: Rock-paper-scissors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case ... | ```python
F=str(input())
M=str(input())
S=str(input())
if ((F=='scissors' and M==S=='paper') or (F=='paper' and M==S=='rock') or (F=='rock' and M==S=='scissors')):
print('F')
elif ((S=='scissors' and M==F=='paper') or (S=='paper' and M==F=='rock') or (S=='rock' and M==F=='scissors')):
print('S')
elif ((M... | 3.9305 |
14 | A | Letter | PROGRAMMING | 800 | [
"implementation"
] | A. Letter | 1 | 64 | A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w... | The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ... | Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. | [
"6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n",
"3 3\n***\n*.*\n***\n"
] | [
"***\n*..\n***\n*..\n***\n",
"***\n*.*\n***\n"
] | none | 0 | [
{
"input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..",
"output": "***\n*..\n***\n*..\n***"
},
{
"input": "3 3\n***\n*.*\n***",
"output": "***\n*.*\n***"
},
{
"input": "1 1\n*",
"output": "*"
},
{
"input": "2 1\n*\n*",
"output": "*\n*"
},
{
"input"... | 1,677,146,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n, m = map(int, input().split())
grid = [input() for _ in range(n)]
# Initialize top-left and bottom-right corners to the entire sheet
top_left = (m, n)
bottom_right = (0, 0)
# Scan each row to find first and last shaded square
for i in range(n):
if '*' in grid[i]:
left = grid[i].index('*')
... | Title: Letter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe... | ```python
n, m = map(int, input().split())
grid = [input() for _ in range(n)]
# Initialize top-left and bottom-right corners to the entire sheet
top_left = (m, n)
bottom_right = (0, 0)
# Scan each row to find first and last shaded square
for i in range(n):
if '*' in grid[i]:
left = grid[i].index... | 0 |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,594,577,761 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l,r = list(map(int,input().split()))
l += (l&1)
elif r-l>1 :
print (l,l+1,l+2)
else :
print(-1) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l,r = list(map(int,input().split()))
l += (l&1)
elif r-l>1 :
print (l,l+1,l+2)
else :
print(-1)
``` | -1 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,570,112,297 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 218 | 2,560,000 | s= input()
l= 'heidi'
c=0
i=0
for i in s:
if i==l[c]:
c+=1
if c==5:
print('YES')
else:
print('NO') | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s= input()
l= 'heidi'
c=0
i=0
for i in s:
if i==l[c]:
c+=1
if c==5:
print('YES')
else:
print('NO')
``` | -1 | |
600 | D | Area of Two Circles' Intersection | PROGRAMMING | 2,000 | [
"geometry"
] | null | null | You are given two circles. Find the area of their intersection. | The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) — the position of the center and the radius of the first circle.
The second line contains three integers *x*2,<=*y*2,<=*r*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109,<=1<=≤<=*r*2<=≤<=109) — the position of the cen... | Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"0 0 4\n6 0 4\n",
"0 0 5\n11 0 5\n"
] | [
"7.25298806364175601379\n",
"0.00000000000000000000\n"
] | none | 0 | [
{
"input": "0 0 4\n6 0 4",
"output": "7.25298806364175601379"
},
{
"input": "0 0 5\n11 0 5",
"output": "0.00000000000000000000"
},
{
"input": "0 0 10\n9 0 1",
"output": "3.14159265358979311600"
},
{
"input": "0 0 2\n2 2 2",
"output": "2.28318530717958647659"
},
{
... | 1,649,671,187 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 77 | 3,481,600 | import math
def main():
x1, y1, r1 = [int(i) for i in input().split()]
x2, y2, r2 = [int(i) for i in input().split()]
a, b = x2 - x1, y2 - y1
t = a ** 2 - r2 ** 2 + b ** 2 + r1 ** 2
s1, s2 = map(lambda x: math.pi * x ** 2, [r1, r2])
r = ((x1 - x2) ** 2 + (y1 - y2) ** 5) ** 0.5
... | Title: Area of Two Circles' Intersection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two circles. Find the area of their intersection.
Input Specification:
The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) —... | ```python
import math
def main():
x1, y1, r1 = [int(i) for i in input().split()]
x2, y2, r2 = [int(i) for i in input().split()]
a, b = x2 - x1, y2 - y1
t = a ** 2 - r2 ** 2 + b ** 2 + r1 ** 2
s1, s2 = map(lambda x: math.pi * x ** 2, [r1, r2])
r = ((x1 - x2) ** 2 + (y1 - y2) ** 5) **... | -1 | |
608 | B | Hamming Distance Sum | PROGRAMMING | 1,500 | [
"combinatorics",
"strings"
] | null | null | Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam... | The first line of the input contains binary string *a* (1<=≤<=|*a*|<=≤<=200<=000).
The second line of the input contains binary string *b* (|*a*|<=≤<=|*b*|<=≤<=200<=000).
Both strings are guaranteed to consist of characters '0' and '1' only. | Print a single integer — the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|. | [
"01\n00111\n",
"0011\n0110\n"
] | [
"3\n",
"2\n"
] | For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ... | 1,000 | [
{
"input": "01\n00111",
"output": "3"
},
{
"input": "0011\n0110",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "0\n1",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1... | 1,451,431,319 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 1,126,400 | a = input()
b = input()
ans = 0
numZeros = []
numOnes = []
for i in range(len(a)):
numZeros.append(b[i:len(b) - len(a) + 1 + i].count('0'))
numOnes.append(b[i:len(b) - len(a) + 1 + i].count('1'))
for i in range(len(a)):
if a[i] == '0':
ans += numOnes[i]
else:
ans += num... | Title: Hamming Distance Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Genos needs your help. He was asked to solve the following programming problem by Saitama:
The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de... | ```python
a = input()
b = input()
ans = 0
numZeros = []
numOnes = []
for i in range(len(a)):
numZeros.append(b[i:len(b) - len(a) + 1 + i].count('0'))
numOnes.append(b[i:len(b) - len(a) + 1 + i].count('1'))
for i in range(len(a)):
if a[i] == '0':
ans += numOnes[i]
else:
... | 0 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,695,839,839 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
list = list(map(int, input().split()))
maxiumum = max(list)
sum = 0
for i in list :
sum += maxiumum - i
print(sum)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = int(input())
list = list(map(int, input().split()))
maxiumum = max(list)
sum = 0
for i in list :
sum += maxiumum - i
print(sum)
``` | 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,606,763,679 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | t=int(input())
arr=[int(i) for i in input().split()]
z=[arr[0]]
arr=arr[1:]
t=(t-1)//2
even=[]
odd=[]
for i in range(t):
even+=[arr[2*i]]
odd+=[arr[2*i+1]]
even.sort()
odd.sort()
even=even[::-1]
for i in range(t):
z+=[even[i],odd[i]]
print(z) | 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
t=int(input())
arr=[int(i) for i in input().split()]
z=[arr[0]]
arr=arr[1:]
t=(t-1)//2
even=[]
odd=[]
for i in range(t):
even+=[arr[2*i]]
odd+=[arr[2*i+1]]
even.sort()
odd.sort()
even=even[::-1]
for i in range(t):
z+=[even[i],odd[i]]
print(z)
``` | 0 | |
15 | E | Triangles | PROGRAMMING | 2,600 | [
"combinatorics",
"dp"
] | E. Triangles | 1 | 64 | Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fear of the wolf, but by a strange, in his opinion, pattern of the forest that has *n* level... | The input data contain the only even integer *n* (2<=≤<=*n*<=≤<=106). | Output the only number — the amount of Peter's routes modulo 1000000009. | [
"2\n",
"4\n"
] | [
"10\n",
"74\n"
] | none | 0 | [
{
"input": "2",
"output": "10"
},
{
"input": "4",
"output": "74"
},
{
"input": "6",
"output": "1354"
},
{
"input": "8",
"output": "163594"
},
{
"input": "10",
"output": "122492554"
},
{
"input": "966",
"output": "154440215"
},
{
"input": "9... | 1,690,503,237 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1690503237.4375904")# 1690503237.4376109 | Title: Triangles
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Last summer Peter was at his granny's in the country, when a wolf attacked sheep in the nearby forest. Now he fears to walk through the forest, to walk round the forest, even to get out of the house. He explains this not by the fe... | ```python
print("_RANDOM_GUESS_1690503237.4375904")# 1690503237.4376109
``` | 0 |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,641,901,752 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 61 | 0 | n=int(input())
l=list(map(int,input().split()))
x=[]
for i in range(len(l)-1):
if l[i] < l[i+1]:
x.append(0)
elif l[i] > l[i+1]:
x.append(2)
elif l[i]==l[i+1]:
x.append(1)
y=sorted(x)
if 1<=n and n<=100:
if y == x:
print('YES')
else:
print('NO... | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
n=int(input())
l=list(map(int,input().split()))
x=[]
for i in range(len(l)-1):
if l[i] < l[i+1]:
x.append(0)
elif l[i] > l[i+1]:
x.append(2)
elif l[i]==l[i+1]:
x.append(1)
y=sorted(x)
if 1<=n and n<=100:
if y == x:
print('YES')
else:
... | 3 | |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,699,451,807 | 2,147,483,647 | PyPy 3 | OK | TESTS | 105 | 248 | 7,372,800 | from collections import Counter
n = int(input())
groups = list(map(int, input().split()))
group_counts = Counter(groups)
taxis_needed = group_counts[4] + group_counts[3]
group_counts[1] = max(group_counts[1]-group_counts[3],0)
taxis_needed += (2 * group_counts[2] + group_counts[1] + 3) // 4
print(taxis_needed) | Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu... | ```python
from collections import Counter
n = int(input())
groups = list(map(int, input().split()))
group_counts = Counter(groups)
taxis_needed = group_counts[4] + group_counts[3]
group_counts[1] = max(group_counts[1]-group_counts[3],0)
taxis_needed += (2 * group_counts[2] + group_counts[1] + 3) // 4
print(taxis... | 3 | |
321 | B | Ciel and Duel | PROGRAMMING | 1,900 | [
"dp",
"flows",
"greedy"
] | null | null | Fox Ciel is playing a card game with her friend Jiro.
Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.
Now is Ciel's battle phase, Ciel can do the follo... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of cards Jiro and Ciel have.
Each of the next *n* lines contains a string *position* and an integer *strength* (0<=≤<=*strength*<=≤<=8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack,... | Output an integer: the maximal damage Jiro can get. | [
"2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500\n",
"3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001\n",
"2 4\nDEF 0\nATK 0\n0\n0\n1\n1\n"
] | [
"3000\n",
"992\n",
"1\n"
] | In the first test case, Ciel has 3 cards with same *strength*. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damag... | 1,000 | [
{
"input": "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500",
"output": "3000"
},
{
"input": "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001",
"output": "992"
},
{
"input": "2 4\nDEF 0\nATK 0\n0\n0\n1\n1",
"output": "1"
},
{
"input": "1 1\nATK 100\n99",
"output": "0"
},
{... | 1,685,118,302 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 74 | 124 | 1,536,000 | import bisect
from sys import stdin, stdout
def inp():
return int(stdin.readline())
def inlt():
return list(map(int, stdin.readline().strip().split()))
def insr():
s = stdin.readline().strip()
return list(s[:len(s)])
def invr():
return map(int, stdin.readline().strip().spli... | Title: Ciel and Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a card game with her friend Jiro.
Jiro has *n* cards, each one has two attributes: *position* (Attack or Defense) and *strength*. Fox Ciel has *m* cards, each one has these two attributes too. It's kn... | ```python
import bisect
from sys import stdin, stdout
def inp():
return int(stdin.readline())
def inlt():
return list(map(int, stdin.readline().strip().split()))
def insr():
s = stdin.readline().strip()
return list(s[:len(s)])
def invr():
return map(int, stdin.readline().st... | 0 | |
917 | A | The Monster | PROGRAMMING | 1,800 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.
Thus, he came up with a puzzle to te... | The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000). | Print the answer to Will's puzzle in the first and only line of output. | [
"((?))\n",
"??()??\n"
] | [
"4\n",
"7\n"
] | For the first sample testcase, the pretty substrings of *s* are:
1. "(?" which can be transformed to "()". 1. "?)" which can be transformed to "()". 1. "((?)" which can be transformed to "(())". 1. "(?))" which can be transformed to "(())".
For the second sample testcase, the pretty substrings of *s* are:
1. "?... | 500 | [
{
"input": "((?))",
"output": "4"
},
{
"input": "??()??",
"output": "7"
},
{
"input": "?????)(???",
"output": "21"
},
{
"input": "()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((((()))))))))",
"output": "62"
},
{
"input": "))((()(()((((())... | 1,517,332,947 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 5,529,600 | s = input()
k = 0
def check(i, j, s):
if i < 0 or j > len(s) - 1:
return 0
elif (s[i] == '(' and s[j] == ')' or s[i] == '?' and s[j] == '?') and j - i + 1 != len(s):
print(s[i:j + 1])
return check(i - 1, j + 1, s) + 1
return 0
def check1(i, s):
if i - 2 < 0:
... | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster th... | ```python
s = input()
k = 0
def check(i, j, s):
if i < 0 or j > len(s) - 1:
return 0
elif (s[i] == '(' and s[j] == ')' or s[i] == '?' and s[j] == '?') and j - i + 1 != len(s):
print(s[i:j + 1])
return check(i - 1, j + 1, s) + 1
return 0
def check1(i, s):
if i - ... | 0 | |
31 | D | Chocolate | PROGRAMMING | 2,000 | [
"dfs and similar",
"implementation"
] | D. Chocolate | 2 | 256 | Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a se... | The first line contains 3 integers *W*, *H* and *n* (1<=≤<=*W*,<=*H*,<=*n*<=≤<=100) — width of the bar, height of the bar and amount of breaks. Each of the following *n* lines contains four integers *x**i*,<=1,<=*y**i*,<=1,<=*x**i*,<=2,<=*y**i*,<=2 — coordinates of the endpoints of the *i*-th break (0<=≤<=*x**i*,<=1<=≤... | Output *n*<=+<=1 numbers — areas of the resulting parts in the increasing order. | [
"2 2 2\n1 0 1 2\n0 1 1 1\n",
"2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1\n",
"2 4 2\n0 1 2 1\n0 3 2 3\n"
] | [
"1 1 2 ",
"1 1 1 1 ",
"2 2 4 "
] | none | 2,000 | [
{
"input": "2 2 2\n1 0 1 2\n0 1 1 1",
"output": "1 1 2 "
},
{
"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1",
"output": "1 1 1 1 "
},
{
"input": "2 4 2\n0 1 2 1\n0 3 2 3",
"output": "2 2 4 "
},
{
"input": "5 5 3\n2 1 2 5\n0 1 5 1\n4 0 4 1",
"output": "1 4 8 12 "
},
{
... | 1,641,346,616 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 8 | 154 | 2,560,000 | from bisect import bisect_right
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO(... | Title: Chocolate
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob has a rectangular chocolate bar of the size *W*<=×<=*H*. He introduced a cartesian coordinate system so that the point (0,<=0) corresponds to the lower-left corner of the bar, and the point (*W*,<=*H*) corresponds to the uppe... | ```python
from bisect import bisect_right
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer ... | 0 |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,580,724,609 | 2,147,483,647 | PyPy 3 | OK | TESTS | 128 | 156 | 0 | a,b=list(map(int,input().split()))
#a_dict={"0":0,"1":0,"2":0,"3":0,"4":0}
#b_dict={"0":0,"1":0,"2":0,"3":0,"4":0}
temp=a
#print(temp//5)
a_dict={"0":temp//5,"1":temp//5,"2":temp//5,"3":temp//5,"4":temp//5}
temp=temp%5
while temp:
a_dict[str(temp)]=a_dict[str(temp)]+1
temp-=1
temp=b
b... | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
a,b=list(map(int,input().split()))
#a_dict={"0":0,"1":0,"2":0,"3":0,"4":0}
#b_dict={"0":0,"1":0,"2":0,"3":0,"4":0}
temp=a
#print(temp//5)
a_dict={"0":temp//5,"1":temp//5,"2":temp//5,"3":temp//5,"4":temp//5}
temp=temp%5
while temp:
a_dict[str(temp)]=a_dict[str(temp)]+1
temp-=1
... | 3 | |
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,186 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
if k==1 and l==1 and m==1 and n==1:
print(d)
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())
if k==1 and l==1 and m==1 and n==1:
print(d)
print(k+(2*l)+m+n)
``` | 0 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,597,644,211 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 109 | 0 | import math
def gcd(a,b):
while(b):
a %= b
a,b = b,a
return a
a,b,c = map(int,input().split())
g = gcd(a,b)
if c%g == 0:
print('Yes')
else:
print('No')
| Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
import math
def gcd(a,b):
while(b):
a %= b
a,b = b,a
return a
a,b,c = map(int,input().split())
g = gcd(a,b)
if c%g == 0:
print('Yes')
else:
print('No')
``` | 0 | |
522 | D | Closest Equals | PROGRAMMING | 2,000 | [
"*special",
"data structures"
] | null | null | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (*x*<=≠<=*y*), that:
- both indexes of the elements lie within range [*l**j*,<=*r**j*], that is, *l... | The first line of the input contains a pair of integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=5·105) — the length of the sequence and the number of queries, correspondingly.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Next *m* lines contain the queries, one pe... | Print *m* integers — the answers to each query. If there is no valid match for some query, please print -1 as an answer to this query. | [
"5 3\n1 1 2 3 2\n1 5\n2 4\n3 5\n",
"6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6\n"
] | [
"1\n-1\n2\n",
"2\n2\n3\n-1\n2\n"
] | none | 2,000 | [
{
"input": "5 3\n1 1 2 3 2\n1 5\n2 4\n3 5",
"output": "1\n-1\n2"
},
{
"input": "6 5\n1 2 1 3 2 3\n4 6\n1 3\n2 5\n2 4\n1 6",
"output": "2\n2\n3\n-1\n2"
},
{
"input": "10 6\n2 2 1 5 6 4 9 8 5 4\n1 2\n1 10\n2 10\n2 9\n5 5\n2 8",
"output": "1\n1\n4\n5\n-1\n-1"
},
{
"input": "1 1\... | 1,425,758,133 | 17,733 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 7 | 3,000 | 41,881,600 | #!/usr/bin/env python3
# coding: utf-8
n, m = map(int, input().split())
a = map(int, input().split())
intervals = []
last_position = {}
for i, ai in enumerate(a, start=1):
if ai in last_position:
intervals.append((last_position[ai], i))
last_position[ai] = i
del a
del last_position
... | Title: Closest Equals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* and *m* queries *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*). For each query you need to print the minimum distance between such pair of elements *a**x* and *a**y* (... | ```python
#!/usr/bin/env python3
# coding: utf-8
n, m = map(int, input().split())
a = map(int, input().split())
intervals = []
last_position = {}
for i, ai in enumerate(a, start=1):
if ai in last_position:
intervals.append((last_position[ai], i))
last_position[ai] = i
del a
del last_p... | 0 | |
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs som... | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaran... | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1... | 1,522,151,334 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 154 | 7,065,600 | n, s, t = map(int, input().split())
p = [(int(x) - 1) for x in input().split()]
if s == t:
print(0)
else:
x = s
ret = 0
flag = 0
while x != t:
ret += 1
x = p[x]
if x == s:
print(-1)
flag = 1
break
if flag == 0:
print(ret)
| Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the ... | ```python
n, s, t = map(int, input().split())
p = [(int(x) - 1) for x in input().split()]
if s == t:
print(0)
else:
x = s
ret = 0
flag = 0
while x != t:
ret += 1
x = p[x]
if x == s:
print(-1)
flag = 1
break
if flag == 0:
print(r... | 0 | |
586 | B | Laurenty and Shop | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The town where Laurenty lives in is not large. The houses in it are located in two rows, *n* houses in each... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=50) — the number of houses in each row.
Each of the next two lines contains *n*<=-<=1 space-separated integer — values *a**ij* (1<=≤<=*a**ij*<=≤<=100).
The last line contains *n* space-separated integers *b**j* (1<=≤<=*b**j*<=≤<=100). | Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home. | [
"4\n1 2 3\n3 2 1\n3 2 2 3\n",
"3\n1 2\n3 3\n2 1 3\n",
"2\n1\n1\n1 1\n"
] | [
"12\n",
"11\n",
"4\n"
] | The first sample is shown on the figure above.
In the second sample, Laurenty's path can look as follows:
- Laurenty crosses the avenue, the waiting time is 3; - Laurenty uses the second crossing in the first row, the waiting time is 2; - Laurenty uses the first crossing in the first row, the waiting time is 1; ... | 1,000 | [
{
"input": "4\n1 2 3\n3 2 1\n3 2 2 3",
"output": "12"
},
{
"input": "3\n1 2\n3 3\n2 1 3",
"output": "11"
},
{
"input": "2\n1\n1\n1 1",
"output": "4"
},
{
"input": "2\n1\n1\n2 1",
"output": "5"
},
{
"input": "3\n1 100\n1 1\n100 100 100",
"output": "204"
},
... | 1,444,644,192 | 3,192 | PyPy 3 | WRONG_ANSWER | PRETESTS | 8 | 171 | 3,891,200 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
def dijkstra(adjList,s, v1, v2):
num = len(adjList)
dist = [10**8 for i in range(num)]
prev = [-1 for i in range(num)]
queue = []
heappush(queue,(0,s))
dist[s] = 0
while queue != []:
v_co... | Title: Laurenty and Shop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.
The ... | ```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
def dijkstra(adjList,s, v1, v2):
num = len(adjList)
dist = [10**8 for i in range(num)]
prev = [-1 for i in range(num)]
queue = []
heappush(queue,(0,s))
dist[s] = 0
while queue != []:
... | 0 | |
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,610,115,682 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 358 | 11,673,600 | n = int(input())
A = list(map(int,input().split()))
B = [0]*(n+1)
B[0] = -1
t = n
for i in range(len(A)):
if A[i] == t and t != 0:
print(t,end=' ')
v = t-1
while v > 0 and B[v] == 1:
print(v,end=' ')
v -= 1
t = v
print()
else:
... | 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
n = int(input())
A = list(map(int,input().split()))
B = [0]*(n+1)
B[0] = -1
t = n
for i in range(len(A)):
if A[i] == t and t != 0:
print(t,end=' ')
v = t-1
while v > 0 and B[v] == 1:
print(v,end=' ')
v -= 1
t = v
print()
... | 3 | |
804 | B | Minimum number of steps | PROGRAMMING | 1,400 | [
"combinatorics",
"greedy",
"implementation",
"math"
] | null | null | We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<... | The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106. | Print the minimum number of steps modulo 109<=+<=7. | [
"ab\n",
"aab\n"
] | [
"1\n",
"3\n"
] | The first example: "ab" → "bba".
The second example: "aab" → "abba" → "bbaba" → "bbbbaa". | 1,000 | [
{
"input": "ab",
"output": "1"
},
{
"input": "aab",
"output": "3"
},
{
"input": "aaaaabaabababaaaaaba",
"output": "17307"
},
{
"input": "abaabaaabbabaabab",
"output": "1795"
},
{
"input": "abbaa",
"output": "2"
},
{
"input": "abbaaabaabaaaaabbbbaababaa... | 1,688,629,899 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 46 | 4,403,200 | MODULO = 1e9 + 7
PATTERN = "ab"
PATTERN_REPLACEMENT = "bba"
def count_for_pattern_occurences(text: str, count = 0):
count_pattern = text.count(PATTERN)
if count_pattern == 0:
return count
return count_for_pattern_occurences(
text=text.replace(PATTERN, PATTERN_REPLACEMENT, count_p... | Title: Minimum number of steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr... | ```python
MODULO = 1e9 + 7
PATTERN = "ab"
PATTERN_REPLACEMENT = "bba"
def count_for_pattern_occurences(text: str, count = 0):
count_pattern = text.count(PATTERN)
if count_pattern == 0:
return count
return count_for_pattern_occurences(
text=text.replace(PATTERN, PATTERN_REPLACEMEN... | -1 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,691,570,724 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 342 | 26,828,800 |
n = int(input())
l = input().split()
m = int(input())
lm = input().split()
d = {}
c = 1
a = 0
v = 0
for i in l:
d[i] = c
c += 1
for j in lm:
a += d[j]
v += (n+1-d[j])
print(a, v)
'''n = int(input())
a = list(map(int, input().split(" ")))
m = int(input())
b = list(map(int, input().spl... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
l = input().split()
m = int(input())
lm = input().split()
d = {}
c = 1
a = 0
v = 0
for i in l:
d[i] = c
c += 1
for j in lm:
a += d[j]
v += (n+1-d[j])
print(a, v)
'''n = int(input())
a = list(map(int, input().split(" ")))
m = int(input())
b = list(map(int, i... | 3 | |
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,685,894,619 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 6 | 124 | 2,764,800 | n,m=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
li.sort()
ans=0
c=0
i=0
while li[i]<0 and c<m:
ans+=li[i]
c+=1
i+=1
print(abs(ans)) | 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,m=map(int,input().strip().split())
li=list(map(int,input().strip().split()))
li.sort()
ans=0
c=0
i=0
while li[i]<0 and c<m:
ans+=li[i]
c+=1
i+=1
print(abs(ans))
``` | -1 |
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,697,519,558 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 | n=input()
d=max(map(int,(n,n[:-1],n[:-2]+n[-1])))
print(d) | 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=input()
d=max(map(int,(n,n[:-1],n[:-2]+n[-1])))
print(d)
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,694,346,926 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | y=(input())
y=y.replace('--','2')
y=y.replace('-.','1')
y=y.replace('.','0')
print(y) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
y=(input())
y=y.replace('--','2')
y=y.replace('-.','1')
y=y.replace('.','0')
print(y)
``` | 3.977 |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,490,554,082 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 4,608,000 | ilyushaT, artistsT, timeline = [int(x) for x in input().split(' ')]
drownArtists = 0
ArtistTime = artistsT
IlyushaTime = ilyushaT
for sec in range(1, timeline+1):
if sec == IlyushaTime and sec == ArtistTime:
drownArtists += 1
if sec == ArtistTime:
ArtistTime += artistsT
if sec == IlyushaTime:
Ilyusha... | Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
ilyushaT, artistsT, timeline = [int(x) for x in input().split(' ')]
drownArtists = 0
ArtistTime = artistsT
IlyushaTime = ilyushaT
for sec in range(1, timeline+1):
if sec == IlyushaTime and sec == ArtistTime:
drownArtists += 1
if sec == ArtistTime:
ArtistTime += artistsT
if sec == IlyushaTime:
... | 3 | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,529,412,413 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 102,400 | n,k = [int(i) for i in input().split()]
s = input()
from collections import Counter as C
c = C(s)
f = 1
for i in c:
if c[i] > k :
f = 0
print ('NO')
if f:
print ("YES") | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
n,k = [int(i) for i in input().split()]
s = input()
from collections import Counter as C
c = C(s)
f = 1
for i in c:
if c[i] > k :
f = 0
print ('NO')
if f:
print ("YES")
``` | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,619,445,975 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 0 | Bruh = list(input())
Index_List = []
g = []
for i in 'hiedi':
if i in Bruh:
Index_List.append(Bruh.index(i))
for i in Index_List:
g += Bruh[i]
if g == ['h', 'i', 'e', 'd', 'i']:
print('NO')
else:
print('YES')
print(g)
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
Bruh = list(input())
Index_List = []
g = []
for i in 'hiedi':
if i in Bruh:
Index_List.append(Bruh.index(i))
for i in Index_List:
g += Bruh[i]
if g == ['h', 'i', 'e', 'd', 'i']:
print('NO')
else:
print('YES')
print(g)
``` | 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,679,857,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 62 | 0 | x,y=map(int,input().split())
l=list(map(int,input().split()))
n,t=1,0
for i in range(x):
if l[i]<0 and n<=y:
t+=(-l[i])
n+=1
print(t) | 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
x,y=map(int,input().split())
l=list(map(int,input().split()))
n,t=1,0
for i in range(x):
if l[i]<0 and n<=y:
t+=(-l[i])
n+=1
print(t)
``` | 0 |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,690,996,167 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 4,096,000 | def can_reach_cell(n, t, a):
current_cell = 1
visited_cells = set()
while current_cell <= t:
if current_cell == t:
return "YES"
if current_cell in visited_cells:
return "NO"
visited_cells.add(current_cell)
current_cell += a[current_cell - 1]
return... | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
def can_reach_cell(n, t, a):
current_cell = 1
visited_cells = set()
while current_cell <= t:
if current_cell == t:
return "YES"
if current_cell in visited_cells:
return "NO"
visited_cells.add(current_cell)
current_cell += a[current_cell - 1]
... | 3 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,632,378,867 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 31 | 77 | 6,963,200 | n=int(input())
matrix=[]
row=[]
if n==2:
row1=input()
row2=input()
row=row1+row2
if row.count('x')==row.count('o'):
print("YES")
exit()
else:
print("NO")
exit()
for i in range(n):
string=input()
for char in string:
row.append(char)
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n=int(input())
matrix=[]
row=[]
if n==2:
row1=input()
row2=input()
row=row1+row2
if row.count('x')==row.count('o'):
print("YES")
exit()
else:
print("NO")
exit()
for i in range(n):
string=input()
for char in string:
row.append(... | 0 | |
5 | A | Chat Servers Outgoing Traffic | PROGRAMMING | 1,000 | [
"implementation"
] | A. Chat Server's Outgoing Traffic | 1 | 64 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
- Include a person... | Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
- +<name> for 'Add' command. - -<name> for 'Remove' command. - <sender_name>:<message_text> for 'Send' command.
<name> and <s... | Print a single number — answer to the problem. | [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
] | [
"9\n",
"14\n"
] | none | 0 | [
{
"input": "+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate",
"output": "9"
},
{
"input": "+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate",
"output": "14"
},
{
"input": "+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIO... | 1,638,400,819 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | count = 0
lenMessage = 0
str = input()
while (str):
if(str.find("-") != -1):
count -= 1
if (str.find("+") != -1):
count += 1
if(str.find(":") != -1):
lenMessage += count * len(str[(str.find(":") + 1):(len(str))])
str = input()
print(lenMessage)
| Title: Chat Servers Outgoing Traffic
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in fr... | ```python
count = 0
lenMessage = 0
str = input()
while (str):
if(str.find("-") != -1):
count -= 1
if (str.find("+") != -1):
count += 1
if(str.find(":") != -1):
lenMessage += count * len(str[(str.find(":") + 1):(len(str))])
str = input()
print(lenMessage)
``` | -1 |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,577,002,503 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 92 | 307,200 | t=int(input())
a1=int(input())
a2=str(a1)
a=list(a2)
x1=[]
for i in range(t):
x=int(a[i])
p1=(10-x)
if p1==10:
p1=0
else:
p1=p1%10
s=""
for j in range(t):
ii=int(a[j])
ff=(ii+p1)%10
s+=str(ff)
for j in range(t):
if s[j]=="0":
... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
t=int(input())
a1=int(input())
a2=str(a1)
a=list(a2)
x1=[]
for i in range(t):
x=int(a[i])
p1=(10-x)
if p1==10:
p1=0
else:
p1=p1%10
s=""
for j in range(t):
ii=int(a[j])
ff=(ii+p1)%10
s+=str(ff)
for j in range(t):
if s... | -1 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,680,712,206 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 40 | 92 | 0 |
def is_lucky_ticket(n, t):
t_str = str(t)
diff = 0
n //= 2
for i in range(n):
l_num, r_num = int(t_str[i]), int(t_str[i + n])
if l_num not in [4, 7] or r_num not in [4, 7]:
return 'NO'
diff += l_num - r_num
return 'YES' if diff == 0 else 'NO'
d... | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
def is_lucky_ticket(n, t):
t_str = str(t)
diff = 0
n //= 2
for i in range(n):
l_num, r_num = int(t_str[i]), int(t_str[i + n])
if l_num not in [4, 7] or r_num not in [4, 7]:
return 'NO'
diff += l_num - r_num
return 'YES' if diff == 0 else '... | -1 | |
574 | B | Bear and Three Musketeers | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs",
"hashing"
] | null | null | Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys.
There are *n* warriors. Richelimakieu wants to choose thre... | The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other.
*i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**... | If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). | [
"5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n",
"7 4\n2 1\n3 6\n5 1\n1 7\n"
] | [
"2\n",
"-1\n"
] | In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti... | 1,000 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5",
"output": "2"
},
{
"input": "7 4\n2 1\n3 6\n5 1\n1 7",
"output": "-1"
},
{
"input": "5 0",
"output": "-1"
},
{
"input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4",
"output": "5"
},
{
... | 1,620,611,101 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 13,004,800 | f = lambda: map(int, input().split())
n, m = f()
p, s = [], [set() for i in range(n + 1)]
for j in range(m):
a, b = f()
p += [(a, b, c) for c in s[a].intersection(s[b])]
s[a].add(b)
s[b].add(a)
k = [len(s[i]) for i in range(n + 1)]
print(min(k[a] + k[b] + k[c] for a, b, c in p) - 6 if p else -1... | Title: Bear and Three Musketeers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Do you know a story about the three musketeers? Anyway, you will learn about its origins now.
Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br... | ```python
f = lambda: map(int, input().split())
n, m = f()
p, s = [], [set() for i in range(n + 1)]
for j in range(m):
a, b = f()
p += [(a, b, c) for c in s[a].intersection(s[b])]
s[a].add(b)
s[b].add(a)
k = [len(s[i]) for i in range(n + 1)]
print(min(k[a] + k[b] + k[c] for a, b, c in p) - 6 if... | 3 | |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input":... | 1,696,233,272 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # Input
str1 = input().lower() # Convert to lowercase for case-insensitive comparison
str2 = input().lower()
# Compare the strings
if str1 < str2:
print("-1")
elif str1 > str2:
print("1")
else:
print("0")
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in thi... | Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. ... | ```python
# Input
str1 = input().lower() # Convert to lowercase for case-insensitive comparison
str2 = input().lower()
# Compare the strings
if str1 < str2:
print("-1")
elif str1 > str2:
print("1")
else:
print("0")
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 c... | 0 |
555 | A | Case of Matryoshkas | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can... | The first line contains integers *n* (1<=≤<=*n*<=≤<=105) and *k* (1<=≤<=*k*<=≤<=105) — the number of matryoshkas and matryoshka chains in the initial configuration.
The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m**i* (1<=≤<=*m**i*<=≤<=*n*), and then *m**i* numbers *a... | In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration. | [
"3 2\n2 1 2\n1 3\n",
"7 3\n3 1 3 7\n2 2 5\n2 4 6\n"
] | [
"1\n",
"10\n"
] | In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3.
In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds. | 250 | [
{
"input": "3 2\n2 1 2\n1 3",
"output": "1"
},
{
"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6",
"output": "10"
},
{
"input": "1 1\n1 1",
"output": "0"
},
{
"input": "3 2\n1 2\n2 1 3",
"output": "3"
},
{
"input": "5 3\n1 4\n3 1 2 3\n1 5",
"output": "2"
},
{
"in... | 1,437,280,486 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 40 | 2,000 | 7,782,400 | n, k = map(int, input().split(' '))
for i in range(k):
x = input().split(' ')
if x[1] == '1':
y = [int(j) for j in x[2:]]
z = 0
while len(y) > 0:
if y[0] == z+2:
y = y[1:]
z += 1
else:
break
print(2*n-k-1... | Title: Case of Matryoshkas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of *n* matryoshka dolls that can be nested ... | ```python
n, k = map(int, input().split(' '))
for i in range(k):
x = input().split(' ')
if x[1] == '1':
y = [int(j) for j in x[2:]]
z = 0
while len(y) > 0:
if y[0] == z+2:
y = y[1:]
z += 1
else:
break
pri... | 0 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,665,219,821 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | w = list(map(int, input().split()))
b = [1]
for i in range(1,len(w)):
if w[i] > w [i - 1]:
b.append(b[i - 1] + 1)
else:
b.append(1)
print(max(b)) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
w = list(map(int, input().split()))
b = [1]
for i in range(1,len(w)):
if w[i] > w [i - 1]:
b.append(b[i - 1] + 1)
else:
b.append(1)
print(max(b))
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is... | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 0 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
... | 1,448,989,037 | 4,937 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 61 | 0 | N = int(input())
S = [ int(x) for x in input() ]
current = S[0]
trailing = abs(current-1)
seq_len = 1
a = 0
check = True
i = 1
while i < len(S):
x = S[i]
if x == trailing:
a = 0
current, trailing = trailing, current
seq_len += 1
elif check:
seq_len += 1
check = False
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questi... | ```python
N = int(input())
S = [ int(x) for x in input() ]
current = S[0]
trailing = abs(current-1)
seq_len = 1
a = 0
check = True
i = 1
while i < len(S):
x = S[i]
if x == trailing:
a = 0
current, trailing = trailing, current
seq_len += 1
elif check:
seq_len += 1
check = ... | 0 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,688,791,734 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | var = input()
nums = var.split(" ")
var = input()
mont = var.split(" ")
final = 0
for i in range(int(nums[1])):
found = 0
for j in range(len(mont)):
if int(mont[j]) < 0:
mont[j] = int(mont[j]) * -1
found = 1
break
if found == 0:
mont[0] = int(mont[j]) * -1
for i in mont... | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
var = input()
nums = var.split(" ")
var = input()
mont = var.split(" ")
final = 0
for i in range(int(nums[1])):
found = 0
for j in range(len(mont)):
if int(mont[j]) < 0:
mont[j] = int(mont[j]) * -1
found = 1
break
if found == 0:
mont[0] = int(mont[j]) * -1
for... | 0 | |
988 | B | Substrings Sort | PROGRAMMING | 1,100 | [
"sortings",
"strings"
] | null | null | You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su... | The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings.
The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters.
Some strings might be equal. | If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes).
Otherwise print "YES" (without quotes) and $n$ given strings in required order. | [
"5\na\naba\nabacaba\nba\naba\n",
"5\na\nabacaba\nba\naba\nabab\n",
"3\nqwerty\nqwerty\nqwerty\n"
] | [
"YES\na\nba\naba\naba\nabacaba\n",
"NO\n",
"YES\nqwerty\nqwerty\nqwerty\n"
] | In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba". | 0 | [
{
"input": "5\na\naba\nabacaba\nba\naba",
"output": "YES\na\nba\naba\naba\nabacaba"
},
{
"input": "5\na\nabacaba\nba\naba\nabab",
"output": "NO"
},
{
"input": "3\nqwerty\nqwerty\nqwerty",
"output": "YES\nqwerty\nqwerty\nqwerty"
},
{
"input": "1\nwronganswer",
"output": "Y... | 1,653,672,426 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 77 | 512,000 | def check(a,b):
m=len(a)
n=len(b)
ans=False
for i in range(n-m+1):
if b[i:i+m]==a:
ans=True
break
return ans
t=int(input())
list=[]
for i in range(t):
str=input()
list.append((len(str),str))
list.sort()
final=[]
for p in range(len(l... | Title: Substrings Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.
String ... | ```python
def check(a,b):
m=len(a)
n=len(b)
ans=False
for i in range(n-m+1):
if b[i:i+m]==a:
ans=True
break
return ans
t=int(input())
list=[]
for i in range(t):
str=input()
list.append((len(str),str))
list.sort()
final=[]
for p in r... | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,534,610,545 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 342 | 204,800 | n = int(input())
l = list(map(int,input().split()))
s = list(set(l))
l = sorted(l)
a = []
k = 0
for i in range(len(s)):
for j in range(len(l)):
if s[i] == l[j]:
k += 1
a.append(k)
k = 0
print(max(a),len(s)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
l = list(map(int,input().split()))
s = list(set(l))
l = sorted(l)
a = []
k = 0
for i in range(len(s)):
for j in range(len(l)):
if s[i] == l[j]:
k += 1
a.append(k)
k = 0
print(max(a),len(s))
``` | 3.914119 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,691,575,862 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 25 | 92 | 0 | n=int(input())
s=str(n)
if s.count("4")+s.count("7")==len(s):
print("YES")
else:
if n%4==0 or n%7==0:
print("YES")
else:
print("NO") | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n=int(input())
s=str(n)
if s.count("4")+s.count("7")==len(s):
print("YES")
else:
if n%4==0 or n%7==0:
print("YES")
else:
print("NO")
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,620,032,372 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 0 | n=int(input())
s1=0
s2=0
s3=0
for i in range(n):
x,y,z=map(int,input().split())
s1=s1+x
s2=s2+y
s3=s3+z
if(s1==0 and s2==0 and s3==0):
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
s1=0
s2=0
s3=0
for i in range(n):
x,y,z=map(int,input().split())
s1=s1+x
s2=s2+y
s3=s3+z
if(s1==0 and s2==0 and s3==0):
print('YES')
else:
print('NO')
``` | 3.969 |
186 | B | Growing Mushrooms | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules ... | The first input line contains four integer numbers *n*, *t*1, *t*2, *k* (1<=≤<=*n*,<=*t*1,<=*t*2<=≤<=1000; 1<=≤<=*k*<=≤<=100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly.
Each of the following... | Print the final results' table: *n* lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate. | [
"2 3 3 50\n2 4\n4 2\n",
"4 1 1 1\n544 397\n280 101\n280 101\n693 970\n"
] | [
"1 15.00\n2 15.00\n",
"4 1656.07\n1 937.03\n2 379.99\n3 379.99\n"
] | - First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3. | 1,000 | [
{
"input": "2 3 3 50\n2 4\n4 2",
"output": "1 15.00\n2 15.00"
},
{
"input": "4 1 1 1\n544 397\n280 101\n280 101\n693 970",
"output": "4 1656.07\n1 937.03\n2 379.99\n3 379.99"
},
{
"input": "10 1 1 25\n981 1\n352 276\n164 691\n203 853\n599 97\n901 688\n934 579\n910 959\n317 624\n440 737",... | 1,654,351,234 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | n,t1,t2,k = map(int, input().split())
choices = []
for i in range(n):
a,b = map(int, input().split())
hi = max(a*t1 + b*t2 * (1-k/100), b*t1 + a*t2 * (1-k/100))
choices.append((-hi, i+1))
choices.sort()
for h,i in choices:
print(i, "%.2f" % -h)
| Title: Growing Mushrooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event br... | ```python
n,t1,t2,k = map(int, input().split())
choices = []
for i in range(n):
a,b = map(int, input().split())
hi = max(a*t1 + b*t2 * (1-k/100), b*t1 + a*t2 * (1-k/100))
choices.append((-hi, i+1))
choices.sort()
for h,i in choices:
print(i, "%.2f" % -h)
``` | 0 | |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,529,999,324 | 1,124 | Python 3 | WRONG_ANSWER | TESTS | 5 | 124 | 819,200 | from queue import PriorityQueue as PQ
N, kA, kB = [int(c) for c in input().split(" ")]
A = [int(c) for c in input().split(" ")]
B = [int(c) for c in input().split(" ")]
pq = PQ()
for i in range(N):
pq.put(-abs(A[i]-B[i]))
for i in range(kA+kB):
max_value = pq.get()
# print("Get %d from PQ" % ... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
from queue import PriorityQueue as PQ
N, kA, kB = [int(c) for c in input().split(" ")]
A = [int(c) for c in input().split(" ")]
B = [int(c) for c in input().split(" ")]
pq = PQ()
for i in range(N):
pq.put(-abs(A[i]-B[i]))
for i in range(kA+kB):
max_value = pq.get()
# print("Get %d f... | 0 | |
724 | C | Ray Tracing | PROGRAMMING | 1,800 | [
"greedy",
"hashing",
"implementation",
"math",
"number theory",
"sortings"
] | null | null | There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle.
Opposite corners of the room are located at points (0,<=0) and (*n*,<=*m*). Walls of the room are paralle... | The first line of the input contains three integers *n*, *m* and *k* (2<=≤<=*n*,<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — lengths of the room's walls and the number of sensors.
Each of the following *k* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*<=-<=1, 1<=≤<=*y**i*<=≤<=*m*<=-<=1) — coordin... | Print *k* integers. The *i*-th of them should be equal to the number of seconds when the ray first passes through the point where the *i*-th sensor is located, or <=-<=1 if this will never happen. | [
"3 3 4\n1 1\n1 2\n2 1\n2 2\n",
"3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n",
"7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n"
] | [
"1\n-1\n-1\n2\n",
"1\n-1\n-1\n2\n5\n-1\n",
"13\n2\n9\n5\n-1\n"
] | In the first sample, the ray will consequently pass through the points (0, 0), (1, 1), (2, 2), (3, 3). Thus, it will stop at the point (3, 3) after 3 seconds.
In the second sample, the ray will consequently pass through the following points: (0, 0), (1, 1), (2, 2), (3, 3), (2, 4), (1, 3), (0, 2), (1, 1), (2, 0), (3, 1... | 1,500 | [
{
"input": "3 3 4\n1 1\n1 2\n2 1\n2 2",
"output": "1\n-1\n-1\n2"
},
{
"input": "3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3",
"output": "1\n-1\n-1\n2\n5\n-1"
},
{
"input": "7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3",
"output": "13\n2\n9\n5\n-1"
},
{
"input": "10 10 10\n3 8\n1 7\n2 3\n4 2\n4 8\n... | 1,490,399,205 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 4,710,400 | import math
def egcd(m1, m2):
if m2 == 0: return (m1, 1, 0)
else:
gcd, a1, a2 = egcd(m2, m1 % m2)
return (gcd, a2, a1 - a2*(m1//m2))
def crt(x1, m1, x2, m2):
gcd, a1, a2 = egcd(m1, m2)
if x1 % gcd != x2 % gcd: return math.inf
else: return (x1*a2*m2//gcd + x2*a1*m1//gcd) % (m1*m2//g... | Title: Ray Tracing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *k* sensors located in the rectangular room of size *n*<=×<=*m* meters. The *i*-th sensor is located at point (*x**i*,<=*y**i*). All sensors are located at distinct points strictly inside the rectangle.
Opposite... | ```python
import math
def egcd(m1, m2):
if m2 == 0: return (m1, 1, 0)
else:
gcd, a1, a2 = egcd(m2, m1 % m2)
return (gcd, a2, a1 - a2*(m1//m2))
def crt(x1, m1, x2, m2):
gcd, a1, a2 = egcd(m1, m2)
if x1 % gcd != x2 % gcd: return math.inf
else: return (x1*a2*m2//gcd + x2*a1*m1//gcd) %... | 0 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,679,160,806 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | n=int(input())
print(f'{n-9} {9}' if n&1 else f'{n-4} {4}')
| Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
n=int(input())
print(f'{n-9} {9}' if n&1 else f'{n-4} {4}')
``` | 3 | |
821 | C | Okabe and Boxes | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"trees"
] | null | null | Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which are to add a box to the top of the stack, and *n* of which are to remove a box from the top of the sta... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of boxes.
Each of the next 2*n* lines of input starts with a string "add" or "remove". If the line starts with the "add", an integer *x* (1<=≤<=*x*<=≤<=*n*) follows, indicating that Daru should add the box with number *x* to the top of... | Print the minimum number of times Daru needs to reorder the boxes to successfully complete all of Okabe's commands. | [
"3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n",
"7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n"
] | [
"1\n",
"2\n"
] | In the first sample, Daru should reorder the boxes after adding box 3 to the stack.
In the second sample, Daru should reorder the boxes after adding box 4 and box 7 to the stack. | 1,500 | [
{
"input": "3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove",
"output": "1"
},
{
"input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove",
"output": "2"
},
{
"input": "4\nadd 1\nadd 3\nremove\nadd 4\nadd 2\nremove\nremove\nremov... | 1,546,972,527 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 3,000 | 23,040,000 | l=[]
t=0
p=1
d={}
last=-1
ans=0
n=int(input())
for i in range(1,n+1) :
d[i]=0
for i in range(1,2*n+1) :
x = input()
if x[0]=="a" :
z,y = x.split()
l.append(int(y))
else :
#print(l[-1],p)
if l[-1]!=p :
ans+=1
#print(ans)
... | Title: Okabe and Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe and Super Hacker Daru are stacking and removing boxes. There are *n* boxes numbered from 1 to *n*. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2*n* commands: *n* of which a... | ```python
l=[]
t=0
p=1
d={}
last=-1
ans=0
n=int(input())
for i in range(1,n+1) :
d[i]=0
for i in range(1,2*n+1) :
x = input()
if x[0]=="a" :
z,y = x.split()
l.append(int(y))
else :
#print(l[-1],p)
if l[-1]!=p :
ans+=1
#print(ans)
... | 0 | |
805 | B | 3-palindrome | PROGRAMMING | 1,000 | [
"constructive algorithms"
] | null | null | In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string. | Print the string that satisfies all the constraints.
If there are multiple answers, print any of them. | [
"2\n",
"3\n"
] | [
"aa\n",
"bba\n"
] | A palindrome is a sequence of characters which reads the same backward and forward. | 1,000 | [
{
"input": "2",
"output": "aa"
},
{
"input": "3",
"output": "aab"
},
{
"input": "38",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa"
},
{
"input": "47",
"output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab"
},
{
"input": "59",
"output": "aabbaabbaabb... | 1,598,076,448 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 140 | 21,196,800 | n = int(input())
print(('aabb'*50000)[:n]) | Title: 3-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.
He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o... | ```python
n = int(input())
print(('aabb'*50000)[:n])
``` | 3 | |
1,003 | C | Intense Heat | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually cal... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 5000$) — the ... | Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than $k$ consecutive days.
Your answer will be considered correct if the following condition holds: $|res - res_0| < 10^{-6}$, where $res$ is your answer, and $res_0$ is the answer given by the... | [
"4 3\n3 4 1 2\n"
] | [
"2.666666666666667\n"
] | none | 0 | [
{
"input": "4 3\n3 4 1 2",
"output": "2.666666666666667"
},
{
"input": "5 1\n3 10 9 10 6",
"output": "10.000000000000000"
},
{
"input": "5 2\n7 3 3 1 8",
"output": "5.000000000000000"
},
{
"input": "5 3\n1 7 6 9 1",
"output": "7.333333333333333"
},
{
"input": "5 4... | 1,616,067,261 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 307,200 | import sys
total, days = map(int, sys.stdin.readline().rstrip().split(' '))
temp = list(map(int,sys.stdin.readline().rstrip().split(' ')))
temp_sum = []
result = 0
temp_sum.append(result)
for i in temp:
result += i
temp_sum.append(result)
maximum = 0
for d in range(days,total+1,1):
for i in... | Title: Intense Heat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sou... | ```python
import sys
total, days = map(int, sys.stdin.readline().rstrip().split(' '))
temp = list(map(int,sys.stdin.readline().rstrip().split(' ')))
temp_sum = []
result = 0
temp_sum.append(result)
for i in temp:
result += i
temp_sum.append(result)
maximum = 0
for d in range(days,total+1,1):
... | 0 | |
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,548,337,491 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 307,200 | n = int(input())
board = []
for _ in range(n):
board.append(input())
for i in range(n):
for j in range(n):
os = 0
if i == 0:
if j == 0:
if board[i][j+1] == 'o':
os += 1
if board[i+1][j] == 'o':
os += 1
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n = int(input())
board = []
for _ in range(n):
board.append(input())
for i in range(n):
for j in range(n):
os = 0
if i == 0:
if j == 0:
if board[i][j+1] == 'o':
os += 1
if board[i+1][j] == 'o':
os += 1
... | -1 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,695,465,938 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 307,200 | from collections import deque
v1=int(input());b=deque();c=0;c1=[];c2=[]
if v1==3:
print(1,3)
elif v1==2 or v1==1:
print(1)
else:
for i in range(1,v1+1):
if i%2==1:
c1.append(i)
else:
c2.append(i)
for i in range(len(c1)):
c2.append(c1[i])
print(len(c... | Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
from collections import deque
v1=int(input());b=deque();c=0;c1=[];c2=[]
if v1==3:
print(1,3)
elif v1==2 or v1==1:
print(1)
else:
for i in range(1,v1+1):
if i%2==1:
c1.append(i)
else:
c2.append(i)
for i in range(len(c1)):
c2.append(c1[i])
p... | 0 | |
888 | E | Maximum Subsequence | PROGRAMMING | 1,800 | [
"bitmasks",
"divide and conquer",
"meet-in-the-middle"
] | null | null | You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*) in such a way that the value of is maximized. Chosen sequence can be empty.
Print the maximum possibl... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=35, 1<=≤<=*m*<=≤<=109).
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum possible value of . | [
"4 4\n5 2 4 1\n",
"3 20\n199 41 299\n"
] | [
"3\n",
"19\n"
] | In the first example you can choose a sequence *b* = {1, 2}, so the sum <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c856546022c2feee13d02a4ec9cd1d361ab3a756.png" style="max-width: 100.0%;max-height: 100.0%;"/> is equal to 7 (and that's 3 after taking it modulo 4).
In the second example... | 0 | [
{
"input": "4 4\n5 2 4 1",
"output": "3"
},
{
"input": "3 20\n199 41 299",
"output": "19"
},
{
"input": "5 10\n47 100 49 2 56",
"output": "9"
},
{
"input": "5 1000\n38361 75847 14913 11499 8297",
"output": "917"
},
{
"input": "10 10\n48 33 96 77 67 59 35 15 14 86"... | 1,672,400,180 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 264 | 11,776,000 | from bisect import bisect_right
def get_sum(arr,mask):
t=0
for i in range(len(arr)):
if mask&(1<<i):
t+=(arr[i])
t%=m
return t
n,m=map(int,input().split())
a=list(map(int,input().split()))
a1=a[:(n+1)//2]
a2=a[(n+1)//2:]
left=[]
for x in range(2**len(a1)):
l... | Title: Maximum Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* consisting of *n* integers, and additionally an integer *m*. You have to choose some sequence of indices *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b*1<=<<=*b*2<=<<=...<=<<=*b**k*<=≤<=*n*... | ```python
from bisect import bisect_right
def get_sum(arr,mask):
t=0
for i in range(len(arr)):
if mask&(1<<i):
t+=(arr[i])
t%=m
return t
n,m=map(int,input().split())
a=list(map(int,input().split()))
a1=a[:(n+1)//2]
a2=a[(n+1)//2:]
left=[]
for x in range(2**len(a1... | 3 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,557,864,159 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | R = lambda : list(map(int, input().split()))
x = [[4, 3, 2, 1],
[1, 4, 3, 2],
[2, 1, 4, 3],
[3, 2, 1, 4]]
dic = {0:[(1, 0), (2, 1), (3, 2)],
1:[(0, 2), (2, 0), (3, 1)],
2:[(0, 1), (1, 3), (3, 0)],
3:[(0, 0), (1, 1), (2, 2)]
}
l = [R(), R(), R(), R()]
ans = 0
for ... | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
R = lambda : list(map(int, input().split()))
x = [[4, 3, 2, 1],
[1, 4, 3, 2],
[2, 1, 4, 3],
[3, 2, 1, 4]]
dic = {0:[(1, 0), (2, 1), (3, 2)],
1:[(0, 2), (2, 0), (3, 1)],
2:[(0, 1), (1, 3), (3, 0)],
3:[(0, 0), (1, 1), (2, 2)]
}
l = [R(), R(), R(), R()]
ans... | 0 | |
177 | A2 | Good Matrix Elements | PROGRAMMING | 800 | [
"implementation"
] | null | null | The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the main diagonal. - Elements of the secondary diagonal. - Elements of the "middle" row — the row which ha... | The first line of input data contains a single odd integer *n*. Each of the next *n* lines contains *n* integers *a**ij* (0<=≤<=*a**ij*<=≤<=100) separated by single spaces — the elements of the given matrix.
The input limitations for getting 30 points are:
- 1<=≤<=*n*<=≤<=5
The input limitations for getting 100 po... | Print a single integer — the sum of good matrix elements. | [
"3\n1 2 3\n4 5 6\n7 8 9\n",
"5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n"
] | [
"45\n",
"17\n"
] | In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. | 70 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "45"
},
{
"input": "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1",
"output": "17"
},
{
"input": "1\n3",
"output": "3"
},
{
"input": "5\n27 7 3 11 72\n19 49 68 19 59\n41 25 37 64 65\n8 39 96 62 90\n13 37 43 26 33",
... | 1,563,691,538 | 2,147,483,647 | Python 3 | OK | TESTS2 | 33 | 248 | 0 | n = int(input())
mid = int((n-1)/2)
su = 0
for i in range(n):
l = list(map(int,input().split()))
if i != mid:
su = su + l[i]+l[n-1-i]+l[mid]
else:
su = su+sum(l)
print(su) | Title: Good Matrix Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an *n*<=×<=*n* size matrix, where *n* is odd. The Smart Beaver considers the following matrix elements good:
- Elements of the ... | ```python
n = int(input())
mid = int((n-1)/2)
su = 0
for i in range(n):
l = list(map(int,input().split()))
if i != mid:
su = su + l[i]+l[n-1-i]+l[mid]
else:
su = su+sum(l)
print(su)
``` | 3 | |
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output"... | 1,628,865,305 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 6,758,400 | [yc,bc] = map(int,input().split())
[yb,gb,bb] = map(int,input().split())
x = (yb*2+gb)-yc
y = (bb*3+gb)-bc
if x < 0:
x = 0
if y < 0:
y = 0
print(x+y) | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obta... | ```python
[yc,bc] = map(int,input().split())
[yb,gb,bb] = map(int,input().split())
x = (yb*2+gb)-yc
y = (bb*3+gb)-bc
if x < 0:
x = 0
if y < 0:
y = 0
print(x+y)
``` | 3 | |
825 | D | Suitable Replacement | PROGRAMMING | 1,500 | [
"binary search",
"greedy",
"implementation"
] | null | null | You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=106).
The second line contains string *t* (1<=≤<=|*t*|<=≤<=106). | Print string *s* with '?' replaced with small Latin letters in such a way that suitability of that string is maximal.
If there are multiple strings with maximal suitability then print any of them. | [
"?aa?\nab\n",
"??b?\nza\n",
"abcd\nabacaba\n"
] | [
"baab\n",
"azbz\n",
"abcd\n"
] | In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2.
In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them.
In the third exam... | 0 | [
{
"input": "?aa?\nab",
"output": "baab"
},
{
"input": "??b?\nza",
"output": "azbz"
},
{
"input": "abcd\nabacaba",
"output": "abcd"
},
{
"input": "mqwstphetbfrsyxuzdww\nrutseqtsbh",
"output": "mqwstphetbfrsyxuzdww"
},
{
"input": "????????????????????\nxwkxsxlrre",
... | 1,516,792,093 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 18,944,000 | s=input()
t=input()
n=len(s)
m=len(t)
k=0
for i in range(n):
if s[i]=='?':
k+=1
d={}
for i in range(m):
if t[i] not in d:
d[t[i]]=[1,0]
else:
d[t[i]][0]+=1
for i in range(n):
if s[i] in d:
d[s[i]][1]+=1
l,r=0,n+1
while l+1!=r:
c=(l+r)//2
e=m*c
for x in d:
... | Title: Suitable Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters.
Suitability of string *s* is calculated by following metric:
Any two letters can be swapped po... | ```python
s=input()
t=input()
n=len(s)
m=len(t)
k=0
for i in range(n):
if s[i]=='?':
k+=1
d={}
for i in range(m):
if t[i] not in d:
d[t[i]]=[1,0]
else:
d[t[i]][0]+=1
for i in range(n):
if s[i] in d:
d[s[i]][1]+=1
l,r=0,n+1
while l+1!=r:
c=(l+r)//2
e=m*c
for x ... | 0 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,683,239,874 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 921,600 | # 1 - length & operations
# 2 - String
# 3 - Lines Of operations
# Example:
# 5 3
# wxhak
# 3 3 h x : wxxak
# 1 5 x a : waaak
# 1 3 w g : gaaak
# >> Output: gaaak
"""
{
'0': [3, 3, 'h', 'x'],
'1': [1, 5, 'x', 'a'],
'2': [1, 3, 'w', 'g']
}
"""
# user = {
# '0': "[3... | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
# 1 - length & operations
# 2 - String
# 3 - Lines Of operations
# Example:
# 5 3
# wxhak
# 3 3 h x : wxxak
# 1 5 x a : waaak
# 1 3 w g : gaaak
# >> Output: gaaak
"""
{
'0': [3, 3, 'h', 'x'],
'1': [1, 5, 'x', 'a'],
'2': [1, 3, 'w', 'g']
}
"""
# user = {
# ... | -1 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,530,811,839 | 3,339 | Python 3 | OK | TESTS | 42 | 327 | 9,830,400 | n = int(input())
a = [int(i) for i in input().split()]
d = {}
s = set()
for i in a:
if d.get(i):
d[i] += 1
else:
d[i] = 1
ans = 0
for i in a:
d[i] -= 1
if d[i] == 0:
d.pop(i)
if i not in s:
ans += len(d.keys())
s.add(i)
print(ans) | Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
n = int(input())
a = [int(i) for i in input().split()]
d = {}
s = set()
for i in a:
if d.get(i):
d[i] += 1
else:
d[i] = 1
ans = 0
for i in a:
d[i] -= 1
if d[i] == 0:
d.pop(i)
if i not in s:
ans += len(d.keys())
s.add(i)
print(ans)
``` | 3 | |
375 | A | Divisible by Seven | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resu... | The first line contains positive integer *a* in the decimal record. It is guaranteed that the record of number *a* contains digits: 1, 6, 8, 9. Number *a* doesn't contain any leading zeroes. The decimal representation of number *a* contains at least 4 and at most 106 characters. | Print a number in the decimal notation without leading zeroes — the result of the permutation.
If it is impossible to rearrange the digits of the number *a* in the required manner, print 0. | [
"1689\n",
"18906\n"
] | [
"1869\n",
"18690\n"
] | none | 500 | [
{
"input": "1689",
"output": "1869"
},
{
"input": "18906",
"output": "18690"
},
{
"input": "2419323689",
"output": "2432391689"
},
{
"input": "8589157262",
"output": "5857221986"
},
{
"input": "2717172350336955863014903670481525170997949309274087058935108848979319... | 1,600,888,667 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 55 | 1,000 | 6,144,000 | a=input()
count0=0
resp=''
vez1=True
vez2=True
vez3=True
vez4=True
for i in a:
if i=='0':
count0+=1
elif i=='1' and vez1==True:
vez1=False
elif i=='6' and vez2==True:
vez2=False
elif i=='8' and vez3==True:
vez3=False
elif i=='9' and vez4==True:
vez4=False
... | Title: Divisible by Seven
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have number *a*, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.
Number *a* doesn't ... | ```python
a=input()
count0=0
resp=''
vez1=True
vez2=True
vez3=True
vez4=True
for i in a:
if i=='0':
count0+=1
elif i=='1' and vez1==True:
vez1=False
elif i=='6' and vez2==True:
vez2=False
elif i=='8' and vez3==True:
vez3=False
elif i=='9' and vez4==True:
vez4... | 0 | |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,590,544,141 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 404 | 2,150,400 | # Wires numbered 1 to n from top to bottom
# Supposed there are a i birds sitting on the i-th wire.
# when bird die all birds on his left on i-th wire jumb on wire number i-1 , if there is no upper they fly away
# on his right they jumb down in wire i+1 if there is no down wire they fly away
# Shass shot m birds
#... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
# Wires numbered 1 to n from top to bottom
# Supposed there are a i birds sitting on the i-th wire.
# when bird die all birds on his left on i-th wire jumb on wire number i-1 , if there is no upper they fly away
# on his right they jumb down in wire i+1 if there is no down wire they fly away
# Shass shot ... | -1 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,688,305,875 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | from itertools import pairwise
s = input()
x1 = "AB"
x2 = "BA"
c1 = 1
c2 = 1
l1 = []
l2 = []
l3 = []
pairs = pairwise(s)
for i, j in pairs:
pair = i + j
if pair == x1:
if c1 % 2:
l1.append('$')
else:
l1.append('$')
l3.append('#')
... | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
from itertools import pairwise
s = input()
x1 = "AB"
x2 = "BA"
c1 = 1
c2 = 1
l1 = []
l2 = []
l3 = []
pairs = pairwise(s)
for i, j in pairs:
pair = i + j
if pair == x1:
if c1 % 2:
l1.append('$')
else:
l1.append('$')
l3.append('#')... | -1 | |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,684,344,835 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | t = int(input())
l =list(map(int, input().split()))
for i in l :
print(i * 4 + 1) | Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
t = int(input())
l =list(map(int, input().split()))
for i in l :
print(i * 4 + 1)
``` | 0 | |
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"out... | 1,645,936,801 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | // Online C++ Compiler
// Use this online editor to compile and run C++ code online
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,s;
cin>>n>>s;
int x[n];
int y[n];
int k[n];
float r[n];
for(int i=0;i<n;i++){
cin>>x[i];
cin>>y[i];
cin>>k[i];
r[i]=x[i]*x[i]+y[i]*y[i];
}
... | Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding... | ```python
// Online C++ Compiler
// Use this online editor to compile and run C++ code online
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,s;
cin>>n>>s;
int x[n];
int y[n];
int k[n];
float r[n];
for(int i=0;i<n;i++){
cin>>x[i];
cin>>y[i];
cin>>k[i];
r[i]=x[i]*x[i]+y[i]*... | -1 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,904,198 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | n,d=map(int,input().split())
l=list(map(int,input().split()))
k=set()
for i in range(n):
if i==0:
k.add(l[i]-d)
first=l[i]+d
try:
if l[i+1]-d>=first:
k.add(l[i]+d)
continue
except:
k.add(l[i]+d)
continue
... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n,d=map(int,input().split())
l=list(map(int,input().split()))
k=set()
for i in range(n):
if i==0:
k.add(l[i]-d)
first=l[i]+d
try:
if l[i+1]-d>=first:
k.add(l[i]+d)
continue
except:
k.add(l[i]+d)
co... | 3 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,698,510,218 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 31 | 0 | number = int(input())
count = 0
for n in range(number):
string = str(input())
if (string[0] == "+" or string[len(string)-1] == "+"):
count += 1
if (string[0] == "-" or string[len(string)-1] == "-"):
count -= 1
print(count)
| Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
number = int(input())
count = 0
for n in range(number):
string = str(input())
if (string[0] == "+" or string[len(string)-1] == "+"):
count += 1
if (string[0] == "-" or string[len(string)-1] == "-"):
count -= 1
print(count)
``` | 3 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,591,159,756 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | n,m=map(int,input().split())
if(m<=2*(n+1) and m>=n-1):
if(n==m):
s='01'*(n)
print(s)
elif(n<m):
s=''
while(n!=m):
s+='110'
m-=2
n-=1
x='10'*n
print(s+x)
elif(n>m):
s='01'*m
s+='0'
pri... | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
n,m=map(int,input().split())
if(m<=2*(n+1) and m>=n-1):
if(n==m):
s='01'*(n)
print(s)
elif(n<m):
s=''
while(n!=m):
s+='110'
m-=2
n-=1
x='10'*n
print(s+x)
elif(n>m):
s='01'*m
s+='0'
... | 0 | |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,614,412,461 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 39,116,800 | f=open("input.txt","r")
l1=f.read().split("\n")
f.close()
a=int(l1[0])
arr=list(map(int,l1[1].split()))
flag=True
s1=set(arr)
for i in s1:
if arr.count(i)%2==0:
# print("i=",i)
flag=True
else:
f=open("output.txt","w+")
f.write("-1")
f.close()
flag=F... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
f=open("input.txt","r")
l1=f.read().split("\n")
f.close()
a=int(l1[0])
arr=list(map(int,l1[1].split()))
flag=True
s1=set(arr)
for i in s1:
if arr.count(i)%2==0:
# print("i=",i)
flag=True
else:
f=open("output.txt","w+")
f.write("-1")
f.close()
... | 0 | |
794 | A | Bank Robbery | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f... | The first line of input contains three space-separated integers, *a*, *b* and *c* (1<=≤<=*b*<=<<=*a*<=<<=*c*<=≤<=109), denoting the positions of Oleg, the first security guard and the second security guard, respectively.
The next line of input contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the numbe... | Output a single integer: the maximum number of banknotes Oleg can take. | [
"5 3 7\n8\n4 7 5 5 3 6 2 8\n",
"6 5 7\n5\n1 5 7 92 3\n"
] | [
"4\n",
"0\n"
] | In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first se... | 500 | [
{
"input": "5 3 7\n8\n4 7 5 5 3 6 2 8",
"output": "4"
},
{
"input": "6 5 7\n5\n1 5 7 92 3",
"output": "0"
},
{
"input": "3 2 4\n1\n3",
"output": "1"
},
{
"input": "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6",
"output": "8"
},
{
"input": "7 3 10\n5\n3 3 3 3 3",
"output... | 1,606,740,714 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 155 | 7,884,800 | # https://codeforces.com/problemset/problem/794/A
a, b, c = map(int, input().split())
n = int(input())
ans = 0
for i in map(int, input().split()):
if b < i < c:
ans += 1
print(ans) | Title: Bank Robbery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes.
Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and... | ```python
# https://codeforces.com/problemset/problem/794/A
a, b, c = map(int, input().split())
n = int(input())
ans = 0
for i in map(int, input().split()):
if b < i < c:
ans += 1
print(ans)
``` | 3 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,595,914,037 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 248 | 20,172,800 | import math
n=int(input())
if int(math.sqrt(n))%2==0:
print('YES')
else:
print('NO') | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
import math
n=int(input())
if int(math.sqrt(n))%2==0:
print('YES')
else:
print('NO')
``` | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,699,551,617 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | s = input()
t = "heidi"
cur = 0
for i in range(len(s)):
if cur < 5 and t[cur] == s[i]:
cur = cur + 1
if cur == 5:
print("Yes")
else:
print("No") | Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
t = "heidi"
cur = 0
for i in range(len(s)):
if cur < 5 and t[cur] == s[i]:
cur = cur + 1
if cur == 5:
print("Yes")
else:
print("No")
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,586,664,514 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 |
n = int(input())
arr = [int(x) % 2 for x in input().split()]
a = arr.count(1)
b = arr.count(0)
if a == 1:
print(arr.index(1)+1)
else:
print(arr.index(0)+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n = int(input())
arr = [int(x) % 2 for x in input().split()]
a = arr.count(1)
b = arr.count(0)
if a == 1:
print(arr.index(1)+1)
else:
print(arr.index(0)+1)
``` | 3.9455 |
678 | B | The Same Calendar | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ... | The only line contains integer *y* (1000<=≤<=*y*<=<<=100'000) — the year of the calendar. | Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar. | [
"2016\n",
"2000\n",
"50501\n"
] | [
"2044\n",
"2028\n",
"50507\n"
] | Today is Monday, the 13th of June, 2016. | 0 | [
{
"input": "2016",
"output": "2044"
},
{
"input": "2000",
"output": "2028"
},
{
"input": "50501",
"output": "50507"
},
{
"input": "1000",
"output": "1006"
},
{
"input": "1900",
"output": "1906"
},
{
"input": "1899",
"output": "1905"
},
{
"i... | 1,569,397,746 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | def year(x):
if x%400==0:
return 2
elif x%4==0 and x%100!=0:
return 2
else:
return 1
a=int(input())
b=a
s=year(a)
while(True):
a=a+1
s=s+year(a)
if s%7==0 and year(b)==year(a+1):
print(a+1)
break | Title: The Same Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful t... | ```python
def year(x):
if x%400==0:
return 2
elif x%4==0 and x%100!=0:
return 2
else:
return 1
a=int(input())
b=a
s=year(a)
while(True):
a=a+1
s=s+year(a)
if s%7==0 and year(b)==year(a+1):
print(a+1)
break
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,697,372,031 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 62 | 0 | def split(string, sep=" "):
prev = 0
for i, char in enumerate(string):
if char == sep:
if i != prev:
yield string[prev:i]
prev = i + 1
ret = string[prev:]
if ret:
yield ret
s = input()
t = input()
i = 0
for inst in t:
if s[i] == inst:
... | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
def split(string, sep=" "):
prev = 0
for i, char in enumerate(string):
if char == sep:
if i != prev:
yield string[prev:i]
prev = i + 1
ret = string[prev:]
if ret:
yield ret
s = input()
t = input()
i = 0
for inst in t:
if s[i] == i... | 3 | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,517,069,183 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,632,000 | def sr(s):
for i in range(1, len(s)):
val = s[i]
j = i - 1
while (j >= 0) and (s[j] > val):
s[j+1] = s[j]
j = j - 1
s[j+1] = val
return(s)
r=int(input())
b=input().split()
def g (f) :
for i in range(len(f)) :
f[i]=int(f[i])
re... | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
def sr(s):
for i in range(1, len(s)):
val = s[i]
j = i - 1
while (j >= 0) and (s[j] > val):
s[j+1] = s[j]
j = j - 1
s[j+1] = val
return(s)
r=int(input())
b=input().split()
def g (f) :
for i in range(len(f)) :
f[i]=int(f[i... | 0 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,607,939,267 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | n = int(input())
a = input().split(' ')
b = set(a)
s = []
for i in b:
s.append(a.count(i))
print(max(s)) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n = int(input())
a = input().split(' ')
b = set(a)
s = []
for i in b:
s.append(a.count(i))
print(max(s))
``` | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,679,390,246 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 154 | 2,867,200 | import string
k = int(input())
s = input()
res = ""
a = list(string.ascii_lowercase)
for c in a:
if s.count(c) % k != 0:
print(-1)
exit(0)
if s.count(c) != 0:
res += c
print(res*k)
| Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
import string
k = int(input())
s = input()
res = ""
a = list(string.ascii_lowercase)
for c in a:
if s.count(c) % k != 0:
print(-1)
exit(0)
if s.count(c) != 0:
res += c
print(res*k)
``` | 0 | |
1,006 | A | Adjacent Replacements | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occu... | The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) — the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. | Print $n$ integers — $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. | [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
] | [
"1 1 3 5 9\n",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "5\n1 2 4 5 10",
"output": "1 1 3 5 9"
},
{
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000",
"output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"
},
{
"input": "1\n999999999",
"output": "999999999"
},
{
"input": "1\n1000000000",... | 1,645,812,947 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 18 | 62 | 2,457,600 | input()
print(*[x-1 if x%2 == 0 else x for x in map(int, input().split())]) | Title: Adjacent Replacements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace... | ```python
input()
print(*[x-1 if x%2 == 0 else x for x in map(int, input().split())])
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,642,213,999 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 122 | 0 | t = input()
x = t.replace(" ","")
vowel = "aeiouyAEIOUY"
if x[-2] in vowel:
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
t = input()
x = t.replace(" ","")
vowel = "aeiouyAEIOUY"
if x[-2] in vowel:
print("YES")
else:
print("NO")
``` | 3.9695 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,699,796,150 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | s = input()
# Check if Caps Lock is turned on
if s.isupper() or (s[0].islower() and s[1:].isupper()):
result = s.lower()
else:
result = s
# Print the resulting string
print(result)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
s = input()
# Check if Caps Lock is turned on
if s.isupper() or (s[0].islower() and s[1:].isupper()):
result = s.lower()
else:
result = s
# Print the resulting string
print(result)
``` | 0 | |
8 | B | Obsession with Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | B. Obsession with Robots | 2 | 64 | The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ... | The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. | In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). | [
"LLUUUR\n",
"RRUULLDD\n"
] | [
"OK\n",
"BUG\n"
] | none | 0 | [
{
"input": "LLUUUR",
"output": "OK"
},
{
"input": "RRUULLDD",
"output": "BUG"
},
{
"input": "L",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "R",
"output": "OK"
},
{
"input": "RR",
"output": "OK"
},
{
"input": "DL",
"... | 1,666,009,543 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | from collections import deque
path = input()
coord = set((0,0)); temp = (0,0)
for c in path:
if c=='L': temp = (temp[0],temp[1]-1)
elif c=='R': temp = (temp[0],temp[1]+1)
elif c=='U': temp = (temp[0]-1,temp[1])
else: temp = (temp[0]+1,temp[1])
if temp in coord: print('BUG'); exit()
coor... | Title: Obsession with Robots
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr... | ```python
from collections import deque
path = input()
coord = set((0,0)); temp = (0,0)
for c in path:
if c=='L': temp = (temp[0],temp[1]-1)
elif c=='R': temp = (temp[0],temp[1]+1)
elif c=='U': temp = (temp[0]-1,temp[1])
else: temp = (temp[0]+1,temp[1])
if temp in coord: print('BUG'); exit()... | -1 |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,644,907,854 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | n=int(input())
t=[]
for i in range(n):
x=input()
t.append(x)
for j in range(len(t)):
if j==0:
print("NO")
else:
for k in range(j):
if t[j]==t[k]:
print("YES")
break
else:
print("NO")
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
n=int(input())
t=[]
for i in range(n):
x=input()
t.append(x)
for j in range(len(t)):
if j==0:
print("NO")
else:
for k in range(j):
if t[j]==t[k]:
print("YES")
break
else:
print("NO")
... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,695,171,954 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 61 | 0 | a = str(input())
b = str(input())
c = ""
i = 0
while i < len(a):
while i < len(b):
if a[i] == b[i]:
c+="0"
i+=1
elif a[i] != b[i]:
c+="1"
i+=1
print(c)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a = str(input())
b = str(input())
c = ""
i = 0
while i < len(a):
while i < len(b):
if a[i] == b[i]:
c+="0"
i+=1
elif a[i] != b[i]:
c+="1"
i+=1
print(c)
``` | 3.98475 |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,562,657,582 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 108 | 0 | s1=input()
s2=input()
new_c=0;new_s=''
for i in range(len(s1)):
if s1[i] != s2[i]:
new_c=(ord(s1[i])+ord(s2[i]))//2 if (ord(s1[i])+ord(s2[i]))//2 != ord(s1[i]) else 0
break
if new_c != 0:
new_s = s1[:i] + chr(new_c) + s1[i+1:]
else:
new_s = 'No such string'
print(new_s) | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s1=input()
s2=input()
new_c=0;new_s=''
for i in range(len(s1)):
if s1[i] != s2[i]:
new_c=(ord(s1[i])+ord(s2[i]))//2 if (ord(s1[i])+ord(s2[i]))//2 != ord(s1[i]) else 0
break
if new_c != 0:
new_s = s1[:i] + chr(new_c) + s1[i+1:]
else:
new_s = 'No such string'
print(new_s)
... | 0 | |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) — the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number — the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,699,368,988 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 31 | 0 | n,k = map(int,input().split())
while k > 0:
s = str(n)
if s[-1] == "0":
n = int(n / 10)
else:
n = int(n - 1)
k -= 1
print (n) | Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
n,k = map(int,input().split())
while k > 0:
s = str(n)
if s[-1] == "0":
n = int(n / 10)
else:
n = int(n - 1)
k -= 1
print (n)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,605,558,074 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 216 | 0 | #перевод
t=list(input())
s=list(reversed(list(input())))
if t==s:
print('YES')
else:
print('NO') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
#перевод
t=list(input())
s=list(reversed(list(input())))
if t==s:
print('YES')
else:
print('NO')
``` | 3.946 |
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,005,429 | 529 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 62 | 5,632,000 | n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1,n):
if a[i] - a[i - 1] > k:
print(-1)
exit()
ans = 1
now = 0
for i in range(n):
if a[i] - a[now] >= k:
ans += 1
now = i
print(ans)
| Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1,n):
if a[i] - a[i - 1] > k:
print(-1)
exit()
ans = 1
now = 0
for i in range(n):
if a[i] - a[now] >= k:
ans += 1
now = i
print(ans)
``` | 0 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,698,765,718 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 124 | 0 | _, leng = map(int, input().split())
numbs = map(int, input().split())
for numb in sorted(numbs, reverse=True):
if leng % numb == 0:
print(leng // numb)
break | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
_, leng = map(int, input().split())
numbs = map(int, input().split())
for numb in sorted(numbs, reverse=True):
if leng % numb == 0:
print(leng // numb)
break
``` | 3 | |
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,685,621,393 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 202 | 0 | n = int(input())
cmp = -1000000030
tree = 0
t_x = 0
while n > 0:
x, h = map(int, input().split())
# First try to cut the tree down at the left, at [x-h,x]
if x - h > cmp:
cmp = x
tree += 1
# If not possible, try cutting it down at the right, at [x,x+h]
elif x > cmp:
... | 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())
cmp = -1000000030
tree = 0
t_x = 0
while n > 0:
x, h = map(int, input().split())
# First try to cut the tree down at the left, at [x-h,x]
if x - h > cmp:
cmp = x
tree += 1
# If not possible, try cutting it down at the right, at [x,x+h]
elif... | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,691,170,381 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | a = input().strip('{').strip('}').replace(',', '').split()
c = 0
b = []
for elem in a:
if elem not in b:
c += 1
b.append(elem)
print(c) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a = input().strip('{').strip('}').replace(',', '').split()
c = 0
b = []
for elem in a:
if elem not in b:
c += 1
b.append(elem)
print(c)
``` | 3 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest in... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000... | 1,583,257,131 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | a = int(input())
b = int(input())
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
print(a + b) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
a = int(input())
b = int(input())
while a != 0 and b != 0:
if a > b:
a = a % b
else:
b = b % a
print(a + b)
``` | -1 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,572,088,962 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 372 | 1,126,400 | from fractions import Fraction
x,y=[int(a) for a in input().split()]
if x>y:
l=7-x
else:
l=7-y
k=Fraction(l/6)
if l==6:
print("1/1")
else:
print(k) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
x,y=[int(a) for a in input().split()]
if x>y:
l=7-x
else:
l=7-y
k=Fraction(l/6)
if l==6:
print("1/1")
else:
print(k)
``` | 0 |
689 | C | Mike and Chocolate Thieves | PROGRAMMING | 1,700 | [
"binary search",
"combinatorics",
"math"
] | null | null | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous... | The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say. | Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1. | [
"1\n",
"8\n",
"10\n"
] | [
"8\n",
"54\n",
"-1\n"
] | In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the po... | 1,500 | [
{
"input": "1",
"output": "8"
},
{
"input": "8",
"output": "54"
},
{
"input": "10",
"output": "-1"
},
{
"input": "27",
"output": "152"
},
{
"input": "28206",
"output": "139840"
},
{
"input": "32",
"output": "184"
},
{
"input": "115",
"o... | 1,468,053,132 | 6,072 | PyPy 3 | OK | TESTS | 54 | 1,247 | 17,305,600 | n = int(input())
l, r = 0, 10**16
D = [x ** 3.0 for x in range(2, 170417)]
DD = [x*x*x for x in range(2, 170417)]
while l < r:
m = (l+r) // 2
if sum(int(m/d) for d in D) < n:
l = m + 1
else:
r = m;
if sum(l//d for d in DD) == n:
print(l);
else :
print(-1);
| Title: Mike and Chocolate Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thi... | ```python
n = int(input())
l, r = 0, 10**16
D = [x ** 3.0 for x in range(2, 170417)]
DD = [x*x*x for x in range(2, 170417)]
while l < r:
m = (l+r) // 2
if sum(int(m/d) for d in D) < n:
l = m + 1
else:
r = m;
if sum(l//d for d in DD) == n:
print(l);
else :
print(-1);
``... | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,594,123,518 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 30 | 216 | 6,656,000 | n,k=map(int,input().split())
a=list(input().split())
d=[]
for i in a:
d1=i.count('4')
d1+=i.count('7')
d.append(d1)
d.sort()
i=n
while(d[i-1]>k):
i-=1
print(i) | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n,k=map(int,input().split())
a=list(input().split())
d=[]
for i in a:
d1=i.count('4')
d1+=i.count('7')
d.append(d1)
d.sort()
i=n
while(d[i-1]>k):
i-=1
print(i)
``` | -1 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,695,120,761 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | n = int(input())
def is_happy(a: int) -> bool:
r = a % 10
happy = True
while a != 0:
if r != 4 and r != 7:
happy = False
a = a // 10
r = a % 10
return happy
semi_happy = False
for num in range(1, n + 1):
if is_happy(num) and n % num == 0:
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
def is_happy(a: int) -> bool:
r = a % 10
happy = True
while a != 0:
if r != 4 and r != 7:
happy = False
a = a // 10
r = a % 10
return happy
semi_happy = False
for num in range(1, n + 1):
if is_happy(num) and n % num == 0:... | 3 | |
535 | A | Tavas and Nafas | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words.
He ate coffee mix without... | The first and only line of input contains an integer *s* (0<=≤<=*s*<=≤<=99), Tavas's score. | In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. | [
"6\n",
"99\n",
"20\n"
] | [
"six\n",
"ninety-nine\n",
"twenty\n"
] | You can find all you need to know about English numerals in [http://en.wikipedia.org/wiki/English_numerals](https://en.wikipedia.org/wiki/English_numerals) . | 500 | [
{
"input": "6",
"output": "six"
},
{
"input": "99",
"output": "ninety-nine"
},
{
"input": "20",
"output": "twenty"
},
{
"input": "10",
"output": "ten"
},
{
"input": "15",
"output": "fifteen"
},
{
"input": "27",
"output": "twenty-seven"
},
{
... | 1,584,433,562 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 2,150,400 | n = input()
ans = 0
dict = {'4' : 1, '7' : 2}
for i in n:
ans = ans * 2 + dict[i]
print(ans)
| Title: Tavas and Nafas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score wit... | ```python
n = input()
ans = 0
dict = {'4' : 1, '7' : 2}
for i in n:
ans = ans * 2 + dict[i]
print(ans)
``` | -1 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,663,339,455 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 1,331,200 | n,m,a= list(map(int,input().split()))
i = 1
j = 1
while a*i < n:
i += 1
while a*j < m:
j += 1
print(i*j) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a= list(map(int,input().split()))
i = 1
j = 1
while a*i < n:
i += 1
while a*j < m:
j += 1
print(i*j)
``` | 0 |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,648,213,903 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 3,379,200 | from math import *
def mdc(num1, num2):
rest = None
if(num1 == num2):
return int(num1/2)
while (rest != 0):
rest = num1 % num2
num1 = num2
num2 = rest
return num1
a,b,c = map(int,input().split())
lado1 = mdc(a,b)
#print(lado1)
lado2 = mdc(a,c)
#pr... | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
from math import *
def mdc(num1, num2):
rest = None
if(num1 == num2):
return int(num1/2)
while (rest != 0):
rest = num1 % num2
num1 = num2
num2 = rest
return num1
a,b,c = map(int,input().split())
lado1 = mdc(a,b)
#print(lado1)
lado2 = mdc... | -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.