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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,504,023,610 | 4,510 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | a = [float(x) for x in input().strip().split(' ')]
l = int(a[0]); r = int(a[1]); x = int(a[2]); y = int(a[3]); k = a[4]
start = (l)/y
end = (r)/x
flag = False
for i in range(l,r):
for j in range(x,y):
if i/j == k:
flag = True
break
if flag==True:
print("YES")
else:
... | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
a = [float(x) for x in input().strip().split(' ')]
l = int(a[0]); r = int(a[1]); x = int(a[2]); y = int(a[3]); k = a[4]
start = (l)/y
end = (r)/x
flag = False
for i in range(l,r):
for j in range(x,y):
if i/j == k:
flag = True
break
if flag==True:
print("YES")... | 0 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,556,113,158 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 249 | 9,318,400 | from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for val in a:
d[val] += 1
res = []
ok = True
while d[4] > 0:
if d[1] == 0 or d[2] == 0:
ok = False
break
res.append([1, 2, 4])
for x in (1, 2, 4):
d[x] -=... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for val in a:
d[val] += 1
res = []
ok = True
while d[4] > 0:
if d[1] == 0 or d[2] == 0:
ok = False
break
res.append([1, 2, 4])
for x in (1, 2, 4):
... | 3 | |
5 | C | Longest Regular Bracket Sequence | PROGRAMMING | 1,900 | [
"constructive algorithms",
"data structures",
"dp",
"greedy",
"sortings",
"strings"
] | C. Longest Regular Bracket Sequence | 2 | 256 | This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical expression. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.... | The first line of the input file contains a non-empty string, consisting of «(» and «)» characters. Its length does not exceed 106. | Print the length of the longest substring that is a regular bracket sequence, and the number of such substrings. If there are no such substrings, write the only line containing "0 1". | [
")((())))(()())\n",
"))(\n"
] | [
"6 2\n",
"0 1\n"
] | none | 0 | [
{
"input": ")((())))(()())",
"output": "6 2"
},
{
"input": "))(",
"output": "0 1"
},
{
"input": "()(())()",
"output": "8 1"
},
{
"input": "((((()(((",
"output": "2 1"
},
{
"input": "))))()())))",
"output": "4 1"
},
{
"input": "(()())()(())()()())())()(... | 1,573,750,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 | for tc in range(1):
s=input()
c=0
ans=0
l=0
an=[0]*(len(s)+1)
for i in range(0,len(s)):
if l==0:
if s[i]=='(':
c-=1
l+=1
else:
c=0
l=0
continue
elif l!=0:
... | Title: Longest Regular Bracket Sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
This is yet another problem dealing with regular bracket sequences.
We should remind you that a bracket sequence is called regular, if by inserting «+» and «1» into it we can get a correct mathematical exp... | ```python
for tc in range(1):
s=input()
c=0
ans=0
l=0
an=[0]*(len(s)+1)
for i in range(0,len(s)):
if l==0:
if s[i]=='(':
c-=1
l+=1
else:
c=0
l=0
continue
eli... | 0 |
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon... | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output"... | 1,584,038,863 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 248 | 0 | import math
a=int(input())
b=list(map(int,input().split()))
b.sort()
soma=0
for i in range (-1,-a-1,-1):
if i%2==1:
soma+=b[i]**2*math.pi
else:
soma-=b[i]**2*math.pi
print ("%.10f"%(soma))
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in... | ```python
import math
a=int(input())
b=list(map(int,input().split()))
b.sort()
soma=0
for i in range (-1,-a-1,-1):
if i%2==1:
soma+=b[i]**2*math.pi
else:
soma-=b[i]**2*math.pi
print ("%.10f"%(soma))
``` | 3 | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,475,699,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 62 | 0 | import math
start, end, base = input().split()
start = int(start)
end = int(end)
base = int(base)
count = 0
list = []
res = int(math.pow(base, count))
while res <= end:
if res >= start and res <= end:
list.append(res)
elif res < start:
res = -1
list.append(res)
... | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
import math
start, end, base = input().split()
start = int(start)
end = int(end)
base = int(base)
count = 0
list = []
res = int(math.pow(base, count))
while res <= end:
if res >= start and res <= end:
list.append(res)
elif res < start:
res = -1
list.append(... | 0 | |
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ... | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has... | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
}... | 1,622,293,338 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sat May 29 20:58:31 2021
@author: nagan
"""
'''
a = int(input())
b = int(input())
c = int(input())
ans = 0
while True:
if a >= 1:
if b >= 2:
if c >= 4:
ans += 7
a -= 1
b -= 2
... | Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sat May 29 20:58:31 2021
@author: nagan
"""
'''
a = int(input())
b = int(input())
c = int(input())
ans = 0
while True:
if a >= 1:
if b >= 2:
if c >= 4:
ans += 7
a -= 1
b -= 2
... | 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,679,643,580 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | a = input()
for i in range(0, len(a) - 1):
if a[i] == 'A' and a[i + 1] == 'B':
a = a.replace(a[i], 'x', 1)
a = a.replace(a[i + 1], 'y', 1)
if 'BA' in a:
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
a = input()
for i in range(0, len(a) - 1):
if a[i] == 'A' and a[i + 1] == 'B':
a = a.replace(a[i], 'x', 1)
a = a.replace(a[i + 1], 'y', 1)
if 'BA' in a:
print('YES')
else:
print('NO')
``` | 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,691,512,118 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 0 | count=0
n=int(input())
while(n!=0):
if n>=1 and n<5:
count=count+n
break
elif n>=10 and n<20:
count=count+n//10
n=n%10
elif n>=20 and n<100:
count=count+n//20
n=n%20
elif n>=5 and n<10:
count=count+n//5
n=n%5
else:
... | 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
count=0
n=int(input())
while(n!=0):
if n>=1 and n<5:
count=count+n
break
elif n>=10 and n<20:
count=count+n//10
n=n%10
elif n>=20 and n<100:
count=count+n//20
n=n%20
elif n>=5 and n<10:
count=count+n//5
n=n%5
el... | 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,559,798,549 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | x= input()
y="hello"
i=0
j=0
while(i<len(x) or j<5):
if(x[i]==y[j]):
j+=1
i+=1
if(j>3):
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
x= input()
y="hello"
i=0
j=0
while(i<len(x) or j<5):
if(x[i]==y[j]):
j+=1
i+=1
if(j>3):
print("YES")
else:
print("NO")
``` | -1 |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,679,057,323 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | a = list(input())
b = list(input())
s = a + b
d = list(input())
s.sort()
d.sort()
if(s == d):
print('YES')
else:
print('NO') | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
a = list(input())
b = list(input())
s = a + b
d = list(input())
s.sort()
d.sort()
if(s == d):
print('YES')
else:
print('NO')
``` | 3 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,486,159,272 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 13 | 1,000 | 4,915,200 |
def search(y, z):
j = 0
end = 0
lampka = 0
for i in range(len(y) - len(z) + 1):
while y[i + j] == z[j]:
if j == (len(z) - 1):
end = j + 1 + i
return [True, end]
lampka = 1
break
j += 1
if lampka ... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
def search(y, z):
j = 0
end = 0
lampka = 0
for i in range(len(y) - len(z) + 1):
while y[i + j] == z[j]:
if j == (len(z) - 1):
end = j + 1 + i
return [True, end]
lampka = 1
break
j += 1
... | 0 |
185 | B | Mushroom Scientists | PROGRAMMING | 1,800 | [
"math",
"ternary search"
] | null | null | As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formu... | The first line contains a single integer *S* (1<=≤<=*S*<=≤<=103) — the maximum sum of coordinates of the sought point.
The second line contains three space-separated integers *a*, *b*, *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=103) — the numbers that describe the metric of mushroom scientists. | Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.
A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists ... | [
"3\n1 1 1\n",
"3\n2 0 0\n"
] | [
"1.0 1.0 1.0\n",
"3.0 0.0 0.0\n"
] | none | 1,000 | [
{
"input": "3\n1 1 1",
"output": "1.0 1.0 1.0"
},
{
"input": "3\n2 0 0",
"output": "3.0 0.0 0.0"
},
{
"input": "10\n1 6 3",
"output": "1.0 6.0 3.0"
},
{
"input": "9\n8 2 0",
"output": "7.2 1.8 0.0"
},
{
"input": "1\n0 9 2",
"output": "0.0 0.8181818181818182 0.... | 1,633,493,643 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 6,963,200 | s = int(input())
a, b, c = map(int, input().split())
if a == 0 and b == 0 and c == 0:
print(0, 0, 0)
else:
x = 1.0*a*s/(a+b+c)
y = 1.0*b*s/(a+b+c)
z = 1.0*c*s/(a+b+c)
print(x, y, z) | Title: Mushroom Scientists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate s... | ```python
s = int(input())
a, b, c = map(int, input().split())
if a == 0 and b == 0 and c == 0:
print(0, 0, 0)
else:
x = 1.0*a*s/(a+b+c)
y = 1.0*b*s/(a+b+c)
z = 1.0*c*s/(a+b+c)
print(x, y, z)
``` | 3 | |
845 | B | Luba And The Ticket | PROGRAMMING | 1,600 | [
"brute force",
"greedy",
"implementation"
] | null | null | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0. | Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky. | [
"000000\n",
"123456\n",
"111000\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one re... | 0 | [
{
"input": "000000",
"output": "0"
},
{
"input": "123456",
"output": "2"
},
{
"input": "111000",
"output": "1"
},
{
"input": "120111",
"output": "0"
},
{
"input": "999999",
"output": "0"
},
{
"input": "199880",
"output": "1"
},
{
"input": "... | 1,586,476,831 | 2,147,483,647 | PyPy 3 | OK | TESTS | 145 | 218 | 3,788,800 | s = input()
min_d = 6
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
for e in range(10):
for f in range(10):
if a + b + c == d + e + f:
k = 0
... | Title: Luba And The Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make th... | ```python
s = input()
min_d = 6
for a in range(10):
for b in range(10):
for c in range(10):
for d in range(10):
for e in range(10):
for f in range(10):
if a + b + c == d + e + f:
k = 0
... | 3 | |
404 | A | Valera and X | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the... | The first line contains integer *n* (3<=≤<=*n*<=<<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper. | Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. | [
"5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n",
"3\nwsw\nsws\nwsw\n",
"3\nxpx\npxp\nxpe\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox",
"output": "NO"
},
{
"input": "3\nwsw\nsws\nwsw",
"output": "YES"
},
{
"input": "3\nxpx\npxp\nxpe",
"output": "NO"
},
{
"input": "5\nliiil\nilili\niilii\nilili\nliiil",
"output": "YES"
},
{
"input": "7\nbwccccb\nck... | 1,655,479,170 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 46 | 512,000 | n = int(input())
arr = [["" for i in range(n)] for j in range(n)]
for i in range(n):
arr[i] = list(input())
pt1, pt2 = 0, n -1
set_diag, set_other = set(), set()
for i in range(n):
set_diag.add(arr[i][pt1])
set_diag.add(arr[i][pt2])
for j in range(n):
if j != pt1 and j != pt2:
... | Title: Valera and X
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a... | ```python
n = int(input())
arr = [["" for i in range(n)] for j in range(n)]
for i in range(n):
arr[i] = list(input())
pt1, pt2 = 0, n -1
set_diag, set_other = set(), set()
for i in range(n):
set_diag.add(arr[i][pt1])
set_diag.add(arr[i][pt2])
for j in range(n):
if j != pt1 and j !=... | 0 | |
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that... | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so t... | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
... | 1,538,007,343 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | '''
Created on 26/09/2018
@author: ernesto
'''
# XXX: http://codeforces.com/contest/1040/problem/B
if __name__ == '__main__':
n, k = [int(x) for x in input().strip().split(" ")]
tam_seccion = min((k << 1) + 1, n)
num_secciones = n // tam_seccion
sobrante_secciones = n % tam_seccion
puntos_de_volte... | Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming t... | ```python
'''
Created on 26/09/2018
@author: ernesto
'''
# XXX: http://codeforces.com/contest/1040/problem/B
if __name__ == '__main__':
n, k = [int(x) for x in input().strip().split(" ")]
tam_seccion = min((k << 1) + 1, n)
num_secciones = n // tam_seccion
sobrante_secciones = n % tam_seccion
punto... | -1 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,673,872,031 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | t = int(input())
for p in range(t):
n = int(input())
a = list(map(int, input().split()))
s = input()
n, m = map(int, input().split())
flag = True
for i in range(n):
a = [[] for i in range(n)]
if flag:
print("YES")
else:
print("NO")
for i in range(n):
print(" ".join(... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
t = int(input())
for p in range(t):
n = int(input())
a = list(map(int, input().split()))
s = input()
n, m = map(int, input().split())
flag = True
for i in range(n):
a = [[] for i in range(n)]
if flag:
print("YES")
else:
print("NO")
for i in range(n):
print... | -1 | |
813 | C | The Tag Game | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs"
] | null | null | Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob go... | The first line contains two integer numbers *n* and *x* (2<=≤<=*n*<=≤<=2·105, 2<=≤<=*x*<=≤<=*n*).
Each of the next *n*<=-<=1 lines contains two integer numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=*n*) — edges of the tree. It is guaranteed that the edges form a valid tree. | Print the total number of moves Alice and Bob will make. | [
"4 3\n1 2\n2 3\n2 4\n",
"5 2\n1 2\n2 3\n3 4\n2 5\n"
] | [
"4\n",
"6\n"
] | In the first example the tree looks like this:
The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the secon... | 0 | [
{
"input": "4 3\n1 2\n2 3\n2 4",
"output": "4"
},
{
"input": "5 2\n1 2\n2 3\n3 4\n2 5",
"output": "6"
},
{
"input": "2 2\n2 1",
"output": "2"
},
{
"input": "3 3\n2 1\n3 1",
"output": "2"
},
{
"input": "3 3\n1 2\n3 2",
"output": "4"
},
{
"input": "10 4\... | 1,496,679,130 | 4,030 | Python 3 | WRONG_ANSWER | TESTS | 7 | 61 | 307,200 | n, x = map(int, input().split())
x -= 1
a = [[]for i in range(n)]
for i in range(n-1):
l, r = map(int, input().split())
a[l-1].append(r-1)
a[r-1].append(l-1)
dist = [0] * n
disttoleaf = [0] * n
visit = [False] * n
def dfs(v, d):
visit[v] = True
dist[v] = d
ans = 0
for vNext in a[v]:
... | Title: The Tag Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree.
Alic... | ```python
n, x = map(int, input().split())
x -= 1
a = [[]for i in range(n)]
for i in range(n-1):
l, r = map(int, input().split())
a[l-1].append(r-1)
a[r-1].append(l-1)
dist = [0] * n
disttoleaf = [0] * n
visit = [False] * n
def dfs(v, d):
visit[v] = True
dist[v] = d
ans = 0
for vNext in a[v... | 0 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,534,727,354 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 248 | 0 | num_pedal_axle_stars = int(input())
num_pedal_axle_stars_teeth = list(map(int, input().split()))
num_rear_wheel_axle_stars = int(input())
num_rear_wheel_axle_stars_teeth = list(map(int, input().split()))
max_int = 0
num_max_int = 0
for rear_teeth in num_rear_wheel_axle_stars_teeth:
for pedal_teeth in num_ped... | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
num_pedal_axle_stars = int(input())
num_pedal_axle_stars_teeth = list(map(int, input().split()))
num_rear_wheel_axle_stars = int(input())
num_rear_wheel_axle_stars_teeth = list(map(int, input().split()))
max_int = 0
num_max_int = 0
for rear_teeth in num_rear_wheel_axle_stars_teeth:
for pedal_teeth ... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,489,332,437 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
def UltraFast ( a , b)
for in range (len(a))
if a[i]=b[i]
print 0
else
return 1 | 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
def UltraFast ( a , b)
for in range (len(a))
if a[i]=b[i]
print 0
else
return 1
``` | -1 |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,676,100,758 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def main():
words = str(input().strip())
words_array = words.split('\n')
for i in range(1, len(words_array)):
word = words_array[i]
if len(word) <= 10:
print(word)
elif len(word) > 10:
length_s = len(word) - 2
print(word[0] + str(length_... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
def main():
words = str(input().strip())
words_array = words.split('\n')
for i in range(1, len(words_array)):
word = words_array[i]
if len(word) <= 10:
print(word)
elif len(word) > 10:
length_s = len(word) - 2
print(word[0] + s... | 0 |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,622,096,962 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 278 | 2,969,600 | n=int(input())
a=(n**2)+1
l=[]
c=0
for i in range(1,n*n+1):
l.append(i)
l.append(a-i)
#l=l[:a-1]
for i in range(0,len(l),n):
if c<n:
print(*l[i:i+n])
c+=1
else:
break | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n=int(input())
a=(n**2)+1
l=[]
c=0
for i in range(1,n*n+1):
l.append(i)
l.append(a-i)
#l=l[:a-1]
for i in range(0,len(l),n):
if c<n:
print(*l[i:i+n])
c+=1
else:
break
``` | 3 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,655,649,944 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | def main():
n, m = [int(j) for j in input().split()]
count = 0
for a in range(1001):
b = n - a * a
if int(pow(abs(b), 0.5)) ** 2 == b and b >= 0 and b ** 2 + a == m:
#print(a, b)
count += 1
print(count)
main()
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
def main():
n, m = [int(j) for j in input().split()]
count = 0
for a in range(1001):
b = n - a * a
if int(pow(abs(b), 0.5)) ** 2 == b and b >= 0 and b ** 2 + a == m:
#print(a, b)
count += 1
print(count)
main()
``` | 0 | |
140 | C | New Year Snowmen | PROGRAMMING | 1,800 | [
"binary search",
"data structures",
"greedy"
] | null | null | As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they've already made *n* snowballs with radii equal to *r*1, *r*2, ..., *r**n*. To make a snowman, one nee... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of snowballs. The next line contains *n* integers — the balls' radii *r*1, *r*2, ..., *r**n* (1<=≤<=*r**i*<=≤<=109). The balls' radii can coincide. | Print on the first line a single number *k* — the maximum number of the snowmen. Next *k* lines should contain the snowmen's descriptions. The description of each snowman should consist of three space-separated numbers — the big ball's radius, the medium ball's radius and the small ball's radius. It is allowed to print... | [
"7\n1 2 3 4 5 6 7\n",
"3\n2 2 3\n"
] | [
"2\n3 2 1\n6 5 4\n",
"0\n"
] | none | 1,500 | [
{
"input": "7\n1 2 3 4 5 6 7",
"output": "2\n7 5 3\n6 4 2"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n255317",
"output": "0"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2\n3 2 1\n3 2 1"
},
{
"input": "6\n1 2 2 2 3 3",
"output": "1\n3 2 1"
},
... | 1,482,889,747 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 4,608,000 | n = input()
linea = input().split(' ')
sol =0
arrsols = []
arrsol = []
while len(linea) >=3:
if linea[0] < linea[1] < linea[2]:
sol=sol+1
arrsol.append(linea[2])
arrsol.append(linea[1])
arrsol.append(linea[0])
arrsols.append(arrsol)
arrsol=[]
linea.po... | Title: New Year Snowmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As meticulous Gerald sets the table and caring Alexander sends the postcards, Sergey makes snowmen. Each showman should consist of three snowballs: a big one, a medium one and a small one. Sergey's twins help him: they... | ```python
n = input()
linea = input().split(' ')
sol =0
arrsols = []
arrsol = []
while len(linea) >=3:
if linea[0] < linea[1] < linea[2]:
sol=sol+1
arrsol.append(linea[2])
arrsol.append(linea[1])
arrsol.append(linea[0])
arrsols.append(arrsol)
arrsol=[]
... | 0 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,671,991,798 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 13 | 122 | 0 | n1=input()
n2=n1[::-1]
t1=input()
t2=input()
if len(t1)+len(t2)<=len(n1):
if t1 in n1 and t2 in n1 and t1 in n2 and t2 in n2 and n1.index(t1)<len(n1)-n2.index(t2) and n2.index(t1)<len(n2)-n1.index(t2):
print("both")
elif t1 in n1 and t2 in n1 and n1.index(t1)<len(n1)-n2.index(t2):
print(... | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
n1=input()
n2=n1[::-1]
t1=input()
t2=input()
if len(t1)+len(t2)<=len(n1):
if t1 in n1 and t2 in n1 and t1 in n2 and t2 in n2 and n1.index(t1)<len(n1)-n2.index(t2) and n2.index(t1)<len(n2)-n1.index(t2):
print("both")
elif t1 in n1 and t2 in n1 and n1.index(t1)<len(n1)-n2.index(t2):
... | 0 |
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,617,883,975 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | t = input()
s = input()
if len(t) != len(s):
print('NO')
else:
valid = True
for i in range(len(t)):
if t[i] != s[len(t)-i-1]:
valid = False
if valid:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
t = input()
s = input()
if len(t) != len(s):
print('NO')
else:
valid = True
for i in range(len(t)):
if t[i] != s[len(t)-i-1]:
valid = False
if valid:
print('YES')
else:
print('NO')
``` | 3.969 |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,691,342,340 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 31 | 1,228,800 | def F(n, cnt = 0):
global a, b, c
if n==0:
return cnt
if n < 0:
return 0
return max(F(n - a, cnt + 1), F(n - b, cnt + 1), F(n - c, cnt + 1))
n, a, b, c = map(int,input().split())
ld = [a, b, c]
ld.sort()
print(F(n))
| Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
def F(n, cnt = 0):
global a, b, c
if n==0:
return cnt
if n < 0:
return 0
return max(F(n - a, cnt + 1), F(n - b, cnt + 1), F(n - c, cnt + 1))
n, a, b, c = map(int,input().split())
ld = [a, b, c]
ld.sort()
print(F(n))
``` | -1 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,663,478,458 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 102,400 | from collections import defaultdict
T = input()
b, s, c = [int(x) for x in input().split()]
q, w, e = [int(x) for x in input().split()]
m = int(input())
B, S, C = T.count('B'), T.count('S'), T.count('C')
l, r = 0, 10**15
while l < r:
mid = l+r>>1
if q*max(0, mid*B-b)+w*max(0, mid*S-s)+e*max(0, mid*C-c) <= m: ... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
from collections import defaultdict
T = input()
b, s, c = [int(x) for x in input().split()]
q, w, e = [int(x) for x in input().split()]
m = int(input())
B, S, C = T.count('B'), T.count('S'), T.count('C')
l, r = 0, 10**15
while l < r:
mid = l+r>>1
if q*max(0, mid*B-b)+w*max(0, mid*S-s)+e*max(0, mid*C... | 3 | |
548 | B | Mike and Fun | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"greedy",
"implementation"
] | null | null | Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s... | The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000).
The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes).
The next *q* lines contain the inf... | After each round, print the current score of the bears. | [
"5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n"
] | [
"3\n4\n3\n3\n4\n"
] | none | 1,000 | [
{
"input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3",
"output": "3\n4\n3\n3\n4"
},
{
"input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1",
"output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1"
},
{
"input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\... | 1,486,670,842 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 23,142,400 | n,m,q = [int(i) for i in input().split()]
a = []
b = []
ans = []
for i in range(n):
x=[int(i) for i in input().split()]
s=sum(x)
a.append(x)
b.append(s)
for i in range(q):
x,y = [int(i) for i in input().split()]
if a[x-1][y-1]==0:
a[x-1][y-1] = 1
b[x-1]+=1
els... | Title: Mike and Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ... | ```python
n,m,q = [int(i) for i in input().split()]
a = []
b = []
ans = []
for i in range(n):
x=[int(i) for i in input().split()]
s=sum(x)
a.append(x)
b.append(s)
for i in range(q):
x,y = [int(i) for i in input().split()]
if a[x-1][y-1]==0:
a[x-1][y-1] = 1
b[x-1]+=... | 0 | |
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,614,951 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | for i in range(5):
row=list(int(input().split()))
for k in range(5):
if list[k]==1:
c=k
r=i
steps=abs(c-2)+abs(r-2)
print(steps) | 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):
row=list(int(input().split()))
for k in range(5):
if list[k]==1:
c=k
r=i
steps=abs(c-2)+abs(r-2)
print(steps)
``` | -1 | |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,640,594,177 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n=int(input())
list=input().split()
x=list.index(max(list))
list1=(list[:x])
list2=(list[x:])
if (list1==sorted(list1)) and (list2==sorted(list2, reverse= True)):
print('YES')
else:
print('NO') | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
n=int(input())
list=input().split()
x=list.index(max(list))
list1=(list[:x])
list2=(list[x:])
if (list1==sorted(list1)) and (list2==sorted(list2, reverse= True)):
print('YES')
else:
print('NO')
``` | 0 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,624,513,098 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 102,400 | n=int(input())
ll=[]
rl=[]
for i in range(n):
l,r=input().split()
ll.append(l),rl.append(r)
cl,cr=ll.count('1'),rl.count('1')
if(cl>cr):
s1=n-cl
if(cr>rl.count('0')):
s2=n-cr
else:
s2=cr
else:
s1=n-cr
if(cl>ll.count('0'))... | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n=int(input())
ll=[]
rl=[]
for i in range(n):
l,r=input().split()
ll.append(l),rl.append(r)
cl,cr=ll.count('1'),rl.count('1')
if(cl>cr):
s1=n-cl
if(cr>rl.count('0')):
s2=n-cr
else:
s2=cr
else:
s1=n-cr
if(cl>ll.c... | 0 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,600,187,613 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 409,600 | import random
n, k = map(int, input().split(' '))
alph = 'abcdefghijklmnopqrstuvwxyz'
password = ''
i = 0
while i < k:
letter = random.choice(alph)
if letter not in password:
password += letter
i += 1
repetitions = n / k
password = password*int(repetitions)
if n % k != 0:
password... | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the foll... | ```python
import random
n, k = map(int, input().split(' '))
alph = 'abcdefghijklmnopqrstuvwxyz'
password = ''
i = 0
while i < k:
letter = random.choice(alph)
if letter not in password:
password += letter
i += 1
repetitions = n / k
password = password*int(repetitions)
if n % k != 0:
... | 0 | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,662,509,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | data = input().split(" ")
r = int(data[0])
d = int(data[1])
n = int(input())
i = 1
counter = 0
while i <= n:
row = input().split(" ")
x = int(row[0])
y = int(row[0])
rc = int(row[0])
d = (x**2 + y**2)**0.5
if d+rc <= r and d-rc >= r-d:
counter = counter + 1
i = i + ... | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
data = input().split(" ")
r = int(data[0])
d = int(data[1])
n = int(input())
i = 1
counter = 0
while i <= n:
row = input().split(" ")
x = int(row[0])
y = int(row[0])
rc = int(row[0])
d = (x**2 + y**2)**0.5
if d+rc <= r and d-rc >= r-d:
counter = counter + 1
... | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,625,199,459 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 154 | 0 | # -*- coding: utf-8 -*-
"""Untitled74.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1TMF3empw9H5Gg2AyJyAuduDgxMfS09yH
"""
n=int(input())
l1=list(map(int,input().split()))
c1=0
c2=0
for x in range(0,3):
if l1[x]%2==0:
c1=c1+1
else:
c... | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
# -*- coding: utf-8 -*-
"""Untitled74.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1TMF3empw9H5Gg2AyJyAuduDgxMfS09yH
"""
n=int(input())
l1=list(map(int,input().split()))
c1=0
c2=0
for x in range(0,3):
if l1[x]%2==0:
c1=c1+1
e... | 3.9615 |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1<=000) — the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,641,212,197 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | length=int(input())
l=list(map(int,input().split())
i=2
while i < length and l[i-1] < l[i]:
i+=1
while i < length and l[i-1] == l[i]:
i+=1
while i < length and l[i-1] > l[i]:
i+=1
if i==length:
print("yes")
else:
print("no") | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
length=int(input())
l=list(map(int,input().split())
i=2
while i < length and l[i-1] < l[i]:
i+=1
while i < length and l[i-1] == l[i]:
i+=1
while i < length and l[i-1] > l[i]:
i+=1
if i==length:
print("yes")
else:
print("no")
``` | -1 | |
828 | B | Black Square | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum pos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the sizes of the sheet.
The next *n* lines contain *m* letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | [
"5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"1 2\nBB\n",
"3 3\nWWW\nWWW\nWWW\n"
] | [
"5\n",
"-1\n",
"1\n"
] | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | 750 | [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW",
"output": "5"
},
{
"input": "1 2\nBB",
"output": "-1"
},
{
"input": "3 3\nWWW\nWWW\nWWW",
"output": "1"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n... | 1,641,408,188 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | def ingresarMatriz(m,n):
matriz=[[]]
fila=[]
for i in range (0,m):
fila=[]
for j in range (0,n):
fila.append(1)
if i==0:
matriz[i]=fila
else:
matriz.append(fila)
return matriz
def modificarMatriz(matriz,m,n):
for i in... | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a checkered sheet of paper of size *n*<=×<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w... | ```python
def ingresarMatriz(m,n):
matriz=[[]]
fila=[]
for i in range (0,m):
fila=[]
for j in range (0,n):
fila.append(1)
if i==0:
matriz[i]=fila
else:
matriz.append(fila)
return matriz
def modificarMatriz(matriz,m,n):
... | 0 | |
868 | A | Bark to Unlock | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | The first line contains two lowercase English letters — the password on the phone.
The second line contains single integer *n* (1<=≤<=*n*<=≤<=100) — the number of words Kashtanka knows.
The next *n* lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to b... | Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ah\n1\nha\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" produ... | 250 | [
{
"input": "ya\n4\nah\noy\nto\nha",
"output": "YES"
},
{
"input": "hp\n2\nht\ntp",
"output": "NO"
},
{
"input": "ah\n1\nha",
"output": "YES"
},
{
"input": "bb\n4\nba\nab\naa\nbb",
"output": "YES"
},
{
"input": "bc\n4\nca\nba\nbb\ncc",
"output": "YES"
},
{
... | 1,507,192,719 | 5,619 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 62 | 0 | k = str(input())
n = int(input())
s = []
for i in range(n):
s.append(str(input()))
if k in s:
print('YES')
else:
for i in range(len(s)):
if k in s[i] + s[i]:
print('YES')
break
if i == len(s)-1 and k not in s[i] + s[i]:
print('NO')
... | Title: Bark to Unlock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a passw... | ```python
k = str(input())
n = int(input())
s = []
for i in range(n):
s.append(str(input()))
if k in s:
print('YES')
else:
for i in range(len(s)):
if k in s[i] + s[i]:
print('YES')
break
if i == len(s)-1 and k not in s[i] + s[i]:
print... | 0 | |
873 | A | Chores | PROGRAMMING | 800 | [
"implementation"
] | null | null | Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on some chores. She can choose not more than *k* any chores and do each of them in *x* units of ... | The first line contains three integers *n*,<=*k*,<=*x* (1<=≤<=*k*<=≤<=*n*<=≤<=100,<=1<=≤<=*x*<=≤<=99) — the number of chores Luba has to do, the number of chores she can do in *x* units of time, and the number *x* itself.
The second line contains *n* integer numbers *a**i* (2<=≤<=*a**i*<=≤<=100) — the time Luba has to... | Print one number — minimum time Luba needs to do all *n* chores. | [
"4 2 2\n3 6 7 10\n",
"5 2 1\n100 100 100 100 100\n"
] | [
"13\n",
"302\n"
] | In the first example the best option would be to do the third and the fourth chore, spending *x* = 2 time on each instead of *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, respectively. Then the answer is 3 + 6 + 2 + 2 = 13.
In the second example Luba can choose any two chores to spend *x... | 0 | [
{
"input": "4 2 2\n3 6 7 10",
"output": "13"
},
{
"input": "5 2 1\n100 100 100 100 100",
"output": "302"
},
{
"input": "1 1 1\n100",
"output": "1"
},
{
"input": "100 1 99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 ... | 1,507,818,063 | 962 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,k,x=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
e=0
for i in range(n):
e+=m[i]
for i in range(k):
j=n-1-i
if m[j]>k:
e=e-m[j]+x
print(e) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba has to do *n* chores today. *i*-th chore takes *a**i* units of time to complete. It is guaranteed that for every the condition *a**i*<=≥<=*a**i*<=-<=1 is met, so the sequence is sorted.
Also Luba can work really hard on s... | ```python
n,k,x=map(int,input().split(' '))
m=list(map(int,input().split(' ')))
e=0
for i in range(n):
e+=m[i]
for i in range(k):
j=n-1-i
if m[j]>k:
e=e-m[j]+x
print(e)
``` | 0 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,557,789,613 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | r, x, y, x_, y_ = map(int, input().split())
print(ceil(((x - x_)**2 + (y - y_)**2) / 2))
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
r, x, y, x_, y_ = map(int, input().split())
print(ceil(((x - x_)**2 + (y - y_)**2) / 2))
``` | -1 | |
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==... | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
... | 1,567,068,266 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | x,y=map(int,input().split())
p=list()
n=0
for i in range(y):
a=int(input())
k=a%x
if k in p :n+=1
else :p.append(k)
print(n*2 if n!=0 else -1) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbere... | ```python
x,y=map(int,input().split())
p=list()
n=0
for i in range(y):
a=int(input())
k=a%x
if k in p :n+=1
else :p.append(k)
print(n*2 if n!=0 else -1)
``` | 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,595,327,109 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 108 | 6,656,000 | temp=input()
temp=temp.split(" ")
temp=list(map(int,temp))
l=temp[0]
r=temp[1]
if l%2!=0:
l+=1
if r-l<=1:
print(-1)
else:
print(l,l+1,l+2) | 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
temp=input()
temp=temp.split(" ")
temp=list(map(int,temp))
l=temp[0]
r=temp[1]
if l%2!=0:
l+=1
if r-l<=1:
print(-1)
else:
print(l,l+1,l+2)
``` | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,684,675,564 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | a=int(input())
sol=0
while a > 0:
if a%2 == 1:
sol += 1
a//=2
print(sol) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
a=int(input())
sol=0
while a > 0:
if a%2 == 1:
sol += 1
a//=2
print(sol)
``` | 3 | |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,695,326,214 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,k=map(int,input().split())
a=list(map(int,input().split()))
ts=0
neg=0
zf=0
fp=1e18
for i in a:
if i<0:
neg+=1
if i==0:
zf=1
if i>0:
fp=i
if neg==0:
if not k&1 and not zf:
ts=sum(a[1:])-a[0]
else:
ts=sum(a)
else:
if zf or neg>=k:
... | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
ts=0
neg=0
zf=0
fp=1e18
for i in a:
if i<0:
neg+=1
if i==0:
zf=1
if i>0:
fp=i
if neg==0:
if not k&1 and not zf:
ts=sum(a[1:])-a[0]
else:
ts=sum(a)
else:
if zf or neg... | 0 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,695,284,017 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 122 | 2,764,800 | a,b=map(int,input().split())
even=[]
odd =[]
for i in range(a):
if i%2==0:
even.append(i)
else:
odd.append(i)
odd.append(even)
print(odd[b-1]) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
a,b=map(int,input().split())
even=[]
odd =[]
for i in range(a):
if i%2==0:
even.append(i)
else:
odd.append(i)
odd.append(even)
print(odd[b-1])
``` | -1 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,682,261,416 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 124 | 0 | n,m,a=map(int,input().split())
k=(n+a-1)//a
r=(m+a-1)//a
print(k*r) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=map(int,input().split())
k=(n+a-1)//a
r=(m+a-1)//a
print(k*r)
``` | 3.938 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,588,917,561 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 140 | 20,172,800 | n , d= map(int, input().split())
t = list(map(int, input().split()))
Devus_time = sum(t) + (n-1)*10
if Devus_time>d:
print(-1)
else:
Churus_time = (n-1)*2 + (d-Devus_time)//5
print(Churus_time) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n , d= map(int, input().split())
t = list(map(int, input().split()))
Devus_time = sum(t) + (n-1)*10
if Devus_time>d:
print(-1)
else:
Churus_time = (n-1)*2 + (d-Devus_time)//5
print(Churus_time)
``` | 3 | |
933 | A | A Twisty Movement | PROGRAMMING | 1,800 | [
"dp"
] | null | null | A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence.
The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*). | Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence. | [
"4\n1 2 1 2\n",
"10\n1 1 2 2 2 1 1 2 2 1\n"
] | [
"4\n",
"9\n"
] | In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4.
In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9. | 500 | [
{
"input": "4\n1 2 1 2",
"output": "4"
},
{
"input": "10\n1 1 2 2 2 1 1 2 2 1",
"output": "9"
},
{
"input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 ... | 1,518,625,003 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 61 | 5,529,600 | n=int(input())
a=[int(k)-1 for k in input().split(" ")]
print(a)
nbmax= [0,0,0,0]
for k in a:
if k:
nbmax[1]=max(nbmax[1]+1,nbmax[0]+1)
nbmax[3]=max(nbmax[3]+1,nbmax[2]+1)
else:
nbmax[0]+=1
nbmax[2]=max(nbmax[1]+1,nbmax[2]+1)
print (max(nbmax)) | Title: A Twisty Movement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon.
A perform... | ```python
n=int(input())
a=[int(k)-1 for k in input().split(" ")]
print(a)
nbmax= [0,0,0,0]
for k in a:
if k:
nbmax[1]=max(nbmax[1]+1,nbmax[0]+1)
nbmax[3]=max(nbmax[3]+1,nbmax[2]+1)
else:
nbmax[0]+=1
nbmax[2]=max(nbmax[1]+1,nbmax[2]+1)
print (max(nbmax))
``` | 0 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,664,129,636 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 654 | 10,342,400 | import math
a, b = list(map(int, input().split()))
n = int(input())
def gcd(a, b):
if a < b:
a, b = b, a
while b > 0:
r = a % b
a = b
b = r
return a
d = gcd(a, b)
factors = []
for i in range(1, math.floor(math.sqrt(d)) + 1):
if d % i == 0:
factors.append(i)
fa... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
import math
a, b = list(map(int, input().split()))
n = int(input())
def gcd(a, b):
if a < b:
a, b = b, a
while b > 0:
r = a % b
a = b
b = r
return a
d = gcd(a, b)
factors = []
for i in range(1, math.floor(math.sqrt(d)) + 1):
if d % i == 0:
factors.append(... | 3.817236 |
242 | B | Big Segment | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment.
It is guaranteed that no two segments c... | Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1.
The segments are numbered starting from 1 in the order in which they appear in the input. | [
"3\n1 1\n2 2\n3 3\n",
"6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n"
] | [
"-1\n",
"3\n"
] | none | 1,000 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "-1"
},
{
"input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10",
"output": "3"
},
{
"input": "4\n1 5\n2 2\n2 4\n2 5",
"output": "1"
},
{
"input": "5\n3 3\n1 3\n2 2\n2 3\n1 2",
"output": "2"
},
{
"input": "7\n7 7\n8 8\n3 7\n1 6\n1 ... | 1,541,122,696 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 0 | class Segment:
def __init__(self, l, r):
self.l = l
self.r = r
n = int(input())
a = []
minl = 1e9
maxr = 0
for i in range(n):
l, r = map(int, input().split())
a.append(Segment(l, r))
if (l < minl):
minl = l
if (r > maxr):
maxr = r
found = False
for... | Title: Big Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*].
You have suggested that one of the defined segments ... | ```python
class Segment:
def __init__(self, l, r):
self.l = l
self.r = r
n = int(input())
a = []
minl = 1e9
maxr = 0
for i in range(n):
l, r = map(int, input().split())
a.append(Segment(l, r))
if (l < minl):
minl = l
if (r > maxr):
maxr = r
found = ... | 0 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,693,640,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | # Read the input word
word = input()
# Check if the Caps Lock rule should be applied
if word.isupper() or (word[0].islower() and word[1:].isupper()):
# Apply the rule: toggle the case of all letters
word = word.swapcase()
# Print the result
print(word)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
# Read the input word
word = input()
# Check if the Caps Lock rule should be applied
if word.isupper() or (word[0].islower() and word[1:].isupper()):
# Apply the rule: toggle the case of all letters
word = word.swapcase()
# Print the result
print(word)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,631,989,107 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 186 | 20,172,800 | a = input().split()
s = int(a[0])*int(a[1])
if s % 2 == 1:
s -= 1
print(int(s/2))
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
a = input().split()
s = int(a[0])*int(a[1])
if s % 2 == 1:
s -= 1
print(int(s/2))
``` | 3.915925 |
519 | C | A and B and Team Training | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi... | The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session. | Print the maximum number of teams that can be formed. | [
"2 6\n",
"4 5\n"
] | [
"2\n",
"3\n"
] | Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB). | 1,500 | [
{
"input": "2 6",
"output": "2"
},
{
"input": "4 5",
"output": "3"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "3 3",
"output": "2"
},
{
"input": "500000 500000",
"output": "333333"
},
{
"input": "70 100",
"output": "56"
},
{
"input": ... | 1,625,560,264 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 24 | 62 | 0 | #
#####################################################################################################################
from math import ceil
def nTeamsMax(nExperienced, nNewbies):
diffInMembers = abs(nExperienced-nNewbies)
curr_nTeams = min(nExperienced, nNewbies)
return curr_nTeams if diffInMe... | Title: A and B and Team Training
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea... | ```python
#
#####################################################################################################################
from math import ceil
def nTeamsMax(nExperienced, nNewbies):
diffInMembers = abs(nExperienced-nNewbies)
curr_nTeams = min(nExperienced, nNewbies)
return curr_nTeams i... | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,623,342,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | hello = ['h','e','l','o']
string = input()
inputs = []
for index in range(len(string)):
if len(inputs) > 0:
if not inputs[-1] == string[index]:
inputs.append(string[index])
else:
inputs.append(string[index])
def logic(hello_list, input_list):
lh, li = len(hello_list), len(input_list)
ind = l... | 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
hello = ['h','e','l','o']
string = input()
inputs = []
for index in range(len(string)):
if len(inputs) > 0:
if not inputs[-1] == string[index]:
inputs.append(string[index])
else:
inputs.append(string[index])
def logic(hello_list, input_list):
lh, li = len(hello_list), len(input_list)... | 0 |
325 | B | Stadium and Games | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1018), the number of games that should be played.
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. | Print all possible numbers of invited teams in ascending order, one per line. If exactly *n* games cannot be played, output one number: -1. | [
"3\n",
"25\n",
"2\n"
] | [
"3\n4\n",
"20\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3",
"output": "3\n4"
},
{
"input": "25",
"output": "20"
},
{
"input": "2",
"output": "-1"
},
{
"input": "1",
"output": "2"
},
{
"input": "15",
"output": "10\n16"
},
{
"input": "314",
"output": "-1"
},
{
"input": "524800",
"o... | 1,602,790,247 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 307,200 | import sys
import math
def prost(numb):
ans = []
for i in range(3, int(math.sqrt(numb)) + 1, 2):
if numb % i == 0:
ans.append(i)
if i != numb // i:
ans.append(numb // i)
return ans
def step(n):
ans = 1
power = 0
while ans <= n:
... | Title: Stadium and Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Daniel is organizing a football tournament. He has come up with the following tournament format:
1. In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one g... | ```python
import sys
import math
def prost(numb):
ans = []
for i in range(3, int(math.sqrt(numb)) + 1, 2):
if numb % i == 0:
ans.append(i)
if i != numb // i:
ans.append(numb // i)
return ans
def step(n):
ans = 1
power = 0
while ans <= ... | 0 | |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,652,673,532 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 372 | 41,676,800 | y, k, n = map(int, input().split())
x = k - y
l = []
while((x + y) <= n):
if(x >= 1):
l.append(x)
x += k
if(l == []):
print(-1)
else:
print(*l) | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
y, k, n = map(int, input().split())
x = k - y
l = []
while((x + y) <= n):
if(x >= 1):
l.append(x)
x += k
if(l == []):
print(-1)
else:
print(*l)
``` | 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,584,168,124 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | a = int(input())
b = int(input())
z = abs(a-b)//2
x = z*(z+1)
if abs(a-b)%2 !=0:
y = z+1
else:
y =0
print(x+y) | 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
a = int(input())
b = int(input())
z = abs(a-b)//2
x = z*(z+1)
if abs(a-b)%2 !=0:
y = z+1
else:
y =0
print(x+y)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are an assistant director in a new musical play. The play consists of *n* musical parts, each part must be performed by exactly one actor. After the casting the director chose *m* actors who can take part in the play. Your task is to assign the parts to actors. However, there are several limitations.
First, each a... | The first line contains a single integer *n* — the number of parts in the play (1<=≤<=*n*<=≤<=105).
Next *n* lines contain two space-separated integers each, *a**j* and *b**j* — the range of notes for the *j*-th part (1<=≤<=*a**j*<=≤<=*b**j*<=≤<=109).
The next line contains a single integer *m* — the number of actors... | If there is an assignment that meets all the criteria aboce, print a single word "YES" (without the quotes) in the first line.
In the next line print *n* space-separated integers. The *i*-th integer should be the number of the actor who should perform the *i*-th part. If there are multiple correct assignments, print a... | [
"3\n1 3\n2 4\n3 5\n2\n1 4 2\n2 5 1\n",
"3\n1 3\n2 4\n3 5\n2\n1 3 2\n2 5 1\n"
] | [
"YES\n1 1 2\n",
"NO\n"
] | none | 0 | [] | 1,420,650,994 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 405 | 120,729,600 | n = int(input()) #количество партий
parts = [[0]*2 for _ in range(n)]
import copy
for i in range(n):
a,b = map(int,input().split(' '))#диапазон партий
parts[i][0],parts[i][1] = a,b #присв.
m = int(input())#кол-во актеров
actors = [[0]*3 for _ in range(m)]
for j in range(m):
a,b,c = map(int,input(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are an assistant director in a new musical play. The play consists of *n* musical parts, each part must be performed by exactly one actor. After the casting the director chose *m* actors who can take part in the play. Your tas... | ```python
n = int(input()) #количество партий
parts = [[0]*2 for _ in range(n)]
import copy
for i in range(n):
a,b = map(int,input().split(' '))#диапазон партий
parts[i][0],parts[i][1] = a,b #присв.
m = int(input())#кол-во актеров
actors = [[0]*3 for _ in range(m)]
for j in range(m):
a,b,c = map(... | 0 | |
445 | A | DZY Loves Chessboard | PROGRAMMING | 1,200 | [
"dfs and similar",
"implementation"
] | null | null | DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ... | Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell.
If multiple answers exist, print any of them. It ... | [
"1 1\n.\n",
"2 2\n..\n..\n",
"3 3\n.-.\n---\n--."
] | [
"B\n",
"BW\nWB\n",
"B-B\n---\n--B"
] | In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.
In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.
In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are. | 500 | [
{
"input": "1 1\n.",
"output": "B"
},
{
"input": "2 2\n..\n..",
"output": "BW\nWB"
},
{
"input": "3 3\n.-.\n---\n--.",
"output": "B-B\n---\n--B"
},
{
"input": "3 1\n-\n.\n.",
"output": "-\nW\nB"
},
{
"input": "11 11\n-----------\n-----------\n-----------\n--------... | 1,609,763,145 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 217 | 3,788,800 | from collections import *
import bisect
import heapq
from collections import deque
def canBipartite():
"""
vertices are numbered from 0 , 1 ...to n - 1
Return True if we can color the n vertices with 2 colors,
given than vertices on both sides of an edge must have different colors.
... | Title: DZY Loves Chessboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chessboard, and he enjoys playing with it.
He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ... | ```python
from collections import *
import bisect
import heapq
from collections import deque
def canBipartite():
"""
vertices are numbered from 0 , 1 ...to n - 1
Return True if we can color the n vertices with 2 colors,
given than vertices on both sides of an edge must have different colo... | 3 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,566,322,626 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 155 | 409,600 | n = int(input())
v = input()
count = 0
right = 0
left = 0
second = 0
for i in range(0,len(v)):
if v[i]=='<' and second==0:
count+=1
elif v[i]=='<' and second:
second -= 1
elif v[i]=='>':
second+=1
print(abs(count) + second) | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
n = int(input())
v = input()
count = 0
right = 0
left = 0
second = 0
for i in range(0,len(v)):
if v[i]=='<' and second==0:
count+=1
elif v[i]=='<' and second:
second -= 1
elif v[i]=='>':
second+=1
print(abs(count) + second)
``` | 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,698,830,871 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n = int(input())
c = 0
for i in range(n):
a = list(map(int,input().split()))
aa = a.count(1)
if aa >= 2:
c += 1
print(c) | 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())
c = 0
for i in range(n):
a = list(map(int,input().split()))
aa = a.count(1)
if aa >= 2:
c += 1
print(c)
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,684,151,419 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 62 | 0 | a=input()
s=0
for i in range(0,len(a)):
for j in range(i,len(a)):
for h in range(j,len(a)):
if a[i]=='Q' and a[j]=='A' and a[h]=='Q':
s += 1
print(s) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
a=input()
s=0
for i in range(0,len(a)):
for j in range(i,len(a)):
for h in range(j,len(a)):
if a[i]=='Q' and a[j]=='A' and a[h]=='Q':
s += 1
print(s)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,673,010,027 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s = input()
uc = 0
lc = 0
for char in s:
if char >= 'a' and char <= 'z':
lc += 1
elif char >= 'A' and char <= 'Z':
uc += 1
if uc > lc:
print(s.upper())
else:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
uc = 0
lc = 0
for char in s:
if char >= 'a' and char <= 'z':
lc += 1
elif char >= 'A' and char <= 'Z':
uc += 1
if uc > lc:
print(s.upper())
else:
print(s.lower())
``` | 3.977 |
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t... | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food pac... | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of ty... | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"inp... | 1,687,903,823 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 77 | 1,331,200 | n,m=map(int,input().split())
ll=list(map(str,input().split()))
r=0
k=m//n
t=1
while t<=k:
dict2 = dict()
for i in ll:
if i in dict2:
dict2[i] += 1
else:
dict2[i] = 1
x=0
while x<n and max((dict2.values()))>=t:
for i in dict2:
if ... | Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
E... | ```python
n,m=map(int,input().split())
ll=list(map(str,input().split()))
r=0
k=m//n
t=1
while t<=k:
dict2 = dict()
for i in ll:
if i in dict2:
dict2[i] += 1
else:
dict2[i] = 1
x=0
while x<n and max((dict2.values()))>=t:
for i in dict2:
... | 3 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,697,221,272 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 154 | 7,987,200 | ln = int(input())
arr = sorted(list(map(int,input().split())))
for i in range(ln-1,1,-1):
arr[0] += (arr[i]-arr[1])
arr[i] = arr[1]
n = arr[0]-arr[1]
if (n//ln == n/ln and arr[0]>=arr[1] and n%ln==0) or ln==1:
print(ln)
else:
print(ln-1) | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
ln = int(input())
arr = sorted(list(map(int,input().split())))
for i in range(ln-1,1,-1):
arr[0] += (arr[i]-arr[1])
arr[i] = arr[1]
n = arr[0]-arr[1]
if (n//ln == n/ln and arr[0]>=arr[1] and n%ln==0) or ln==1:
print(ln)
else:
print(ln-1)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить *n* ножек одинаковой длины. При составлении ножки любые две части могут быть соединены дру... | В первой строке задано число *n* (1<=≤<=*n*<=≤<=1000) — количество ножек у стола, купленного Васей.
Во второй строке следует последовательность из 2*n* целых положительных чисел *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=100<=000) — длины частей ножек стола в произвольном порядке. | Выведите *n* строк по два целых числа в каждой — длины частей ножек, которые надо соединить друг с другом. Гарантируется, что всегда возможно собрать *n* ножек одинаковой длины. Если ответов несколько, разрешается вывести любой из них. | [
"3\n1 3 2 4 5 3\n",
"3\n1 1 1 2 2 2\n"
] | [
"1 5\n2 4\n3 3\n",
"1 2\n2 1\n1 2\n"
] | none | 0 | [
{
"input": "3\n1 3 2 4 5 3",
"output": "1 5\n2 4\n3 3"
},
{
"input": "3\n1 1 1 2 2 2",
"output": "1 2\n1 2\n1 2"
},
{
"input": "1\n3 7",
"output": "3 7"
},
{
"input": "10\n9 13 18 7 18 13 2 2 5 16 3 17 5 4 18 2 15 11 7 15",
"output": "2 18\n2 18\n2 18\n3 17\n4 16\n5 15\n5... | 1,458,746,635 | 1,435 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 46 | 4,608,000 | n = int(input())
a = list(map(int, input().split()))
d = sum(a) // n
was = [False] * (2 * n)
for i in range(2 * n):
for j in range(i + 1, 2 * n):
if was[j]: continue
if a[i] + a[j] == d:
print(a[i], a[j])
was[i] = False
was[j] = False | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Вася купил стол, у которого *n* ножек. Каждая ножка состоит из двух частей, которые соединяются друг с другом. Каждая часть может быть произвольной положительной длины, но гарантируется, что из всех 2*n* частей возможно составить ... | ```python
n = int(input())
a = list(map(int, input().split()))
d = sum(a) // n
was = [False] * (2 * n)
for i in range(2 * n):
for j in range(i + 1, 2 * n):
if was[j]: continue
if a[i] + a[j] == d:
print(a[i], a[j])
was[i] = False
was[j] = False
``` | 0 | |
122 | B | Lucky Substring | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | 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.
One day Petya was delivered a string *s*, containing only digits. He needs to find a string that
- ... | The single line contains a non-empty string *s* whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes. | In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes). | [
"047\n",
"16\n",
"472747\n"
] | [
"4\n",
"-1\n",
"7\n"
] | The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String *x* is lexicographically less than string *y* either if *x* is a prefix of *y*, or exists such *i* (1 ≤ *i* ≤ *min*(|*x*|, |*y*|)), that *x*<sub class="lower-index">*i*</sub> < *y*<sub class="lower... | 1,000 | [
{
"input": "047",
"output": "4"
},
{
"input": "16",
"output": "-1"
},
{
"input": "472747",
"output": "7"
},
{
"input": "1925",
"output": "-1"
},
{
"input": "5486846414848445484",
"output": "4"
},
{
"input": "516160414",
"output": "4"
},
{
"... | 1,690,424,652 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 307,200 | from collections import Counter
s = Counter(input())
res = 4 if s["4"] >= s["7"] > 0 else 7 if s["7"] > 0 else -1
print(res)
| Title: Lucky Substring
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
from collections import Counter
s = Counter(input())
res = 4 if s["4"] >= s["7"] > 0 else 7 if s["7"] > 0 else -1
print(res)
``` | 0 | |
630 | A | Again Twenty Five! | PROGRAMMING | 800 | [
"number theory"
] | null | null | The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. | Output the last two digits of 5*n* without spaces between them. | [
"2\n"
] | [
"25"
] | none | 0 | [
{
"input": "2",
"output": "25"
},
{
"input": "7",
"output": "25"
},
{
"input": "1000000000000000000",
"output": "25"
},
{
"input": "2000000000000000000",
"output": "25"
},
{
"input": "987654321012345678",
"output": "25"
}
] | 1,689,865,288 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a = int(input())
print(5 ** a) | Title: Again Twenty Five!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge... | ```python
a = int(input())
print(5 ** a)
``` | 0 | |
68 | B | Energy exchange | PROGRAMMING | 1,600 | [
"binary search"
] | B. Energy exchange | 2 | 256 | It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the *i*-th accumulator has *a**i* units of energy. Energy ... | First line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10000,<=0<=≤<=*k*<=≤<=99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains *n* integers *a*1,<=*a*2,<=... ,<=*a**n* — amounts of energy in the first, second, .., *n*-th accumulator respectively ... | Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10<=-<=6. | [
"3 50\n4 2 1\n",
"2 90\n1 11\n"
] | [
"2.000000000\n",
"1.909090909\n"
] | none | 1,000 | [
{
"input": "3 50\n4 2 1",
"output": "2.000000000"
},
{
"input": "2 90\n1 11",
"output": "1.909090909"
},
{
"input": "5 26\n42 65 23 43 64",
"output": "45.415178571"
},
{
"input": "5 45\n964 515 454 623 594",
"output": "594.109756098"
},
{
"input": "1 20\n784",
... | 1,624,457,343 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 998 | 409,600 | n, k = map(int, input().split())
accumulators = list(map(int, input().split()))
low = 0
high = 1000
for i in range(100):
less = 0
more = 0
mid = low + (high - low) / 2
for i in range(n):
if accumulators[i] > mid:
more += accumulators[i] - mid
else:
... | Title: Energy exchange
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every ... | ```python
n, k = map(int, input().split())
accumulators = list(map(int, input().split()))
low = 0
high = 1000
for i in range(100):
less = 0
more = 0
mid = low + (high - low) / 2
for i in range(n):
if accumulators[i] > mid:
more += accumulators[i] - mid
else:
... | 3.749737 |
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti... | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal... | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$.... | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
... | 1,651,501,624 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 61 | 512,000 | import math
#from decimal import *
#from collections import deque
def transformare_baza(numar,baza):
transformare=""
while numar>=baza:
rest=numar%baza
numar=numar//baza
transformare+=str(rest)
transformare+=str(numar)
noua_baza=transformare[::-1]
return noua_baza
def produs_cifre(n... | Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Gi... | ```python
import math
#from decimal import *
#from collections import deque
def transformare_baza(numar,baza):
transformare=""
while numar>=baza:
rest=numar%baza
numar=numar//baza
transformare+=str(rest)
transformare+=str(numar)
noua_baza=transformare[::-1]
return noua_baza
def prod... | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,687,585,905 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 921,600 | import string
message = input()
msg = message.lower().split(" ")
for m in msg:
if(m.isdigit()):
continue
elif len(m)==0:
continue
elif len(m)>10:
mid = len(m)-2
first = m[0]
last = m[-1]
# print(first, last, len(message))
print(f"{first}{m... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
import string
message = input()
msg = message.lower().split(" ")
for m in msg:
if(m.isdigit()):
continue
elif len(m)==0:
continue
elif len(m)>10:
mid = len(m)-2
first = m[0]
last = m[-1]
# print(first, last, len(message))
print(f... | 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,613,063,906 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | s = input()
if s[0].islower():
print(s.upper())
else:
print(s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
if s[0].islower():
print(s.upper())
else:
print(s.lower())
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,539,262,573 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 155 | 1,024,000 | s = input()
h , e , l1 , l2 , o = False , False , False , False , False
for c in s:
if c == 'h':
h = True
elif h and c == 'e':
e = True
elif (not l1) and e and c == 'l':
l1 = True
elif l1 and c == 'l':
l2 = True;
elif l2 and c == 'o':
o = True
if h and e and l1 and l2 and o:
print('YES')
else:
print('... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
h , e , l1 , l2 , o = False , False , False , False , False
for c in s:
if c == 'h':
h = True
elif h and c == 'e':
e = True
elif (not l1) and e and c == 'l':
l1 = True
elif l1 and c == 'l':
l2 = True;
elif l2 and c == 'o':
o = True
if h and e and l1 and l2 and o:
print('YES')
else... | 3.920593 |
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,643,821,479 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 93 | 0 | #For fast I/O
import sys
input = lambda: sys.stdin.readline().strip()
Homura = input()
Madoka = input()
l = len(Homura)
ans = ''
for i in range(l):
a = int(Homura[i])
b = int(Madoka[i])
c = a^b
ans += str(c)
print(ans)
| 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
#For fast I/O
import sys
input = lambda: sys.stdin.readline().strip()
Homura = input()
Madoka = input()
l = len(Homura)
ans = ''
for i in range(l):
a = int(Homura[i])
b = int(Madoka[i])
c = a^b
ans += str(c)
print(ans)
``` | 3.97675 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,677,864,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 409,600 | import string
word = input("")
list_of_alphabet = list(string.ascii_lowercase)
i = 0
j = 0
k = 1
result = 0
while (k != len(word)):
if(abs(list_of_alphabet.index(word[j]) - list_of_alphabet.index(word[k])) >= 13):
result += 26 - abs(list_of_alphabet.index(word[j]) - list_of_alphabet.index(word[k]))
els... | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
import string
word = input("")
list_of_alphabet = list(string.ascii_lowercase)
i = 0
j = 0
k = 1
result = 0
while (k != len(word)):
if(abs(list_of_alphabet.index(word[j]) - list_of_alphabet.index(word[k])) >= 13):
result += 26 - abs(list_of_alphabet.index(word[j]) - list_of_alphabet.index(word[k]... | 0 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,607,453,854 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 155 | 0 | # A. Professor GukiZ's Robot
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x_diff = abs(x1 - x2)
y_diff = abs(y1 - y2)
ans = min(x_diff, y_diff) + abs(x_diff - y_diff)
print(ans)
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
# A. Professor GukiZ's Robot
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
x_diff = abs(x1 - x2)
y_diff = abs(y1 - y2)
ans = min(x_diff, y_diff) + abs(x_diff - y_diff)
print(ans)
``` | 3 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,582,408,236 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 374 | 8,089,600 | import random, math
from copy import deepcopy as dc
# To Genrate Random Number for Test-Cases
def randomNumber(s, e):
return random.randint(s, e)
# To Generate Random Array for Test-Cases
def randomArray(s, e, s_size, e_size):
size = random.randint(s_size, e_size)
arr = [randomNumber(s, e) for i in range(size)]
r... | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
import random, math
from copy import deepcopy as dc
# To Genrate Random Number for Test-Cases
def randomNumber(s, e):
return random.randint(s, e)
# To Generate Random Array for Test-Cases
def randomArray(s, e, s_size, e_size):
size = random.randint(s_size, e_size)
arr = [randomNumber(s, e) for i in range... | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,672,133,171 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 62 | 0 | n,m=map(int,input().split())
a=sorted([int(i) for i in input().split()])
c=[]
for i in range(m-n+1):
c.append(a[i+n-1]-a[i])
print(min(c))
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m=map(int,input().split())
a=sorted([int(i) for i in input().split()])
c=[]
for i in range(m-n+1):
c.append(a[i+n-1]-a[i])
print(min(c))
``` | 3 | |
908 | C | New Year and Curling | PROGRAMMING | 1,500 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one by one in order from 1 to *n*.
When she slides the *i*-th disk, she will place its center at the point (*... | The first line will contain two integers *n* and *r* (1<=≤<=*n*,<=*r*<=≤<=1<=000), the number of disks, and the radius of the disks, respectively.
The next line will contain *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=1<=000) — the *x*-coordinates of the disks. | Print a single line with *n* numbers. The *i*-th number denotes the *y*-coordinate of the center of the *i*-th disk. The output will be accepted if it has absolute or relative error at most 10<=-<=6.
Namely, let's assume that your answer for a particular value of a coordinate is *a* and the answer of the jury is *b*. ... | [
"6 2\n5 5 6 8 3 12\n"
] | [
"2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613\n"
] | The final positions of the disks will look as follows:
In particular, note the position of the last disk. | 1,000 | [
{
"input": "6 2\n5 5 6 8 3 12",
"output": "2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613"
},
{
"input": "1 1\n5",
"output": "1"
},
{
"input": "5 300\n939 465 129 611 532",
"output": "300 667.864105343 1164.9596696 1522.27745533 2117.05388391"
},
{
"input": "5 ... | 1,514,642,375 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 342 | 5,734,400 | import math
n,r=map(int,input().split())
x=list(map(int,input().split()))
y=[r]
def collision(t,a):
m=0
p=0
z=False
for i in range(len(t)):
if (a<=t[i]+2*r and a>=t[i]-2*r):
if y[i]>m:
m=y[i]
p=i
... | Title: New Year and Curling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Carol is currently curling.
She has *n* disks each with radius *r* on the 2D plane.
Initially she has all these disks above the line *y*<==<=10100.
She then will slide the disks towards the line *y*<==<=0 one b... | ```python
import math
n,r=map(int,input().split())
x=list(map(int,input().split()))
y=[r]
def collision(t,a):
m=0
p=0
z=False
for i in range(len(t)):
if (a<=t[i]+2*r and a>=t[i]-2*r):
if y[i]>m:
m=y[i]
p=i
... | 0 | |
906 | B | Seating of Students | PROGRAMMING | 2,200 | [
"brute force",
"constructive algorithms",
"math"
] | 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. | 1,250 | [
{
"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,517,898,518 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef v... | Title: Seating of Students
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 neigh... | ```python
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
... | -1 | |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,426,928,665 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | a = int(input())
b = int(input())
count = 1
area = a * b
while a != b:
count += 1
if a > b:
area -= a * a
a -= b
elif a < b:
area -= b*b
b -= a
else:
break
print(count)
| Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
a = int(input())
b = int(input())
count = 1
area = a * b
while a != b:
count += 1
if a > b:
area -= a * a
a -= b
elif a < b:
area -= b*b
b -= a
else:
break
print(count)
``` | -1 | |
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that... | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th... | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1... | 1,691,289,259 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 31 | 0 | n,l = map(int,input().split())
a=[*map(int,input().split())]
a.sort()
d1=min(a)
d2=abs(l-max(a))
dls= [abs(a[x]-a[x+1]) for x in range(len(a)-1) ]
dl = float(max(dls)/2)
r1=max(d1,d2)
rf=max(r1,dl)
print(rf) | Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi... | ```python
n,l = map(int,input().split())
a=[*map(int,input().split())]
a.sort()
d1=min(a)
d2=abs(l-max(a))
dls= [abs(a[x]-a[x+1]) for x in range(len(a)-1) ]
dl = float(max(dls)/2)
r1=max(d1,d2)
rf=max(r1,dl)
print(rf)
``` | -1 | |
991 | D | Bishwock | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.
Vasya has a board wi... | The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. | Output a single integer — the maximum amount of bishwocks that can be placed onto the given board. | [
"00\n00\n",
"00X00X0XXX0\n0XXX0X00X00\n",
"0X0X0\n0X0X0\n",
"0XXX0\n00000\n"
] | [
"1",
"4",
"0",
"2"
] | none | 1,500 | [
{
"input": "00\n00",
"output": "1"
},
{
"input": "00X00X0XXX0\n0XXX0X00X00",
"output": "4"
},
{
"input": "0X0X0\n0X0X0",
"output": "0"
},
{
"input": "0XXX0\n00000",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\nX",
"output": "... | 1,693,641,207 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | s=''.join(x+y for x,y in zip(input(),input()))
n=len(s)//2
f=[0]*n
b=[0]*n
if n<2:print(0)
for i in range(n):
j=2*i
if i<n-1:
f[i]=s[j:j+4].count('X')<2
if i>0:
f[i]=max(f[i-1],max(b[i-1],f[i-2])+f[i])
c=s[j-2:j+2].count('X')
b[i]=max(b[i-2]+(c<2), f[i-2]*(i>1)+(c... | Title: Bishwock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occup... | ```python
s=''.join(x+y for x,y in zip(input(),input()))
n=len(s)//2
f=[0]*n
b=[0]*n
if n<2:print(0)
for i in range(n):
j=2*i
if i<n-1:
f[i]=s[j:j+4].count('X')<2
if i>0:
f[i]=max(f[i-1],max(b[i-1],f[i-2])+f[i])
c=s[j-2:j+2].count('X')
b[i]=max(b[i-2]+(c<2), f[i-2... | 0 | |
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,633,068,428 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 154 | 6,758,400 | def trans (a,b):
x=len(b)
for i in range (0,x):
if a[i]==b[x-1-i]:
continue
else:
return False
return True
a=input()
b=input()
if trans (a,b):
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
def trans (a,b):
x=len(b)
for i in range (0,x):
if a[i]==b[x-1-i]:
continue
else:
return False
return True
a=input()
b=input()
if trans (a,b):
print ("YES")
else:
print ("NO")
``` | 3.948911 |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,649,623,556 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | for _ in range(int(input())):
a = int(input())
b = list(map(int,input().split()))
c1=b.count(1)
c2=b.count(2)
c3=b.count(3)
c4=b.count(4)
c6=b.count(6)
x=[]
if b.count(4) :
if c1>=c4*2 and c2>=c4*2:
while c4!=0:
x.append([1,2,4])
... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
for _ in range(int(input())):
a = int(input())
b = list(map(int,input().split()))
c1=b.count(1)
c2=b.count(2)
c3=b.count(3)
c4=b.count(4)
c6=b.count(6)
x=[]
if b.count(4) :
if c1>=c4*2 and c2>=c4*2:
while c4!=0:
x.append([1,2,... | -1 | |
248 | B | Chilly Willy | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.
Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous... | A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. | [
"1\n",
"5\n"
] | [
"-1\n",
"10080"
] | none | 1,000 | [
{
"input": "1",
"output": "-1"
},
{
"input": "5",
"output": "10080"
},
{
"input": "6",
"output": "100170"
},
{
"input": "4",
"output": "1050"
},
{
"input": "15",
"output": "100000000000110"
},
{
"input": "16",
"output": "1000000000000050"
},
{
... | 1,695,778,935 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 92 | 5,632,000 | import math
a = int(input())
b = 2*3*5*7
digits = int(math.log10(b))+1
if a < digits:
print("-1")
else:
print(b*math.ceil((10**(a-1))/b)) | Title: Chilly Willy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit... | ```python
import math
a = int(input())
b = 2*3*5*7
digits = int(math.log10(b))+1
if a < digits:
print("-1")
else:
print(b*math.ceil((10**(a-1))/b))
``` | 0 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,622,454,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 78 | 3,379,200 | n=int(input())
lst=list(map(int,input().split()))
T=lst.count(2);O=n-T
if T==0:
print(O//3)
elif O==0:
print('0')
elif T>O:
print(O)
elif T<O:
print(T+(O-T)//3) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n=int(input())
lst=list(map(int,input().split()))
T=lst.count(2);O=n-T
if T==0:
print(O//3)
elif O==0:
print('0')
elif T>O:
print(O)
elif T<O:
print(T+(O-T)//3)
``` | 0 | |
600 | D | Area of Two Circles' Intersection | PROGRAMMING | 2,000 | [
"geometry"
] | null | null | You are given two circles. Find the area of their intersection. | The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) — the position of the center and the radius of the first circle.
The second line contains three integers *x*2,<=*y*2,<=*r*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109,<=1<=≤<=*r*2<=≤<=109) — the position of the cen... | Print the area of the intersection of the circles. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"0 0 4\n6 0 4\n",
"0 0 5\n11 0 5\n"
] | [
"7.25298806364175601379\n",
"0.00000000000000000000\n"
] | none | 0 | [
{
"input": "0 0 4\n6 0 4",
"output": "7.25298806364175601379"
},
{
"input": "0 0 5\n11 0 5",
"output": "0.00000000000000000000"
},
{
"input": "0 0 10\n9 0 1",
"output": "3.14159265358979311600"
},
{
"input": "0 0 2\n2 2 2",
"output": "2.28318530717958647659"
},
{
... | 1,624,879,400 | 3,500 | Python 3 | WRONG_ANSWER | TESTS | 27 | 77 | 0 | import math
x1, y1, r1 = [int(x) for x in input().split()]
x2, y2, r2 = [int(x) for x in input().split()]
dd = (x1 - x2) ** 2 + (y1 - y2) ** 2
d = math.sqrt(dd)
if dd >= (r1 + r2) ** 2:
print(0)
exit()
if d <= abs(r2 - r1):
print(math.pi * (min(r1, r2) ** 2))
exit()
f1 = r1 * r1 * m... | Title: Area of Two Circles' Intersection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two circles. Find the area of their intersection.
Input Specification:
The first line contains three integers *x*1,<=*y*1,<=*r*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109,<=1<=≤<=*r*1<=≤<=109) —... | ```python
import math
x1, y1, r1 = [int(x) for x in input().split()]
x2, y2, r2 = [int(x) for x in input().split()]
dd = (x1 - x2) ** 2 + (y1 - y2) ** 2
d = math.sqrt(dd)
if dd >= (r1 + r2) ** 2:
print(0)
exit()
if d <= abs(r2 - r1):
print(math.pi * (min(r1, r2) ** 2))
exit()
f1 = r... | 0 | |
570 | C | Replacement | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"implementation"
] | null | null | Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string *s*, of all occurrences of the substring let's choose the first one, and replace thi... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300<=000) the length of the string and the number of queries.
The second line contains string *s*, consisting of *n* lowercase English letters and period signs.
The following *m* lines contain the descriptions of queries. The *i*-th line contains i... | Print *m* numbers, one per line, the *i*-th of these numbers must be equal to the value of *f*(*s*) after performing the *i*-th assignment. | [
"10 3\n.b..bz....\n1 h\n3 c\n9 f\n",
"4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n"
] | [
"4\n3\n1\n",
"1\n3\n1\n1\n"
] | Note to the first sample test (replaced periods are enclosed in square brackets).
The original string is ".b..bz....".
- after the first query *f*(hb..bz....) = 4 ("hb[..]bz...." → "hb.bz[..].." → "hb.bz[..]." → "hb.bz[..]" → "hb.bz.")- after the second query *f*(hbс.bz....) = 3 ("hbс.bz[..].." → "hb... | 1,500 | [
{
"input": "10 3\n.b..bz....\n1 h\n3 c\n9 f",
"output": "4\n3\n1"
},
{
"input": "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a",
"output": "1\n3\n1\n1"
},
{
"input": "3 3\n...\n1 .\n2 a\n3 b",
"output": "2\n0\n0"
},
{
"input": "5 1\n.....\n5 z",
"output": "3"
},
{
"input": "1 5\n... | 1,567,545,062 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 2,457,600 | #Codeforces 570 C - Replacement
n,m=map(int,input().split())
s = list(input())
dots = 0
groups = 0
prev = "x" #whatever char distinct of .
for l in s:
if l == ".":
dots += 1
if prev != ".":
groups += 1
prev = l
#print(dots,groups)
for _ in range(m):
x,c = input().split()
x = int(x) - 1
a = x-1>=0 and s[x-1]... | Title: Replacement
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Daniel has a string *s*, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive period... | ```python
#Codeforces 570 C - Replacement
n,m=map(int,input().split())
s = list(input())
dots = 0
groups = 0
prev = "x" #whatever char distinct of .
for l in s:
if l == ".":
dots += 1
if prev != ".":
groups += 1
prev = l
#print(dots,groups)
for _ in range(m):
x,c = input().split()
x = int(x) - 1
a = x-1>=0 ... | 0 | |
508 | A | Pasha and Pixels | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos... | The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*... | If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0. | [
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n",
"5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n"
] | [
"4\n",
"5\n",
"0\n"
] | none | 500 | [
{
"input": "2 2 4\n1 1\n1 2\n2 1\n2 2",
"output": "4"
},
{
"input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1",
"output": "5"
},
{
"input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2",
"output": "0"
},
{
"input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3",
... | 1,668,417,839 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 187 | 0 | n,m,k=map(int,input().split())
a=[[0]*(m+1) for _ in range(n+1)]
b=[]
for i in range(k):
x,y=map(int,input().split())
a[x][y]=i+1
for i in range(n-1):
for j in range(m-1):
if a[i+1][j+1]!=0 and a[i+1][j+2]!=0 and a[i+2][j+1]!=0 and a[i+2][j+2]!=0:
b.append(max(a[i+1][j+1],a[i+... | Title: Pasha and Pixels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ... | ```python
n,m,k=map(int,input().split())
a=[[0]*(m+1) for _ in range(n+1)]
b=[]
for i in range(k):
x,y=map(int,input().split())
a[x][y]=i+1
for i in range(n-1):
for j in range(m-1):
if a[i+1][j+1]!=0 and a[i+1][j+2]!=0 and a[i+2][j+1]!=0 and a[i+2][j+2]!=0:
b.append(max(a[i+1]... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3.
Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего бра... | В первой строке входных данных следуют два различных целых числа *a* и *b* (1<=≤<=*a*,<=*b*<=≤<=3, *a*<=≠<=*b*) — номера братьев, которые пришли на встречу вовремя. Номера даны в произвольном порядке. | Выведите единственное целое число — номер брата, который опоздал на встречу. | [
"3 1\n"
] | [
"2\n"
] | none | 0 | [
{
"input": "3 1",
"output": "2"
},
{
"input": "2 1",
"output": "3"
},
{
"input": "2 3",
"output": "1"
},
{
"input": "1 2",
"output": "3"
},
{
"input": "1 3",
"output": "2"
},
{
"input": "3 2",
"output": "1"
}
] | 1,458,592,758 | 23,958 | Python 3 | OK | TESTS | 6 | 62 | 4,608,000 | x = input()
if x.find('1') == -1:
print(1)
if x.find('2') == -1:
print(2)
if x.find('3') == -1:
print(3)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3.
Когда пришло время встречи, один из братьев опоздал. По заданным но... | ```python
x = input()
if x.find('1') == -1:
print(1)
if x.find('2') == -1:
print(2)
if x.find('3') == -1:
print(3)
``` | 3 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,613,681,355 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 218 | 0 | col = list(map(int, input().split()))
ans = sum([i//3 for i in col])
ans += min([i%3 for i in col])
m = min(col)
ans2 = m + sum([(i-m)//3 for i in col])
print(max(ans, ans2))
| Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
col = list(map(int, input().split()))
ans = sum([i//3 for i in col])
ans += min([i%3 for i in col])
m = min(col)
ans2 = m + sum([(i-m)//3 for i in col])
print(max(ans, ans2))
``` | 0 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,580,770,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | a , b , c = input().split(' ')
if int(c) == 0:
if int(a) == int(b):
print('YES')
else:
print('NO')
else:
if (int(b)-int(a)) % int(c):
print('NO')
else:
print('YES') | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a , b , c = input().split(' ')
if int(c) == 0:
if int(a) == int(b):
print('YES')
else:
print('NO')
else:
if (int(b)-int(a)) % int(c):
print('NO')
else:
print('YES')
``` | 0 | |
796 | B | Find The Bone | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at the position *x*<==<=*i*.
The problematic bone is initially at the position *x*<==<=1. Zane will co... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=106, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.
The second line contains *m* distinct integers *h*1,<=*h*2,<=...,<=*h**m* (1<=≤<=*h**i*<=≤<=*... | Print one integer — the final position along the *x*-axis of the bone. | [
"7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n",
"5 1 2\n2\n1 2\n2 4\n"
] | [
"1",
"2"
] | In the first sample, after the operations, the bone becomes at *x* = 2, *x* = 5, *x* = 7, and *x* = 1, respectively.
In the second sample, after the first operation, the bone becomes at *x* = 2, and falls into the hole onto the ground. | 750 | [
{
"input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1",
"output": "1"
},
{
"input": "5 1 2\n2\n1 2\n2 4",
"output": "2"
},
{
"input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11",
"output": "55"
},
{
"input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5... | 1,583,161,227 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 307,200 | n,m,k=map(int,input().split())
a=list(map(int,input().split()));r=1
b=[1]+[0]*(n-1);c=0
for i in range(k):
s,d=map(int,input().split())
if s==r or d==1:
c=1
if c!=1:
c=0
continue
elif s in a :
r=s
break
elif d in a:
r=d
break
... | Title: Find The Bone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard is going to perform a magic show shuffling the cups.
There are *n* cups, numbered from 1 to *n*, placed along the *x*-axis on a table that has *m* holes on it. More precisely, cup *i* is on the table at t... | ```python
n,m,k=map(int,input().split())
a=list(map(int,input().split()));r=1
b=[1]+[0]*(n-1);c=0
for i in range(k):
s,d=map(int,input().split())
if s==r or d==1:
c=1
if c!=1:
c=0
continue
elif s in a :
r=s
break
elif d in a:
r=d
... | 0 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,621,697,709 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 77 | 0 | n = int(input())
l = []
for _ in range(n):
b = list(input().split())
l.append(b[0])
m = len(l[0])
e = 0
for i in range(n):
for j in range(m):
c = 0
if (i-1>=0 and l[i-1][j] == 'o'):
c += 1
if (i+1<n and l[i+1][j] == 'o'):
c += 1
if (j-1>=... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n = int(input())
l = []
for _ in range(n):
b = list(input().split())
l.append(b[0])
m = len(l[0])
e = 0
for i in range(n):
for j in range(m):
c = 0
if (i-1>=0 and l[i-1][j] == 'o'):
c += 1
if (i+1<n and l[i+1][j] == 'o'):
c += 1
... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,691,658,777 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | t=int(input())
for i in range(t):
x=str(input())
x=x.replace("WUB"," ")
print(x) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
t=int(input())
for i in range(t):
x=str(input())
x=x.replace("WUB"," ")
print(x)
``` | -1 | |
106 | A | Card Game | PROGRAMMING | 1,000 | [
"implementation"
] | A. Card Game | 2 | 256 | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", ... | The first line contains the tramp suit. It is "S", "H", "D" or "C".
The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the... | Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes). | [
"H\nQH 9S\n",
"S\n8D 6D\n",
"C\n7H AS\n"
] | [
"YES\n",
"YES",
"NO"
] | none | 500 | [
{
"input": "H\nQH 9S",
"output": "YES"
},
{
"input": "S\n8D 6D",
"output": "YES"
},
{
"input": "C\n7H AS",
"output": "NO"
},
{
"input": "C\nKC 9C",
"output": "YES"
},
{
"input": "D\n7D KD",
"output": "NO"
},
{
"input": "H\n7H KD",
"output": "YES"
... | 1,571,741,122 | 2,147,483,647 | Python 3 | OK | TESTS | 78 | 248 | 0 | #import math
#n, m = input().split()
#n = int (n)
#m = int (m)
#n, m, k = input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#n = int(input())
#m = int(input())
#s = input()
##t = input()
#a = list(map(int, input().split()))
#print(l)
#c = list(map(int, input().split()))
#x1, y1, x2, y2 =map(int,in... | Title: Card Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselve... | ```python
#import math
#n, m = input().split()
#n = int (n)
#m = int (m)
#n, m, k = input().split()
#n = int (n)
#m = int (m)
#k = int (k)
#n = int(input())
#m = int(input())
#s = input()
##t = input()
#a = list(map(int, input().split()))
#print(l)
#c = list(map(int, input().split()))
#x1, y1, x2, y2 =... | 3.938 |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,485,670,360 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 6 | 327 | 268,390,400 | n, k = list(map(int, input().split()))
A = [1]
q = 2
for i in range(n - 1):
A = A + [q] + A
q += 1
print(A[k - 1])
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
n, k = list(map(int, input().split()))
A = [1]
q = 2
for i in range(n - 1):
A = A + [q] + A
q += 1
print(A[k - 1])
``` | 0 | |
484 | B | Maximum Value | PROGRAMMING | 2,100 | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*. | The first line contains integer *n* — the length of the sequence (1<=≤<=*n*<=≤<=2·105).
The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=106). | Print the answer to the problem. | [
"3\n3 4 5\n"
] | [
"2\n"
] | none | 1,000 | [
{
"input": "3\n3 4 5",
"output": "2"
},
{
"input": "3\n1 2 4",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n1000000",
"output": "0"
},
{
"input": "2\n1000000 999999",
"output": "1"
},
{
"input": "12\n4 4 10 13 28 30 41 43 58 61 7... | 1,419,175,075 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 265 | 12,800,000 | def main():
input()
aa = sorted(map(int, input().split()))
maxa = aa[-1]
m = [False] * (maxa + 1)
x = []
b = res = 0
for a in aa:
if b != a:
m[a] = True
for i in range(b, a):
x.append(b)
b = a
x.append(b)
for a in range(maxa... | Title: Maximum Value
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. Find the maximum possible value of (integer remainder of *a**i* divided by *a**j*), where 1<=≤<=*i*,<=*j*<=≤<=*n* and *a**i*<=≥<=*a**j*.
Input Specification:
The ... | ```python
def main():
input()
aa = sorted(map(int, input().split()))
maxa = aa[-1]
m = [False] * (maxa + 1)
x = []
b = res = 0
for a in aa:
if b != a:
m[a] = True
for i in range(b, a):
x.append(b)
b = a
x.append(b)
for a in ... | 0 | |
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,599,402,117 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 592 | 0 | a,b=-1,-1
ans=1
c=[]
for i in range(int(input())):
h,m=map(int,input().split())
if h==a and m==b:
ans+=1
else:
a=h
b=m
c.append(ans)
ans=1
c.append(ans)
print(max(c))
| 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
a,b=-1,-1
ans=1
c=[]
for i in range(int(input())):
h,m=map(int,input().split())
if h==a and m==b:
ans+=1
else:
a=h
b=m
c.append(ans)
ans=1
c.append(ans)
print(max(c))
``` | 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,610,460,126 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | try:
n = int(input())
x = 0
while(n > 0):
a,b,c = map(int, input().strip())
x = x + a + b + c
n = n - 1
if(x == 0):
print("YES")
else:
print("NO")
except:
pass
| 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
try:
n = int(input())
x = 0
while(n > 0):
a,b,c = map(int, input().strip())
x = x + a + b + c
n = n - 1
if(x == 0):
print("YES")
else:
print("NO")
except:
pass
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.