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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
986 | D | Perfect Encoding | PROGRAMMING | 3,100 | [
"fft",
"math"
] | null | null | You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o... | In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. | Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. | [
"36\n",
"37\n",
"12345678901234567890123456789\n"
] | [
"10\n",
"11\n",
"177\n"
] | none | 2,500 | [
{
"input": "36",
"output": "10"
},
{
"input": "37",
"output": "11"
},
{
"input": "12345678901234567890123456789",
"output": "177"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input... | 1,696,936,794 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 249 | 5,939,200 |
import decimal
from math import ceil, floor, inf, log
n = input()
if n=='1':
print(1)
exit()
decimal.getcontext().prec = len(n)+6
decimal.getcontext().Emax = len(n)+6
log3 = log(10)*(len(n)-1)/log(3)
pref = n
if len(pref)>20:
pref = pref[:20]
pref = pref[0] + '.' + pref[1:]
log3 += log(floa... | Title: Perfect Encoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the paramete... | ```python
import decimal
from math import ceil, floor, inf, log
n = input()
if n=='1':
print(1)
exit()
decimal.getcontext().prec = len(n)+6
decimal.getcontext().Emax = len(n)+6
log3 = log(10)*(len(n)-1)/log(3)
pref = n
if len(pref)>20:
pref = pref[:20]
pref = pref[0] + '.' + pref[1:]
log3 +... | 3 | |
920 | C | Swap Adjacent Elements | PROGRAMMING | 1,400 | [
"dfs and similar",
"greedy",
"math",
"sortings",
"two pointers"
] | null | null | You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<=1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. T... | The first line contains one integer *n* (2<=≤<=*n*<=≤<=200000) — the number of elements in the array.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=200000) — the elements of the array. Each integer from 1 to *n* appears exactly once.
The third line contains a string of *n*<=-<=1 char... | If it is possible to sort the array in ascending order using any sequence of swaps you are allowed to make, print YES. Otherwise, print NO. | [
"6\n1 2 5 3 4 6\n01110\n",
"6\n1 2 5 3 4 6\n01010\n"
] | [
"YES\n",
"NO\n"
] | In the first example you may swap *a*<sub class="lower-index">3</sub> and *a*<sub class="lower-index">4</sub>, and then swap *a*<sub class="lower-index">4</sub> and *a*<sub class="lower-index">5</sub>. | 0 | [
{
"input": "6\n1 2 5 3 4 6\n01110",
"output": "YES"
},
{
"input": "6\n1 2 5 3 4 6\n01010",
"output": "NO"
},
{
"input": "6\n1 6 3 4 5 2\n01101",
"output": "NO"
},
{
"input": "6\n2 3 1 4 5 6\n01111",
"output": "NO"
},
{
"input": "4\n2 3 1 4\n011",
"output": "NO... | 1,518,344,882 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 124 | 1,000 | 19,456,000 | n = int(input())
s = input().split()
cs = input()
t = []
if cs == (n-1)*'1':
st = True
else:
st = True
for c in s:
t.append(int(c))
for x in range(n):
if t[x]!=x+1:
pos=0
while(t[x+pos]!=x+1):
pos+=1
if cs[x:x+pos]!=pos*'1':
st = False
break
... | Title: Swap Adjacent Elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have an array *a* consisting of *n* integers. Each integer from 1 to *n* appears exactly once in this array.
For some indices *i* (1<=≤<=*i*<=≤<=*n*<=-<=1) it is possible to swap *i*-th element with (*i*<=+<... | ```python
n = int(input())
s = input().split()
cs = input()
t = []
if cs == (n-1)*'1':
st = True
else:
st = True
for c in s:
t.append(int(c))
for x in range(n):
if t[x]!=x+1:
pos=0
while(t[x+pos]!=x+1):
pos+=1
if cs[x:x+pos]!=pos*'1':
st = False
... | 0 | |
875 | A | Classroom Watch | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109). | In the first line print one integer *k* — number of different values of *x* satisfying the condition.
In next *k* lines print these values in ascending order. | [
"21\n",
"20\n"
] | [
"1\n15\n",
"0\n"
] | In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such *x*. | 500 | [
{
"input": "21",
"output": "1\n15"
},
{
"input": "20",
"output": "0"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "3",
"output": "0"
},
{
"input": "100000001",
"output": "2\n99999937\n100000000"
},
{
"i... | 1,603,988,750 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 151,244,800 | from itertools import permutations
from sys import stdin,stdout
def is_possible(n,x):
num_sum=int(x)
for i in x:
num_sum+=int(i)
return n==num_sum
n=input()
n_int=int(n)
poss="0123456789"
ans=[]
for i in range(1,len(n)+1):
se=list(permutations(poss,i))
for j in se:
temp... | Title: Classroom Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe... | ```python
from itertools import permutations
from sys import stdin,stdout
def is_possible(n,x):
num_sum=int(x)
for i in x:
num_sum+=int(i)
return n==num_sum
n=input()
n_int=int(n)
poss="0123456789"
ans=[]
for i in range(1,len(n)+1):
se=list(permutations(poss,i))
for j in se:
... | 0 | |
343 | A | Rational Resistance | PROGRAMMING | 1,600 | [
"math",
"number theory"
] | null | null | Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R*0<==<=1. Elements with other resistance can be constructed from these resistors. In this problem, we wil... | The single input line contains two space-separated integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1018). It is guaranteed that the fraction is irreducible. It is guaranteed that a solution always exists. | Print a single number — the answer to the problem.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier. | [
"1 1\n",
"3 2\n",
"199 200\n"
] | [
"1\n",
"3\n",
"200\n"
] | In the first sample, one resistor is enough.
In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5305da389756aab6... | 500 | [
{
"input": "1 1",
"output": "1"
},
{
"input": "3 2",
"output": "3"
},
{
"input": "199 200",
"output": "200"
},
{
"input": "1 1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "21 8",
"output": "7... | 1,406,890,075 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 122 | 0 | print(max([int(i)for i in input().split()])) | Title: Rational Resistance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.
However, all Mike has is lots of identical resistors with unit resistance *R... | ```python
print(max([int(i)for i in input().split()]))
``` | 0 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,697,369,937 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | x,y = list(map(int,input().split()))
y1 = y
z = list(map(int,input().split()))
count = 0
for i in range(x):
if y < 0:
count -= 1
break
elif y == 0:
break
y -= min(z[i],8)
count += 1
print(count) if x*8 >= y1 and sum(z) >= y1 else print(-1) | Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
x,y = list(map(int,input().split()))
y1 = y
z = list(map(int,input().split()))
count = 0
for i in range(x):
if y < 0:
count -= 1
break
elif y == 0:
break
y -= min(z[i],8)
count += 1
print(count) if x*8 >= y1 and sum(z) >= y1 else print(-1)
``` | 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,691,593,788 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 500 | 19,558,400 | n = int(input())
n = pow(5,n)
a = n%10
n//=10
b = n%10
print(f"{b}{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
n = int(input())
n = pow(5,n)
a = n%10
n//=10
b = n%10
print(f"{b}{a}")
``` | 0 | |
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ... | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2... | 1,660,210,694 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | d = int(input())
n = int(input())
przhm = list(map(int, input().split()))
slv = dict()
amn = 0
for i in range (len(przhm) - 1):
if przhm[i] == d:
continue
if przhm[i] not in slv:
slv[przhm[i]] = 1
else:
slv[przhm[i]] += 1
sps = slv.items()
for j in sps:
... | Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any ... | ```python
d = int(input())
n = int(input())
przhm = list(map(int, input().split()))
slv = dict()
amn = 0
for i in range (len(przhm) - 1):
if przhm[i] == d:
continue
if przhm[i] not in slv:
slv[przhm[i]] = 1
else:
slv[przhm[i]] += 1
sps = slv.items()
for j i... | 3 | |
559 | B | Equivalent Strings | PROGRAMMING | 1,700 | [
"divide and conquer",
"hashing",
"sortings",
"strings"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 1,000 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,567,311,806 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | x = ""
y = ""
dp = {}
def pE(xl, yl, l):
if (xl,yl) in dp:
return dp[(xl,yl)]
if l&1:
for i in range(l):
if x[xl+i] != y[yl+i]:
return False
return True
n = l/2
dp[(xl,yl)] = (pE(xl,yl+n,n) and pE(xl+n,yl,n)) or (pE(xl+n,yl+n,n) and p... | Title: Equivalent Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split str... | ```python
x = ""
y = ""
dp = {}
def pE(xl, yl, l):
if (xl,yl) in dp:
return dp[(xl,yl)]
if l&1:
for i in range(l):
if x[xl+i] != y[yl+i]:
return False
return True
n = l/2
dp[(xl,yl)] = (pE(xl,yl+n,n) and pE(xl+n,yl,n)) or (pE(xl+n,yl+... | -1 | |
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,579,381,871 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 155 | 1,228,800 | n,m=map(int,input().split())
a=input().split()
ls=[0 for i in range(100)]
for i in range(m):
ls[int(a[i])-1]+=1
a.sort(reverse=True)
ans=m//n
while ans:
count=0
for i in range(100):
count+=ls[i]//ans
if(count>=n):
break
ans-=1
print(max(ans,0)) | 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())
a=input().split()
ls=[0 for i in range(100)]
for i in range(m):
ls[int(a[i])-1]+=1
a.sort(reverse=True)
ans=m//n
while ans:
count=0
for i in range(100):
count+=ls[i]//ans
if(count>=n):
break
ans-=1
print(max(ans,0))
``` | 3 | |
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"... | 1,698,823,027 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | n=int(input())
main=[]
count=0
for i in range(0,n):
lst=list(map(int, input().split()))
main.append(lst)
for j in main:
if j[1]-j[0]>+2:
count+=1
print(count)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want ... | ```python
n=int(input())
main=[]
count=0
for i in range(0,n):
lst=list(map(int, input().split()))
main.append(lst)
for j in main:
if j[1]-j[0]>+2:
count+=1
print(count)
``` | 0 | |
681 | C | Heap Operations | PROGRAMMING | 1,600 | [
"constructive algorithms",
"data structures",
"greedy"
] | null | null | Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the heap; - extract the minimum element from the heap;
Thus, at any moment of time the heap contains se... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of the records left in Petya's journal.
Each of the following *n* lines describe the records in the current log in the order they are applied. Format described in the statement is used. All numbers in the input are integers... | The first line of the output should contain a single integer *m* — the minimum possible number of records in the modified sequence of operations.
Next *m* lines should contain the corrected sequence of records following the format of the input (described in the statement), one per line and in the order they are applie... | [
"2\ninsert 3\ngetMin 4\n",
"4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2\n"
] | [
"4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4\n",
"6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2\n"
] | In the first sample, after number 3 is inserted into the heap, the minimum number is 3. To make the result of the first getMin equal to 4 one should firstly remove number 3 from the heap and then add number 4 into the heap.
In the second sample case number 1 is inserted two times, so should be similarly removed twice. | 1,500 | [
{
"input": "2\ninsert 3\ngetMin 4",
"output": "4\ninsert 3\nremoveMin\ninsert 4\ngetMin 4"
},
{
"input": "4\ninsert 1\ninsert 1\nremoveMin\ngetMin 2",
"output": "6\ninsert 1\ninsert 1\nremoveMin\nremoveMin\ninsert 2\ngetMin 2"
},
{
"input": "1\ninsert 1",
"output": "1\ninsert 1"
},... | 1,680,720,631 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 327 | 30,720,000 | import sys
input = lambda: sys.stdin.readline().rstrip()
from heapq import *
ans = []
v = []
for _ in range(int(input())):
A = input().split()
a = A[0]
if a=='insert':
b = int(A[1])
ans.append(a+' ' +str(b))
heappush(v,b)
elif a=='getMin':
b = i... | Title: Heap Operations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has recently learned data structure named "Binary heap".
The heap he is now operating with allows the following operations:
- put the given number into the heap; - get the value of the minimum element in the ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from heapq import *
ans = []
v = []
for _ in range(int(input())):
A = input().split()
a = A[0]
if a=='insert':
b = int(A[1])
ans.append(a+' ' +str(b))
heappush(v,b)
elif a=='getMin':
... | 3 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,516,853,535 | 675 | Python 3 | OK | TESTS | 44 | 62 | 5,632,000 | def f(m):
global n,k
if(2*(m*k+m)<=n):
return True
else:
return False
n, k = [int(x) for x in input().split()]
l = -1
r = n
while( l+1!= r):
mid = (l+r) // 2
if(f(mid)):
l =mid
else:
r = mid
print(l,l*k,n-(l+l*k),sep = " ")
| Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
def f(m):
global n,k
if(2*(m*k+m)<=n):
return True
else:
return False
n, k = [int(x) for x in input().split()]
l = -1
r = n
while( l+1!= r):
mid = (l+r) // 2
if(f(mid)):
l =mid
else:
r = mid
print(l,l*k,n-(l+l*k),sep = " ")
``` | 3 | |
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,698,243,881 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 46 | 0 | n = int(input())
a = list(map(int,input().split()))
counter = 0
a.sort()
while True:
if (sum(a))/n >= 4.5:
break
else:
a[0] = 5
a.sort()
counter += 1
print(counter)
| 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
n = int(input())
a = list(map(int,input().split()))
counter = 0
a.sort()
while True:
if (sum(a))/n >= 4.5:
break
else:
a[0] = 5
a.sort()
counter += 1
print(counter)
``` | 3 | |
926 | I | A Vital Problem | PROGRAMMING | 1,700 | [] | null | null | Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute.
Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes u... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of alarms.
Each of the next *n* lines contains a description of one alarm. Each description has a format "hh:mm", where *hh* is the hour when the alarm rings, and *mm* is the minute of that hour when the alarm rings. The number of hours is b... | Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. *hh* denotes the number of hours, and *mm* denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better. | [
"1\n05:43\n",
"4\n22:00\n03:21\n16:03\n09:59\n"
] | [
"23:59\n",
"06:37\n"
] | In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time. | 0 | [
{
"input": "1\n05:43",
"output": "23:59"
},
{
"input": "4\n22:00\n03:21\n16:03\n09:59",
"output": "06:37"
},
{
"input": "20\n23:59\n00:00\n00:01\n00:02\n00:03\n00:04\n00:05\n00:06\n00:07\n00:08\n00:09\n00:10\n00:11\n00:12\n00:13\n00:14\n00:15\n00:16\n00:17\n00:18",
"output": "23:40"
... | 1,521,363,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 93 | 7,065,600 | n = int(input())
time = [0 for r in range(2881)]
for i in range(n):
h, m = map(int, input().split(':'))
time[h * 60 + m] = 1
time[1440 + h * 60 + m] = 1
ans = 0
cur_ans = 0
for i in range(2881):
if time[i] != 1:
cur_ans += 1
continue
ans = max(ans, cur_ans)
cur_ans = 0
h = str(ans // 6... | Title: A Vital Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute.
Determine the longest time segment when Polycarp can sleep, i. e... | ```python
n = int(input())
time = [0 for r in range(2881)]
for i in range(n):
h, m = map(int, input().split(':'))
time[h * 60 + m] = 1
time[1440 + h * 60 + m] = 1
ans = 0
cur_ans = 0
for i in range(2881):
if time[i] != 1:
cur_ans += 1
continue
ans = max(ans, cur_ans)
cur_ans = 0
h = st... | 0 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,648,645,225 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 451 | 8,294,400 | n = int(input())
l = input().split()
cities = [int(i) for i in l]
left, right = cities[0], cities[-1]
last = float('inf')
m = max(cities[0] - left, right - cities[0])
for i in range(1, len(cities)):
diff = cities[i] - cities[i-1]
print(min(last, diff), end=" ")
last = diff
print(m)
m = max(cities[... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
l = input().split()
cities = [int(i) for i in l]
left, right = cities[0], cities[-1]
last = float('inf')
m = max(cities[0] - left, right - cities[0])
for i in range(1, len(cities)):
diff = cities[i] - cities[i-1]
print(min(last, diff), end=" ")
last = diff
print(m)
m = m... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the *k* obtained minimums. What is the maximum possible inte... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=<=105) — the size of the array *a* and the number of subsegments you have to split the array to.
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (<=-<=109<=<=≤<=<=*a**i*<=≤<=<=109). | Print single integer — the maximum possible integer you can get if you split the array into *k* non-empty subsegments and take maximum of minimums on the subsegments. | [
"5 2\n1 2 3 4 5\n",
"5 1\n-4 -5 -3 -2 -1\n"
] | [
"5\n",
"-5\n"
] | A subsegment [*l*, *r*] (*l* ≤ *r*) of array *a* is the sequence *a*<sub class="lower-index">*l*</sub>, *a*<sub class="lower-index">*l* + 1</sub>, ..., *a*<sub class="lower-index">*r*</sub>.
Splitting of array *a* of *n* elements into *k* subsegments [*l*<sub class="lower-index">1</sub>, *r*<sub class="lower-index... | 0 | [
{
"input": "5 2\n1 2 3 4 5",
"output": "5"
},
{
"input": "5 1\n-4 -5 -3 -2 -1",
"output": "-5"
},
{
"input": "10 2\n10 9 1 -9 -7 -9 3 8 -10 5",
"output": "10"
},
{
"input": "10 4\n-8 -1 2 -3 9 -8 4 -3 5 9",
"output": "9"
},
{
"input": "1 1\n504262064",
"output... | 1,648,660,723 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 512,000 | while True:
try:
x = input()
n, k = list(map(int, x.split()))
x = input()
arr = list(map(int, x.split()))
if n == 1:
print(min(arr))
elif n > 2:
print(max(arr))
else:
prefix_min_l = [0] * n
prefix_min_l[0] = arr[... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a*1,<=*a*2,<=...,<=*a**n* consisting of *n* integers, and an integer *k*. You have to split the array into exactly *k* non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ... | ```python
while True:
try:
x = input()
n, k = list(map(int, x.split()))
x = input()
arr = list(map(int, x.split()))
if n == 1:
print(min(arr))
elif n > 2:
print(max(arr))
else:
prefix_min_l = [0] * n
prefix_min_l... | 0 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,566,852,362 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 218 | 0 | st = input()
l = [ i for i in st]
l.sort()
n = len(st)
stc = l[n-1]
n1 = l.index(l[n-1])
n2 = n - n1
if n2 == 0:
print(stc)
else:
print(stc * n2)
| Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
st = input()
l = [ i for i in st]
l.sort()
n = len(st)
stc = l[n-1]
n1 = l.index(l[n-1])
n2 = n - n1
if n2 == 0:
print(stc)
else:
print(stc * n2)
``` | 3 | |
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,690,811,480 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | num = int(input())
array = []
evenCount = 0
oddCount = 0
for i in range(num):
array.append(int(input()))
if array[i] % 2 == 0:
evenCount += 1
else:
oddCount += 1
if evenCount == 1:
for j in range(num):
if array[j] % 2 == 0:
print(j + 1)
if oddCount... | 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
num = int(input())
array = []
evenCount = 0
oddCount = 0
for i in range(num):
array.append(int(input()))
if array[i] % 2 == 0:
evenCount += 1
else:
oddCount += 1
if evenCount == 1:
for j in range(num):
if array[j] % 2 == 0:
print(j + 1)
i... | -1 |
474 | A | Keyboard | PROGRAMMING | 900 | [
"implementation"
] | null | null | Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean... | First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right).
Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ... | Print a line that contains the original message. | [
"R\ns;;upimrrfod;pbr\n"
] | [
"allyouneedislove\n"
] | none | 500 | [
{
"input": "R\ns;;upimrrfod;pbr",
"output": "allyouneedislove"
},
{
"input": "R\nwertyuiop;lkjhgfdsxcvbnm,.",
"output": "qwertyuiolkjhgfdsazxcvbnm,"
},
{
"input": "L\nzxcvbnm,kjhgfdsaqwertyuio",
"output": "xcvbnm,.lkjhgfdswertyuiop"
},
{
"input": "R\nbubbuduppudup",
"outp... | 1,694,567,430 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 46 | 0 | ll='qwertyuiopasdfghjkl;zxcvbnm,./'
#b='s;;upimrrfod;pbr'
if input()=='R':
b=input()
c=''
for x in b:
if ll.find(x)==0:
c+=ll[len(ll)-1]
else:
c+=ll[ll.find(x)%len(ll)-1]
print(c)
else:
b=input()
c=''
for x in b:
if ll.find... | Title: Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:
Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately.... | ```python
ll='qwertyuiopasdfghjkl;zxcvbnm,./'
#b='s;;upimrrfod;pbr'
if input()=='R':
b=input()
c=''
for x in b:
if ll.find(x)==0:
c+=ll[len(ll)-1]
else:
c+=ll[ll.find(x)%len(ll)-1]
print(c)
else:
b=input()
c=''
for x in b:
... | 3 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,569,553,229 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 218 | 0 | xz,xy,yz = map(int,input().split())
x = ((xz*xy)/yz)**0.5
print(int(4*(x+xy/x+xz/x))) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
xz,xy,yz = map(int,input().split())
x = ((xz*xy)/yz)**0.5
print(int(4*(x+xy/x+xz/x)))
``` | 3 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,619,602,069 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 0 | '''
n = int(input())
holder, cycle, br, m = n, 2, 1, 2
if n > 2:
while n - 2:
if br == 1:
print(m, end=" ")
m += cycle
if m > holder:
m -= holder
print(m, end=" ")
n -= 1
br += 1
cycle += 1
elif n == 2:
print(2)
''... | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
'''
n = int(input())
holder, cycle, br, m = n, 2, 1, 2
if n > 2:
while n - 2:
if br == 1:
print(m, end=" ")
m += cycle
if m > holder:
m -= holder
print(m, end=" ")
n -= 1
br += 1
cycle += 1
elif n == 2:
pr... | 3.969 |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,592,774,682 | 2,147,483,647 | Python 3 | OK | TESTS | 79 | 202 | 9,523,200 | n = int(input())
lista = list(map(int,input().split()))
lista.sort()
countDiff = 1
diff = []
for i in range(n-1):
if(lista[i] != lista[i + 1]):
countDiff +=1
value = lista[i + 1] - lista[i]
diff.append(value)
if(countDiff < 3):
print("YES")
elif(countDiff > 3):
pri... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
n = int(input())
lista = list(map(int,input().split()))
lista.sort()
countDiff = 1
diff = []
for i in range(n-1):
if(lista[i] != lista[i + 1]):
countDiff +=1
value = lista[i + 1] - lista[i]
diff.append(value)
if(countDiff < 3):
print("YES")
elif(countDiff > 3)... | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,630,412,810 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 374 | 33,792,000 | n = int(input())
ans = []
base = sum(list(map(int, input().split())))
for _ in range(2):
new = sum(list(map(int, input().split())))
ans.append(base - new)
base = new
for answer in ans:
print(answer)
| Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
n = int(input())
ans = []
base = sum(list(map(int, input().split())))
for _ in range(2):
new = sum(list(map(int, input().split())))
ans.append(base - new)
base = new
for answer in ans:
print(answer)
``` | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,680,999,825 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 0 | a={'A':1,'B':1,'C':1}
b=[]
for i in range(3):
x=input()
b.append(x)
if x[1]=='>':
a[x[0]]+=1
else :
a[x[2]]+=1
if b[1]==b[0] or b[1]==b[2] or b[0]==b[2]:
print('Impossible')
else :
c=[a['A'],a['B'],a['C']]
if c.count(2)>1:
print('Impossible')
else :
for i ... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
a={'A':1,'B':1,'C':1}
b=[]
for i in range(3):
x=input()
b.append(x)
if x[1]=='>':
a[x[0]]+=1
else :
a[x[2]]+=1
if b[1]==b[0] or b[1]==b[2] or b[0]==b[2]:
print('Impossible')
else :
c=[a['A'],a['B'],a['C']]
if c.count(2)>1:
print('Impossible')
else :
... | 3.977 |
45 | A | Codecraft III | PROGRAMMING | 900 | [
"implementation"
] | A. Codecraft III | 2 | 256 | Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa... | The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III. | Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December. | [
"November\n3\n",
"May\n24\n"
] | [
"February\n",
"May\n"
] | none | 0 | [
{
"input": "November\n3",
"output": "February"
},
{
"input": "May\n24",
"output": "May"
},
{
"input": "April\n0",
"output": "April"
},
{
"input": "September\n0",
"output": "September"
},
{
"input": "August\n0",
"output": "August"
},
{
"input": "June\n1... | 1,602,923,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 186 | 0 | a=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
inp=input()
b=int(input())
if b%12==0:
print(inp)
elif(b<12):
i=(a.index(inp))+1
g=12-b
h=i-g
print(a[h-1])
| Title: Codecraft III
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *... | ```python
a=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
inp=input()
b=int(input())
if b%12==0:
print(inp)
elif(b<12):
i=(a.index(inp))+1
g=12-b
h=i-g
print(a[h-1])
``` | 0 |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,699,106,243 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 92 | 9,830,400 | n = int(input())
a = [int(i) for i in input().split()]
ans = 0
p = 0
for i in range(n):
if a[i] > 0:
p += a[i]
else:
if p == 0:
ans += 1
else:
p -= 1
print(ans)
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
p = 0
for i in range(n):
if a[i] > 0:
p += a[i]
else:
if p == 0:
ans += 1
else:
p -= 1
print(ans)
``` | 3 | |
475 | B | Strongly Connected City | PROGRAMMING | 1,400 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes... | The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets.
The second line contains a string of length *n*, made of characters '<' and '>', denoting direction of each horizontal street. If the *i*-th character... | If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". | [
"3 3\n><>\nv^v\n",
"4 6\n<><>\nv^v^v^\n"
] | [
"NO\n",
"YES\n"
] | The figure above shows street directions in the second sample test case. | 1,000 | [
{
"input": "3 3\n><>\nv^v",
"output": "NO"
},
{
"input": "4 6\n<><>\nv^v^v^",
"output": "YES"
},
{
"input": "2 2\n<>\nv^",
"output": "YES"
},
{
"input": "2 2\n>>\n^v",
"output": "NO"
},
{
"input": "3 3\n>><\n^^v",
"output": "YES"
},
{
"input": "3 4\n>>... | 1,542,691,546 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
with open(sys.stdin) as f:
line1 = f.readline().strip('\n').split()
numh, numv = line1[0], line1[1]
hor = f.readline().strip('\n').split('')
vert = f.readline().strip('\n').split('')
if (hor[0], vert[0]) == ('<', '^') or
(hor[-1], vert[0]) == ('<', 'v') or
... | Title: Strongly Connected City
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one... | ```python
import sys
with open(sys.stdin) as f:
line1 = f.readline().strip('\n').split()
numh, numv = line1[0], line1[1]
hor = f.readline().strip('\n').split('')
vert = f.readline().strip('\n').split('')
if (hor[0], vert[0]) == ('<', '^') or
(hor[-1], vert[0]) == ('<', 'v') or ... | -1 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,693,574,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def maximize_number(n):
s = str(n)
if n > 0:
print(n)
else:
for i in range(1, len(s) - 1):
if s[i] > s[i + 1]:
return int(s[:i] + s[i+1:])
return int(s[:-1])
n = int(input())
print(maximize_number(n))
| Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
def maximize_number(n):
s = str(n)
if n > 0:
print(n)
else:
for i in range(1, len(s) - 1):
if s[i] > s[i + 1]:
return int(s[:i] + s[i+1:])
return int(s[:-1])
n = int(input())
print(maximize_number(n))
`... | 0 | |
230 | A | Dragons | PROGRAMMING | 1,000 | [
"greedy",
"sortings"
] | null | null | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit... | The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | [
"2 2\n1 99\n100 0\n",
"10 1\n100 100\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | 500 | [
{
"input": "2 2\n1 99\n100 0",
"output": "YES"
},
{
"input": "10 1\n100 100",
"output": "NO"
},
{
"input": "123 2\n78 10\n130 0",
"output": "YES"
},
{
"input": "999 2\n1010 10\n67 89",
"output": "YES"
},
{
"input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1",
"output": "YE... | 1,698,157,954 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | s, n = map(int, input().split())
data = []
for i in range(n):
dragonStrength, gain = map(int, input().split())
data.append((dragonStrength, gain))
data = sorted(data)
Won = True
for i in data:
if s > i[0]:
s += i[1]
else:
print("NO")
Won = False
break
if Won... | Title: Dragons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du... | ```python
s, n = map(int, input().split())
data = []
for i in range(n):
dragonStrength, gain = map(int, input().split())
data.append((dragonStrength, gain))
data = sorted(data)
Won = True
for i in data:
if s > i[0]:
s += i[1]
else:
print("NO")
Won = False
bre... | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,692,987,511 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | a = input()
zero = one = 0
for i in a:
if int(i) == 0:
zero += 1
one = 0
else:
one += 1
zero = 0
if zero == 7 or one == 7:
print('YES')
break
else:
print('NO')
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
a = input()
zero = one = 0
for i in a:
if int(i) == 0:
zero += 1
one = 0
else:
one += 1
zero = 0
if zero == 7 or one == 7:
print('YES')
break
else:
print('NO')
``` | 3.977 |
499 | B | Lecture | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi... | The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages.
The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel... | Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. | [
"4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n",
"5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n"
] | [
"codeforces round letter round\n",
"hbnyiyc joll joll un joll\n"
] | none | 500 | [
{
"input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest",
"output": "codeforces round letter round"
},
{
"input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll",
"output": "hbnyiyc joll joll un joll"
},
{
"input"... | 1,601,915,628 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 202 | 4,505,600 | n, m = map(int, input().split())
dict = {}
for i in range(m):
str1, str2 = input().split()
dict[str1] = str2
prof = input().split()
res = []
for i in prof:
if len(dict[i]) < len(i):
res.append(dict[i])
else:
res.append(i)
res = " ".join(res)
print(res)
| Title: Lecture
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first ... | ```python
n, m = map(int, input().split())
dict = {}
for i in range(m):
str1, str2 = input().split()
dict[str1] = str2
prof = input().split()
res = []
for i in prof:
if len(dict[i]) < len(i):
res.append(dict[i])
else:
res.append(i)
res = " ".join(res)
print(res)
``` | 3 | |
236 | A | Boy or Girl | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
Bu... | The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. | If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). | [
"wjmzbmr\n",
"xiaodao\n",
"sevenkplus\n"
] | [
"CHAT WITH HER!\n",
"IGNORE HIM!\n",
"CHAT WITH HER!\n"
] | For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". | 500 | [
{
"input": "wjmzbmr",
"output": "CHAT WITH HER!"
},
{
"input": "xiaodao",
"output": "IGNORE HIM!"
},
{
"input": "sevenkplus",
"output": "CHAT WITH HER!"
},
{
"input": "pezu",
"output": "CHAT WITH HER!"
},
{
"input": "wnemlgppy",
"output": "CHAT WITH HER!"
},... | 1,698,173,908 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | nickname=input()
l=len(nickname)
if nickname.count(nickname[i])>1:
l-=nickname.count(nickname[i])
if l%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!') | Title: Boy or Girl
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though... | ```python
nickname=input()
l=len(nickname)
if nickname.count(nickname[i])>1:
l-=nickname.count(nickname[i])
if l%2==0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!')
``` | -1 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,681,845,865 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 140 | 13,516,800 | n = int(input())
a = list(map(int,input().split()))
p = 0
c = 0
for i in a:
if i!=-1:
p+=i
else:
if p==0:
c+=1
else:
p-=1
print(c)
| Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
n = int(input())
a = list(map(int,input().split()))
p = 0
c = 0
for i in a:
if i!=-1:
p+=i
else:
if p==0:
c+=1
else:
p-=1
print(c)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,697,004,143 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | #program
def abbreviate_words(n, words):
abbreviated_words = []
for word in words:
if len(word) > 10:
abbreviation = word[0] + str(len(word) - 2) + word[-1]
abbreviated_words.append(abbreviation)
else:
abbreviated_words.append(word)
for abbreviation in ab... | 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
#program
def abbreviate_words(n, words):
abbreviated_words = []
for word in words:
if len(word) > 10:
abbreviation = word[0] + str(len(word) - 2) + word[-1]
abbreviated_words.append(abbreviation)
else:
abbreviated_words.append(word)
for abbrevia... | 3.977 |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,694,696,492 | 2,147,483,647 | Python 3 | OK | TESTS | 62 | 46 | 0 | Limak, Bob = map(int, input().split())
t = 0
while True:
Limak = Limak*3
Bob = Bob*2
t += 1
if Limak > Bob:
print(t)
break | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
Limak, Bob = map(int, input().split())
t = 0
while True:
Limak = Limak*3
Bob = Bob*2
t += 1
if Limak > Bob:
print(t)
break
``` | 3 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,697,873,779 | 2,147,483,647 | PyPy 3-64 | MEMORY_LIMIT_EXCEEDED | TESTS | 3 | 1,216 | 268,390,400 | num=int(input())
t=[]
ocu=set()
for i in range(num):
x,h=map(int,input().split())
t.append([x,h])
ocu.add(x)
ctree=0
for i in t:
lef={i for i in range(i[0]-i[1],i[0])}
if len(lef.intersection(ocu))==0:
ocu.union(lef)
ctree+=1
else:
ri={i for i in range(i[0]+... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
num=int(input())
t=[]
ocu=set()
for i in range(num):
x,h=map(int,input().split())
t.append([x,h])
ocu.add(x)
ctree=0
for i in t:
lef={i for i in range(i[0]-i[1],i[0])}
if len(lef.intersection(ocu))==0:
ocu.union(lef)
ctree+=1
else:
ri={i for i in r... | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,679,419,739 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | import math
ins = [int(x) for x in input().split()]
x = round(math.sqrt(ins[0] * ins[2] // ins[1]))
z = ins[2]//x
y = ins[1]//z
# print(x , y ,z)
print(4*(x + y + z)) | Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
ins = [int(x) for x in input().split()]
x = round(math.sqrt(ins[0] * ins[2] // ins[1]))
z = ins[2]//x
y = ins[1]//z
# print(x , y ,z)
print(4*(x + y + z))
``` | 3 | |
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,628,207,698 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 6,963,200 | n_m = input().split()
cells_array = []
A=['B','W']
for i in range(int(n_m[0])):
cells = input()
cells_list = list(cells)
cells_array.append(cells_list)
for j in range(len(cells_array)):
for k in range(int(n_m[1])):
if cells_array[j][k] == '.':
cells_array[j][k]=A[(j+k)%2]
for i in... | 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
n_m = input().split()
cells_array = []
A=['B','W']
for i in range(int(n_m[0])):
cells = input()
cells_list = list(cells)
cells_array.append(cells_list)
for j in range(len(cells_array)):
for k in range(int(n_m[1])):
if cells_array[j][k] == '.':
cells_array[j][k]=A[(j+k)%2]... | 3 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,591,118,324 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n,r=map(int,input().split())
l=list(map(int,input().split()))
x,y=0,0
for k in range(1,n+1):
d=[]
for i in range(n):
d.append(l[i]+(i+1)*k)
s=sum(d[:k])
if(s<=r):
x=i+1
y=s
print(x,y)
| Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
n,r=map(int,input().split())
l=list(map(int,input().split()))
x,y=0,0
for k in range(1,n+1):
d=[]
for i in range(n):
d.append(l[i]+(i+1)*k)
s=sum(d[:k])
if(s<=r):
x=i+1
y=s
print(x,y)
``` | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,633,977,455 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 216 | 2,150,400 | n,m=map(int,input().split())
start_time=time.time()
count=0
for b in range(1001):
for a in range(1001):
if (a*a+b==n) and (a+b*b==m):
count=count+1
print(count)
print("--- %s seconds ---" % (time. time() - start_time))
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n,m=map(int,input().split())
start_time=time.time()
count=0
for b in range(1001):
for a in range(1001):
if (a*a+b==n) and (a+b*b==m):
count=count+1
print(count)
print("--- %s seconds ---" % (time. time() - start_time))
``` | -1 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,687,142,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 27 | 62 | 0 | x = int(input())
result = []
def prime(n):
for i in range(2,n):
if n % i == 0:
return False
return True
for i in range(x//2):
x1, x2 = i, x-i
if prime(x1) is False and prime(x2) is False:
result.append(x1)
result.append(x2)
break
for i in re... | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
x = int(input())
result = []
def prime(n):
for i in range(2,n):
if n % i == 0:
return False
return True
for i in range(x//2):
x1, x2 = i, x-i
if prime(x1) is False and prime(x2) is False:
result.append(x1)
result.append(x2)
break
f... | 0 | |
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-... | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input"... | 1,681,557,913 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n = int(input())
t = int(input())
a = 10**(n - 1)
b = a // t
print((b + 2) * t)
| Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larg... | ```python
n = int(input())
t = int(input())
a = 10**(n - 1)
b = a // t
print((b + 2) * t)
``` | -1 | |
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should cons... | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter... | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcde... | 1,609,921,084 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 0 | n, k = [int(x) for x in input().split()]
origk = k
res = ""
while n>0:
k = origk
o = 97
while k>0 and n>0:
res = res+ chr(o)
o+=1
k-=1
n-=1
print(res)
| 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
n, k = [int(x) for x in input().split()]
origk = k
res = ""
while n>0:
k = origk
o = 97
while k>0 and n>0:
res = res+ chr(o)
o+=1
k-=1
n-=1
print(res)
``` | 3 | |
818 | D | Multicolored Cars | PROGRAMMING | 1,700 | [
"data structures",
"implementation"
] | null | null | Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like this. Firstly Alice chooses some color *A*, then Bob chooses some color *B* (*A*<=≠<=*B*). After each ca... | The first line contains two integer numbers *n* and *A* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*A*<=≤<=106) – number of cars and the color chosen by Alice.
The second line contains *n* integer numbers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=106) — colors of the cars that Alice and Bob will encounter in the order of their app... | Output such color *B* (1<=≤<=*B*<=≤<=106) that if Bob chooses it then he will win the game. If there are multiple solutions, print any of them. If there is no such color then print -1.
It is guaranteed that if there exists any solution then there exists solution with (1<=≤<=*B*<=≤<=106). | [
"4 1\n2 1 4 2\n",
"5 2\n2 2 4 5 3\n",
"3 10\n1 2 3\n"
] | [
"2\n",
"-1\n",
"4\n"
] | Let's consider availability of colors in the first example:
- *cnt*<sub class="lower-index">2</sub>(*i*) ≥ *cnt*<sub class="lower-index">1</sub>(*i*) for every *i*, and color 2 can be the answer. - *cnt*<sub class="lower-index">4</sub>(2) < *cnt*<sub class="lower-index">1</sub>(2), so color 4 isn't the winning o... | 0 | [
{
"input": "4 1\n2 1 4 2",
"output": "2"
},
{
"input": "5 2\n2 2 4 5 3",
"output": "-1"
},
{
"input": "3 10\n1 2 3",
"output": "4"
},
{
"input": "1 1\n2",
"output": "3"
},
{
"input": "1 2\n2",
"output": "-1"
},
{
"input": "10 6\n8 5 1 6 6 5 10 6 9 8",
... | 1,526,071,931 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 77 | 7,065,600 | aracSayisi,aliceRenk=map(int,input().split())
araclar=list(map(int,input().split()))
renk_tekrar={}
CB=-1
CA=0;
for i in range(aracSayisi):
if(araclar[i]==aliceRenk):
CA+=1
elif(araclar[i] in renk_tekrar):
renk_tekrar[araclar[i]]+=1
else:
renk_tekrar[araclar[i]]=1
liste_renk=list... | Title: Multicolored Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob got very bored during a long car trip so they decided to play a game. From the window they can see cars of different colors running past them. Cars are going one after another.
The game rules are like t... | ```python
aracSayisi,aliceRenk=map(int,input().split())
araclar=list(map(int,input().split()))
renk_tekrar={}
CB=-1
CA=0;
for i in range(aracSayisi):
if(araclar[i]==aliceRenk):
CA+=1
elif(araclar[i] in renk_tekrar):
renk_tekrar[araclar[i]]+=1
else:
renk_tekrar[araclar[i]]=1
liste... | 0 | |
344 | A | Magnets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit... | On the single line of the output print the number of groups of magnets. | [
"6\n10\n10\n10\n01\n10\n10\n",
"4\n01\n01\n10\n10\n"
] | [
"3\n",
"2\n"
] | The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.
The second testcase has two groups, each consisting of two magnets. | 500 | [
{
"input": "6\n10\n10\n10\n01\n10\n10",
"output": "3"
},
{
"input": "4\n01\n01\n10\n10",
"output": "2"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n01\n10",
"output": "2"
},
{
"input": "2\n10\n10",
"output": "1"
},
{
"input": "3\n10\n01\n10",... | 1,699,457,423 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
l = []
for i in range(n):
l.append(int(input()))
group = 0
maxm = 0
for i in range(len(l)-1):
if l[i] == l[i+1]:
group += 1
maxm = max(group, maxm)
print(maxm) | Title: Magnets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets... | ```python
n = int(input())
l = []
for i in range(n):
l.append(int(input()))
group = 0
maxm = 0
for i in range(len(l)-1):
if l[i] == l[i+1]:
group += 1
maxm = max(group, maxm)
print(maxm)
``` | 0 | |
178 | A2 | Educational Game | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some pr... | The first input line contains a single integer *n*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=104), separated by single spaces.
The input limitations for getting 20 points are:
- 1<=≤<=*n*<=≤<=300
The input limitations for getting 50 points are:
- 1<=≤<=*n*<=≤<=2000
The input limitations f... | Print exactly *n*<=-<=1 lines: the *k*-th output line must contain the minimum number of moves needed to make the first *k* elements of the original sequence *a**i* equal to zero.
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 sp... | [
"4\n1 0 1 2\n",
"8\n1 2 3 4 5 6 7 8\n"
] | [
"1\n1\n3\n",
"1\n3\n6\n10\n16\n24\n40\n"
] | none | 30 | [
{
"input": "4\n1 0 1 2",
"output": "1\n1\n3"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "1\n3\n6\n10\n16\n24\n40"
},
{
"input": "5\n4 1 4 7 6",
"output": "4\n5\n9\n17"
},
{
"input": "9\n13 13 7 11 3 9 3 5 5",
"output": "13\n26\n33\n44\n47\n69\n79\n117"
},
{
"in... | 1,673,509,952 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS2 | 0 | 60 | 0 | n = int(input())
lst = []
for i in range(n - 1):
x = [*map(int, input().split())]
for j in x:
lst.append(j)
Sum = 0
for k in range(1, n + 1):
if lst.count(k) == 1:
Sum += 1
print(Sum) | Title: Educational Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of *n* non-negative integers *a**i* nu... | ```python
n = int(input())
lst = []
for i in range(n - 1):
x = [*map(int, input().split())]
for j in x:
lst.append(j)
Sum = 0
for k in range(1, n + 1):
if lst.count(k) == 1:
Sum += 1
print(Sum)
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 0 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,593,353,652 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 155 | 20,480,000 | from collections import Counter
n=int(input())
l=[0]*n
lx=[0]*n
ly=[0]*n
for i in range(n):
a,b=map(int,input().split())
l[i]=[a,b]
lx[i]=a
ly[i]=b
x=len(l)
res=list(set(tuple(e) for e in l))
y=len(res)
cx=Counter(lx)
cy=Counter(ly)
#print(cx,cy)
c=0
for e in c... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need ... | ```python
from collections import Counter
n=int(input())
l=[0]*n
lx=[0]*n
ly=[0]*n
for i in range(n):
a,b=map(int,input().split())
l[i]=[a,b]
lx[i]=a
ly[i]=b
x=len(l)
res=list(set(tuple(e) for e in l))
y=len(res)
cx=Counter(lx)
cy=Counter(ly)
#print(cx,cy)
c=0
... | 0 | |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors... | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ... | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReal... | 1,622,906,107 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 0 | # -*- coding: utf-8 -*-
"""
Created on Sat Jun 5 23:05:06 2021
@author: nagan
"""
n = int(input())
d = {'purple':'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind'}
for i in range(n):
a = input()
d.pop(a)
print(len(d))
for i in d:
print(d[i])
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 5 23:05:06 2021
@author: nagan
"""
n = int(input())
d = {'purple':'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind'}
for i in range(n):
a = input()
d.pop(a)
print(len(d))
for i in d:
print(d[i]... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,590,509,171 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 280 | 0 | a, b, c = map(int, input().split())
e = 1
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
while True:
if e % 2 != 0:
s = gcd(a, c)
else:
s = gcd(b, c)
if s > c:
break
else:
c -= s
e += 1
if e % 2 == 0:... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
a, b, c = map(int, input().split())
e = 1
def gcd(x, y):
if y == 0:
return x
else:
return gcd(y, x % y)
while True:
if e % 2 != 0:
s = gcd(a, c)
else:
s = gcd(b, c)
if s > c:
break
else:
c -= s
e += 1
if e... | 3 | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,583,289,489 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 155 | 2,150,400 | n,m,z=map(int,input().split())
x,y=[],[]
for i in range(1,z//n+1):
x.append(n*i)
for i in range(1,z//m+1):
y.append(m*i)
l=set(x)&set(y)
print(len(l))
| Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
n,m,z=map(int,input().split())
x,y=[],[]
for i in range(1,z//n+1):
x.append(n*i)
for i in range(1,z//m+1):
y.append(m*i)
l=set(x)&set(y)
print(len(l))
``` | 3 | |
801 | A | Vicious Keyboard | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maxi... | The first line will contain a string *s* consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100. | Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character. | [
"VK\n",
"VV\n",
"V\n",
"VKKKKKKKKKVVVVVVVVVK\n",
"KVKV\n"
] | [
"1\n",
"1\n",
"0\n",
"3\n",
"1\n"
] | For the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.
For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.
For the fourth case, we ... | 500 | [
{
"input": "VK",
"output": "1"
},
{
"input": "VV",
"output": "1"
},
{
"input": "V",
"output": "0"
},
{
"input": "VKKKKKKKKKVVVVVVVVVK",
"output": "3"
},
{
"input": "KVKV",
"output": "1"
},
{
"input": "VKKVVVKVKVK",
"output": "5"
},
{
"input... | 1,492,357,689 | 789 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 61 | 5,529,600 | s=input()
ans=s.count('VK')
x=s.count('VV')
y=s.count('KK')
if x!=0 or y!=0:
ans+=1
print(ans) | Title: Vicious Keyboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonio has a keyboard with only two letters, "V" and "K".
One day, he has typed out a string *s* with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter i... | ```python
s=input()
ans=s.count('VK')
x=s.count('VV')
y=s.count('KK')
if x!=0 or y!=0:
ans+=1
print(ans)
``` | 0 | |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,651,940,084 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 0 | # your code goes here
n=int(input())
lst1=set()
for i in range(n):
s=input()
lst1.add(s)
print(len(lst1))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
# your code goes here
n=int(input())
lst1=set()
for i in range(n):
s=input()
lst1.add(s)
print(len(lst1))
``` | 3.977 |
234 | B | Reading | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very lig... | The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour. | In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print an... | [
"5 3\n20 10 30 40 10\n",
"6 5\n90 20 35 40 60 100\n"
] | [
"20\n1 3 4 \n",
"35\n1 3 4 5 6 \n"
] | In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | 0 | [
{
"input": "5 3\n20 10 30 40 10",
"output": "20\n1 3 4 "
},
{
"input": "6 5\n90 20 35 40 60 100",
"output": "35\n1 3 4 5 6 "
},
{
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 2... | 1,675,455,814 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | f_in = open('input.txt')
n, k = f.readline().split()
n = int(n)
k = int(k)
mas = f.readline().split()
f_in.close()
f_out = open('output.txt', 'w')
mas_index = []
for i in range(n):
mas[i] = int(mas[i])
for j in range(k):
if j == (k - 1): f_out.write(max(mas))
mas_index.append(mas.ind... | Title: Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every ho... | ```python
f_in = open('input.txt')
n, k = f.readline().split()
n = int(n)
k = int(k)
mas = f.readline().split()
f_in.close()
f_out = open('output.txt', 'w')
mas_index = []
for i in range(n):
mas[i] = int(mas[i])
for j in range(k):
if j == (k - 1): f_out.write(max(mas))
mas_index.appe... | -1 | |
264 | A | Escape from Stones | PROGRAMMING | 1,200 | [
"constructive algorithms",
"data structures",
"implementation",
"two pointers"
] | null | null | Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order.
The stones always fall to the center of Liss's ... | The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". | Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. | [
"llrlr\n",
"rrlll\n",
"lrlrr\n"
] | [
"3\n5\n4\n2\n1\n",
"1\n2\n5\n4\n3\n",
"2\n4\n5\n3\n1\n"
] | In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1. | 500 | [
{
"input": "llrlr",
"output": "3\n5\n4\n2\n1"
},
{
"input": "rrlll",
"output": "1\n2\n5\n4\n3"
},
{
"input": "lrlrr",
"output": "2\n4\n5\n3\n1"
},
{
"input": "lllrlrllrl",
"output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1"
},
{
"input": "llrlrrrlrr",
"output": "3\n5\n6... | 1,694,624,103 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 1,528 | 50,995,200 | s = input()
l, r = [], []
for i in range(len(s)):
if s[i] == 'l':
l.append(i+1)
else:
r.append(i+1)
for n in r:
print(n)
for i in range(len(l)-1,-1,-1):
print(l[i])
| Title: Escape from Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ... | ```python
s = input()
l, r = [], []
for i in range(len(s)):
if s[i] == 'l':
l.append(i+1)
else:
r.append(i+1)
for n in r:
print(n)
for i in range(len(l)-1,-1,-1):
print(l[i])
``` | 3 | |
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,573,855 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | from math import floor
m,n=map(int,input().split())
area=m*n
print(floor(area/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
from math import floor
m,n=map(int,input().split())
area=m*n
print(floor(area/2))
``` | 3.956411 |
592 | A | PawnChess | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed... | The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'.
It's guaranteed that there will not be white pawns on the first row neither black pawns on the ... | Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. | [
"........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n",
"..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n"
] | [
"A\n",
"B\n"
] | In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner. | 500 | [
{
"input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.",
"output": "B"
},
{
"input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.",
"output": "A"
},
{
"input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n......... | 1,678,882,399 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 93 | 0 | a = [input() for i in range(8)]
ra, rb = 8, 8
for j in range(8) :
for i in range(8) :
if a[i][j] == 'W' :
ra = min(ra, i)
if a[i][j] != '.' :
break
for j in range(8) :
for i in range(7,-1,-1) :
if a[i][j] == 'B' :
rb = min(rb, 7 - i)
... | Title: PawnChess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess».
This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ... | ```python
a = [input() for i in range(8)]
ra, rb = 8, 8
for j in range(8) :
for i in range(8) :
if a[i][j] == 'W' :
ra = min(ra, i)
if a[i][j] != '.' :
break
for j in range(8) :
for i in range(7,-1,-1) :
if a[i][j] == 'B' :
rb = min(rb, 7 - ... | 3 | |
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there w... | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},... | 1,631,021,339 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 20,172,800 | a,b,n = map(int,input().split())
if a == 0:
if b:
print('No solution')
else:
print(0)
elif b == 0:
if n == 0:
print('No solution')
else:
print(0)
elif b % a:
print('No solution')
else:
b //= a
q = True
for i in range(b,1 - b):
if i... | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as th... | ```python
a,b,n = map(int,input().split())
if a == 0:
if b:
print('No solution')
else:
print(0)
elif b == 0:
if n == 0:
print('No solution')
else:
print(0)
elif b % a:
print('No solution')
else:
b //= a
q = True
for i in range(b,1 - b):
... | 0 |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,583,600,783 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | s,v1,v2,t1,t2=map(int,input().split())
a=(s*v1)+2*t1
b= (s*v2)+2*t2
if (a<b):
print("First")
if (a==b):
print("Friendship")
if (a>b):
print("second")
| Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2=map(int,input().split())
a=(s*v1)+2*t1
b= (s*v2)+2*t2
if (a<b):
print("First")
if (a==b):
print("Friendship")
if (a>b):
print("second")
``` | 0 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,504,013,348 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 61 | 0 | # encoding: utf-8
string = input().strip()
k = int(input())
print('impossible' if len(string) < k else max(0, k - len(set(string))))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
# encoding: utf-8
string = input().strip()
k = int(input())
print('impossible' if len(string) < k else max(0, k - len(set(string))))
``` | 3 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,588,832,419 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 218 | 6,656,000 | n = int(input())
grades = [int(i) for i in input().split()]
a, b = map(int, input().split())
k = 0
for i in range(a, b):
k += grades[i-1]
print(k)
| Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n = int(input())
grades = [int(i) for i in input().split()]
a, b = map(int, input().split())
k = 0
for i in range(a, b):
k += grades[i-1]
print(k)
``` | 3.933102 |
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,604,393,272 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | s = input()
ts = 0
tz = 0
for i in range(len(s)):
if 'z'>=s[i]>='a':
ts += 1
else:
tz += 1
if ts>=tz:
print(s.lower())
else:
print(s.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
ts = 0
tz = 0
for i in range(len(s)):
if 'z'>=s[i]>='a':
ts += 1
else:
tz += 1
if ts>=tz:
print(s.lower())
else:
print(s.upper())
``` | 3.93 |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,525,352,025 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 93 | 7,065,600 |
k, n, s, p = input().split()[:4]
k, n, s, p = int(k), int(n), int(s), int(p)
tmp = n / s
if not tmp.is_integer():
tmp = int(tmp) + 1
else:
tmp = int(tmp)
tmp *= k
res = tmp / p
if not res.is_integer():
res = int(res) + 1
else:
res = int(res)
print(res)
| Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
k, n, s, p = input().split()[:4]
k, n, s, p = int(k), int(n), int(s), int(p)
tmp = n / s
if not tmp.is_integer():
tmp = int(tmp) + 1
else:
tmp = int(tmp)
tmp *= k
res = tmp / p
if not res.is_integer():
res = int(res) + 1
else:
res = int(res)
print(res)
``` | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,516,922 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | y = int(input())
while True:
y += 1
flag = True
for i in str(y):
if str(y).count(i) > 1:
flag = False;
if flag:
print(y)
break | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
y = int(input())
while True:
y += 1
flag = True
for i in str(y):
if str(y).count(i) > 1:
flag = False;
if flag:
print(y)
break
``` | 3 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,621,483,147 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n,d=map(int,input().split())
x=list(map(int,input().split()))
a=abs(min(x))
b=max(x)
print(b//a+1) | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n,d=map(int,input().split())
x=list(map(int,input().split()))
a=abs(min(x))
b=max(x)
print(b//a+1)
``` | 0 | |
6 | C | Alice, Bob and Chocolate | PROGRAMMING | 1,200 | [
"greedy",
"two pointers"
] | C. Alice, Bob and Chocolate | 2 | 64 | Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right). | Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob. | [
"5\n2 9 8 2 7\n"
] | [
"2 3\n"
] | none | 0 | [
{
"input": "5\n2 9 8 2 7",
"output": "2 3"
},
{
"input": "1\n1",
"output": "1 0"
},
{
"input": "2\n1 1",
"output": "1 1"
},
{
"input": "3\n1 1 1",
"output": "2 1"
},
{
"input": "4\n1 1 1 1",
"output": "2 2"
},
{
"input": "1\n6",
"output": "1 0"
}... | 1,684,326,256 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 |
n=int(input())
nums = list(map(int,input().split()))
from_left = 0
from_right = 0
j=n-1
for i in range(n):
from_left = from_left+nums[i]
while j!=i and from_left>=from_right+nums[j]:
from_right=from_right+nums[j]
j=j-1
# print(i,j)
if i==j:
j=j-1
break
if i+1==j:
# j=j... | Title: Alice, Bob and Chocolate
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo... | ```python
n=int(input())
nums = list(map(int,input().split()))
from_left = 0
from_right = 0
j=n-1
for i in range(n):
from_left = from_left+nums[i]
while j!=i and from_left>=from_right+nums[j]:
from_right=from_right+nums[j]
j=j-1
# print(i,j)
if i==j:
j=j-1
break
if i+1==j:
... | 0 |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,699,241,879 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 0 | def ex(n):
chod = [1, 2, 3, 4, 5]
if n in chod:
return 1
k = 4
final = 0
while True:
if n - chod[k] == 0:
return final + 1
elif n - chod[k] > 0:
final += 1
n = n - chod[k]
else:
k -= 1
n = int(input())
print(ex(n))
... | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
def ex(n):
chod = [1, 2, 3, 4, 5]
if n in chod:
return 1
k = 4
final = 0
while True:
if n - chod[k] == 0:
return final + 1
elif n - chod[k] > 0:
final += 1
n = n - chod[k]
else:
k -= 1
n = int(input())
print(e... | 3 | |
57 | B | Martian Architecture | PROGRAMMING | 1,600 | [
"implementation"
] | B. Martian Architecture | 2 | 256 | Chris the Rabbit found the traces of an ancient Martian civilization. The brave astronomer managed to see through a small telescope an architecture masterpiece — "A Road to the Sun". The building stands on cubical stones of the same size. The foundation divides the entire "road" into cells, into which the cubical stone... | The first line contains three space-separated integers: *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=105,<=1<=≤<=*k*<=≤<=*min*(*n*,<=100)) which is the number of cells, the number of "Roads to the Sun" and the number of cells in the query correspondingly. Each of the following *m* roads contain three space-separated integers: ... | You have to print a single number on a single line which is the sum of stones in all the cells Chris is interested in.
Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). | [
"5 2 1\n1 5 1\n2 4 1\n3\n",
"3 2 1\n1 3 1\n1 3 1\n2\n",
"3 2 1\n1 3 1\n1 3 1\n3\n"
] | [
"5\n",
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "5 2 1\n1 5 1\n2 4 1\n3",
"output": "5"
},
{
"input": "3 2 1\n1 3 1\n1 3 1\n2",
"output": "4"
},
{
"input": "3 2 1\n1 3 1\n1 3 1\n3",
"output": "6"
},
{
"input": "10 10 3\n6 10 74\n7 9 35\n3 6 63\n2 4 80\n2 10 78\n10 10 13\n4 10 16\n1 2 13\n3 7 17\n4 6 67\n9 8 10",... | 1,553,952,839 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 2,000 | 8,806,400 | n, m, k = (int(x) for x in input().strip().split())
roads = []
for i in range(m):
roads.append([int(x) for x in input().strip().split()])
_k = sorted([int(x) for x in input().strip().split()])
ful_s = 0
for road in roads:
s = 0
c = 0
for el in _k:
if el >= road[0]:
if el > road[1]:
... | Title: Martian Architecture
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Chris the Rabbit found the traces of an ancient Martian civilization. The brave astronomer managed to see through a small telescope an architecture masterpiece — "A Road to the Sun". The building stands on cubical ston... | ```python
n, m, k = (int(x) for x in input().strip().split())
roads = []
for i in range(m):
roads.append([int(x) for x in input().strip().split()])
_k = sorted([int(x) for x in input().strip().split()])
ful_s = 0
for road in roads:
s = 0
c = 0
for el in _k:
if el >= road[0]:
if el > ... | 0 |
1,006 | B | Polycarp's Practice | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann... | The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are p... | In the first line of the output print the maximum possible total profit.
In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ... | [
"8 3\n5 4 2 6 5 1 9 2\n",
"5 1\n1 1 1 1 1\n",
"4 2\n1 2000 2000 2\n"
] | [
"20\n3 2 3",
"1\n5\n",
"4000\n2 2\n"
] | The first example is described in the problem statement.
In the second example there is only one possible distribution.
In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. | 0 | [
{
"input": "8 3\n5 4 2 6 5 1 9 2",
"output": "20\n4 1 3"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "1\n5"
},
{
"input": "4 2\n1 2000 2000 2",
"output": "4000\n2 2"
},
{
"input": "1 1\n2000",
"output": "2000\n1"
},
{
"input": "1 1\n1234",
"output": "1234\n1"
... | 1,652,914,126 | 4,726 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,505,600 | line1=str(input())
line1=line1.split(" ")
n=int(line1[0])
k=int(line1[1])
string=str(input())
string=string.split(" ")
sort=[]
notsort=[]
for i in range(n):
sort.append(int(string[i]))
notsort.append(int(string[i]))
sort.sort()
maximum=[]
sum=0
maximumind=[]
for i in range(1,k+1):
maximum.ap... | Title: Polycarp's Practice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least... | ```python
line1=str(input())
line1=line1.split(" ")
n=int(line1[0])
k=int(line1[1])
string=str(input())
string=string.split(" ")
sort=[]
notsort=[]
for i in range(n):
sort.append(int(string[i]))
notsort.append(int(string[i]))
sort.sort()
maximum=[]
sum=0
maximumind=[]
for i in range(1,k+1):
... | 0 | |
597 | A | Divisibility | PROGRAMMING | 1,600 | [
"math"
] | null | null | Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*. | The only line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=1018;<=-<=1018<=≤<=*a*<=≤<=*b*<=≤<=1018). | Print the required number. | [
"1 1 10\n",
"2 -4 4\n"
] | [
"10\n",
"5\n"
] | none | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "2 -4 4",
"output": "5"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 0 0",
"output": "1"
},
{
"input": "1 0 1",
"output": "2"
},
{
"input": "1 10181 10182",
"output": "2"
},
{
"inpu... | 1,450,960,398 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 56 | 1,000 | 0 | b = list(map(int, input().split()))
k = b[0]
a = b[1]
b = b[2]
n = 0
for x in range(a, b + 1):
if x % k == 0:
n += 1
print(n) | Title: Divisibility
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find the number of *k*-divisible numbers on the segment [*a*,<=*b*]. In other words you need to find the number of such integer values *x* that *a*<=≤<=*x*<=≤<=*b* and *x* is divisible by *k*.
Input Specification:
The onl... | ```python
b = list(map(int, input().split()))
k = b[0]
a = b[1]
b = b[2]
n = 0
for x in range(a, b + 1):
if x % k == 0:
n += 1
print(n)
``` | 0 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,669,113,246 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import sys
input = sys.stdin.readline
out = 0
n, a, b = map(int, input().split())
x = abs(b) % n
if (b>0):
if ((a+x)%n == 0):
print(n)
else: print((a+x)%n)
else:
print((a+(n-x)))
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
import sys
input = sys.stdin.readline
out = 0
n, a, b = map(int, input().split())
x = abs(b) % n
if (b>0):
if ((a+x)%n == 0):
print(n)
else: print((a+x)%n)
else:
print((a+(n-x)))
``` | 0 | |
478 | A | Initial Bet | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program ... | The input consists of a single line containing five integers *c*1,<=*c*2,<=*c*3,<=*c*4 and *c*5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0<=≤<=*c*1,<=*c*2,<=*c*3,<=*c*4,<=*c*5<=≤<=100). | Print the only line containing a single positive integer *b* — the number of coins in the initial bet of each player. If there is no such value of *b*, then print the only value "-1" (quotes for clarity). | [
"2 5 4 0 4\n",
"4 5 9 2 1\n"
] | [
"3\n",
"-1\n"
] | In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player; 1. One coin is passed from the fourth player to the fifth player; 1. One coin is passed from the first player to the third player; 1. One coin is passed from the fourth player to... | 500 | [
{
"input": "2 5 4 0 4",
"output": "3"
},
{
"input": "4 5 9 2 1",
"output": "-1"
},
{
"input": "0 0 0 0 0",
"output": "-1"
},
{
"input": "1 2 1 2 3",
"output": "-1"
},
{
"input": "100 0 0 0 0",
"output": "20"
},
{
"input": "2 3 4 5 6",
"output": "4"... | 1,664,992,109 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 61 | 0 | def main():
v = [int(i) for i in input().split()]
s = sum(v)
if s % 5 == 0 and s != 0:
print(s // 5)
else:
print(-1)
if __name__ == "__main__":
main()
| Title: Initial Bet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are five people playing a game called "Generosity". Each person gives some non-zero number of coins *b* as an initial bet. After all players make their bets of *b* coins, the following operation is repeated for severa... | ```python
def main():
v = [int(i) for i in input().split()]
s = sum(v)
if s % 5 == 0 and s != 0:
print(s // 5)
else:
print(-1)
if __name__ == "__main__":
main()
``` | 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,677,997,290 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 3,686,400 | a=input()
n=len(a)
s=0
for i in range(1,2**n):
mask=bin(i)[2:].zfill(n)
s1=''
for j in range(n): s1+=a[j]*int(mask[j])
if s1=='QAQ': 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()
n=len(a)
s=0
for i in range(1,2**n):
mask=bin(i)[2:].zfill(n)
s1=''
for j in range(n): s1+=a[j]*int(mask[j])
if s1=='QAQ': s+=1
print(s)
``` | 0 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,688,998,694 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 122 | 0 | n=int(input())
if n<0:
ld=(-1*n)%10
a_ld=(-1*n)//10
lbd= (a_ld)%10
lbd_n=(a_ld)//10
lbd_n=((lbd_n*10)+ld)
ans1=a_ld*-1
ans2=lbd_n*-1
if ans1>ans2:
print(ans1)
else:
print(ans2)
else:
print(n)
| Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n=int(input())
if n<0:
ld=(-1*n)%10
a_ld=(-1*n)//10
lbd= (a_ld)%10
lbd_n=(a_ld)//10
lbd_n=((lbd_n*10)+ld)
ans1=a_ld*-1
ans2=lbd_n*-1
if ans1>ans2:
print(ans1)
else:
print(ans2)
else:
print(n)
``` | 3 | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,454,841,669 | 5,769 | Python 3 | OK | TESTS | 82 | 62 | 0 | n = int(input())
a = int(input())
b = int(input())
c = int(input())
l = 0
while n >= a or n >= b:
if n >= b and b - c < a:
nl1 = (n - b) // (b - c)
nl2 = n // b
nl = max(nl1, nl2)
l += nl
n -= (b - c) * nl
else:
nl = n // a
l += nl
n -= a * nl
pr... | Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
n = int(input())
a = int(input())
b = int(input())
c = int(input())
l = 0
while n >= a or n >= b:
if n >= b and b - c < a:
nl1 = (n - b) // (b - c)
nl2 = n // b
nl = max(nl1, nl2)
l += nl
n -= (b - c) * nl
else:
nl = n // a
l += nl
n -= ... | 3 | |
784 | F | Crunching Numbers Just for You | PROGRAMMING | 1,900 | [
"*special",
"implementation"
] | null | null | You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order. | The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). | Output space-separated elements of the sorted array. | [
"3 3 1 2\n"
] | [
"1 2 3 \n"
] | Remember, this is a very important feature, and you have to make sure the customers appreciate it! | 0 | [
{
"input": "3 3 1 2",
"output": "1 2 3 "
},
{
"input": "10 54 100 27 1 33 27 80 49 27 6",
"output": "1 6 27 27 27 33 49 54 80 100 "
}
] | 1,680,287,663 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = [int(i) for i in input().split()][:-1]
print(*sorted(a)) | Title: Crunching Numbers Just for You
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done.... | ```python
a = [int(i) for i in input().split()][:-1]
print(*sorted(a))
``` | 0 | |
989 | C | A Mist of Florescence | PROGRAMMING | 1,800 | [
"constructive algorithms",
"graphs"
] | null | null | "I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a ... | The first and only line of input contains four space-separated integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively. | In the first line, output two space-separated integers $n$ and $m$ ($1 \leq n, m \leq 50$) — the number of rows and the number of columns in the grid respectively.
Then output $n$ lines each consisting of $m$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and '... | [
"5 3 2 1\n",
"50 50 1 1\n",
"1 6 4 5\n"
] | [
"4 7\nDDDDDDD\nDABACAD\nDBABACD\nDDDDDDD",
"4 50\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nABABABABABABABABABABABABABABABABABABABABABABABABAB\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"7 7\nDDDDDDD\nDDDBDBD\nDDCDCDD\nDBDADBD\nDDCDCDD\nDB... | In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one. | 1,500 | [
{
"input": "5 3 2 1",
"output": "5 13\nAABABBBBCDDAD\nABAABBBBCDADD\nAAAABBBBCDDAD\nAAAABCBBCDADD\nAAAABBBBCDDDD"
},
{
"input": "50 50 1 1",
"output": "10 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABAB... | 1,530,356,212 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | def main():
(a, A), (b, B), (c, C), (d, D) = sorted(zip(map(int, input().split()), 'ABCD'))
aa = A.join(B * (b - 1)) if b > 1 else A
bb = B.join(A * (a - 1)) if b > 1 else B
cc = C.join(D * (d - 1)) if d > 1 else C
dd = D.join(C * (c - 1)) if d > 1 else D
print(4, len(aa) + len(cc))
print(aa... | Title: A Mist of Florescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds... | ```python
def main():
(a, A), (b, B), (c, C), (d, D) = sorted(zip(map(int, input().split()), 'ABCD'))
aa = A.join(B * (b - 1)) if b > 1 else A
bb = B.join(A * (a - 1)) if b > 1 else B
cc = C.join(D * (d - 1)) if d > 1 else C
dd = D.join(C * (c - 1)) if d > 1 else D
print(4, len(aa) + len(cc))
... | 0 | |
194 | B | Square | PROGRAMMING | 1,200 | [
"math"
] | null | null | There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwa... | The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases.
The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. | For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input.
Please do not use the %lld specifier to read or write 64-bit... | [
"3\n4 8 100\n"
] | [
"17\n33\n401\n"
] | none | 1,000 | [
{
"input": "3\n4 8 100",
"output": "17\n33\n401"
},
{
"input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13",
"output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27"
},
{
"input": "3\n13 17 21",
"output... | 1,662,196,024 | 2,147,483,647 | PyPy 3 | OK | TESTS | 8 | 124 | 4,403,200 | import math
n = int(input())
a = list(map(int,input().split()))
for i in a:
print(1 + ((4 * i * (i + 1)) // math.gcd(4 * i ,i + 1)) // (i + 1)) | Title: Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the ... | ```python
import math
n = int(input())
a = list(map(int,input().split()))
for i in a:
print(1 + ((4 * i * (i + 1)) // math.gcd(4 * i ,i + 1)) // (i + 1))
``` | 3 | |
958 | D1 | Hyperspace Jump (easy) | PROGRAMMING | 1,400 | [
"expression parsing",
"math"
] | null | null | The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independe... | The first line of the input contains a single integer *m* (1<=≤<=*m*<=≤<=200<=000) – the number of ships. The next *m* lines describe one jump coordinate each, given as an arithmetic expression. An expression has the form (a+b)/c. Namely, it consists of: an opening parenthesis (, a positive integer *a* of up to two dec... | Print a single line consisting of *m* space-separated integers. The *i*-th integer should be equal to the number of ships whose coordinate is equal to that of the *i*-th ship (including the *i*-th ship itself). | [
"4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7\n"
] | [
"1 2 2 1 "
] | In the sample testcase, the second and the third ship will both end up at the coordinate 3.
Note that this problem has only two versions – easy and hard. | 0 | [
{
"input": "4\n(99+98)/97\n(26+4)/10\n(12+33)/15\n(5+1)/7",
"output": "1 2 2 1 "
},
{
"input": "10\n(44+98)/19\n(36+58)/47\n(62+74)/68\n(69+95)/82\n(26+32)/29\n(32+46)/39\n(32+24)/28\n(47+61)/54\n(39+13)/26\n(98+98)/98",
"output": "1 9 9 9 9 9 9 9 9 9 "
},
{
"input": "30\n(89+76)/87\n(81... | 1,631,059,369 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 608 | 19,763,200 | # _
#####################################################################################################################
def main():
return nShipsWithSameCoordinate(int(input()), {})
def nShipsWithSameCoordinate(nShips, nShipsAt):
ships_Coordinates = list(range(nShips))
for i in ships_Coordinat... | Title: Hyperspace Jump (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Rebel fleet is on the run. It consists of *m* ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebe... | ```python
# _
#####################################################################################################################
def main():
return nShipsWithSameCoordinate(int(input()), {})
def nShipsWithSameCoordinate(nShips, nShipsAt):
ships_Coordinates = list(range(nShips))
for i in ships... | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,634,732,943 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 187 | 19,251,200 | n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
print(sum(A)-sum(B))
print(sum(B)-sum(C)) | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]
print(sum(A)-sum(B))
print(sum(B)-sum(C))
``` | 3 | |
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=*min*(100<=000,<=*n*2)) — the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the number of the row and the number of the col... | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18... | 1,658,718,114 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 1,153 | 28,774,400 | from collections import defaultdict as dc
n,m=[int(x) for x in input().split()]
ans=n*n
mpr,mpc=dc(lambda:False),dc(lambda:False)
stR,stC=set(),set()
for _ in range(m):
x,y=[int(c) for c in input().split()]
if mpr[x]==False:
ans-=(n-len(stC))
stR.add(x)
mpr[x]=True
if mpc[... | Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=×<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's a... | ```python
from collections import defaultdict as dc
n,m=[int(x) for x in input().split()]
ans=n*n
mpr,mpc=dc(lambda:False),dc(lambda:False)
stR,stC=set(),set()
for _ in range(m):
x,y=[int(c) for c in input().split()]
if mpr[x]==False:
ans-=(n-len(stC))
stR.add(x)
mpr[x]=True
... | 3 | |
424 | B | Megacity | PROGRAMMING | 1,200 | [
"binary search",
"greedy",
"implementation",
"sortings"
] | null | null | The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city.
The city of Tomsk can be represented as point on the plane with ... | The first line of the input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=103; 1<=≤<=*s*<=<<=106) — the number of locatons around Tomsk city and the population of the city. Then *n* lines follow. The *i*-th line contains three integers — the *x**i* and *y**i* coordinate values of the *i*-th location and the numbe... | In the output, print "-1" (without the quotes), if Tomsk won't be able to become a megacity. Otherwise, in the first line print a single real number — the minimum radius of the circle that the city needs to expand to in order to become a megacity.
The answer is considered correct if the absolute or relative error don'... | [
"4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n",
"4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n",
"2 1\n1 1 999997\n2 2 1\n"
] | [
"2.8284271\n",
"1.4142136\n",
"-1"
] | none | 1,000 | [
{
"input": "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1",
"output": "2.8284271"
},
{
"input": "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1",
"output": "1.4142136"
},
{
"input": "2 1\n1 1 999997\n2 2 1",
"output": "-1"
},
{
"input": "4 999998\n3 3 10\n-3 3 10\n3 -3 10\n-3 -3 10",
"out... | 1,494,159,715 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | '''input
2 1
1 1 999997
2 2 1
'''
n, s = map(int, input().split())
l = {}
for _ in range(n):
a, b, k = map(int, input().split())
l[(a**2+b**2)**0.5] = k
for x in sorted(l):
s += l[x]
if s >= 1000000:
print(x)
break
else:
print(-1)
| Title: Megacity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding... | ```python
'''input
2 1
1 1 999997
2 2 1
'''
n, s = map(int, input().split())
l = {}
for _ in range(n):
a, b, k = map(int, input().split())
l[(a**2+b**2)**0.5] = k
for x in sorted(l):
s += l[x]
if s >= 1000000:
print(x)
break
else:
print(-1)
``` | 0 | |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,664,231,601 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 23 | 62 | 0 | #!/usr/bin/python3
import sys
sq = []
for i, line in enumerate(sys.stdin.readlines()):
sq.append([c == '#' for c in line.strip()])
def thing(sq):
for i in range(3):
for j in range(3):
c = 0
if sq[i][j] == sq[i][j+1]:
c += 1
if sq[i][j] == sq[i+1][j]:
c += 1
if sq[i][j] == sq[i+1][j+1]:
c ... | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
#!/usr/bin/python3
import sys
sq = []
for i, line in enumerate(sys.stdin.readlines()):
sq.append([c == '#' for c in line.strip()])
def thing(sq):
for i in range(3):
for j in range(3):
c = 0
if sq[i][j] == sq[i][j+1]:
c += 1
if sq[i][j] == sq[i+1][j]:
c += 1
if sq[i][j] == sq[i+1][j+... | 0 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,633,442,097 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 20,172,800 | q='01235689'
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=0
f=0
for i in a:
for j in range(0,i+1):
if str(j) not in q:
s+=1
if s<=m:
f+=1
s=0
print(f)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
q='01235689'
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=0
f=0
for i in a:
for j in range(0,i+1):
if str(j) not in q:
s+=1
if s<=m:
f+=1
s=0
print(f)
``` | 0 | |
919 | B | Perfect Number | PROGRAMMING | 1,100 | [
"binary search",
"brute force",
"dp",
"implementation",
"number theory"
] | null | null | We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. | A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). | A single number, denoting the $k$-th smallest perfect integer. | [
"1\n",
"2\n"
] | [
"19\n",
"28\n"
] | The first perfect integer is $19$ and the second one is $28$. | 750 | [
{
"input": "1",
"output": "19"
},
{
"input": "2",
"output": "28"
},
{
"input": "13",
"output": "136"
},
{
"input": "101",
"output": "1432"
},
{
"input": "1023",
"output": "100270"
},
{
"input": "9999",
"output": "10800010"
},
{
"input": "10... | 1,675,766,261 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | t=int(input())
for i in range(t):
n=input()
for i in range(1,10001):
if int(n)+i==10:
print(n+str(i))
break | Title: Perfect Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
Input Specification:
A singl... | ```python
t=int(input())
for i in range(t):
n=input()
for i in range(1,10001):
if int(n)+i==10:
print(n+str(i))
break
``` | -1 | |
888 | B | Buggy Robot | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo... | The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100).
The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. | Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. | [
"4\nLDUR\n",
"5\nRRRUU\n",
"6\nLLRRRR\n"
] | [
"4\n",
"0\n",
"4\n"
] | none | 0 | [
{
"input": "4\nLDUR",
"output": "4"
},
{
"input": "5\nRRRUU",
"output": "0"
},
{
"input": "6\nLLRRRR",
"output": "4"
},
{
"input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR",
"output": "76"
},
{
"input": "89\nLDL... | 1,624,716,266 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 0 | n=int(input())
s=input()
a,b,c,d=0,0,0,0
for i in range(n):
if s[i]=='L':
a+=1
elif s[i]=='R':
b+=1
elif s[i]=='U':
c+=1
else:
d+=1
print(2*(min(a,b)+min(c,d))) | Title: Buggy Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform:
- U — move from the ce... | ```python
n=int(input())
s=input()
a,b,c,d=0,0,0,0
for i in range(n):
if s[i]=='L':
a+=1
elif s[i]=='R':
b+=1
elif s[i]=='U':
c+=1
else:
d+=1
print(2*(min(a,b)+min(c,d)))
``` | 3 | |
44 | E | Anfisa the Monkey | PROGRAMMING | 1,400 | [
"dp"
] | E. Anfisa the Monkey | 2 | 256 | Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into *k* lines not shorter than *a* and not longer than *b*, for the text to resemble h... | The first line contains three integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=200, 1<=≤<=*a*<=≤<=*b*<=≤<=200). The second line contains a sequence of lowercase Latin letters — the text typed by Anfisa. It is guaranteed that the given line is not empty and its length does not exceed 200 symbols. | Print *k* lines, each of which contains no less than *a* and no more than *b* symbols — Anfisa's text divided into lines. It is not allowed to perform any changes in the text, such as: deleting or adding symbols, changing their order, etc. If the solution is not unique, print any of them. If there is no solution, print... | [
"3 2 5\nabrakadabra\n",
"4 1 2\nabrakadabra\n"
] | [
"ab\nrakad\nabra\n",
"No solution\n"
] | none | 0 | [
{
"input": "3 2 5\nabrakadabra",
"output": "abra\nkada\nbra"
},
{
"input": "4 1 2\nabrakadabra",
"output": "No solution"
},
{
"input": "3 1 2\nvgnfpo",
"output": "vg\nnf\npo"
},
{
"input": "5 3 4\nvrrdnhazvexzjfv",
"output": "vrr\ndnh\nazv\nexz\njfv"
},
{
"input":... | 1,652,239,891 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 |
k,a,b = map(int,input().split())
qo = input()
def find(word,a,b):
rs = len(word)
cs = rs/k
if cs < a or cs > b:
print("No solution")
exit(0)
for i in range(k):
length = len(word)
index = round(length/(k-i))
print(word[:index])
... | Title: Anfisa the Monkey
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she ... | ```python
k,a,b = map(int,input().split())
qo = input()
def find(word,a,b):
rs = len(word)
cs = rs/k
if cs < a or cs > b:
print("No solution")
exit(0)
for i in range(k):
length = len(word)
index = round(length/(k-i))
print(word[:index... | 3.977 |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,588,192,028 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 218 | 0 | sides=[int(i) for i in input().split()] ## insert 3 varibles
sides.sort() ## sorting method High - low
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]: ## basically checking for triangle properties
print("TRIANGLE")
elif sides[0]+side... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
sides=[int(i) for i in input().split()] ## insert 3 varibles
sides.sort() ## sorting method High - low
if sides[0]+sides[1]>sides[2]:
print("TRIANGLE")
elif sides[1]+sides[2]>sides[3]: ## basically checking for triangle properties
print("TRIANGLE")
elif sid... | 3.9455 |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,697,741,269 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 25 | 124 | 0 | n = int(input())
if (('4' in str(n) and '7' in str(n) and (len(str(n)) == str(n).count('4') + str(n).count('7')))) or ((n % 4 == 0) or (n % 7 == 0)):
print('YES')
else:
print('NO') | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
n = int(input())
if (('4' in str(n) and '7' in str(n) and (len(str(n)) == str(n).count('4') + str(n).count('7')))) or ((n % 4 == 0) or (n % 7 == 0)):
print('YES')
else:
print('NO')
``` | 0 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,638,556,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a,b,c,d,e =map(int,input().split())
p = (b*a) +d +1
q = (c*a) +e +1
if p<q:
print("First")
elif p>q :
print("Second")
else:
print("Friendship") | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
a,b,c,d,e =map(int,input().split())
p = (b*a) +d +1
q = (c*a) +e +1
if p<q:
print("First")
elif p>q :
print("Second")
else:
print("Friendship")
``` | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,656,241,331 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 53 | 154 | 32,665,600 | # author: violist
# created: 26.06.2022 12:53:28
import sys
from collections import defaultdict
input = sys.stdin.readline
a = input()[:-1]
b = input()[:-1]
if (len(a) != len(b)):
print("NO")
sys.exit()
n = len(a)
cnt = 0
for i in range(n):
if (a[i] != b[i]):
cnt += 1
x, y = de... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
# author: violist
# created: 26.06.2022 12:53:28
import sys
from collections import defaultdict
input = sys.stdin.readline
a = input()[:-1]
b = input()[:-1]
if (len(a) != len(b)):
print("NO")
sys.exit()
n = len(a)
cnt = 0
for i in range(n):
if (a[i] != b[i]):
cnt += 1
... | 3 | |
976 | E | Well played! | PROGRAMMING | 2,100 | [
"greedy",
"sortings"
] | null | null | Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns *n* creatures, *i*-th of them can be described with two numbers — its health *hp**i* and its damage *dmg**i*. Max also ha... | The first line contains three integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*a*<=≤<=20, 0<=≤<=*b*<=≤<=2·105) — the number of creatures, spells of the first type and spells of the second type, respectively.
The *i*-th of the next *n* lines contain two number *hp**i* and *dmg**i* (1<=≤<=*hp**i*,<=*dmg**i*<=≤<=109) ... | Print single integer — maximum total damage creatures can deal. | [
"2 1 1\n10 15\n6 1\n",
"3 0 3\n10 8\n7 11\n5 2\n"
] | [
"27\n",
"26\n"
] | In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27.
In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on... | 0 | [
{
"input": "2 1 1\n10 15\n6 1",
"output": "27"
},
{
"input": "3 0 3\n10 8\n7 11\n5 2",
"output": "26"
},
{
"input": "1 0 0\n2 1",
"output": "1"
},
{
"input": "1 0 200000\n1 2",
"output": "2"
},
{
"input": "7 5 7\n29 25\n84 28\n34 34\n14 76\n85 9\n40 57\n99 88",
... | 1,657,747,272 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 16,281,600 | from sys import stdin,exit
def select(arr, left, right, k):
while True:
if left == right:
return left
pivotIndex = pivot(arr, left, right)
pivotIndex = partition(arr, left, right, pivotIndex, k)
if k == pivotIndex:
return k
elif k < pivotIndex:
... | Title: Well played!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns *n* creatures, *i*-th o... | ```python
from sys import stdin,exit
def select(arr, left, right, k):
while True:
if left == right:
return left
pivotIndex = pivot(arr, left, right)
pivotIndex = partition(arr, left, right, pivotIndex, k)
if k == pivotIndex:
return k
elif k < pivotInd... | 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,639,563,155 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 216 | 0 | inp = input()
count = {'l': 0, 'u': 0}
for i in inp:
if i.isupper():
count['u'] += 1
else:
count['l'] += 1
if count['u'] > count['l']:
print(inp.upper())
else:
print(inp.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
inp = input()
count = {'l': 0, 'u': 0}
for i in inp:
if i.isupper():
count['u'] += 1
else:
count['l'] += 1
if count['u'] > count['l']:
print(inp.upper())
else:
print(inp.lower())
``` | 3.946 |
989 | C | A Mist of Florescence | PROGRAMMING | 1,800 | [
"constructive algorithms",
"graphs"
] | null | null | "I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds of flowers in the wood, Amaranths, Begonias, Centaureas and Dianthuses.
The wood can be represented by a ... | The first and only line of input contains four space-separated integers $a$, $b$, $c$ and $d$ ($1 \leq a, b, c, d \leq 100$) — the required number of connected components of Amaranths, Begonias, Centaureas and Dianthuses, respectively. | In the first line, output two space-separated integers $n$ and $m$ ($1 \leq n, m \leq 50$) — the number of rows and the number of columns in the grid respectively.
Then output $n$ lines each consisting of $m$ consecutive English letters, representing one row of the grid. Each letter should be among 'A', 'B', 'C' and '... | [
"5 3 2 1\n",
"50 50 1 1\n",
"1 6 4 5\n"
] | [
"4 7\nDDDDDDD\nDABACAD\nDBABACD\nDDDDDDD",
"4 50\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\nABABABABABABABABABABABABABABABABABABABABABABABABAB\nBABABABABABABABABABABABABABABABABABABABABABABABABA\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
"7 7\nDDDDDDD\nDDDBDBD\nDDCDCDD\nDBDADBD\nDDCDCDD\nDB... | In the first example, each cell of Amaranths, Begonias and Centaureas forms a connected component, while all the Dianthuses form one. | 1,500 | [
{
"input": "5 3 2 1",
"output": "5 13\nAABABBBBCDDAD\nABAABBBBCDADD\nAAAABBBBCDDAD\nAAAABCBBCDADD\nAAAABBBBCDDDD"
},
{
"input": "50 50 1 1",
"output": "10 50\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\nABABABABABABABABABABABABABABABABABABABABABABABABAA\nBABABABABABABABABABABABABABABABAB... | 1,528,780,746 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | quotas = [int(x) - 1 for x in input().split()]
grid = [['a'] * 50 for _ in range(12)] + \
[['b'] * 50 for _ in range(12)] + \
[['c'] * 50 for _ in range(12)] + \
[['d'] * 50 for _ in range(12)]
def poke(row, f_idx):
for i in range(row + 1, row + 12, 2):
for j in range(1, 50, 2):
... | Title: A Mist of Florescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"I've been here once," Mino exclaims with delight, "it's breathtakingly amazing."
"What is it like?"
"Look, Kanno, you've got your paintbrush, and I've got my words. Have a try, shall we?"
There are four kinds... | ```python
quotas = [int(x) - 1 for x in input().split()]
grid = [['a'] * 50 for _ in range(12)] + \
[['b'] * 50 for _ in range(12)] + \
[['c'] * 50 for _ in range(12)] + \
[['d'] * 50 for _ in range(12)]
def poke(row, f_idx):
for i in range(row + 1, row + 12, 2):
for j in range(1, 50... | 3 | |
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,656,041,217 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n=input().split()
print(int(int(n[0])*int(n[1])/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
n=input().split()
print(int(int(n[0])*int(n[1])/2))
``` | 3.977 |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,611,567,177 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 307,200 | def geti(a):
return int(float(a))
n=geti(input())
x=[]
d=[]
tmp=''
for i in range(0,n):
tmp=input().split()
x.append(geti(tmp[0]))
d.append(geti(tmp[1]))
import sys
for i in range(0,n):
for j in range(i+1,n):
if x[i]+d[i]==x[j] and x[j]+d[j]==x[i]:
print('YES')
sys.ex... | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
def geti(a):
return int(float(a))
n=geti(input())
x=[]
d=[]
tmp=''
for i in range(0,n):
tmp=input().split()
x.append(geti(tmp[0]))
d.append(geti(tmp[1]))
import sys
for i in range(0,n):
for j in range(i+1,n):
if x[i]+d[i]==x[j] and x[j]+d[j]==x[i]:
print('YES')
... | 3.968428 |
580 | A | Kefa and First Steps | PROGRAMMING | 900 | [
"brute force",
"dp",
"implementation"
] | null | null | Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. | [
"6\n2 2 1 3 4 1\n",
"3\n2 2 9\n"
] | [
"3",
"3"
] | In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.
In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. | 750 | [
{
"input": "6\n2 2 1 3 4 1",
"output": "3"
},
{
"input": "3\n2 2 9",
"output": "3"
},
{
"input": "5\n10 100 111 1 2",
"output": "3"
},
{
"input": "10\n1 2 3 4 1 2 3 4 5 6",
"output": "6"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... | 1,689,535,175 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 77 | 13,516,800 | n=int(input())
a1=list(map(int,input().split()))
k=1
c=1
for i in range(1,n):
if a1[i]>=a1[i-1]:
k+=1
else:
c=max(k,c)
k=1
c=max(k,c)
print(c) | Title: Kefa and First Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l... | ```python
n=int(input())
a1=list(map(int,input().split()))
k=1
c=1
for i in range(1,n):
if a1[i]>=a1[i-1]:
k+=1
else:
c=max(k,c)
k=1
c=max(k,c)
print(c)
``` | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,699,204,525 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | q=input()
print(q.title()) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
q=input()
print(q.title())
``` | 0 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,674,904,864 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | import sys, math
inputt = lambda: sys.stdin.readline().strip()
ints = lambda: list(map(int, input().split()))
printn = lambda x: sys.stdout.write(x+'\n')
printnn = lambda x: sys.stdout.write(x)
n=int(input())
a = ints()
b, c = 0, 0
for i in range(n//2):
b+=max(a[0], a[-1])
a.remove(max(a[0], a[-1]))... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
import sys, math
inputt = lambda: sys.stdin.readline().strip()
ints = lambda: list(map(int, input().split()))
printn = lambda x: sys.stdout.write(x+'\n')
printnn = lambda x: sys.stdout.write(x)
n=int(input())
a = ints()
b, c = 0, 0
for i in range(n//2):
b+=max(a[0], a[-1])
a.remove(max(a[0... | 3 | |
632 | C | The Smallest String Concatenation | PROGRAMMING | 1,700 | [
"sortings",
"strings"
] | null | null | You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list of strings, output the lexicographically smallest concatenation. | The first line contains integer *n* — the number of strings (1<=≤<=*n*<=≤<=5·104).
Each of the next *n* lines contains one string *a**i* (1<=≤<=|*a**i*|<=≤<=50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104. | Print the only string *a* — the lexicographically smallest string concatenation. | [
"4\nabba\nabacaba\nbcd\ner\n",
"5\nx\nxx\nxxa\nxxaa\nxxaaa\n",
"3\nc\ncb\ncba\n"
] | [
"abacabaabbabcder\n",
"xxaaaxxaaxxaxxx\n",
"cbacbc\n"
] | none | 0 | [
{
"input": "4\nabba\nabacaba\nbcd\ner",
"output": "abacabaabbabcder"
},
{
"input": "5\nx\nxx\nxxa\nxxaa\nxxaaa",
"output": "xxaaaxxaaxxaxxx"
},
{
"input": "3\nc\ncb\ncba",
"output": "cbacbc"
},
{
"input": "10\naba\nabaaca\naba\nacaaaabbac\nabaacac\nb\ncabbcccaab\nbaacbb\nbcab... | 1,630,511,512 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 3,000 | 7,577,600 | n = int(input())
a = []
for i in range(n):
a.append(input())
for i in range(0,n):
for j in range(i+1,n):
if(a[i]+a[j]>a[j]+a[i]):
s=a[i]
a[i]=a[j]
a[j]=s
print("".join(a))
| Title: The Smallest String Concatenation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a list of *n* strings *a*1,<=*a*2,<=...,<=*a**n*. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.
Given the list ... | ```python
n = int(input())
a = []
for i in range(n):
a.append(input())
for i in range(0,n):
for j in range(i+1,n):
if(a[i]+a[j]>a[j]+a[i]):
s=a[i]
a[i]=a[j]
a[j]=s
print("".join(a))
``` | 0 | |
740 | B | Alyona and flowers | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≤<=*a**i*<=≤<=100).
The next *m* lines contain the description of the ... | Print single integer — the maximum possible value added to the Alyona's happiness. | [
"5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n",
"4 3\n1 2 3 4\n1 3\n2 4\n1 1\n",
"2 2\n-1 -2\n1 1\n1 2\n"
] | [
"7\n",
"16\n",
"0\n"
] | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | 1,000 | [
{
"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4",
"output": "7"
},
{
"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1",
"output": "16"
},
{
"input": "2 2\n-1 -2\n1 1\n1 2",
"output": "0"
},
{
"input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5",
"output": "8"
},
{
"inpu... | 1,647,186,268 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 77 | 0 | def heyBoy(tempArr,l,r,arr):
freqArr=tempArr[::]
if(r+1<len(arr)):
freqArr[r+1]-=1
arr[l]+=1
numbers=0
happ=0
for i in range(len(arr)):
numbers+=freqArr[i]
happ+=freqArr[i]*numbers
return happ,freqArr
n,q=map(int,input().split())
arr=list(map(int,input()... | Title: Alyona and flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative.
Let's define a subarra... | ```python
def heyBoy(tempArr,l,r,arr):
freqArr=tempArr[::]
if(r+1<len(arr)):
freqArr[r+1]-=1
arr[l]+=1
numbers=0
happ=0
for i in range(len(arr)):
numbers+=freqArr[i]
happ+=freqArr[i]*numbers
return happ,freqArr
n,q=map(int,input().split())
arr=list(map(i... | 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.