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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
132 | A | Turing Tape | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using the following method.
The integers of the array are processed one ... | The input will consist of a single line *text* which contains the message printed using the described method. String *text* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *text* will be between 32 (space) and 126 (tilde), inclusive. | Output the initial array, which was used to produce *text*, one integer per line. | [
"Hello, World!\n"
] | [
"238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162\n"
] | Let's have a closer look at the beginning of the example. The first character is "H" with ASCII-code 72 = 01001000<sub class="lower-index">2</sub>. Its reverse is 00010010<sub class="lower-index">2</sub> = 18, and this number should become the result of the second step of processing. The result of the first step is con... | 500 | [
{
"input": "Hello, World!",
"output": "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162"
},
{
"input": "N",
"output": "142"
},
{
"input": "!{|aPUBKs[k\"HE;>O&(Nf}N4,*#g*<3sQXFJ'?Z/H9L[xx Rc5\"8~v}84+wv]w[oO0e':MaNy&6*]jRkYomz[o?=13Y?!fzA3eC\\",
"output": "124\n166\n160\n184\n... | 1,634,124,034 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,150,400 | from math import ceil
for _ in range(int(input())):
a,b = map(int,input().split())
print(ceil(a/b)*b-a) | Title: Turing Tape
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence ... | ```python
from math import ceil
for _ in range(int(input())):
a,b = map(int,input().split())
print(ceil(a/b)*b-a)
``` | -1 | |
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be perfo... | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espr... | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81... | 1,553,590,591 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | a,b,xx,yy=[int(i) for i in input().split()]
x,y=[int(i) for i in input().split()]
xx-=a
yy-=b
if x==1 and xx%2==0:
print("NO")
exit(0)
elif y==1 and yy%2==0:
print("NO")
exit(0)
if xx%x==0 and yy%y==0 or xx%(2*x)==0 and yy%(2*y)==0:
print("YES")
else:
print("NO")
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with... | ```python
a,b,xx,yy=[int(i) for i in input().split()]
x,y=[int(i) for i in input().split()]
xx-=a
yy-=b
if x==1 and xx%2==0:
print("NO")
exit(0)
elif y==1 and yy%2==0:
print("NO")
exit(0)
if xx%x==0 and yy%y==0 or xx%(2*x)==0 and yy%(2*y)==0:
print("YES")
else:
print("NO")
... | 0 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,660,051,803 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 124 | 409,600 | from collections import defaultdict, deque
n = int(input())
adj_list = defaultdict(list)
for i in range(1, n+1):
cur = int(input())
adj_list[cur].append(i)
q = deque(adj_list[-1])
level = 0
ans = 0
while q:
size = len(q)
ans = max(ans, size)
level+=1
for i_ in range(size):
... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
from collections import defaultdict, deque
n = int(input())
adj_list = defaultdict(list)
for i in range(1, n+1):
cur = int(input())
adj_list[cur].append(i)
q = deque(adj_list[-1])
level = 0
ans = 0
while q:
size = len(q)
ans = max(ans, size)
level+=1
for i_ in range(... | 3 | |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,578,794,664 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 109 | 512,000 | n=int(input())
if n==1:
print('Sheldon')
elif n==2:
print('Leonard')
elif n==3:
print('Penny')
elif n==4:
print('Rajesh')
elif n==5:
print('Howard')
else:
s=5
i=1
while True:
m=2**i
if n<=s+m:
print('Sheldon')
break
elif ... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n=int(input())
if n==1:
print('Sheldon')
elif n==2:
print('Leonard')
elif n==3:
print('Penny')
elif n==4:
print('Rajesh')
elif n==5:
print('Howard')
else:
s=5
i=1
while True:
m=2**i
if n<=s+m:
print('Sheldon')
break
... | 3.944546 |
837 | A | Text Volume | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text. | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text.
The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. | Print one integer number — volume of text. | [
"7\nNonZERO\n",
"24\nthis is zero answer text\n",
"24\nHarbour Space University\n"
] | [
"5\n",
"0\n",
"1\n"
] | In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters. | 0 | [
{
"input": "7\nNonZERO",
"output": "5"
},
{
"input": "24\nthis is zero answer text",
"output": "0"
},
{
"input": "24\nHarbour Space University",
"output": "1"
},
{
"input": "2\nWM",
"output": "2"
},
{
"input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWd... | 1,553,526,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | input()
S= input()
an=0
for s in S:
if ord(s) >= 65 and ord(s) <= 90:
an += 1
print(an) | Title: Text Volume
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the tex... | ```python
input()
S= input()
an=0
for s in S:
if ord(s) >= 65 and ord(s) <= 90:
an += 1
print(an)
``` | 0 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,590,593,635 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 0 | n=int(input())
a=[int(i) for i in input().split()]
b=list(set(a))
c=[]
d=[]
for i in range(n):
c.append(a.count(a[i]))
for i in range(n):
d.append(a[i]*c[i])
m=max(d)
p=d.index(m)
print(c[p],len(b)) | 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())
a=[int(i) for i in input().split()]
b=list(set(a))
c=[]
d=[]
for i in range(n):
c.append(a.count(a[i]))
for i in range(n):
d.append(a[i]*c[i])
m=max(d)
p=d.index(m)
print(c[p],len(b))
``` | 0 |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,498,808,311 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 5,529,600 | s=input()
l=len(s)
x,c=0,0
for i in range(0,l-1):
w=s[i:i+2]
if w=="VK":
x+=1
if w=="VV" or w=="KK":
c+=1
for i in range(0,l-2):
w=s[i:i+3]
if w=="VKK" or w=="KKV" or w=="VVK" or w=="KVV":
c-=1
if c>0:
x+=1
print(x)
| Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s=input()
l=len(s)
x,c=0,0
for i in range(0,l-1):
w=s[i:i+2]
if w=="VK":
x+=1
if w=="VV" or w=="KK":
c+=1
for i in range(0,l-2):
w=s[i:i+3]
if w=="VKK" or w=="KKV" or w=="VVK" or w=="KVV":
c-=1
if c>0:
x+=1
print(x)
``` | 0 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,510,088,583 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 2,000 | 614,400 | n,d=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in range(n):
j=0
while(j<n and l[j]<=l[i]+d):
j+=1
ans+=((j-i-1)*(j-i-2)//2)
print(ans) | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n,d=map(int,input().split())
l=list(map(int,input().split()))
ans=0
for i in range(n):
j=0
while(j<n and l[j]<=l[i]+d):
j+=1
ans+=((j-i-1)*(j-i-2)//2)
print(ans)
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,057,290 | 3,690 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 |
w = input()
if w != 2 and (w % 2) == 0:
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
w = input()
if w != 2 and (w % 2) == 0:
print("YES")
else:
print("NO")
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted... | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct... | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu... | 0 | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2... | 1,575,122,769 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 186 | 1,843,200 | from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
n = int(input())
y = int(input())
z = y
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if(1 in a or 1 in b):
print(-1)
exit(0)
for i in range(n):
x = y/(a[i]-1)
y += x
for i in range(n):
x ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will... | ```python
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
n = int(input())
y = int(input())
z = y
a = list(map(int,input().split()))
b = list(map(int,input().split()))
if(1 in a or 1 in b):
print(-1)
exit(0)
for i in range(n):
x = y/(a[i]-1)
y += x
for i in rang... | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,613,320,250 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | while True:
if len(x) == 1:
if x[0] == n:
print(90)
break
elif x[0] != n:
if x[0] > 15
print(15)
break
else:
print(x[0] + 15)
elif x[0] > 15:
break
print(15)
b = False
break
elif x[i+1] - x[i] >= 15:
print(x[i] + 15)
b... | Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
while True:
if len(x) == 1:
if x[0] == n:
print(90)
break
elif x[0] != n:
if x[0] > 15
print(15)
break
else:
print(x[0] + 15)
elif x[0] > 15:
break
print(15)
b = False
break
elif x[i+1] - x[i] >= 15:
print(x[i] + ... | -1 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,650,624,863 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n = int(input())
h = []
m = []
for i in range(n):
a, b = map(int, input().split())
h.append(a)
m.append(b)
k = 1
for i in range(n-1):
if h[i] == h[i+1]:
if m[i] == m[i+1]:
k = k+1
print(k) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
h = []
m = []
for i in range(n):
a, b = map(int, input().split())
h.append(a)
m.append(b)
k = 1
for i in range(n-1):
if h[i] == h[i+1]:
if m[i] == m[i+1]:
k = k+1
print(k)
``` | 0 | |
915 | C | Permute Digits | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | null | null | You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allowed to leave *a* as it is. | The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. | Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. | [
"123\n222\n",
"3921\n10000\n",
"4940\n5000\n"
] | [
"213\n",
"9321\n",
"4940\n"
] | none | 0 | [
{
"input": "123\n222",
"output": "213"
},
{
"input": "3921\n10000",
"output": "9321"
},
{
"input": "4940\n5000",
"output": "4940"
},
{
"input": "23923472834\n23589234723",
"output": "23498743322"
},
{
"input": "102391019\n491010301",
"output": "399211100"
},... | 1,623,065,740 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | a = list(map(int, input()))
l = sorted(a)
l.reverse()
b = int(input())
otv = '0' * len(a)
for i in range(len(a)):
g = int(otv[0:i] + str(l[i]) + otv[i + 1:])
if int(otv[0:i] + str(l[i]) + otv[i + 1:]) > b:
c = 0
while int(otv[0:i] + str(l[c]) + otv[i + 1:]) > b:
c += 1
... | Title: Permute Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0.
It is allow... | ```python
a = list(map(int, input()))
l = sorted(a)
l.reverse()
b = int(input())
otv = '0' * len(a)
for i in range(len(a)):
g = int(otv[0:i] + str(l[i]) + otv[i + 1:])
if int(otv[0:i] + str(l[i]) + otv[i + 1:]) > b:
c = 0
while int(otv[0:i] + str(l[c]) + otv[i + 1:]) > b:
c... | 0 | |
988 | A | Diverse Team | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct.
If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES"... | The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) — the number of students and the size of the team you have to form.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. | If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If t... | [
"5 3\n15 13 15 15 12\n",
"5 4\n15 13 15 15 12\n",
"4 4\n20 10 40 30\n"
] | [
"YES\n1 2 5 \n",
"NO\n",
"YES\n1 2 3 4 \n"
] | All possible answers for the first example:
- {1 2 5} - {2 3 5} - {2 4 5}
Note that the order does not matter. | 0 | [
{
"input": "5 3\n15 13 15 15 12",
"output": "YES\n1 2 5 "
},
{
"input": "5 4\n15 13 15 15 12",
"output": "NO"
},
{
"input": "4 4\n20 10 40 30",
"output": "YES\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "100 53\n16 17 1 2 27 5 9 9 53 24 17... | 1,660,381,198 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n = input().split()
k = int(n[1])
n = int(n[0])
a = input().split()
for i in range(n):
a[i]=int(a[i])
s = set(a)
if(len(s)>=k):
print("YES")
for i in s:
for j in range(len(a)):
if(a[j]==i):
print(j+1,end = " ")
break
else:
... | Title: Diverse Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct... | ```python
n = input().split()
k = int(n[1])
n = int(n[0])
a = input().split()
for i in range(n):
a[i]=int(a[i])
s = set(a)
if(len(s)>=k):
print("YES")
for i in s:
for j in range(len(a)):
if(a[j]==i):
print(j+1,end = " ")
bre... | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,659,556,458 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 92 | 0 | # (n-2) *180 /n = a
# 180 n - 360 = an
# n(180-a) = 360
# n = 360 / (180-a)
t = int(input())
while t:
t-=1
a = int(input())
n = 360 / (180-a)
if(int(n)==n):
print('YES')
else:
print('NO') | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
# (n-2) *180 /n = a
# 180 n - 360 = an
# n(180-a) = 360
# n = 360 / (180-a)
t = int(input())
while t:
t-=1
a = int(input())
n = 360 / (180-a)
if(int(n)==n):
print('YES')
else:
print('NO')
``` | 3 | |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,523,124,283 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 8,396,800 | n,k=map(int,input().split())
import sys
a=list(map(int,sys.stdin.readline().split()))
a.sort()
b=[]
l=0
for i in range(1,k+1):
if i not in a:
if (k-i)>=0:
b.append(i)
k-=i
l+=1
else: break
if k==0:
break
print(l)
print(*b)
| Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
n,k=map(int,input().split())
import sys
a=list(map(int,sys.stdin.readline().split()))
a.sort()
b=[]
l=0
for i in range(1,k+1):
if i not in a:
if (k-i)>=0:
b.append(i)
k-=i
l+=1
else: break
if k==0:
break
print(l)
print(*b)
... | 0 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,697,363,012 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 154 | 1,843,200 | n = int(input())
total = 0
for i in range(n):
nums = input().split()
nums = map(int, nums)
if sum(nums) >= 2:
total += 1
print(total) | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
n = int(input())
total = 0
for i in range(n):
nums = input().split()
nums = map(int, nums)
if sum(nums) >= 2:
total += 1
print(total)
``` | 3 | |
300 | B | Coach | PROGRAMMING | 1,500 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
Before the university programming championship the coach wants to split all students into groups of three. For some pairs of students we know that they want to be on ... | The first line of the input contains integers *n* and *m* (3<=≤<=*n*<=≤<=48, . Then follow *m* lines, each contains a pair of integers *a**i*,<=*b**i* (1<=≤<=*a**i*<=<<=*b**i*<=≤<=*n*) — the pair *a**i*,<=*b**i* means that students with numbers *a**i* and *b**i* want to be on the same team.
It is guaranteed that *n... | If the required division into teams doesn't exist, print number -1. Otherwise, print lines. In each line print three integers *x**i*, *y**i*, *z**i* (1<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=*n*) — the *i*-th team.
If there are multiple answers, you are allowed to print any of them. | [
"3 0\n",
"6 4\n1 2\n2 3\n3 4\n5 6\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"3 2 1 \n",
"-1\n",
"3 2 1 \n"
] | none | 1,000 | [
{
"input": "3 0",
"output": "3 2 1 "
},
{
"input": "6 4\n1 2\n2 3\n3 4\n5 6",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "3 2 1 "
},
{
"input": "6 3\n1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "15 9\n1 4\n1 6\n2 7\n2 11\n4 6\n5 12\n7 11\n9 14\n... | 1,689,230,250 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 312 | 2,252,800 | import sys
from collections import defaultdict
input = sys.stdin.readline
n, m = map(int, input().split())
d = defaultdict(list)
for i in range(m):
u, v = map(int, input().split())
d[u].append(v)
d[v].append(u)
v = [0] * (n + 1)
p = [-1] * (n + 1)
ans = []
al = []
db = []
for i ... | Title: Coach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A programming coach has *n* students to teach. We know that *n* is divisible by 3. Let's assume that all students are numbered from 1 to *n*, inclusive.
Before the university programming championship the coach wants to split all... | ```python
import sys
from collections import defaultdict
input = sys.stdin.readline
n, m = map(int, input().split())
d = defaultdict(list)
for i in range(m):
u, v = map(int, input().split())
d[u].append(v)
d[v].append(u)
v = [0] * (n + 1)
p = [-1] * (n + 1)
ans = []
al = []
db = ... | 3 | |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,684,590,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n = int(input())
i = 1
while (i * (i + 1) * (2 * i + 1)) // 6 <= n:
i += 1
print(i - 1)
| Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
n = int(input())
i = 1
while (i * (i + 1) * (2 * i + 1)) // 6 <= n:
i += 1
print(i - 1)
``` | 0 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,673,970,037 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 77 | 0 | lent =int(input())
b = input()
lst = []
for j in b:
lst.append(j)
ind = lst.index('x')
nu = 0
for i in lst:
lst_s = set(lst)
if len(lst_s) == 1:
nu=lent-2
break
else:
if lst[ind+1] == lst[ind+2] == 'x':
lst.remove('x')
nu +=1
print(nu) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
lent =int(input())
b = input()
lst = []
for j in b:
lst.append(j)
ind = lst.index('x')
nu = 0
for i in lst:
lst_s = set(lst)
if len(lst_s) == 1:
nu=lent-2
break
else:
if lst[ind+1] == lst[ind+2] == 'x':
lst.remove('x')
nu +=1
... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,576,473,152 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s=input()
l=0
u=0
sz=len(s)
for x in s:
if (ord(x)-65)<26:
u+=1
else:
l+=1
if l>=(sz/2):
print(s.lower())
else:
print(s.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
l=0
u=0
sz=len(s)
for x in s:
if (ord(x)-65)<26:
u+=1
else:
l+=1
if l>=(sz/2):
print(s.lower())
else:
print(s.upper())
``` | 3.9455 |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,431,020,972 | 4,772 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 30 | 0 | import sys
def max(n):
if n % 2 == 0: return(int(n**2/2))
else: return(int(n**2/2)+1)
def get(n):
if n == 0:
return("S")
else:
return("L")
n = int(input())
k = int(input())
l = []
m = []
b = 1
count = k
if k > max(n):
print("NO")
sys... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
import sys
def max(n):
if n % 2 == 0: return(int(n**2/2))
else: return(int(n**2/2)+1)
def get(n):
if n == 0:
return("S")
else:
return("L")
n = int(input())
k = int(input())
l = []
m = []
b = 1
count = k
if k > max(n):
print("NO"... | -1 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,588,052,316 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 186 | 8,396,800 | n=int(input())
l=list(map(int,input().split()))
e=[]
o=[]
for i in l:
if i%2==0:
e +=[i]
else:
o +=[i]
if len(o)%2==0:
print(sum(o)+sum(e))
else:
o.sort()
print(sum(e)+sum(o[1:]))
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n=int(input())
l=list(map(int,input().split()))
e=[]
o=[]
for i in l:
if i%2==0:
e +=[i]
else:
o +=[i]
if len(o)%2==0:
print(sum(o)+sum(e))
else:
o.sort()
print(sum(e)+sum(o[1:]))
``` | 3 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,695,786,522 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 5,939,200 | def antonandDanik():
n = int(input())
wonCode = input()
if wonCode.count('A') > wonCode.count('D'):
print("Anton")
elif wonCode.count('A') < wonCode.count('D'):
print("Danik")
else:
print("Friendship")
antonandDanik() | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
def antonandDanik():
n = int(input())
wonCode = input()
if wonCode.count('A') > wonCode.count('D'):
print("Anton")
elif wonCode.count('A') < wonCode.count('D'):
print("Danik")
else:
print("Friendship")
antonandDanik()
``` | 3 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,579,389,922 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 278 | 716,800 |
import re
import sys
stdin = None
with open(0) as file:
stdin = file.read()
DOOR = {"front": 1, "back": 2}
RAIL = { "1": 2, "2": 1}
door, rail = re.findall("(\w+)\n(\d)", stdin)[0]
hand = "L" if DOOR[door] + RAIL[rail] == 3 else "R"
print(door, rail, hand)
| Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
import re
import sys
stdin = None
with open(0) as file:
stdin = file.read()
DOOR = {"front": 1, "back": 2}
RAIL = { "1": 2, "2": 1}
door, rail = re.findall("(\w+)\n(\d)", stdin)[0]
hand = "L" if DOOR[door] + RAIL[rail] == 3 else "R"
print(door, rail, hand)
``` | -1 | |
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,612,327,785 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a = input()
b = input()
c = len(a)
for i in range(0,c):
if (a[i]=="0" and b[i]=="0") or (a[i]=="1" and b[i]=="1":
a[i] = "0"
elif a[i]=="0" and b[i]=="1":
a[i] = "1"
elif a[i]=="1" and b[i]=="0":
a[i] = "1"
print(a)
| 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 = input()
b = input()
c = len(a)
for i in range(0,c):
if (a[i]=="0" and b[i]=="0") or (a[i]=="1" and b[i]=="1":
a[i] = "0"
elif a[i]=="0" and b[i]=="1":
a[i] = "1"
elif a[i]=="1" and b[i]=="0":
a[i] = "1"
print(a)
``` | -1 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,695,334,770 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n,height = map(int,input().split())
h = list(map(int,input().split()))
width=0
for i in range(n):
if h[i]>height:
width+=2
else:
width+=1
print(width) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n,height = map(int,input().split())
h = list(map(int,input().split()))
width=0
for i in range(n):
if h[i]>height:
width+=2
else:
width+=1
print(width)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,598,192,069 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 6,656,000 | a='hello'
b=input()
i=0
for j in range(len(b)):
if(b[j]==a[i]):
i+=1
if(i==len(a)):
break
if(i==len(a)):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
a='hello'
b=input()
i=0
for j in range(len(b)):
if(b[j]==a[i]):
i+=1
if(i==len(a)):
break
if(i==len(a)):
print("YES")
else:
print("NO")
``` | 3.933102 |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,645,914,710 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | days, bowls, dishes = map(int, input().split())
meals = input().split(" ")
wash = 0
for meal in meals:
if int(meal) == 1:
if bowls <= 0:
wash += 1
else:
bowls -= 1
else:
if dishes > 0:
dishes -= 1
elif bowls > 0:
bowls ... | Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
days, bowls, dishes = map(int, input().split())
meals = input().split(" ")
wash = 0
for meal in meals:
if int(meal) == 1:
if bowls <= 0:
wash += 1
else:
bowls -= 1
else:
if dishes > 0:
dishes -= 1
elif bowls > 0:
... | 3 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,668,350,859 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | n=int(input())
a=sorted(list(map(int,input().split())))
mn=10**9
for i in range(n-1):
mn=min(mn,a[i+1]-a[i])
ans=0
for i in range(n-1):
ans+=mn==a[i+1]-a[i]
print(mn,ans) | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
n=int(input())
a=sorted(list(map(int,input().split())))
mn=10**9
for i in range(n-1):
mn=min(mn,a[i+1]-a[i])
ans=0
for i in range(n-1):
ans+=mn==a[i+1]-a[i]
print(mn,ans)
``` | 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,592,314,346 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 307,200 | import math
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
l,r = [int(x) for x in input("").split()]
exists = False
i,j,k = [0,0,0]
for i in range(l, r+1):
for j in range(l, r+1):
for k in range(l, r+1):
if i == j or i == k or j == k:
co... | 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
import math
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
l,r = [int(x) for x in input("").split()]
exists = False
i,j,k = [0,0,0]
for i in range(l, r+1):
for j in range(l, r+1):
for k in range(l, r+1):
if i == j or i == k or j == k:
... | 0 | |
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,697,207,548 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 46 | 102,400 | string = input()
check_ab = string.find("AB")
check_ba = string.find("BA")
if (check_ab != -1 and string.find("BA", check_ab + 2) != -1) or (check_ba != -1 and string.find("AB", check_ba + 2) != -1):
print("YES")
else:
print("NO")
| 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
string = input()
check_ab = string.find("AB")
check_ba = string.find("BA")
if (check_ab != -1 and string.find("BA", check_ab + 2) != -1) or (check_ba != -1 and string.find("AB", check_ba + 2) != -1):
print("YES")
else:
print("NO")
``` | 3 | |
369 | A | Valera and Plates | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can... | The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val... | Print a single integer — the minimum number of times Valera will need to wash a plate/bowl. | [
"3 1 1\n1 2 1\n",
"4 3 1\n1 1 1 1\n",
"3 1 2\n2 2 2\n",
"8 2 2\n1 2 1 2 1 2 1 2\n"
] | [
"1\n",
"1\n",
"0\n",
"4\n"
] | In the first sample Valera will wash a bowl only on the third day, so the answer is one.
In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once.
In the third sample, Valera will have the second type of dish for all... | 500 | [
{
"input": "3 1 1\n1 2 1",
"output": "1"
},
{
"input": "4 3 1\n1 1 1 1",
"output": "1"
},
{
"input": "3 1 2\n2 2 2",
"output": "0"
},
{
"input": "8 2 2\n1 2 1 2 1 2 1 2",
"output": "4"
},
{
"input": "2 100 100\n2 2",
"output": "0"
},
{
"input": "1 1 1\... | 1,552,587,359 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | N, Bowl, Plates = list(map(int, input().split()))
X = list(map(int, input().split()))
Count = 0
for i in range(len(X)):
Plates -= (1 if X[i] == 2 else 0)
Bowl -= (1 if Plates < 0 or X[i] == 1 else 0)
Count += (1 if Bowl < 0 else 0)
print(Count)
| Title: Valera and Plates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a lazy student. He has *m* clean bowls and *k* clean plates.
Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ... | ```python
N, Bowl, Plates = list(map(int, input().split()))
X = list(map(int, input().split()))
Count = 0
for i in range(len(X)):
Plates -= (1 if X[i] == 2 else 0)
Bowl -= (1 if Plates < 0 or X[i] == 1 else 0)
Count += (1 if Bowl < 0 else 0)
print(Count)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th turn, the player whose turn it is selects a prime number smaller than the current number, an... | The input contains a single integer *X*2 (4<=≤<=*X*2<=≤<=106). It is guaranteed that the integer *X*2 is composite, that is, is not prime. | Output a single integer — the minimum possible *X*0. | [
"14\n",
"20\n",
"8192\n"
] | [
"6\n",
"15\n",
"8191\n"
] | In the first test, the smallest possible starting number is *X*<sub class="lower-index">0</sub> = 6. One possible course of the game is as follows:
- Alice picks prime 5 and announces *X*<sub class="lower-index">1</sub> = 10 - Bob picks prime 7 and announces *X*<sub class="lower-index">2</sub> = 14.
In the second ... | 0 | [
{
"input": "14",
"output": "6"
},
{
"input": "20",
"output": "15"
},
{
"input": "8192",
"output": "8191"
},
{
"input": "1000000",
"output": "998677"
},
{
"input": "959806",
"output": "239958"
},
{
"input": "1452",
"output": "1206"
},
{
"inp... | 1,521,493,792 | 5,392 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 639 | 11,059,200 | def find_primes(primes,num):
lis = []
for x in range(2,int(num**0.5)+1):
if num%x == 0 and primes[x] == False:
lis.append(x)
if num%int(num/x) == 0 and primes[int(num/x)] == False:
lis.append(int(num/x))
return lis
def make_prime():
x = [False] * 10 *... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob begin their day with a quick game. They first choose a starting number *X*0<=≥<=3 and try to reach one million by the process described below.
Alice goes first and then they take alternating turns. In the *i*-th tu... | ```python
def find_primes(primes,num):
lis = []
for x in range(2,int(num**0.5)+1):
if num%x == 0 and primes[x] == False:
lis.append(x)
if num%int(num/x) == 0 and primes[int(num/x)] == False:
lis.append(int(num/x))
return lis
def make_prime():
x = [Fal... | -1 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,694,510,768 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | for i in range(5):
a=list(map(int,input().split()))
if 1 in a:
b=a
p=i+1
for m in range(5):
if b[m]==1:
n=m+1
answer=abs(p-3)+abs(n-3)
print(answer)
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
for i in range(5):
a=list(map(int,input().split()))
if 1 in a:
b=a
p=i+1
for m in range(5):
if b[m]==1:
n=m+1
answer=abs(p-3)+abs(n-3)
print(answer)
``` | 3 | |
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,595,853,969 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 6,963,200 | import sys, os.path
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n=int(input())
x=[]
y=[]
z=[]
for i in range(n):
a,b,c=map(int,input().split())
x.append(a)
y.append(b)
z.append(c)
if sum(x)==0 and sum(y)==0 and sum(z)==... | 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
import sys, os.path
if os.path.exists('input.txt'):
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n=int(input())
x=[]
y=[]
z=[]
for i in range(n):
a,b,c=map(int,input().split())
x.append(a)
y.append(b)
z.append(c)
if sum(x)==0 and sum(y)==0 an... | 3.93253 |
79 | B | Colorful Field | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | B. Colorful Field | 2 | 256 | Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
After seeing the field carefully, Ciel found that the crop plants of each cell were planted in f... | In the first line there are four positive integers *n*,<=*m*,<=*k*,<=*t* (1<=≤<=*n*<=≤<=4·104,<=1<=≤<=*m*<=≤<=4·104,<=1<=≤<=*k*<=≤<=103,<=1<=≤<=*t*<=≤<=103), each of which represents the height of the field, the width of the field, the number of waste cells and the number of queries that ask the kind of crop plants in ... | For each query, if the cell is waste, print Waste. Otherwise, print the name of crop plants in the cell: either Carrots or Kiwis or Grapes. | [
"4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1\n"
] | [
"Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots\n"
] | The sample corresponds to the figure in the statement. | 1,000 | [
{
"input": "4 5 5 6\n4 3\n1 3\n3 3\n2 5\n3 2\n1 3\n1 4\n2 3\n2 4\n1 1\n1 1",
"output": "Waste\nGrapes\nCarrots\nKiwis\nCarrots\nCarrots"
},
{
"input": "2 3 2 2\n1 1\n2 2\n2 1\n2 2",
"output": "Grapes\nWaste"
},
{
"input": "31 31 31 4\n4 9\n16 27\n11 29\n8 28\n11 2\n10 7\n22 6\n1 25\n14 8... | 1,685,548,127 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | import sys
from bisect import bisect_left
input = sys.stdin.readline
def solve(n, m, k, t, holes, queries):
holes.sort()
ans = ["Carrots", "Kiwis", "Grapes"]
for q in queries:
idx = bisect_left(holes, q)
if holes[idx] == q:
print("Waste")
continue
... | Title: Colorful Field
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Fox Ciel saw a large field while she was on a bus. The field was a *n*<=×<=*m* rectangle divided into 1<=×<=1 cells. Some cells were wasteland, and other each cell contained crop plants: either carrots or kiwis or grapes.
... | ```python
import sys
from bisect import bisect_left
input = sys.stdin.readline
def solve(n, m, k, t, holes, queries):
holes.sort()
ans = ["Carrots", "Kiwis", "Grapes"]
for q in queries:
idx = bisect_left(holes, q)
if holes[idx] == q:
print("Waste")
con... | 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,636,977,741 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main()
{
int n,e=0,o=0;
cin>>n;
int a[n];
for (int i=0; i<n; i++)
{
cin>>a[i];
if (a[i]%2==0)
{
e++;
}
else
{
o++;
}
}
if (e>o)
{
... | 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
#include <iostream>
using namespace std;
int main()
{
int n,e=0,o=0;
cin>>n;
int a[n];
for (int i=0; i<n; i++)
{
cin>>a[i];
if (a[i]%2==0)
{
e++;
}
else
{
o++;
}
}
if (e>o)
{... | -1 |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,697,969,543 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | # Read the number of soldiers
n = int(input())
# Read the heights of the soldiers
heights = list(map(int, input().split()))
# Initialize variables to count the number of soldiers out of position
out_of_position_start = 0
out_of_position_end = 0
# Initialize variables to keep track of the expected heights f... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
# Read the number of soldiers
n = int(input())
# Read the heights of the soldiers
heights = list(map(int, input().split()))
# Initialize variables to count the number of soldiers out of position
out_of_position_start = 0
out_of_position_end = 0
# Initialize variables to keep track of the expected... | 0 | |
862 | A | Mahmoud and Ehab and the MEX | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX... | The first line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=100, 0<=≤<=*x*<=≤<=100) — the size of the set Dr. Evil owns, and the desired MEX.
The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. | The only line should contain one integer — the minimal number of operations Dr. Evil should perform. | [
"5 3\n0 4 5 6 7\n",
"1 0\n0\n",
"5 0\n1 2 3 4 5\n"
] | [
"2\n",
"1\n",
"0\n"
] | For the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.
For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.
In the third test case the set is already evil. | 500 | [
{
"input": "5 3\n0 4 5 6 7",
"output": "2"
},
{
"input": "1 0\n0",
"output": "1"
},
{
"input": "5 0\n1 2 3 4 5",
"output": "0"
},
{
"input": "10 5\n57 1 47 9 93 37 76 70 78 15",
"output": "4"
},
{
"input": "10 5\n99 98 93 97 95 100 92 94 91 96",
"output": "5"
... | 1,630,861,664 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 6,963,200 | a,mex=map(int,input().split())
c=list(map(int,input().split()))
c=sorted(c)
l=0
i=0
for j in range(a):
if c[j]!=i:
while i+1<mex and c[j]!=i:
l+=1
i+=1
elif c[j]==mex:
l+=1
print(l) | Title: Mahmoud and Ehab and the MEX
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.
Dr. Evil is interested in ... | ```python
a,mex=map(int,input().split())
c=list(map(int,input().split()))
c=sorted(c)
l=0
i=0
for j in range(a):
if c[j]!=i:
while i+1<mex and c[j]!=i:
l+=1
i+=1
elif c[j]==mex:
l+=1
print(l)
``` | 0 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,699,534,617 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | n=int(input())
ans=0
while(n>=100):
n-=100
ans+=1
while(n>=20):
n-=20
ans+=1
while(n>=10):
n-=10
ans+=1
while(n>=5):
n-=5
ans+=1
print(ans+n)
| Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n=int(input())
ans=0
while(n>=100):
n-=100
ans+=1
while(n>=20):
n-=20
ans+=1
while(n>=10):
n-=10
ans+=1
while(n>=5):
n-=5
ans+=1
print(ans+n)
``` | 0 | |
981 | A | Antipalindrome | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2}... | The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. | If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique. | [
"mew\n",
"wuffuw\n",
"qqqqqqqq\n"
] | [
"3\n",
"5\n",
"0\n"
] | "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All sub... | 500 | [
{
"input": "mew",
"output": "3"
},
{
"input": "wuffuw",
"output": "5"
},
{
"input": "qqqqqqqq",
"output": "0"
},
{
"input": "ijvji",
"output": "4"
},
{
"input": "iiiiiii",
"output": "0"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow"... | 1,527,433,118 | 518 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <utility>
std::vector<int> ReadVector(size_t size) {
std::vector<int> vector(size);
for (auto& element : vector) {
std::cin >>... | Title: Antipalindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" ar... | ```python
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <utility>
std::vector<int> ReadVector(size_t size) {
std::vector<int> vector(size);
for (auto& element : vector) {
s... | -1 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,649,816,335 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | start = input().strip()
end = input().strip()
start = [{"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8}[start[0]], int(start[1])]
end = [{"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8}[end[0]], int(end[1])]
print(max(abs(start[0]-end[0]), abs(start[1]-end[1])), end="")
while start != end:
... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
start = input().strip()
end = input().strip()
start = [{"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8}[start[0]], int(start[1])]
end = [{"a":1, "b":2, "c":3, "d":4, "e":5, "f":6, "g":7, "h":8}[end[0]], int(end[1])]
print(max(abs(start[0]-end[0]), abs(start[1]-end[1])), end="")
while start ... | 3.954 |
961 | B | Lecture Sleep | PROGRAMMING | 1,200 | [
"data structures",
"dp",
"implementation",
"two pointers"
] | null | null | Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during ... | The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake.
The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theore... | Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. | [
"6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n"
] | [
"16\n"
] | In the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16. | 0 | [
{
"input": "6 3\n1 3 5 2 5 4\n1 1 0 1 0 0",
"output": "16"
},
{
"input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0",
"output": "30000"
},
{
"input": "3 3\n10 10 10\n1 1 0",
"output": "30"
},
{
"input": "1 1\n423\n0",
"output": "423"
},
{
"input": "6 6\n1 3 5 2 5 4... | 1,586,485,640 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 7,065,600 | time_lecture, awake_time = [int(num) for num in input().split()]
theorems = [int(num) for num in input().split()]
awakeness = [int(num) for num in input().split()]
written = 0
maximum = 0
val_theorems = [theorems[i] if awakeness[i] == 1 else 0 for i in range(len(theorems))]
written = sum(val_theorems)
val_theorems =... | Title: Lecture Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for al... | ```python
time_lecture, awake_time = [int(num) for num in input().split()]
theorems = [int(num) for num in input().split()]
awakeness = [int(num) for num in input().split()]
written = 0
maximum = 0
val_theorems = [theorems[i] if awakeness[i] == 1 else 0 for i in range(len(theorems))]
written = sum(val_theorems)
val_... | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,695,844,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def prime_checker(n):
if n == 1 or n == 0:
return f"{n} is not a prime number"
prime = True
for i in range(2, n):
if n%i == 0:
prime = False
break
return prime
n = int(input())
if n%2 == 0:
print(int(n/2))
print("2 " * int(n/2))
else... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
def prime_checker(n):
if n == 1 or n == 0:
return f"{n} is not a prime number"
prime = True
for i in range(2, n):
if n%i == 0:
prime = False
break
return prime
n = int(input())
if n%2 == 0:
print(int(n/2))
print("2 " * int(n... | 0 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,673,756,284 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | l=list(input())
count=0
ans=26+25
for i in range(len(l)-1):
if l[i]==l[i+1]:
# coun
ans+=25
if l[i]!=l[i+1]:
count+=1
ans+=25
print(ans) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
l=list(input())
count=0
ans=26+25
for i in range(len(l)-1):
if l[i]==l[i+1]:
# coun
ans+=25
if l[i]!=l[i+1]:
count+=1
ans+=25
print(ans)
``` | 3 | |
115 | A | Party | PROGRAMMING | 900 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true:
- Employee *A* is the immedi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees.
The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate... | Print a single integer denoting the minimum number of groups that will be formed in the party. | [
"5\n-1\n1\n2\n1\n-1\n"
] | [
"3\n"
] | For the first example, three groups are sufficient, for example:
- Employee 1 - Employees 2 and 4 - Employees 3 and 5 | 500 | [
{
"input": "5\n-1\n1\n2\n1\n-1",
"output": "3"
},
{
"input": "4\n-1\n1\n2\n3",
"output": "4"
},
{
"input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11",
"output": "4"
},
{
"input": "6\n-1\n-1\n2\n3\n1\n1",
"output": "3"
},
{
"input": "3\n-1\n1\n1",
"output": ... | 1,696,808,609 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 746 | 0 | n = int(input())
parent = [int(input()) for _ in range(n)]
depth = [0] * n
for i in range(n):
d = 0
j = i
while parent[j] != -1 and depth[j] == 0:
j = parent[j] - 1
d += 1
depth[i] = depth[j] + d
print(max(depth)+1)
| Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an... | ```python
n = int(input())
parent = [int(input()) for _ in range(n)]
depth = [0] * n
for i in range(n):
d = 0
j = i
while parent[j] != -1 and depth[j] == 0:
j = parent[j] - 1
d += 1
depth[i] = depth[j] + d
print(max(depth)+1)
``` | 3 | |
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,586,357,367 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 0 |
k = int(input())
parentlist = []
for i in range(0, k):
parentlist.append([int(x) for x in input().split()])
summ = [sum(x) for x in zip(*parentlist)]
if sum(summ) == 0:
print('YES'.strip(''))
else:
print('NO'.strip(''))
# print(summ)
# flatten_list = list(chain.from_iterable(parentlist))
# summ = sum... | 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
k = int(input())
parentlist = []
for i in range(0, k):
parentlist.append([int(x) for x in input().split()])
summ = [sum(x) for x in zip(*parentlist)]
if sum(summ) == 0:
print('YES'.strip(''))
else:
print('NO'.strip(''))
# print(summ)
# flatten_list = list(chain.from_iterable(parentlist))
# ... | 0 |
18 | C | Stripe | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | C. Stripe | 2 | 64 | Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece, ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) — amount of squares in the stripe. The second line contains *n* space-separated numbers — they are the numbers written in the squares of the stripe. These numbers are integer and do not exceed 10000 in absolute value. | Output the amount of ways to cut the stripe into two non-empty pieces so that the sum of numbers from one piece is equal to the sum of numbers from the other piece. Don't forget that it's allowed to cut the stripe along the squares' borders only. | [
"9\n1 5 -6 7 9 -16 0 -2 2\n",
"3\n1 1 1\n",
"2\n0 0\n"
] | [
"3\n",
"0\n",
"1\n"
] | none | 0 | [
{
"input": "9\n1 5 -6 7 9 -16 0 -2 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "2\n0 0",
"output": "1"
},
{
"input": "4\n100 1 10 111",
"output": "1"
},
{
"input": "10\n0 4 -3 0 -2 2 -3 -3 2 5",
"output": "3"
},
{
"input": "... | 1,638,740,301 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 280 | 11,776,000 | n = int(input())
nums = [int(x) for x in input().split()]
leftsum = 0
left = [0 for _ in range(n)]
for x in range(n):
leftsum += nums[x]
left[x] = leftsum
rightsum = 0
right = [0 for _ in range(n)]
for x in range(n - 1, -1, -1):
rightsum += nums[x]
right[x] = rightsum
# print(left)
# print(right)
count = 0
for i ... | Title: Stripe
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once Bob took a paper stripe of *n* squares (the height of the stripe is 1 square). In each square he wrote an integer number, possibly negative. He became interested in how many ways exist to cut this stripe into two pieces so that ... | ```python
n = int(input())
nums = [int(x) for x in input().split()]
leftsum = 0
left = [0 for _ in range(n)]
for x in range(n):
leftsum += nums[x]
left[x] = leftsum
rightsum = 0
right = [0 for _ in range(n)]
for x in range(n - 1, -1, -1):
rightsum += nums[x]
right[x] = rightsum
# print(left)
# print(right)
count ... | 3.842262 |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,668,140,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | def min_number(x):
return min(x,9-x)
number=input()
array = list(number)
array = map(int,array)
array = list(map(min_number,array))
array = map(str,array)
number=int("".join(array))
print(number)
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
def min_number(x):
return min(x,9-x)
number=input()
array = list(number)
array = map(int,array)
array = list(map(min_number,array))
array = map(str,array)
number=int("".join(array))
print(number)
``` | 0 | |
877 | B | Nikita and string | PROGRAMMING | 1,500 | [
"brute force",
"dp"
] | null | null | One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".
Nikita wants to make... | The first line contains a non-empty string of length not greater than 5<=000 containing only lowercase English letters "a" and "b". | Print a single integer — the maximum possible size of beautiful string Nikita can get. | [
"abba\n",
"bab\n"
] | [
"4",
"2"
] | It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful. | 1,000 | [
{
"input": "abba",
"output": "4"
},
{
"input": "bab",
"output": "2"
},
{
"input": "bbabbbaabbbb",
"output": "9"
},
{
"input": "bbabbbbbaaba",
"output": "10"
},
{
"input": "bbabbbababaa",
"output": "9"
},
{
"input": "aabbaababbab",
"output": "8"
}... | 1,593,282,363 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | strs = input()
numa = 0
numb = 0
numaa = 0
flag = 0
flaga = 0
flagb = 0
flagaa = 0
maxslen = 0
for i in strs:
if flag == 0 and i == "b":
continue
flag = 1
if flaga == 0 and i == "a":
numa += 1
continue
if flagb == 0 and i == "b":
flaga = 1
... | Title: Nikita and string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Nikita found the string containing letters "a" and "b" only.
Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st ... | ```python
strs = input()
numa = 0
numb = 0
numaa = 0
flag = 0
flaga = 0
flagb = 0
flagaa = 0
maxslen = 0
for i in strs:
if flag == 0 and i == "b":
continue
flag = 1
if flaga == 0 and i == "a":
numa += 1
continue
if flagb == 0 and i == "b":
flaga... | 0 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,583,963,878 | 2,147,483,647 | Python 3 | OK | TESTS | 159 | 124 | 307,200 | n = int(input())
l = list(map(int,input().split()))
x = max(l)
y = min(l)
c = 0
t1=0
t2=0
for i in range(n):
if(x==l[i]):
t1 = i
for i in range(n):
if(y==l[i]):
t2 = i
p = [0]*7
p[1] = t1-t2
p[2]= t1- 0
p[3]= n-1-t1
p[4] = t2-t1
p[5] = n-1-t2
p[6] = t2-0
print(max(p))
| Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n = int(input())
l = list(map(int,input().split()))
x = max(l)
y = min(l)
c = 0
t1=0
t2=0
for i in range(n):
if(x==l[i]):
t1 = i
for i in range(n):
if(y==l[i]):
t2 = i
p = [0]*7
p[1] = t1-t2
p[2]= t1- 0
p[3]= n-1-t1
p[4] = t2-t1
p[5] = n-1-t2
p[6] = t2-0
print(max(... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 0 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,619,395,743 | 2,147,483,647 | PyPy 3 | OK | TESTS | 104 | 295 | 10,649,600 | def comparadorDePalavras(palavra1, palavra2):
if(palavra1 == palavra2):
return True
if(len(palavra1) != len(palavra2)):
return False
if(len(palavra1) % 2 == 1):
return False
metade = len(palavra1)//2
palavra1_1 = palavra1[:metade]
palavra2_1 = palavra2[:met... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into t... | ```python
def comparadorDePalavras(palavra1, palavra2):
if(palavra1 == palavra2):
return True
if(len(palavra1) != len(palavra2)):
return False
if(len(palavra1) % 2 == 1):
return False
metade = len(palavra1)//2
palavra1_1 = palavra1[:metade]
palavra2_1 = pal... | 3 | |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkg... | 1,653,991,709 | 2,147,483,647 | Python 3 | OK | TESTS | 168 | 46 | 0 | t = input()
k = len(t) // 2 + 1
p = zip(t[:k], t[-k:][::-1])
u, v = 'AHIMOoTUVvWwXxY', 'bd db pq qp'
s = all(a in u and a == b or a + b in v for a, b in p)
print(['NIE', 'TAK'][s])
| Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h... | ```python
t = input()
k = len(t) // 2 + 1
p = zip(t[:k], t[-k:][::-1])
u, v = 'AHIMOoTUVvWwXxY', 'bd db pq qp'
s = all(a in u and a == b or a + b in v for a, b in p)
print(['NIE', 'TAK'][s])
``` | 3 | |
735 | B | Urbanization | PROGRAMMING | 1,100 | [
"greedy",
"number theory",
"sortings"
] | null | null | Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ... | The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city.
The second line conta... | Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ... | [
"2 1 1\n1 5\n",
"4 2 1\n1 4 2 3\n"
] | [
"6.00000000\n",
"6.50000000\n"
] | In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.
In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class=... | 1,000 | [
{
"input": "2 1 1\n1 5",
"output": "6.00000000"
},
{
"input": "4 2 1\n1 4 2 3",
"output": "6.50000000"
},
{
"input": "3 1 2\n1 2 3",
"output": "4.50000000"
},
{
"input": "10 4 6\n3 5 7 9 12 25 67 69 83 96",
"output": "88.91666667"
},
{
"input": "19 7 12\n1 2 4 8 1... | 1,581,525,219 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 171 | 7,782,400 | I = lambda: map(int, input().split())
_, n1, n2 = I()
A = sorted(I(), reverse=True)
if n1 > n2:
n1, n2 = n2, n1
print(sum(A[:n1])/n1 + sum(A[n1:n1+n2])/n2) | Title: Urbanization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o... | ```python
I = lambda: map(int, input().split())
_, n1, n2 = I()
A = sorted(I(), reverse=True)
if n1 > n2:
n1, n2 = n2, n1
print(sum(A[:n1])/n1 + sum(A[n1:n1+n2])/n2)
``` | 3 | |
630 | B | Moore's Law | PROGRAMMING | 1,200 | [
"math"
] | null | null | The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the observation that the number of transistors in a dense integrated circuit doubles approximately ev... | The only line of the input contains a pair of integers *n* (1000<=≤<=*n*<=≤<=10 000) and *t* (0<=≤<=*t*<=≤<=2 000 000 000) — the number of transistors in the initial time and the number of seconds passed since the initial time. | Output one number — the estimate of the number of transistors in a dence integrated circuit in *t* seconds since the initial time. The relative error of your answer should not be greater than 10<=-<=6. | [
"1000 1000000\n"
] | [
"1011.060722383550382782399454922040\n"
] | none | 0 | [
{
"input": "1000 1000000",
"output": "1011.060722383550382782399454922040"
},
{
"input": "1000 0",
"output": "1000"
},
{
"input": "1000 1",
"output": "1000.000011000"
},
{
"input": "1000 2",
"output": "1000.000022000000121000"
},
{
"input": "10000 3",
"output"... | 1,692,988,126 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 31 | 0 | i = input().split()
n = int(i[0])
t = int(i[1])
print(n * 1.0 *(1.000000011 ** t))
| Title: Moore's Law
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city administration of IT City decided to fix up a symbol of scientific and technical progress in the city's main square, namely an indicator board that shows the effect of Moore's law in real time.
Moore's law is the ... | ```python
i = input().split()
n = int(i[0])
t = int(i[1])
print(n * 1.0 *(1.000000011 ** t))
``` | 3 | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,514,205,715 | 415 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | n, m = map(int, input().split())
def sai():
ao, bo = map(int, input().split())
if ao != 0:
print("NO")
return
for i in range(n-1):
a,b = map(int, input().split())
if a > bo:
print("NO")
return
ao, bo = a, b
if b != m:
p... | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
n, m = map(int, input().split())
def sai():
ao, bo = map(int, input().split())
if ao != 0:
print("NO")
return
for i in range(n-1):
a,b = map(int, input().split())
if a > bo:
print("NO")
return
ao, bo = a, b
if b != m:
... | 0 | |
415 | A | Mashmokh and Lights | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. If Mashmokh pushes button with index *i*, then each light with index not less than *i* that is still turn... | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of the factory lights and the pushed buttons respectively. The next line contains *m* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*).
It is guaranteed that all lights... | Output *n* space-separated integers where the *i*-th number is index of the button that turns the *i*-th light off. | [
"5 4\n4 3 1 2\n",
"5 5\n5 4 3 2 1\n"
] | [
"1 1 3 4 4 \n",
"1 2 3 4 5 \n"
] | In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus bu... | 500 | [
{
"input": "5 4\n4 3 1 2",
"output": "1 1 3 4 4 "
},
{
"input": "5 5\n5 4 3 2 1",
"output": "1 2 3 4 5 "
},
{
"input": "16 11\n8 5 12 10 14 2 6 3 15 9 1",
"output": "1 2 2 2 5 5 5 8 8 8 8 8 8 8 8 8 "
},
{
"input": "79 22\n76 32 48 28 33 44 58 59 1 51 77 13 15 64 49 72 74 21 6... | 1,396,800,313 | 1,513 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
for i in range(m):
num=a[i]
while num<=len(b) and b[num-1]==0:
b[num-1]=a[i]
num+=1
print(b) | Title: Mashmokh and Lights
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to *n*. There are *n* buttons in Mashmokh's room indexed from 1 to *n* as well. ... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
for i in range(m):
num=a[i]
while num<=len(b) and b[num-1]==0:
b[num-1]=a[i]
num+=1
print(b)
``` | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,690,892,374 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 85 | 498 | 14,540,800 | import sys
import math
import statistics
import operator
input = lambda :sys.stdin.readline().rstrip()
output =lambda:sys.stdout()
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
fArray=[0,1]
def fibonacci(n):
if n<=len(fArray):
... | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
import sys
import math
import statistics
import operator
input = lambda :sys.stdin.readline().rstrip()
output =lambda:sys.stdout()
def isPrime(n):
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
fArray=[0,1]
def fibonacci(n):
if n<=len(fArr... | 3 | |
734 | B | Anton and Digits | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each... | The only line of the input contains four integers *k*2, *k*3, *k*5 and *k*6 — the number of digits 2, 3, 5 and 6 respectively (0<=≤<=*k*2,<=*k*3,<=*k*5,<=*k*6<=≤<=5·106). | Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box. | [
"5 1 3 4\n",
"1 1 1 1\n"
] | [
"800\n",
"256\n"
] | In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.
In the second samp... | 750 | [
{
"input": "5 1 3 4",
"output": "800"
},
{
"input": "1 1 1 1",
"output": "256"
},
{
"input": "10 2 1 5",
"output": "320"
},
{
"input": "4 2 7 2",
"output": "576"
},
{
"input": "489 292 127 263",
"output": "41856"
},
{
"input": "9557 5242 1190 7734",
... | 1,693,708,446 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 46 | 0 | a, b, d, e = map(int, input().split())
c = 0
r = [a, d, e]
c += min(r) * 256
a -= min(r)
q = [a, b]
c += min(q) * 32
print(c)
| Title: Anton and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Anton found a box with digits in his room. There are *k*2 digits 2, *k*3 digits 3, *k*5 digits 5 and *k*6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he... | ```python
a, b, d, e = map(int, input().split())
c = 0
r = [a, d, e]
c += min(r) * 256
a -= min(r)
q = [a, b]
c += min(q) * 32
print(c)
``` | 3 | |
284 | B | Cows and Poker Game | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any be... | The first line contains a single integer, *n* (2<=≤<=*n*<=≤<=2·105). The second line contains *n* characters, each either "A", "I", or "F". The *i*-th character is "A" if the *i*-th player's status is "ALLIN", "I" if the *i*-th player's status is "IN", or "F" if the *i*-th player's status is "FOLDED". | The first line should contain a single integer denoting the number of players that can currently show their hands. | [
"6\nAFFAAA\n",
"3\nAFI\n"
] | [
"4\n",
"1\n"
] | In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | 1,000 | [
{
"input": "6\nAFFAAA",
"output": "4"
},
{
"input": "3\nAFI",
"output": "1"
},
{
"input": "3\nFFF",
"output": "0"
},
{
"input": "3\nFIF",
"output": "1"
},
{
"input": "3\nAAA",
"output": "3"
},
{
"input": "3\nIII",
"output": "0"
},
{
"input"... | 1,591,434,195 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 9,728,000 |
a = int(input())
t = list(input())
p=0
for k in range(a):
if t[k]!='F':
if k==0:
if 'I' not in t[k+1:]:
p+=1
elif k==a-1:
if 'I' not in t[0:k]:
p+=1
else:
if 'I' not in t[0:k]:
... | Title: Cows and Poker Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player who... | ```python
a = int(input())
t = list(input())
p=0
for k in range(a):
if t[k]!='F':
if k==0:
if 'I' not in t[k+1:]:
p+=1
elif k==a-1:
if 'I' not in t[0:k]:
p+=1
else:
if 'I' not in t[0:k]:
... | 0 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4) = - 1 + 2 - 3 + 4 = 2
*f*(5) = - 1 + 2 - 3 + 4 - 5 = - 3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,693,496,134 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("Hello 31") | Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
print("Hello 31")
``` | 0 | |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,626,010,779 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | a = int(input())
b = int(input())
c = a + b
A = a // 10
B = b // 10
C = c // 10
if A + B == C:
print("YES")
else:
print("NO")
| Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a = int(input())
b = int(input())
c = a + b
A = a // 10
B = b // 10
C = c // 10
if A + B == C:
print("YES")
else:
print("NO")
``` | 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,695,484,108 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 61 | 1,331,200 | def isPrime(n):
if n == 0 or n == 1:
return True
for i in range(2,n//2+1):
if n % i == 0:
return False
return True
n = int(input())
for i in range(2,n):
if (not isPrime(i)) and (not isPrime(n - i)):
print(i,n-i)
break
| 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
def isPrime(n):
if n == 0 or n == 1:
return True
for i in range(2,n//2+1):
if n % i == 0:
return False
return True
n = int(input())
for i in range(2,n):
if (not isPrime(i)) and (not isPrime(n - i)):
print(i,n-i)
break
``` | 3 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,588,239,657 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 233 | 13,516,800 | # https://codeforces.com/contest/699/problem/A
n = int(input())
particles = input()
positions = map(int, input().split())
temp = None
ans = float('inf')
for p, x in zip(particles, positions):
if temp is None:
if p == "R":
temp = x
else:
if p == "R":
temp... | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
# https://codeforces.com/contest/699/problem/A
n = int(input())
particles = input()
positions = map(int, input().split())
temp = None
ans = float('inf')
for p, x in zip(particles, positions):
if temp is None:
if p == "R":
temp = x
else:
if p == "R":
... | 3 | |
815 | A | Karen and Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy",
"implementation"
] | null | null | On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
... | The first line of input contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), the number of rows and the number of columns in the grid, respectively.
The next *n* lines each contain *m* integers. In particular, the *j*-th integer in the *i*-th of these rows contains *g**i*,<=*j* (0<=≤<=*g**i*,<=*j*<=≤<=500). | If there is an error and it is actually not possible to beat the level, output a single integer -1.
Otherwise, on the first line, output a single integer *k*, the minimum number of moves necessary to beat the level.
The next *k* lines should each contain one of the following, describing the moves in the order they mu... | [
"3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1\n",
"3 3\n0 0 0\n0 1 0\n0 0 0\n",
"3 3\n1 1 1\n1 1 1\n1 1 1\n"
] | [
"4\nrow 1\nrow 1\ncol 4\nrow 3\n",
"-1\n",
"3\nrow 1\nrow 2\nrow 3\n"
] | In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:
In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required... | 500 | [
{
"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1",
"output": "4\nrow 1\nrow 1\ncol 4\nrow 3"
},
{
"input": "3 3\n0 0 0\n0 1 0\n0 0 0",
"output": "-1"
},
{
"input": "3 3\n1 1 1\n1 1 1\n1 1 1",
"output": "3\nrow 1\nrow 2\nrow 3"
},
{
"input": "3 5\n2 4 2 2 3\n0 2 0 0 1\n1 3 1 1... | 1,498,164,128 | 2,147,483,647 | Python 3 | OK | TESTS | 177 | 296 | 7,680,000 | """Ввод размера матрицы"""
nm = [int(s) for s in input().split()]
"""Ввод массива"""
a = []
for i in range(nm[0]):
a.append([int(j) for j in input().split()])
rez=[]
def stroka():
global rez
rez_row=[]
rez_r=0
for i in range(nm[0]):
min_row=501
for j in range(nm[1]... | Title: Karen and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with *n* rows and *m* columns. Each cell originally contains the number 0.
One m... | ```python
"""Ввод размера матрицы"""
nm = [int(s) for s in input().split()]
"""Ввод массива"""
a = []
for i in range(nm[0]):
a.append([int(j) for j in input().split()])
rez=[]
def stroka():
global rez
rez_row=[]
rez_r=0
for i in range(nm[0]):
min_row=501
for j in r... | 3 | |
616 | A | Comparing Two Long Integers | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can r... | The first line contains a non-negative integer *a*.
The second line contains a non-negative integer *b*.
The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if *a*<=<<=*b* and the symbol ">" if *a*<=><=*b*. If the numbers are equal print the symbol "=". | [
"9\n10\n",
"11\n10\n",
"00012345\n12345\n",
"0123\n9\n",
"0123\n111\n"
] | [
"<\n",
">\n",
"=\n",
">\n",
">\n"
] | none | 0 | [
{
"input": "9\n10",
"output": "<"
},
{
"input": "11\n10",
"output": ">"
},
{
"input": "00012345\n12345",
"output": "="
},
{
"input": "0123\n9",
"output": ">"
},
{
"input": "0123\n111",
"output": ">"
},
{
"input": "9\n9",
"output": "="
},
{
... | 1,597,679,769 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 2,000 | 3,788,800 | import sys
x = input()
y = input()
if x == "0" and y == "0000":
print("=")
sys.exit()
a = str(x)
b = str(y)
u = a.lstrip("0")
i = b.lstrip("0")
j = int(u)
k = int(i)
if j > k:
print(">")
elif j < k:
print("<")
elif j == k:
print("=")
else:
print("=") | Title: Comparing Two Long Integers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal.
The input size is very large so don't use th... | ```python
import sys
x = input()
y = input()
if x == "0" and y == "0000":
print("=")
sys.exit()
a = str(x)
b = str(y)
u = a.lstrip("0")
i = b.lstrip("0")
j = int(u)
k = int(i)
if j > k:
print(">")
elif j < k:
print("<")
elif j == k:
print("=")
else:
print("=")
... | 0 | |
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,630,910,824 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 154 | 6,758,400 | n, k = map(int, input().split())
print(sum((x.count('4') + x.count('7')) <= k for x in input().split())) | 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())
print(sum((x.count('4') + x.count('7')) <= k for x in input().split()))
``` | 3 | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,482,258,438 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 92 | 4,608,000 | l=int(input())
a=input()
if l%4!=0:
print('===')
else:
z=a.count('A')
x=a.count('C')
c=a.count('G')
v=a.count('T')
t=l//4
if max(z,x,c,v)>t:
print('===')
else:
while z<t:
a=a[:a.index('?')]+'A'+a[a.index('?')+1:]
z+=1
while ... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
l=int(input())
a=input()
if l%4!=0:
print('===')
else:
z=a.count('A')
x=a.count('C')
c=a.count('G')
v=a.count('T')
t=l//4
if max(z,x,c,v)>t:
print('===')
else:
while z<t:
a=a[:a.index('?')]+'A'+a[a.index('?')+1:]
z+=1
... | 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,673,234,965 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s= input()
t = input()
T= []
new = ""
for i in range (len(s)-1,-1, -1):
T.append(s[i])
for m in T:
new = new + m
if t == new:
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
s= input()
t = input()
T= []
new = ""
for i in range (len(s)-1,-1, -1):
T.append(s[i])
for m in T:
new = new + m
if t == new:
print("YES")
else:
print("NO")
``` | 3.977 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,686,462,752 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
l = [int(x) for x in input().split()]
low = l[0]
high = l[0]
cnt = 0
for i in range(1,n):
if l[i] < low:
cnt += 1
low = l[i]
if l[i] > high:
cnt += 1
high = l[i]
print(cnt) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
l = [int(x) for x in input().split()]
low = l[0]
high = l[0]
cnt = 0
for i in range(1,n):
if l[i] < low:
cnt += 1
low = l[i]
if l[i] > high:
cnt += 1
high = l[i]
print(cnt)
``` | 3 | |
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,541,648,528 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 171 | 1,126,400 | from fractions import gcd
a, b, c = [int(x) for x in input().split()]
for i in range(0, c, a):
if (c - i) % b == 0:
print("Yes")
break
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
from fractions import gcd
a, b, c = [int(x) for x in input().split()]
for i in range(0, c, a):
if (c - i) % b == 0:
print("Yes")
break
else:
print("No")
``` | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,693,530,013 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | inp1=int(input())
#inp1=(2x)+(2b)
#inp1=2(x+b)
if inp1%2==0 and inp1>=4:
print("YES")
else:
print("NO") | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
inp1=int(input())
#inp1=(2x)+(2b)
#inp1=2(x+b)
if inp1%2==0 and inp1>=4:
print("YES")
else:
print("NO")
``` | 3.954 |
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisi... | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"in... | 1,604,049,374 | 2,147,483,647 | Python 3 | OK | TESTS | 98 | 109 | 0 | x=input()
y=x.find('1')
x=x[y:]
y=x.count('0')
if(y>5):
print("YES")
else:
print("NO")
| Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some dig... | ```python
x=input()
y=x.find('1')
x=x[y:]
y=x.count('0')
if(y>5):
print("YES")
else:
print("NO")
``` | 3 | |
105 | E | Lift and Throw | PROGRAMMING | 2,500 | [
"brute force"
] | E. Lift and Throw | 1 | 256 | You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The distance between the positions is the absolute difference between the respective numbers.
Lah... | The first line contains three integers: Laharl's position, his movement range and throwing range. The second and the third lines describe Etna's and Flonne's parameters correspondingly in the similar form. It is guaranteed that the three characters occupy distinct positions. All numbers in the input are between 1 and 1... | Print a single number — the maximum ordinal number of position which either Laharl, Etna or Flonne can reach. | [
"9 3 3\n4 3 1\n2 3 3\n"
] | [
"15"
] | Let us explain how to reach position 15 in the sample.
Initially Laharl occupies position 9, Etna — position 4 and Flonne — position 2.
First Laharl moves to position 6.
Then Flonne moves to position 5 and grabs Etna.
Laharl grabs Flonne and throws to position 9.
Flonne throws Etna to position 12.
Etna moves to p... | 2,500 | [] | 1,689,182,657 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1689182657.646913")# 1689182657.646954 | Title: Lift and Throw
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with 1 from the end of half-line, i. e. 1, 2, 3 and so on. The... | ```python
print("_RANDOM_GUESS_1689182657.646913")# 1689182657.646954
``` | 0 |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,699,204,614 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | q=input()
print((q[0]).upper()+q[1:]) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
q=input()
print((q[0]).upper()+q[1:])
``` | 3 | |
141 | B | Hopscotch | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks... | The only input line contains three integers: *a*, *x*, *y*, where *a* (1<=≤<=*a*<=≤<=100) is the side of the square, *x* and *y* (<=-<=106<=≤<=*x*<=≤<=106,<=0<=≤<=*y*<=≤<=106) are coordinates of the stone. | Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes. | [
"1 0 0\n",
"3 1 1\n",
"3 0 10\n",
"3 0 7\n",
"3 4 0\n"
] | [
"-1\n",
"1\n",
"5\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "1 0 0",
"output": "-1"
},
{
"input": "3 1 1",
"output": "1"
},
{
"input": "3 0 10",
"output": "5"
},
{
"input": "3 0 7",
"output": "-1"
},
{
"input": "3 4 0",
"output": "-1"
},
{
"input": "9 3 2",
"output": "1"
},
{
"input": "10... | 1,684,290,604 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 148 | 248 | 8,908,800 | import sys
from typing import Callable
def get_quadrant_num(height, is_double, x) -> int:
if height < 3:
return height
height -= 2
# Calc number of row below
height_row_below = height - 1
r = 2 + 2 * (height_row_below // 2) + height_row_below // 2 + (2 if height_row_below % 2 != 0 ... | Title: Hopscotch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, loo... | ```python
import sys
from typing import Callable
def get_quadrant_num(height, is_double, x) -> int:
if height < 3:
return height
height -= 2
# Calc number of row below
height_row_below = height - 1
r = 2 + 2 * (height_row_below // 2) + height_row_below // 2 + (2 if height_row_below... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,657,095,613 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | f1 = ceil(n/a)
f2 = ceil(m/a)
print(f1 * f2) | 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
f1 = ceil(n/a)
f2 = ceil(m/a)
print(f1 * f2)
``` | -1 |
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ... | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2... | 1,653,607,130 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 2,150,400 | d = int(input())
n = int(input())
arr = [int(e) for e in input().split()]
t = 0
for i in arr[:-1]:
t += d - i
print(t) | Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any ... | ```python
d = int(input())
n = int(input())
arr = [int(e) for e in input().split()]
t = 0
for i in arr[:-1]:
t += d - i
print(t)
``` | 3 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,587,395,675 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 140 | 0 | def get_natural_sum(n):
return n * (n+1) // 2
a = int(input())
b = int(input())
n1, n2 = max(a, b), min(a, b)
dist_a = (n1 - n2) // 2
dist_b = (n1 - n2) - dist_a
print(get_natural_sum(dist_a) + get_natural_sum(dist_b)) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
def get_natural_sum(n):
return n * (n+1) // 2
a = int(input())
b = int(input())
n1, n2 = max(a, b), min(a, b)
dist_a = (n1 - n2) // 2
dist_b = (n1 - n2) - dist_a
print(get_natural_sum(dist_a) + get_natural_sum(dist_b))
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,595,951,672 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 216 | 6,656,000 | n,m=tuple(map(int,input().split()))
def check_prime(n):
for i in range(2,n//2+1):
if n%i==0:
return False
return True
x=n+1
while True:
if check_prime(x):
break
x+=1
if m==x:
print("YES")
else:
print("NO")
| Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,m=tuple(map(int,input().split()))
def check_prime(n):
for i in range(2,n//2+1):
if n%i==0:
return False
return True
x=n+1
while True:
if check_prime(x):
break
x+=1
if m==x:
print("YES")
else:
print("NO")
``` | 3.933602 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,696,585,536 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 184 | 1,843,200 | a = int(input())
d = []
for i in range(a):
t = input()
d.append(t)
s = 0
for j in range(len(d)):
if "1 0 1" in d[j] or "1 1 0" in d[j] or "0 1 1" in d[j] or "1 1 1" in d[j]:
s+=1
print(s)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
a = int(input())
d = []
for i in range(a):
t = input()
d.append(t)
s = 0
for j in range(len(d)):
if "1 0 1" in d[j] or "1 1 0" in d[j] or "0 1 1" in d[j] or "1 1 1" in d[j]:
s+=1
print(s)
``` | 3 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,617,298,594 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | d1, d2, d3 = map(int, input().split())
print(min((d1+d2)<<1, d1+d2+d3))
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1, d2, d3 = map(int, input().split())
print(min((d1+d2)<<1, d1+d2+d3))
``` | 0 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,590,953,215 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 0 | a1a2 = input().split()
a1 = int(a1a2[0])
a2 = int(a1a2[1])
count = 0
while a1>0 and a2>0:
if a1<=a2:
a1 += 1
a2 -= 2
else:
a2 += 1
a1 -= 2
count += 1
print(count)
| Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a1a2 = input().split()
a1 = int(a1a2[0])
a2 = int(a1a2[1])
count = 0
while a1>0 and a2>0:
if a1<=a2:
a1 += 1
a2 -= 2
else:
a2 += 1
a1 -= 2
count += 1
print(count)
``` | 0 | |
628 | C | Bear and String Distance | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of di... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters. | If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that . | [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n"
] | [
"roar",
"db\n",
"-1\n"
] | none | 0 | [
{
"input": "4 26\nbear",
"output": "zcar"
},
{
"input": "2 7\naf",
"output": "hf"
},
{
"input": "3 1000\nhey",
"output": "-1"
},
{
"input": "5 50\nkzsij",
"output": "zaiij"
},
{
"input": "5 500\nvsdxg",
"output": "-1"
},
{
"input": "1 0\na",
"outpu... | 1,606,332,770 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 307,200 | n,k=map(int,input().split())
s=input()
ans=k;r=""
for i in range(len(s)):
if k!=0:
if ord(s[i])+k>122:
r+='z'
k-=(122-ord(s[i]))
else:
x=ord(s[i])+k
r+=chr(x)
k-=(abs(ord(s[i])-x))
else:
r+=s[i]
if k:
prin... | Title: Bear and String Distance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions ... | ```python
n,k=map(int,input().split())
s=input()
ans=k;r=""
for i in range(len(s)):
if k!=0:
if ord(s[i])+k>122:
r+='z'
k-=(122-ord(s[i]))
else:
x=ord(s[i])+k
r+=chr(x)
k-=(abs(ord(s[i])-x))
else:
r+=s[i]
if k:... | 0 | |
846 | A | Curriculum Vitae | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100).
The second line contains *n* space-separated integer numbers *s*1,<=*s*2,<=...,<=*s**n* (0<=≤<=*s**i*<=≤<=1). 0 corresponds to an unsuccessful game, 1 — to a successful one. | Print one integer — the maximum number of games Hideo can leave in his CV so that no unsuccessful game comes after a successful one. | [
"4\n1 1 0 1\n",
"6\n0 1 0 0 1 0\n",
"1\n0\n"
] | [
"3\n",
"4\n",
"1\n"
] | none | 0 | [
{
"input": "4\n1 1 0 1",
"output": "3"
},
{
"input": "6\n0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,504,624,482 | 582 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 921,600 | from sys import stdout
from random import randint
from math import *
import re
n = int(input())
s = input().replace(' ', '')
temp = re.findall("1.*", s)
if not temp:
ans = len(s)
else:
ns = temp[0]
ans = len(s) - len(ns) + max(ns.count('1'), ns.count('0'))
print(ans)
| Title: Curriculum Vitae
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job.
During all his career Hideo has produced *n* g... | ```python
from sys import stdout
from random import randint
from math import *
import re
n = int(input())
s = input().replace(' ', '')
temp = re.findall("1.*", s)
if not temp:
ans = len(s)
else:
ns = temp[0]
ans = len(s) - len(ns) + max(ns.count('1'), ns.count('0'))
print(ans)
``` | 0 | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≤<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≤<=1018, *l*1<=≤<=*r*1, *l*2<=≤<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. | Print one integer — the number of minutes Sonya and Filya will be able to spend together. | [
"1 10 9 20 1\n",
"1 100 50 200 75\n"
] | [
"2\n",
"50\n"
] | In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. | 500 | [
{
"input": "1 10 9 20 1",
"output": "2"
},
{
"input": "1 100 50 200 75",
"output": "50"
},
{
"input": "6 6 5 8 9",
"output": "1"
},
{
"input": "1 1000000000 1 1000000000 1",
"output": "999999999"
},
{
"input": "5 100 8 8 8",
"output": "0"
},
{
"input":... | 1,478,496,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 61 | 0 | s_time1,s_time2,f_time1,f_time2,p_time=map(int,input().split(" "))
timeset=[]
timeset.append(max(s_time1,f_time1))
timeset.append(min(s_time2,f_time2))
time=(timeset[1]+1)-timeset[0]
if p_time >= timeset[0] and p_time <= timeset[1]:
time -= 1
print(time)
| Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
s_time1,s_time2,f_time1,f_time2,p_time=map(int,input().split(" "))
timeset=[]
timeset.append(max(s_time1,f_time1))
timeset.append(min(s_time2,f_time2))
time=(timeset[1]+1)-timeset[0]
if p_time >= timeset[0] and p_time <= timeset[1]:
time -= 1
print(time)
``` | 0 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,642,482,663 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | def check(t):
s=str(t)
c=0
for i in s:
if i!='0' and i!='1':
c=1
break
if c==0:
return True
return False
n=int(input())
d=len(str(n))
c=0
s=str(n)
for i in s:
if i!='0' and i!='1':
c=1
break
if c==0:
p... | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
def check(t):
s=str(t)
c=0
for i in s:
if i!='0' and i!='1':
c=1
break
if c==0:
return True
return False
n=int(input())
d=len(str(n))
c=0
s=str(n)
for i in s:
if i!='0' and i!='1':
c=1
break
if c=... | 0 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,647,520,066 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input());
if not n%2:
print(n//2)
st = "2 " * (n//2)
print(st)
else:
n -= 3
print(n//2 + 1)
st = "2 " * (n//2)
print(st + '3') | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n = int(input());
if not n%2:
print(n//2)
st = "2 " * (n//2)
print(st)
else:
n -= 3
print(n//2 + 1)
st = "2 " * (n//2)
print(st + '3')
``` | 3 | |
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes th... | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose bal... | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
... | 1,695,353,594 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 30 | 0 | n = int(input())
*balls_sizes, = set(map(int,input().split()))
sorted_sizes = sorted(balls_sizes)
#print(sorted_sizes)
def checker(size):
if (sorted_sizes[size] + sorted_sizes[size+1] + sorted_sizes[size+2]) % 3 ==0:
return "YES"
for i in range(0,len(sorted_sizes)-2):
checked = checker(i)
... | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri... | ```python
n = int(input())
*balls_sizes, = set(map(int,input().split()))
sorted_sizes = sorted(balls_sizes)
#print(sorted_sizes)
def checker(size):
if (sorted_sizes[size] + sorted_sizes[size+1] + sorted_sizes[size+2]) % 3 ==0:
return "YES"
for i in range(0,len(sorted_sizes)-2):
checked = che... | 0 | |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,551,889,580 | 3,380 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 109 | 307,200 | import math
import sys
a = list(map(int,input().split()))
x = a[0]
y = a[1]
l = a[2]
r = a[3]
v = []
for i in range(0, 61):
for j in range(0, 61):
if (x ** i + y ** j >= l) and (x ** i + y ** j <= r):
v.append(x ** i + y ** j)
maxi = 0
v.sort()
for i in range(1, len(v)):
maxi = max(maxi,... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
import math
import sys
a = list(map(int,input().split()))
x = a[0]
y = a[1]
l = a[2]
r = a[3]
v = []
for i in range(0, 61):
for j in range(0, 61):
if (x ** i + y ** j >= l) and (x ** i + y ** j <= r):
v.append(x ** i + y ** j)
maxi = 0
v.sort()
for i in range(1, len(v)):
maxi =... | -1 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,649,548,174 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | text = input()
back = text[::-1]
wrong = 0
for i in range(0, len(text)):
if text[i] != back[i]:
if len(text) % 2 == 1 and (len(text)//2)+1 == i-1:
wrong += 1
else:
wrong += .5
if wrong > 1:
break
if wrong > 1:
print("NO")
else:
print("YES")
| Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
text = input()
back = text[::-1]
wrong = 0
for i in range(0, len(text)):
if text[i] != back[i]:
if len(text) % 2 == 1 and (len(text)//2)+1 == i-1:
wrong += 1
else:
wrong += .5
if wrong > 1:
break
if wrong > 1:
print("NO")
else:
print("YES")
``` | 0 | |
219 | D | Choosing Capital for Treeland | PROGRAMMING | 1,700 | [
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to any other one.
The council of the elders has recently decid... | The first input line contains integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of cities in Treeland. Next *n*<=-<=1 lines contain the descriptions of the roads, one road per line. A road is described by a pair of integers *s**i*,<=*t**i* (1<=≤<=*s**i*,<=*t**i*<=≤<=*n*; *s**i*<=≠<=*t**i*) — the numbers of cities, connect... | In the first line print the minimum number of roads to be inversed if the capital is chosen optimally. In the second line print all possible ways to choose the capital — a sequence of indexes of cities in the increasing order. | [
"3\n2 1\n2 3\n",
"4\n1 4\n2 4\n3 4\n"
] | [
"0\n2 \n",
"2\n1 2 3 \n"
] | none | 2,000 | [
{
"input": "3\n2 1\n2 3",
"output": "0\n2 "
},
{
"input": "4\n1 4\n2 4\n3 4",
"output": "2\n1 2 3 "
},
{
"input": "2\n1 2",
"output": "0\n1 "
},
{
"input": "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7",
"output": "3\n4 6 8 "
},
{
"input": "10\n2 3\n1 8\n9 5\n5 4\n6 10\n4... | 1,699,501,539 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 2,058 | 70,860,800 | num_nodes = int(input())
time_array = [0] * (num_nodes + 1)
forward_edges, backward_edges = [[] for _ in range(num_nodes + 1)], [[] for _ in range(num_nodes + 1)]
for _ in range(num_nodes - 1):
x, y = map(int, input().split())
time_array[y] = 1
forward_edges[x].append(y)
backward_edges[y].append(x)
t... | Title: Choosing Capital for Treeland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country Treeland consists of *n* cities, some pairs of them are connected with unidirectional roads. Overall there are *n*<=-<=1 roads in the country. We know that if we don't take the direction of the... | ```python
num_nodes = int(input())
time_array = [0] * (num_nodes + 1)
forward_edges, backward_edges = [[] for _ in range(num_nodes + 1)], [[] for _ in range(num_nodes + 1)]
for _ in range(num_nodes - 1):
x, y = map(int, input().split())
time_array[y] = 1
forward_edges[x].append(y)
backward_edges[y].ap... | 3 | |
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,697,903,886 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 124 | 0 | n=int(input())
n1=str(n)
count=0
for digit in n1:
if digit=='4' or digit=='7':
count+=1
if count==len(n1) and count!=0:
print("YES")
elif (n%4==0 or n%7==0 or n%47==0 or n%74==0 or n%447==0 or n%474==0 or n%477==0 or n%747==0 or n%774==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())
n1=str(n)
count=0
for digit in n1:
if digit=='4' or digit=='7':
count+=1
if count==len(n1) and count!=0:
print("YES")
elif (n%4==0 or n%7==0 or n%47==0 or n%74==0 or n%447==0 or n%474==0 or n%477==0 or n%747==0 or n%774==0):
print("YES")
else:
print("NO")
``... | 3 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,533,036,312 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 109 | 0 | t = list(map(int,input().split()))
a = t[0]
b = t[1]
if abs(a - b) <= 1:
print("YES")
else:
print("NO") | Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
t = list(map(int,input().split()))
a = t[0]
b = t[1]
if abs(a - b) <= 1:
print("YES")
else:
print("NO")
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not neighbors in a new seating."
The class can be represented as a matrix with *n* rows and *m*... | The only line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105; *n*·*m*<=≤<=105) — the number of rows and the number of columns in the required matrix. | If there is no such matrix, output "NO" (without quotes).
Otherwise in the first line output "YES" (without quotes), and in the next *n* lines output *m* integers which form the required matrix. | [
"2 4\n",
"2 1\n"
] | [
"YES\n5 4 7 2 \n3 6 1 8 \n",
"NO\n"
] | In the first test case the matrix initially looks like this:
It's easy to see that there are no two students that are adjacent in both matrices.
In the second test case there are only two possible seatings and in both of them students with numbers 1 and 2 are neighbors. | 0 | [
{
"input": "2 4",
"output": "YES\n5 4 7 2 \n3 6 1 8 "
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "1 1",
"output": "YES\n1"
},
{
"input": "1 2",
"output": "NO"
},
{
"input": "1 3",
"output": "NO"
},
{
"input": "2 2",
"output": "NO"
},
{
... | 1,514,048,564 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<bitset>
#include<queue>
#include<string>
#include<cstr... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students went into a class to write a test and sat in some way. The teacher thought: "Probably they sat in this order to copy works of each other. I need to rearrange them in such a way that students that were neighbors are not ne... | ```python
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>
#include<cstdio>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<bitset>
#include<queue>
#include<string>
#in... | -1 | |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,652,410,529 | 2,147,483,647 | PyPy 3-64 | OK | TESTS1 | 24 | 218 | 18,944,000 | def converte(c):
return (ord(c) - 48)
def main():
n = int(input())
infinito = float("inf")
minima_operacao = [infinito for i in range(n + 1)]
minima_operacao[0] = 0
for i in range(1,n+1):
for c in str(i):
minima_operacao[i] = min(minima_operacao[i], minima_operacao[i - converte(c)]... | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
def converte(c):
return (ord(c) - 48)
def main():
n = int(input())
infinito = float("inf")
minima_operacao = [infinito for i in range(n + 1)]
minima_operacao[0] = 0
for i in range(1,n+1):
for c in str(i):
minima_operacao[i] = min(minima_operacao[i], minima_operacao[i - co... | 3 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,587,204,600 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 155 | 307,200 | a,b = map(int,input().split())
c,d = map(int,input().split())
t = 10**5
i = 0
flag = 0
if d > b:
while i < t:
r = d - b + c*i
if r%a == 0:
flag = 1
break
i = i + 1
if flag == 0:
print(-1)
exit()
else:
print(d+c*i)
else:
while i < t:
r = b - d + a*i
if r%c == 0:
fla... | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
a,b = map(int,input().split())
c,d = map(int,input().split())
t = 10**5
i = 0
flag = 0
if d > b:
while i < t:
r = d - b + c*i
if r%a == 0:
flag = 1
break
i = i + 1
if flag == 0:
print(-1)
exit()
else:
print(d+c*i)
else:
while i < t:
r = b - d + a*i
if r%c == ... | 3 | |
142 | C | Help Caretaker | PROGRAMMING | 2,300 | [
"brute force",
"dp"
] | null | null | Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find place for the agricultural equipment in the warehouse.
He's got problems wi... | The only line contains two space-separated integers *n* and *m* — the sizes of the warehouse (1<=≤<=*n*,<=*m*<=≤<=9). | In the first line print the maximum number of turboplows that can be positioned in the warehouse. In each of the next *n* lines print *m* characters. Use "." (dot) to mark empty space and use successive capital Latin letters ("A" for the first turboplow, "B" for the second one and so on until you reach the number of tu... | [
"3 3\n",
"5 6\n",
"2 2\n"
] | [
"1\nAAA\n.A.\n.A.\n",
"4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D\n",
"0\n..\n..\n"
] | none | 1,500 | [
{
"input": "3 3",
"output": "1\nAAA\n.A.\n.A."
},
{
"input": "5 6",
"output": "4\nA..C..\nAAAC..\nABCCCD\n.B.DDD\nBBB..D"
},
{
"input": "2 2",
"output": "0\n..\n.."
},
{
"input": "4 2",
"output": "0\n..\n..\n..\n.."
},
{
"input": "3 4",
"output": "1\nA...\nAAA... | 1,673,524,504 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | # LUOGU_RID: 99522112
n,a,d=map(int,input().split()) //
print(368131125*a%10**9*12*10**9+1,368131125*d%10**9*12*10**9)
| Title: Help Caretaker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-triv... | ```python
# LUOGU_RID: 99522112
n,a,d=map(int,input().split()) //
print(368131125*a%10**9*12*10**9+1,368131125*d%10**9*12*10**9)
``` | -1 | |
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,697,964,110 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n = int(input())
i = 0
x=0
while(i<n):
s = input()
if(s[1]=='+'):
x=x+1
else:
x=x-1
i=i+1
print(x) | 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
n = int(input())
i = 0
x=0
while(i<n):
s = input()
if(s[1]=='+'):
x=x+1
else:
x=x-1
i=i+1
print(x)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.