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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,618,186,195 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define newl '\n'
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> shows;
for (int i = 0; i < n; i++) {
// l, r
int x, y;
cin >> x >> y;
shows.push... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long
#define newl '\n'
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> shows;
for (int i = 0; i < n; i++) {
// l, r
int x, y;
cin >> x >> y;
... | -1 | |
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c... | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
I... | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"inp... | 1,529,321,836 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 77 | 0 | n,k = map(int,input().split())
l= list(set(map(int,input().split())))
n = len(l)
t= sorted(l,reverse=True)
# ai - aj <k
for i in range(n-1):
for j in range(i+1,n):
if t[i]-t[j]<=k:
l.remove(t[j])
else:
break
print(len(l))
| Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Pe... | ```python
n,k = map(int,input().split())
l= list(set(map(int,input().split())))
n = len(l)
t= sorted(l,reverse=True)
# ai - aj <k
for i in range(n-1):
for j in range(i+1,n):
if t[i]-t[j]<=k:
l.remove(t[j])
else:
break
print(len(l))
``` | 0 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,679,337,786 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n,m=list(map(int,input().split(' ')))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
s=0
for i in a:
if i<=max(a) and 2*i<=max(a):
s=1
break
if s==1:
print(max(a))
else:
print(-1) | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
n,m=list(map(int,input().split(' ')))
a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
s=0
for i in a:
if i<=max(a) and 2*i<=max(a):
s=1
break
if s==1:
print(max(a))
else:
print(-1)
``` | 0 | |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,623,409,447 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | N=5
a=2
b=3
print(N-max(a+1,N-b)+1)
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
N=5
a=2
b=3
print(N-max(a+1,N-b)+1)
``` | -1 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,625,520,480 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 14 | 1,090 | 67,072,000 | from itertools import combinations_with_replacement
from itertools import permutations
n = int(input())
res = 0
tst = int("1" * len(str(n)))
for i in range(len(str(n)) - 1):
res += 2 ** i
combs = list(combinations_with_replacement([0, 1], len(str(n)) - 1))
perm = []
for comb in combs:
perm += list((pe... | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
from itertools import combinations_with_replacement
from itertools import permutations
n = int(input())
res = 0
tst = int("1" * len(str(n)))
for i in range(len(str(n)) - 1):
res += 2 ** i
combs = list(combinations_with_replacement([0, 1], len(str(n)) - 1))
perm = []
for comb in combs:
perm +... | 0 |
67 | A | Partial Teacher | PROGRAMMING | 1,800 | [
"dp",
"graphs",
"greedy",
"implementation"
] | A. Partial Teacher | 1 | 256 | A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same mar... | The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both ha... | Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | [
"5\nLRLR\n",
"5\n=RRR\n"
] | [
"2 1 2 1 2\n",
"1 1 2 3 4\n"
] | none | 500 | [
{
"input": "5\nLRLR",
"output": "2 1 2 1 2"
},
{
"input": "5\n=RRR",
"output": "1 1 2 3 4"
},
{
"input": "6\nRLRL=",
"output": "1 2 1 2 1 1"
},
{
"input": "3\nR=",
"output": "1 2 2"
},
{
"input": "7\nRR==RR",
"output": "1 2 3 3 3 4 5"
},
{
"input": "16... | 1,612,619,519 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 122 | 0 | n=int(input())
a=b=c=0
for i in range(n):
s=input().split(" ")
a+=int(s[0])
b+=int(s[1])
c+=int(s[2])
if a+c+b==0:
print("Yes")
else:
print("No") | Title: Partial Teacher
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gi... | ```python
n=int(input())
a=b=c=0
for i in range(n):
s=input().split(" ")
a+=int(s[0])
b+=int(s[1])
c+=int(s[2])
if a+c+b==0:
print("Yes")
else:
print("No")
``` | -1 |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,674,158,221 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | d1, d2, d3 = map(int, input().split())
path1 = d1 + d2 + d3
path2 = (d1 + d2) * 2
path3 = (d1 + d3) * 2
path4 = (d2 + d3) * 2
print(min(path1, path2, path3, path4))
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1, d2, d3 = map(int, input().split())
path1 = d1 + d2 + d3
path2 = (d1 + d2) * 2
path3 = (d1 + d3) * 2
path4 = (d2 + d3) * 2
print(min(path1, path2, path3, path4))
``` | 3 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,553,628,054 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 43 | 109 | 0 | a = input()
print(min((a.count("n")+a.count("n")//3)//3,a.count("i"),a.count("e")//3,a.count("t")))
| Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
a = input()
print(min((a.count("n")+a.count("n")//3)//3,a.count("i"),a.count("e")//3,a.count("t")))
``` | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,499,684,824 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 17,817,600 | n=int(input())
a=[int(i) for i in input().split()]
onta=[]
l=[]
for i in a:
if i not in onta:
onta.append(i)
else:
onta.remove(i)
l.append(len(onta))
print(max(l))
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n=int(input())
a=[int(i) for i in input().split()]
onta=[]
l=[]
for i in a:
if i not in onta:
onta.append(i)
else:
onta.remove(i)
l.append(len(onta))
print(max(l))
``` | 0 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,518,623,566 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,632,000 | k=input('')
t=k
if k==1:
x=4
print (x)
elif k>36:
x=-1
print (x)
else :
while t>1:
t-=2
print (8,end='')
if t==1:
x=4
print (x) | Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
k=input('')
t=k
if k==1:
x=4
print (x)
elif k>36:
x=-1
print (x)
else :
while t>1:
t-=2
print (8,end='')
if t==1:
x=4
print (x)
``` | -1 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1... | If there is a valid TL value, print it. Otherwise, print -1. | [
"3 6\n4 5 2\n8 9 6 10 7 11\n",
"3 1\n3 4 5\n6\n"
] | [
"5",
"-1\n"
] | none | 500 | [
{
"input": "3 6\n4 5 2\n8 9 6 10 7 11",
"output": "5"
},
{
"input": "3 1\n3 4 5\n6",
"output": "-1"
},
{
"input": "2 5\n45 99\n49 41 77 83 45",
"output": "-1"
},
{
"input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43... | 1,527,225,593 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 186 | 0 | R = lambda: map(int, input().split())
n,m = R()
a = list(R())
b = list(R())
v1 = max(a)
a_2 = [i*2 for i in a]
v2 = min(a_2)
if min(a_2)<=v1 and v1<min(b):
print(v1)
else:
if v2<min(b):
print(v2)
else:
print(-1)
# from bs4 import BeautifulSoup
# import requests
# page = requests.get("http:/... | Title: TL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Val... | ```python
R = lambda: map(int, input().split())
n,m = R()
a = list(R())
b = list(R())
v1 = max(a)
a_2 = [i*2 for i in a]
v2 = min(a_2)
if min(a_2)<=v1 and v1<min(b):
print(v1)
else:
if v2<min(b):
print(v2)
else:
print(-1)
# from bs4 import BeautifulSoup
# import requests
# page = requests.g... | 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,611,675,671 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 280 | 7,270,400 | n=int(input())
choco=list(map(int,input().split()))
i,j=0,n-1
if(n==1):
print(1,0)
else:
a,b=0,0
sumA,sumB=0,0
while(i<=j):
if(i==j and sumA<=sumB):
sumA+=choco[i]
a+=1
i+=1
elif((sumA==0 or sumA<=sumB) ):
sumA+=choco[i]
... | 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())
choco=list(map(int,input().split()))
i,j=0,n-1
if(n==1):
print(1,0)
else:
a,b=0,0
sumA,sumB=0,0
while(i<=j):
if(i==j and sumA<=sumB):
sumA+=choco[i]
a+=1
i+=1
elif((sumA==0 or sumA<=sumB) ):
sumA+=choc... | 3.875831 |
82 | A | Double Cola | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | A. Double Cola | 1 | 256 | Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d... | The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109).
It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. | Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. | [
"1\n",
"6\n",
"1802\n"
] | [
"Sheldon\n",
"Sheldon\n",
"Penny\n"
] | none | 500 | [
{
"input": "1",
"output": "Sheldon"
},
{
"input": "6",
"output": "Sheldon"
},
{
"input": "1802",
"output": "Penny"
},
{
"input": "1",
"output": "Sheldon"
},
{
"input": "2",
"output": "Leonard"
},
{
"input": "3",
"output": "Penny"
},
{
"inpu... | 1,630,579,178 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 6,963,200 | n = int(input())
i=0
while n>=5*((2**i)-1):
i+=1
if 5*(2**(i-1)-1)<n<=5*(2**(i-1)-1)+2**(i-1):
print('Sheldon')
elif 5*(2**(i-1)-1)+2**(i-1)<n<=5*(2**(i-1)-1)+2**(i-1)*2:
print('Leonard')
elif 5*(2**(i-1)-1)+2**(i-1)*2<n<=5**(2*(i-1)-1)+2**(i-1)*3:
print('Penny')
elif 5*(2**(i-1)-1)+2**(i-... | Title: Double Cola
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin... | ```python
n = int(input())
i=0
while n>=5*((2**i)-1):
i+=1
if 5*(2**(i-1)-1)<n<=5*(2**(i-1)-1)+2**(i-1):
print('Sheldon')
elif 5*(2**(i-1)-1)+2**(i-1)<n<=5*(2**(i-1)-1)+2**(i-1)*2:
print('Leonard')
elif 5*(2**(i-1)-1)+2**(i-1)*2<n<=5**(2*(i-1)-1)+2**(i-1)*3:
print('Penny')
elif 5*(2**(i-1)... | 0 |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,678,814,751 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n = int(input())
for i in range(n):
str = input()
if len(str) > 10:
s = str[0] + str(len(str)-2) + str[-1]
print(s)
else:
print(str) | 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
n = int(input())
for i in range(n):
str = input()
if len(str) > 10:
s = str[0] + str(len(str)-2) + str[-1]
print(s)
else:
print(str)
``` | -1 |
0 | none | none | none | 0 | [
"none"
] | null | null | There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates, and their $x$-coordinate is equal to $-100$, while the second group is positioned in suc... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 60$), the number of enemy spaceships with $x = -100$ and the number of enemy spaceships with $x = 100$, respectively.
The second line contains $n$ integers $y_{1,1}, y_{1,2}, \ldots, y_{1,n}$ ($|y_{1,i}| \le 10\,000$) — the $y$-coordinates of the spaces... | Print a single integer – the largest number of enemy spaceships that can be destroyed. | [
"3 9\n1 2 3\n1 2 3 7 8 9 11 12 13\n",
"5 5\n1 2 3 4 5\n1 2 3 4 5\n"
] | [
"9\n",
"10\n"
] | In the first example the first spaceship can be positioned at $(0, 2)$, and the second – at $(0, 7)$. This way all the enemy spaceships in the first group and $6$ out of $9$ spaceships in the second group will be destroyed.
In the second example the first spaceship can be positioned at $(0, 3)$, and the second can be ... | 0 | [
{
"input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13",
"output": "9"
},
{
"input": "5 5\n1 2 3 4 5\n1 2 3 4 5",
"output": "10"
},
{
"input": "50 50\n744 333 562 657 680 467 357 376 759 311 371 327 369 172 286 577 446 922 16 69 350 92 627 852 878 733 148 857 663 969 131 250 563 665 67 169 178 625... | 1,690,704,343 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690704343.2585833")# 1690704343.2586017 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer $y$-coordinates... | ```python
print("_RANDOM_GUESS_1690704343.2585833")# 1690704343.2586017
``` | 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,577,183,821 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | t=int(input())
for i in range(t):
n=input()
print(lower(n)) | 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
t=int(input())
for i in range(t):
n=input()
print(lower(n))
``` | -1 |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,380,987,875 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 0 | x=input().split()
x=[int(p) for p in x]
r,g,b=x[0],x[1],x[2]
def f1(r,g,b):
no1=0
while(r!=0 and g!=0 and b!=0):
r-=1
g-=1
b-=1
no1+=1
return no1,r,g,b
if(r!=0 and g!=0 and b!=0):
no2,r1,g1,b1=f1(r,... | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
x=input().split()
x=[int(p) for p in x]
r,g,b=x[0],x[1],x[2]
def f1(r,g,b):
no1=0
while(r!=0 and g!=0 and b!=0):
r-=1
g-=1
b-=1
no1+=1
return no1,r,g,b
if(r!=0 and g!=0 and b!=0):
no2,r1,g... | 0 | |
722 | B | Verse Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowel... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guarant... | If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | 500 | [
{
"input": "3\n2 2 3\nintel\ncode\nch allenge",
"output": "YES"
},
{
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz",
"output": "NO"
},
{
"input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageo... | 1,629,389,168 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 6,963,200 | n = int(input())
a = list(map(int,input().split(' ')))
f = True
for i in range(0,n):
s = input()
cnt = int(0)
for ii in s:
if ii == 'a' or ii == 'e' or ii == 'o' or ii == 'i' or ii == 'u':
cnt+=1
if a[i] > cnt:
f = False
if f == True:
print("YES")
el... | Title: Verse Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary num... | ```python
n = int(input())
a = list(map(int,input().split(' ')))
f = True
for i in range(0,n):
s = input()
cnt = int(0)
for ii in s:
if ii == 'a' or ii == 'e' or ii == 'o' or ii == 'i' or ii == 'u':
cnt+=1
if a[i] > cnt:
f = False
if f == True:
print(... | 0 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,690,193,599 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | s="hiedi"
k="heidi"
j=0
for i in s:
if i==k[j]:
j+=1
if j==len(k):
print("YES")
else:
print("NO")
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s="hiedi"
k="heidi"
j=0
for i in s:
if i==k[j]:
j+=1
if j==len(k):
print("YES")
else:
print("NO")
``` | 0 | |
622 | B | The Time | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi... | The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=<<=24,<=0<=≤<=*mm*<=<<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes).
The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes... | The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed).
See the examples to check the input/output format. | [
"23:59\n10\n",
"20:20\n121\n",
"10:10\n0\n"
] | [
"00:09\n",
"22:21\n",
"10:10\n"
] | none | 0 | [
{
"input": "23:59\n10",
"output": "00:09"
},
{
"input": "20:20\n121",
"output": "22:21"
},
{
"input": "10:10\n0",
"output": "10:10"
},
{
"input": "12:34\n10000",
"output": "11:14"
},
{
"input": "00:00\n10000",
"output": "22:40"
},
{
"input": "00:00\n14... | 1,551,201,095 | 2,495 | PyPy 3 | OK | TESTS | 59 | 124 | 0 | import sys
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')
s = input()
hr = int(s[0:2])
mn = int(s[3:5])
t = int(input())
mn += t
add = 0
if mn >= 60:
add = ... | Title: The Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes.
Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement.
You can read mo... | ```python
import sys
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline().strip('\n')
s = input()
hr = int(s[0:2])
mn = int(s[3:5])
t = int(input())
mn += t
add = 0
if mn >= 60:
... | 3 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,634,890,589 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 4,505,600 | n,m=[int(x) for x in input().split()]
bulb=set()
for i in range(n):
x,y,z=[int(x) for x in input().split()]
bulb.update(y)
bulb.update(z)
if len(bulb)==m:
print("YES")
else:
print("NO") | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m=[int(x) for x in input().split()]
bulb=set()
for i in range(n):
x,y,z=[int(x) for x in input().split()]
bulb.update(y)
bulb.update(z)
if len(bulb)==m:
print("YES")
else:
print("NO")
``` | -1 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,605,097,909 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 670 | 18,124,800 | I , d = input, {}
for i in [I() for i in range(int(I()))][::-1]:
if i not in d : print(i)
d[i] = 1 | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
I , d = input, {}
for i in [I() for i in range(int(I()))][::-1]:
if i not in d : print(i)
d[i] = 1
``` | 3 | |
802 | A | Heidi and Library (easy) | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are *n* different books, numbered 1 through *n*.
We will ... | The first line of input will contain two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=80). The second line will contain *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) – the sequence of book requests. | On a single line print the minimum cost of buying books at the store so as to satisfy all requests. | [
"4 80\n1 2 2 1\n",
"4 1\n1 2 2 1\n",
"4 2\n1 2 3 1\n"
] | [
"2\n",
"3\n",
"3\n"
] | In the first test case, Heidi is able to keep all books forever. Therefore, she only needs to buy the book 1 before the first day and the book 2 before the second day.
In the second test case, she can only keep one book at a time. Therefore she will need to buy new books on the first, second and fourth day.
In the th... | 0 | [
{
"input": "4 80\n1 2 2 1",
"output": "2"
},
{
"input": "4 1\n1 2 2 1",
"output": "3"
},
{
"input": "4 2\n1 2 3 1",
"output": "3"
},
{
"input": "11 1\n1 2 3 5 1 10 10 1 1 3 5",
"output": "9"
},
{
"input": "5 2\n1 2 3 1 2",
"output": "4"
},
{
"input": "... | 1,683,831,202 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | library = [eval(c) for c in input().split(' ')]
requests = [eval(c) for c in input().split(' ')]
books = []
price = 0
for c in range(library[0]):
if requests[0] in books:
requests.pop(0)
else:
if len(books)+1 > library[1]:
bookwant = []
for c in books:
... | Title: Heidi and Library (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the lib... | ```python
library = [eval(c) for c in input().split(' ')]
requests = [eval(c) for c in input().split(' ')]
books = []
price = 0
for c in range(library[0]):
if requests[0] in books:
requests.pop(0)
else:
if len(books)+1 > library[1]:
bookwant = []
for c in books:... | 0 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,578,131,089 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 0 | n = input()
fl = n.find(".")
if n[fl-1] != 9:
if int(n[fl+1]) < 5:
print(n[:fl])
elif int(n[fl+1]) >= 0.5:
print(n[:fl-1]+str(int(n[fl-1])+1))
else:
print("GOTO Vasilisa.")
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
n = input()
fl = n.find(".")
if n[fl-1] != 9:
if int(n[fl+1]) < 5:
print(n[:fl])
elif int(n[fl+1]) >= 0.5:
print(n[:fl-1]+str(int(n[fl-1])+1))
else:
print("GOTO Vasilisa.")
``` | 0 |
507 | A | Amr and Music | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"sortings"
] | null | null | Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments.
Amr asked for ... | The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. | In the first line output one integer *m* representing the maximum number of instruments Amr can learn.
In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order.
if there are multiple optimal solutions output any. It is not necessary to use al... | [
"4 10\n4 3 1 2\n",
"5 6\n4 3 1 1 2\n",
"1 3\n4\n"
] | [
"4\n1 2 3 4",
"3\n1 3 4",
"0\n"
] | In the first test Amr can learn all 4 instruments.
In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.
In the third test Amr doesn't have enough time to learn the only presented instrument. | 500 | [
{
"input": "4 10\n4 3 1 2",
"output": "4\n1 2 3 4"
},
{
"input": "5 6\n4 3 1 1 2",
"output": "3\n3 4 5"
},
{
"input": "1 3\n4",
"output": "0"
},
{
"input": "2 100\n100 100",
"output": "1\n1"
},
{
"input": "3 150\n50 50 50",
"output": "3\n1 2 3"
},
{
"i... | 1,598,122,735 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 27 | 139 | 21,811,200 | import sys
input=sys.stdin.readline
m,n=map(int,input().split())
a=list(map(int,input().split()))
k=[ ]
while len(k)<n and min(a)<=n:
for i in range(len(a)):
if a[i]==min(a):
n-=a[i]
k.append(i+1)
a[i]=n+1
break
print(len(k))
print(*k)
| Title: Amr and Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.
Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr ... | ```python
import sys
input=sys.stdin.readline
m,n=map(int,input().split())
a=list(map(int,input().split()))
k=[ ]
while len(k)<n and min(a)<=n:
for i in range(len(a)):
if a[i]==min(a):
n-=a[i]
k.append(i+1)
a[i]=n+1
break
print(len(k))
print(*k)
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of elements). If the two integers are equal to *x*, delete both a... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of elements in the sequence.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | In the first line print a single integer *k* — the number of elements in the sequence after you stop performing the operation.
In the second line print *k* integers — the sequence after you stop performing the operation. | [
"6\n5 2 1 1 2 2\n",
"4\n1000000000 1000000000 1000000000 1000000000\n",
"7\n4 10 22 11 12 5 6\n"
] | [
"2\n5 4 ",
"1\n1000000002 ",
"7\n4 10 22 11 12 5 6 "
] | The first example is described in the statements.
In the second example the initial sequence is [1000000000, 1000000000, 1000000000, 1000000000]. After the first operation the sequence is equal to [1000000001, 1000000000, 1000000000]. After the second operation the sequence is [1000000001, 1000000001]. After the third... | 0 | [
{
"input": "6\n5 2 1 1 2 2",
"output": "2\n5 4 "
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000",
"output": "1\n1000000002 "
},
{
"input": "7\n4 10 22 11 12 5 6",
"output": "7\n4 10 22 11 12 5 6 "
},
{
"input": "2\n1 1",
"output": "1\n2 "
},
{
"inpu... | 1,521,355,182 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 61 | 7,065,600 | n = int(input())
a = input().split()
a = [int(x) for x in a]
b = []
for u in a:
b.append(u)
if len(b) > 0 or b[-1] != u:
while (len(b) > 1 and b[-1] == b[-2]):
b[-2] += 1
b.pop()
print(len(b))
if len(b) == 1:
print(b[0])
else:
print(' '.join(b))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (w... | ```python
n = int(input())
a = input().split()
a = [int(x) for x in a]
b = []
for u in a:
b.append(u)
if len(b) > 0 or b[-1] != u:
while (len(b) > 1 and b[-1] == b[-2]):
b[-2] += 1
b.pop()
print(len(b))
if len(b) == 1:
print(b[0])
else:
print(' '.join(b))
... | -1 | |
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,668,085,662 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | k = int(input())
print((k + 1) * 10 - k) | 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
k = int(input())
print((k + 1) * 10 - k)
``` | 0 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,698,005,683 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 62 | 0 | inp = [int(i) for i in input().split()]
n,k,l,c,d,p,nl,np=inp[0],inp[1],inp[2],inp[3],inp[4],inp[5],inp[6],inp[7]
print(min(k*l//nl,c*d, p//np)//n)
| Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
inp = [int(i) for i in input().split()]
n,k,l,c,d,p,nl,np=inp[0],inp[1],inp[2],inp[3],inp[4],inp[5],inp[6],inp[7]
print(min(k*l//nl,c*d, p//np)//n)
``` | 3 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,609,656,862 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 217 | 2,252,800 | from sys import stdin,stdout,exit
import math
import bisect
import math
from math import gcd,floor,sqrt,log
from bisect import bisect_left as bl,bisect_right as br
MOD:int=1000000007
n = int(stdin.readline())
l = list(map(int,stdin.readline().split()))
d={
1:0,
2:0,
3:0,
4:0,
6:0
}
for i in l:
... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
from sys import stdin,stdout,exit
import math
import bisect
import math
from math import gcd,floor,sqrt,log
from bisect import bisect_left as bl,bisect_right as br
MOD:int=1000000007
n = int(stdin.readline())
l = list(map(int,stdin.readline().split()))
d={
1:0,
2:0,
3:0,
4:0,
6:0
}
for ... | -1 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,678,812,400 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 61 | 0 | from collections import *
recipe = input()
b, s, c = map(int, input().split())
onhand = {"B":b, "S":s, "C":c}
pb, ps, pc = map(int, input().split())
price = {"B":pb, "S":ps, "C":pc}
rubles = int(input())
def can_i_make_it( humbergrs ):
track = Counter( recipe )
required = 0
for char in se... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
from collections import *
recipe = input()
b, s, c = map(int, input().split())
onhand = {"B":b, "S":s, "C":c}
pb, ps, pc = map(int, input().split())
price = {"B":pb, "S":ps, "C":pc}
rubles = int(input())
def can_i_make_it( humbergrs ):
track = Counter( recipe )
required = 0
for ... | 0 | |
66 | E | Petya and Post | PROGRAMMING | 2,000 | [
"data structures",
"dp"
] | E. Petya and Post | 2 | 256 | Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post office. In the office he receives a portion of letters and a car. Then ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a**i* — amount of gasoline on the *i*-th station. The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n*. They are the distances between the 1-st and the 2-nd gas stations, between the 2-nd and the 3-rd ones, ..., b... | Print on the first line the number *k* — the number of possible post offices, from which the car can drive one circle along a circular road. Print on the second line *k* numbers in the ascending order — the numbers of offices, from which the car can start. | [
"4\n1 7 2 3\n8 1 1 3\n",
"8\n1 2 1 2 1 2 1 2\n2 1 2 1 2 1 2 1\n"
] | [
"2\n2 4\n",
"8\n1 2 3 4 5 6 7 8\n"
] | none | 2,500 | [
{
"input": "4\n1 7 2 3\n8 1 1 3",
"output": "2\n2 4"
},
{
"input": "8\n1 2 1 2 1 2 1 2\n2 1 2 1 2 1 2 1",
"output": "8\n1 2 3 4 5 6 7 8"
},
{
"input": "20\n31 16 20 30 19 35 8 11 20 45 10 26 21 39 29 52 8 10 37 49\n16 33 41 32 43 24 35 48 19 37 28 26 7 10 23 48 18 2 1 25",
"output": ... | 1,692,213,546 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1692213546.0698802")# 1692213546.069899 | Title: Petya and Post
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the h... | ```python
print("_RANDOM_GUESS_1692213546.0698802")# 1692213546.069899
``` | 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,509,014,747 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | def digits(i):
l = []
str_num = str(i)
for j in range(len(str_num)):
l.append(int(str_num[j]))
return sum(l)
n = int(input())
nums = []
for i in range(1, n):
if i + digits(i) == n:
nums.append(i)
print(len(nums))
if len(nums) > 0:
for i in nums:
print(i)
| 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
def digits(i):
l = []
str_num = str(i)
for j in range(len(str_num)):
l.append(int(str_num[j]))
return sum(l)
n = int(input())
nums = []
for i in range(1, n):
if i + digits(i) == n:
nums.append(i)
print(len(nums))
if len(nums) > 0:
for i in nums:
... | 0 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,683,559,099 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | n=int(input())
a=list(map(int,input().split()))
s=sum(a)
_5=a.count(5)
_0=a.count(0)
if _0!=0:
ans='5'*(_5)+'0'*(_0)
while s/9!=s//9:
s-=5
_5-=1
ans='5'*(_5)+'0'*(_0)
print(int(ans))
else:
print(-1) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
_5=a.count(5)
_0=a.count(0)
if _0!=0:
ans='5'*(_5)+'0'*(_0)
while s/9!=s//9:
s-=5
_5-=1
ans='5'*(_5)+'0'*(_0)
print(int(ans))
else:
print(-1)
``` | 3 | |
327 | B | Hungry Sequence | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1, *a*2, ..., *a**n*, consisting of *n* integers, is Hungry if and only if:
- Its elements are in i... | The input contains a single integer: *n* (1<=≤<=*n*<=≤<=105). | Output a line that contains *n* space-separated integers *a*1 *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=107), representing a possible Hungry sequence. Note, that each *a**i* must not be greater than 10000000 (107) and less than 1.
If there are multiple solutions you can output any one. | [
"3\n",
"5\n"
] | [
"2 9 15\n",
"11 14 20 27 31\n"
] | none | 500 | [
{
"input": "3",
"output": "2 9 15"
},
{
"input": "5",
"output": "11 14 20 27 31"
},
{
"input": "1",
"output": "3"
},
{
"input": "1000",
"output": "3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 ... | 1,653,226,688 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 92 | 3,379,200 | import collections
def apSum(elements):
n = len(elements)
a = elements[0]
d = elements[1] - elements[0]
progressionSum = int( (n/2) * ((2*a) + (n-1)*d))
return progressionSum
def solve(n, numbers):
hashMap = dict()
for i in range(n):
if numbers[i] in hashMap:
... | Title: Hungry Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of *n* integers.
A sequence *a*1... | ```python
import collections
def apSum(elements):
n = len(elements)
a = elements[0]
d = elements[1] - elements[0]
progressionSum = int( (n/2) * ((2*a) + (n-1)*d))
return progressionSum
def solve(n, numbers):
hashMap = dict()
for i in range(n):
if numbers[i] in hashM... | -1 | |
538 | B | Quasi Binary | PROGRAMMING | 1,400 | [
"constructive algorithms",
"dp",
"greedy",
"implementation"
] | null | null | A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106). | In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers.
In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not... | [
"9\n",
"32\n"
] | [
"9\n1 1 1 1 1 1 1 1 1 \n",
"3\n10 11 11 \n"
] | none | 1,000 | [
{
"input": "9",
"output": "9\n1 1 1 1 1 1 1 1 1 "
},
{
"input": "32",
"output": "3\n10 11 11 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "415",
"output": "5\n1 101 101 101 111 "
},
{
"input": "10011",
"output": "1\n10011 "
},
{
"input": "10201... | 1,634,394,285 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | a = input()
b = []
L = len(a)
a = int(a)
k = 0
x = 0
while a != 0:
for j in range(1, L+1):
if ( a / pow(10,j-1) % 10) != 0:
x = x + pow(10, j-1)
a = a - pow(10, j-1)
k = k + 1
b.append(x)
x = 0
a = str(a)
L = len(a)
a = int(a)
print(k)
L = len(b)
for i in rang... | Title: Quasi Binary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer *n*. Repr... | ```python
a = input()
b = []
L = len(a)
a = int(a)
k = 0
x = 0
while a != 0:
for j in range(1, L+1):
if ( a / pow(10,j-1) % 10) != 0:
x = x + pow(10, j-1)
a = a - pow(10, j-1)
k = k + 1
b.append(x)
x = 0
a = str(a)
L = len(a)
a = int(a)
print(k)
L = len(b)
for... | 0 | |
463 | B | Caisa and Pylons | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=><=0) has height *h**i*. The goal of the game is ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons. | Print a single number representing the minimum number of dollars paid by Caisa. | [
"5\n3 4 3 2 4\n",
"3\n4 4 4\n"
] | [
"4\n",
"4\n"
] | In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon. | 1,000 | [
{
"input": "5\n3 4 3 2 4",
"output": "4"
},
{
"input": "3\n4 4 4",
"output": "4"
},
{
"input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20... | 1,568,732,195 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 140 | 1,945,600 | n = int(input())
arr = [0] + list(map(int, input().split()))
cnt = 0
po = 0
for i in range(1, n):
po += arr[i-1] - arr[i]
if po < 0:
cnt += -po
po = 0
print(cnt) | Title: Caisa and Pylons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Caisa solved the problem with the sugar and now he is on the way back to home.
Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0... | ```python
n = int(input())
arr = [0] + list(map(int, input().split()))
cnt = 0
po = 0
for i in range(1, n):
po += arr[i-1] - arr[i]
if po < 0:
cnt += -po
po = 0
print(cnt)
``` | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,690,676,190 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 92 | 0 | x = input()
y = input()
c = 0
for i in range(0, len(x)):
if x[i] == y[(i+1)*-1]:
c += 1
if c == len(x):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
x = input()
y = input()
c = 0
for i in range(0, len(x)):
if x[i] == y[(i+1)*-1]:
c += 1
if c == len(x):
print("YES")
else:
print("NO")
``` | -1 |
412 | B | Network Configuration | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necess... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* deno... | Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. | [
"3 2\n40 20 30\n",
"6 4\n100 20 40 20 50 50\n"
] | [
"30\n",
"40\n"
] | In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal. | 1,000 | [
{
"input": "3 2\n40 20 30",
"output": "30"
},
{
"input": "6 4\n100 20 40 20 50 50",
"output": "40"
},
{
"input": "1 1\n16",
"output": "16"
},
{
"input": "2 1\n10000 17",
"output": "10000"
},
{
"input": "2 2\n200 300",
"output": "200"
},
{
"input": "3 1... | 1,688,173,941 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | # LUOGU_RID: 113633863
def r():return list(map(int,input().split()))
a,b=r();a=r();a.sort();print(a[-b]) | Title: Network Configuration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly a... | ```python
# LUOGU_RID: 113633863
def r():return list(map(int,input().split()))
a,b=r();a=r();a.sort();print(a[-b])
``` | 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,697,739,993 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | y = int(input())
i = y
while True:
if i > y and len(set(str(i))) == 4:
break
i += 1
print(i)
| 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())
i = y
while True:
if i > y and len(set(str(i))) == 4:
break
i += 1
print(i)
``` | 3 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,591,076,759 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 280 | 0 | import math
n = int(input())
ans = 1
while int(bin(ans)[2:]) <= n:
ans += 1
print(ans-1) | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
import math
n = int(input())
ans = 1
while int(bin(ans)[2:]) <= n:
ans += 1
print(ans-1)
``` | 3.86 |
932 | C | Permutation Cycle | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms"
] | null | null | For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows:
Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists.
For given *N*,<=*A*,<=*B*, find a permutation *P* of integers from 1 to *N* such that for 1<=≤<=*i*<=≤<=... | The only line contains three integers *N*,<=*A*,<=*B* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*A*,<=*B*<=≤<=*N*). | If no such permutation exists, output -1. Otherwise, output a permutation of integers from 1 to *N*. | [
"9 2 5\n",
"3 2 1\n"
] | [
"6 5 8 3 4 1 9 2 7",
"1 2 3 "
] | In the first example, *g*(1) = *g*(6) = *g*(7) = *g*(9) = 2 and *g*(2) = *g*(3) = *g*(4) = *g*(5) = *g*(8) = 5
In the second example, *g*(1) = *g*(2) = *g*(3) = 1 | 1,500 | [
{
"input": "9 2 5",
"output": "2 1 4 3 6 7 8 9 5 "
},
{
"input": "3 2 1",
"output": "1 2 3 "
},
{
"input": "7 4 4",
"output": "-1"
},
{
"input": "1000000 999998 3",
"output": "-1"
},
{
"input": "1 1 1",
"output": "1 "
},
{
"input": "993012 997 1001",
... | 1,518,709,593 | 4,293 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 5 | 2,000 | 30,105,600 | n,a,b=map(int,input().split())
x=0
y=0
def solution():
i = 0
global x,y
while i * a <= n:
if (n - (i * a)) % b == 0:
x=i
y=int((n - (i * a)) / b)
return True
i = i + 1
return False
ans=list()
if solution():
start=1
en... | Title: Permutation Cycle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a permutation *P*[1... *N*] of integers from 1 to *N*, function *f* is defined as follows:
Let *g*(*i*) be the minimum positive integer *j* such that *f*(*i*,<=*j*)<==<=*i*. We can show such *j* always exists.
F... | ```python
n,a,b=map(int,input().split())
x=0
y=0
def solution():
i = 0
global x,y
while i * a <= n:
if (n - (i * a)) % b == 0:
x=i
y=int((n - (i * a)) / b)
return True
i = i + 1
return False
ans=list()
if solution():
start... | 0 | |
975 | C | Valhalla Siege | PROGRAMMING | 1,400 | [
"binary search"
] | null | null | Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T... | The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths.
The third line contains $q$ integers $k_1, k_2,... | Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. | [
"5 5\n1 2 1 2 1\n3 10 1 1 1\n",
"4 4\n1 2 3 4\n9 1 10 6\n"
] | [
"3\n5\n4\n4\n3\n",
"1\n4\n4\n1\n"
] | In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die. - after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive. - after the 3-rd minute, the 1-st warrior dies. - after the 4-th minute, the 2-nd warr... | 1,500 | [
{
"input": "5 5\n1 2 1 2 1\n3 10 1 1 1",
"output": "3\n5\n4\n4\n3"
},
{
"input": "4 4\n1 2 3 4\n9 1 10 6",
"output": "1\n4\n4\n1"
},
{
"input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5",
"output": "10\n10\n5"
},
{
"input": "1 1\n56563128\n897699770",
"output": "1"
},
{
... | 1,619,186,743 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 997 | 21,913,600 | from bisect import bisect_right
def bs(s,x):
return bisect_right(s,x)
n,q=map(int,input().split())
l=list(map(int,input().split()))
k=list(map(int,input().split()))
s=[0]
for i in range(n):
s.append(s[i]+l[i])
p=0
for i in range(q):
x=bs(s,(k[i]+p))
p=p+k[i]
if x==n+1:
prin... | Title: Valhalla Siege
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has $n$ warriors, he places them on a straight line ... | ```python
from bisect import bisect_right
def bs(s,x):
return bisect_right(s,x)
n,q=map(int,input().split())
l=list(map(int,input().split()))
k=list(map(int,input().split()))
s=[0]
for i in range(n):
s.append(s[i]+l[i])
p=0
for i in range(q):
x=bs(s,(k[i]+p))
p=p+k[i]
if x==n+1:
... | 3 | |
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 ... | 1,587,277,178 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 124 | 0 | T = int(input())
A = [int(x) for x in input().split()]
print(0 if max(A) <= 25 else max(A) - 25)
| Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t... | ```python
T = int(input())
A = [int(x) for x in input().split()]
print(0 if max(A) <= 25 else max(A) - 25)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya should paint a fence in front of his own cottage. The fence is a sequence of *n* wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1,<=2,<=...,<=*n* from left to right. The height of the *i*-th board is *h**i* centimeters.
Vasya has a ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the number of boards in Vasya's fence.
The second line contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=4·104) — the area that can be painted red and the area that can be painted green, correspondingly.
The third line contains a sequence of *n* ... | Print a single number — the minimum unattractiveness value Vasya can get if he paints his fence completely. If it is impossible to do, print <=-<=1. | [
"4\n5 7\n3 3 4 1\n",
"3\n2 3\n1 3 1\n",
"3\n3 3\n2 2 2\n"
] | [
"3\n",
"2\n",
"-1\n"
] | none | 0 | [] | 1,689,592,468 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689592468.8328443")# 1689592468.8328648 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya should paint a fence in front of his own cottage. The fence is a sequence of *n* wooden boards arranged in a single row. Each board is a 1 centimeter wide rectangle. Let's number the board fence using numbers 1,<=2,<=...,<=*... | ```python
print("_RANDOM_GUESS_1689592468.8328443")# 1689592468.8328648
``` | 0 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,680,610,855 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 27 | 1,000 | 29,696,000 | from heapq import *
N,M = map(int, input().split())
P = [[] for _ in range(N)]
for _ in range(M):
a,b,w = map(int, input().split())
P[a-1].append((b-1,w))
P[b-1].append((a-1,w))
INF = float('inf')
v = [(0,0,-1)]
dist = [[INF,-1] for _ in range(N)]
while v:
d,i,p = heappop(v)
if d... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
from heapq import *
N,M = map(int, input().split())
P = [[] for _ in range(N)]
for _ in range(M):
a,b,w = map(int, input().split())
P[a-1].append((b-1,w))
P[b-1].append((a-1,w))
INF = float('inf')
v = [(0,0,-1)]
dist = [[INF,-1] for _ in range(N)]
while v:
d,i,p = heappop(v)... | 0 |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,614,345,821 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 614,400 | a, b = input(), int(input())
d = [0] * b * 2
for i in range(0, b*2, 2):
h = input().split(" ")
h[0], h[1] = int(h[0]), int(h[1])
d[i] = h[0]
d[i+1] = h[1]
f = [0] * b
for i in range(0, b*2, 2):
m = 0
g = 0
for i2 in range(d[i]-1, d[i+1]):
if a[i2] == "(":
m +... | Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
a, b = input(), int(input())
d = [0] * b * 2
for i in range(0, b*2, 2):
h = input().split(" ")
h[0], h[1] = int(h[0]), int(h[1])
d[i] = h[0]
d[i+1] = h[1]
f = [0] * b
for i in range(0, b*2, 2):
m = 0
g = 0
for i2 in range(d[i]-1, d[i+1]):
if a[i2] == "(":
... | 0 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,679,477,627 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 1,331,200 | n = int(input())
cnt=0
for i in range(1,n//2+1):
if n%i==0:
cnt += 1
print(cnt) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
n = int(input())
cnt=0
for i in range(1,n//2+1):
if n%i==0:
cnt += 1
print(cnt)
``` | 3 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,696,137,149 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | x, y = map(int, input().split())
if y > 0:
if (y == 1) and (x == 0):
print('Yes')
elif ((x - y + 1)%2 == 0) and ((x - y + 1) > 0):
print('Yes')
else:
print('No')
else:
print('No')
| Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
x, y = map(int, input().split())
if y > 0:
if (y == 1) and (x == 0):
print('Yes')
elif ((x - y + 1)%2 == 0) and ((x - y + 1) > 0):
print('Yes')
else:
print('No')
else:
print('No')
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,624,125,551 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | hello ='helo'
new= ''
string = input()
for i in string:
if i in hello and i not in new:
new += i
if new == hello:
print('YES')
else:
print('NO') | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
hello ='helo'
new= ''
string = input()
for i in string:
if i in hello and i not in new:
new += i
if new == hello:
print('YES')
else:
print('NO')
``` | 0 |
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,614,839,040 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input())
l = list(map(int,input().split()))
l.sort()
f = 0
i, j = 0, n-1
tp = l[j]-l[i]
if tp%2==0:
i+=1
j-=1
while i<j:
if l[j]-l[i]!=tp:
f=1
break
i+=1
j-=1
if f==1:
print('NO')
else:
print('YES')
else:
... | 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())
l = list(map(int,input().split()))
l.sort()
f = 0
i, j = 0, n-1
tp = l[j]-l[i]
if tp%2==0:
i+=1
j-=1
while i<j:
if l[j]-l[i]!=tp:
f=1
break
i+=1
j-=1
if f==1:
print('NO')
else:
print('YES')
... | 0 | |
213 | B | Numbers | PROGRAMMING | 1,900 | [
"combinatorics",
"dp"
] | null | null | Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer *n* and array *a*, consisting of ten integers, indexed by numbers from 0 to 9. Your task is to count the number of positi... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100). The next line contains 10 integers *a*[0], *a*[1], ..., *a*[9] (0<=≤<=*a*[*i*]<=≤<=100) — elements of array *a*. The numbers are separated by spaces. | On a single line print the remainder of dividing the answer to the problem by 1000000007 (109<=+<=7). | [
"1\n0 0 0 0 0 0 0 0 0 1\n",
"2\n1 1 0 0 0 0 0 0 0 0\n",
"3\n1 1 0 0 0 0 0 0 0 0\n"
] | [
"1\n",
"1\n",
"36\n"
] | In the first sample number 9 meets the requirements.
In the second sample number 10 meets the requirements.
In the third sample numbers 10, 110, 210, 120, 103 meet the requirements. There are other suitable numbers, 36 in total. | 1,000 | [
{
"input": "1\n0 0 0 0 0 0 0 0 0 1",
"output": "1"
},
{
"input": "2\n1 1 0 0 0 0 0 0 0 0",
"output": "1"
},
{
"input": "3\n1 1 0 0 0 0 0 0 0 0",
"output": "36"
},
{
"input": "4\n0 1 0 1 2 0 0 0 0 0",
"output": "12"
},
{
"input": "5\n2 1 2 0 0 0 0 0 0 0",
"outp... | 1,689,254,848 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1689254848.240621")# 1689254848.240635 | Title: Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves writing all sorts of problems, especially such that he can't solve himself. You've got one of his problems, the one Furik gave to Rubik. And Rubik asks you to solve it.
There is integer *n* and array *a*, consistin... | ```python
print("_RANDOM_GUESS_1689254848.240621")# 1689254848.240635
``` | 0 | |
120 | E | Put Knight! | PROGRAMMING | 1,400 | [
"games",
"math"
] | null | null | Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other. A knight located in square (*r*,<=*c*) can threat squares (*r*<=-<=1,<=*c*<=+<=2), (*r*<=-<=1,<=... | The first line contains integer *T* (1<=≤<=*T*<=≤<=100) — the number of boards, for which you should determine the winning player. Next *T* lines contain *T* integers *n**i* (1<=≤<=*n**i*<=≤<=10000) — the sizes of the chessboards. | For each *n**i*<=×<=*n**i* board print on a single line "0" if Petya wins considering both players play optimally well. Otherwise, print "1". | [
"2\n2\n1\n"
] | [
"1\n0\n"
] | none | 0 | [
{
"input": "2\n2\n1",
"output": "1\n0"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n0\n1\n0\n1\n0\n1\n0\n1"
},
{
"input": "15\n10\n4\n7\n8\n9\n6\n2\n1\n3\n1\n5\n2\n3\n4\n5",
"output": "1\n1\n0\n1\n0\n1\n1\n0\n0\n0\n0\n1\n0\n1\n0"
},
{
"input": "6\n10\n7... | 1,549,628,770 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | for _ in range(int(input())):
n=int(input())
print(1-n%2) | Title: Put Knight!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Gena play a very interesting game "Put a Knight!" on a chessboard *n*<=×<=*n* in size. In this game they take turns to put chess pieces called "knights" on the board so that no two knights could threat each other.... | ```python
for _ in range(int(input())):
n=int(input())
print(1-n%2)
``` | -1 | |
812 | A | Sagheer and Crossroads | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane... | The input consists of four lines with each line describing a road part given in a counter-clockwise order.
Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light. | On a single line, print "YES" if an accident is possible, and "NO" otherwise. | [
"1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n",
"0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n",
"1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.
In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur. | 500 | [
{
"input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1",
"output": "YES"
},
{
"input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1",
"output": "NO"
},
{
"input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0",
"output": "NO"
},
{
"input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1",
"output": "NO"
},
... | 1,516,982,251 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 23 | 62 | 5,632,000 | # -*- coding: utf - 8 -*-
"""
author: mr.math - Hakimov Rahimjon
e-mail: [email protected] or [email protected]
created: 26.01.2018 20:39
"""
# inp = open("input.txt", "r")
# input = inp.readline
# out = open("output.txt", "w")
# print = out.write
TN = 1
# ====================================... | Title: Sagheer and Crossroads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l... | ```python
# -*- coding: utf - 8 -*-
"""
author: mr.math - Hakimov Rahimjon
e-mail: [email protected] or [email protected]
created: 26.01.2018 20:39
"""
# inp = open("input.txt", "r")
# input = inp.readline
# out = open("output.txt", "w")
# print = out.write
TN = 1
# ==========================... | 0 | |
75 | B | Facetook Priority Wall | PROGRAMMING | 1,500 | [
"expression parsing",
"implementation",
"strings"
] | B. Facetook Priority Wall | 2 | 256 | Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be described).
This priority factor will be affected by three types of actions:
- 1. "*X* posted on *Y*'s wall... | The first line contains your name. The second line contains an integer *n*, which is the number of actions (1<=≤<=*n*<=≤<=100). Then *n* lines follow, it is guaranteed that each one contains exactly 1 action in the format given above. There is exactly one space between each two words in a line, and there are no extra s... | Print *m* lines, where *m* is the number of distinct names in the input (excluding yourself). Each line should contain just 1 name. The names should be sorted according to the priority factor with you in the descending order (the highest priority factor should come first). If two or more names have the same priority fa... | [
"ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post\n",
"aba\n1\nlikes likes posted's post\n"
] | [
"fatma\nmona\n",
"likes\nposted\n"
] | none | 1,000 | [
{
"input": "ahmed\n3\nahmed posted on fatma's wall\nfatma commented on ahmed's post\nmona likes ahmed's post",
"output": "fatma\nmona"
},
{
"input": "aba\n1\nlikes likes posted's post",
"output": "likes\nposted"
},
{
"input": "nu\n5\ng commented on pwyndmh's post\nqv posted on g's wall\n... | 1,676,649,737 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 102,400 | from sys import stdin ,stdout
input=stdin.readline
from collections import defaultdict
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
my=input().strip() ; n=int(input()) ; names=defaultdict(int) ; poin=defaultdict(list) ; vis=[0]*201
for i in range(n) :
lis... | Title: Facetook Priority Wall
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Facetook is a well known social network website, and it will launch a new feature called Facetook Priority Wall. This feature will sort all posts from your friends according to the priority factor (it will be describ... | ```python
from sys import stdin ,stdout
input=stdin.readline
from collections import defaultdict
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
my=input().strip() ; n=int(input()) ; names=defaultdict(int) ; poin=defaultdict(list) ; vis=[0]*201
for i in range(n) ... | 0 |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,658,868,032 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 46 | 0 | def gcd(a, b):
if a % b == 0:
return b
return gcd(b, a%b)
a, b, c = map(int, input().split())
if c % gcd(a,b) == 0:
for i in range(c//a + 1):
if (c - a*i)%b == 0:
print('YES')
break
else:
print('NO') | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
def gcd(a, b):
if a % b == 0:
return b
return gcd(b, a%b)
a, b, c = map(int, input().split())
if c % gcd(a,b) == 0:
for i in range(c//a + 1):
if (c - a*i)%b == 0:
print('YES')
break
else:
print('NO')
``` | 0 | |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount ... | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output":... | 1,618,657,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 0 | if __name__ == '__main__':
loops = int(input())
if loops > 36:
print(-1)
else:
res = 0
while loops > 1:
res = res * 10 + 8
loops -= 2
if loops == 1:
res = res * 10
print(res)
| Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to a... | ```python
if __name__ == '__main__':
loops = int(input())
if loops > 36:
print(-1)
else:
res = 0
while loops > 1:
res = res * 10 + 8
loops -= 2
if loops == 1:
res = res * 10
print(res)
``` | 0 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,654,464,062 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | n=int(input())
a=[int(_) for _ in input().split()]
max=0
for ele in set(a):
if a.count(ele)>max:
max=a.count(ele)
print(max) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n=int(input())
a=[int(_) for _ in input().split()]
max=0
for ele in set(a):
if a.count(ele)>max:
max=a.count(ele)
print(max)
``` | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,699,392,102 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | song = input()
# Replace "WUB" with a space and split the string by spaces
decoded_song = song.replace("WUB", " ").split()
# Join the words to reconstruct the original song
original_song = " ".join(decoded_song)
print(original_song)
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
song = input()
# Replace "WUB" with a space and split the string by spaces
decoded_song = song.replace("WUB", " ").split()
# Join the words to reconstruct the original song
original_song = " ".join(decoded_song)
print(original_song)
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,665,199,323 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 |
l=[]
x,y=(map(int,input().split()))
for i in range(x):
l+=input().split()
if ('C' in l) or ('M' in l) or ('Y' in l):
print("#Color")
else:
print('#Black&White')
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
l=[]
x,y=(map(int,input().split()))
for i in range(x):
l+=input().split()
if ('C' in l) or ('M' in l) or ('Y' in l):
print("#Color")
else:
print('#Black&White')
``` | 3 | |
886 | B | Vlad and Cafes | PROGRAMMING | 1,000 | [] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 1,000 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,512,685,940 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 451 | 30,105,600 | from functools import reduce
n = int(input())
dic = {}
a = list(map(int, input().split()))
for i in range(n):
dic[a[i]] = i
arr = []
for i in dic:
arr.append((dic[i], i))
arr.sort()
print(arr[0][1]) | Title: Vlad and Cafes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research... | ```python
from functools import reduce
n = int(input())
dic = {}
a = list(map(int, input().split()))
for i in range(n):
dic[a[i]] = i
arr = []
for i in dic:
arr.append((dic[i], i))
arr.sort()
print(arr[0][1])
``` | 3 | |
182 | D | Common Divisors | PROGRAMMING | 1,400 | [
"brute force",
"hashing",
"implementation",
"math",
"strings"
] | null | null | Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam... | The first input line contains a non-empty string *s*1.
The second input line contains a non-empty string *s*2.
Lengths of strings *s*1 and *s*2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters. | Print the number of common divisors of strings *s*1 and *s*2. | [
"abcdabcd\nabcdabcdabcdabcd\n",
"aaa\naa\n"
] | [
"2\n",
"1\n"
] | In first sample the common divisors are strings "abcd" and "abcdabcd".
In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa". | 1,000 | [
{
"input": "abcdabcd\nabcdabcdabcdabcd",
"output": "2"
},
{
"input": "aaa\naa",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "3"
},
{
"input": "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa",
"output": "4"
},
{
"input": "a\nb",
... | 1,683,575,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 204,800 | divisor = input()
dividend = input()
quotient = dividend.count(divisor)
if quotient * len(divisor) == len(dividend):
print(quotient)
else:
print(1)
| Title: Common Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with.
String *a* is the divisor of string *b* if and only if there exists a positive ... | ```python
divisor = input()
dividend = input()
quotient = dividend.count(divisor)
if quotient * len(divisor) == len(dividend):
print(quotient)
else:
print(1)
``` | 0 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,696,436,854 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | x =int(input())
arr = []
while x > 0:
arr.append(input())
x-=1
n=[]
for item in arr:
if len(item) > 10:
x = item[0]+ str((len(item)-2)) +item[-1]
n.append(x)
else:
n.append(item)
print(n) | 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
x =int(input())
arr = []
while x > 0:
arr.append(input())
x-=1
n=[]
for item in arr:
if len(item) > 10:
x = item[0]+ str((len(item)-2)) +item[-1]
n.append(x)
else:
n.append(item)
print(n)
``` | 0 |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,697,108,379 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n,m=map(int,input().split())
A=[]
s=0
A=list(map(int,input().split()))
for i in A:
if(i>=A[m-1]):
s=s+1
print(s) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n,m=map(int,input().split())
A=[]
s=0
A=list(map(int,input().split()))
for i in A:
if(i>=A[m-1]):
s=s+1
print(s)
``` | 0 | |
834 | B | The Festive Evening | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom... | Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26).
In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. | Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.
You can output each letter in arbitrary case (upper or lower). | [
"5 1\nAABBB\n",
"5 1\nABABB\n"
] | [
"NO\n",
"YES\n"
] | In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the secon... | 1,000 | [
{
"input": "5 1\nAABBB",
"output": "NO"
},
{
"input": "5 1\nABABB",
"output": "YES"
},
{
"input": "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "NO"
},
{
"input": "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA",
"output": "YES"
},
{
"input": "5 2\nABACA",
"output": "NO"
... | 1,501,429,168 | 3,868 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 77 | 4,608,000 | alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
a, b = map(int, input().split())
s = input()
people = []
letters = [0 for x in range(26)]
for x in range(a):
p = alphabet.index(s[x])
people.append(p)
letters... | Title: The Festive Evening
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here... | ```python
alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
a, b = map(int, input().split())
s = input()
people = []
letters = [0 for x in range(26)]
for x in range(a):
p = alphabet.index(s[x])
people.append(p)
... | -1 | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,484,473,815 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 4,608,000 | n = int(input())
a = 1
while n>a:
n-=a
a+=1
print(n) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
n = int(input())
a = 1
while n>a:
n-=a
a+=1
print(n)
``` | 0 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=<<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,697,434,211 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 93 | 9,625,600 | mp = {0: 1, 1: 1}
vec = []
def getLen(n):
if n == 0 or n == 1:
return 1
m = n // 2
mp[m] = getLen(m)
mp[n] = 2 * mp[m] + 1
return mp[n]
def getAns(n, interval):
if n == 1:
return len(interval)
elif n == 0:
return 0
else:
length = mp[n // 2]
cnt... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
mp = {0: 1, 1: 1}
vec = []
def getLen(n):
if n == 0 or n == 1:
return 1
m = n // 2
mp[m] = getLen(m)
mp[n] = 2 * mp[m] + 1
return mp[n]
def getAns(n, interval):
if n == 1:
return len(interval)
elif n == 0:
return 0
else:
length = mp[n // 2]
... | 3 | |
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, th... | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/c... | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWW... | 1,587,032,909 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 218 | 0 | import math
#variabila cu care vom tine minte nr de patratele care trebuie sa le coloram cu negru
countB = 0
#citim 8 linii din consola
for i in range(8):
line = input()
#pentru fiecare caracter din linie
for char in line:
#verificam daca este B
if char == 'B':
... | Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de... | ```python
import math
#variabila cu care vom tine minte nr de patratele care trebuie sa le coloram cu negru
countB = 0
#citim 8 linii din consola
for i in range(8):
line = input()
#pentru fiecare caracter din linie
for char in line:
#verificam daca este B
if cha... | 0 |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,597,041,481 | 2,147,483,647 | PyPy 3 | OK | TESTS | 19 | 404 | 30,515,200 | n=int(input())
l=list(map(int,input().split()))
c=0
f=1
for i in range(n):
if(l[i]==i):
c=c+1
elif(f==1 and l[l[i]]==i):
c=c+2
f=0
if(f==1 and c<n):
c=c+1
print(c) | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
n=int(input())
l=list(map(int,input().split()))
c=0
f=1
for i in range(n):
if(l[i]==i):
c=c+1
elif(f==1 and l[l[i]]==i):
c=c+2
f=0
if(f==1 and c<n):
c=c+1
print(c)
``` | 3 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,628,897,902 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 186 | 15,155,200 | n = int(input())
A = list(map(int, input().split()))
def solve(n,A):
ans = ''
B = [0]*n
for i in range(n-1):
B[i] = A[i] + A[i+1]
B[n-1] = A[n-1]
for b in B:
ans += str(b) + ' '
print(ans)
solve(n,A) | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
n = int(input())
A = list(map(int, input().split()))
def solve(n,A):
ans = ''
B = [0]*n
for i in range(n-1):
B[i] = A[i] + A[i+1]
B[n-1] = A[n-1]
for b in B:
ans += str(b) + ' '
print(ans)
solve(n,A)
``` | 3 | |
979 | A | Pizza, Pizza, Pizza!!! | PROGRAMMING | 1,000 | [
"math"
] | null | null | Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele... | A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. | A single integer — the number of straight cuts Shiro needs. | [
"3\n",
"4\n"
] | [
"2",
"5"
] | To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them.
To cut the round pizza into five equal parts one has to make five cuts. | 500 | [
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "5"
},
{
"input": "10",
"output": "11"
},
{
"input": "10000000000",
"output": "10000000001"
},
{
"input": "1234567891",
"output": "617283946"
},
{
"input": "7509213957",
"output": "37546069... | 1,528,964,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 28 | 78 | 0 | n = int(input().strip()) + 1
if n == 0:
print(0)
else:
print(n // 2 if n % 2 == 0 else n)
| Title: Pizza, Pizza, Pizza!!!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthd... | ```python
n = int(input().strip()) + 1
if n == 0:
print(0)
else:
print(n // 2 if n % 2 == 0 else n)
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,595,472,114 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 6,656,000 | a,b,c=map(int,input().split())
m=a+b+a+b
n=b+c+c+b
p=a+c+c+a
q=a+c+b
print(min(m,n,p,q))
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a,b,c=map(int,input().split())
m=a+b+a+b
n=b+c+c+b
p=a+c+c+a
q=a+c+b
print(min(m,n,p,q))
``` | 3 | |
380 | C | Sereja and Brackets | PROGRAMMING | 2,000 | [
"data structures",
"schedules"
] | null | null | Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o... | The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ... | Print the answer to each question on a single line. Print the answers in the order they go in the input. | [
"())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n"
] | [
"0\n0\n2\n10\n4\n6\n6\n"
] | A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s... | 1,500 | [
{
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10",
"output": "0\n0\n2\n10\n4\n6\n6"
},
{
"input": "(((((()((((((((((()((()(((((\n1\n8 15",
"output": "0"
},
{
"input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ... | 1,673,060,740 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 1,000 | 8,396,800 | s = input()
m = int(input())
queries = []
for i in range(m):
queries.append(map(int, input().split()))
for q in queries:
l, r = q
sub = s[l-1:r]
correct = 0
while sub.find("()") != -1:
correct += 2
sub = sub.replace("()", "", 1)
print(correct)
| Title: Sereja and Brackets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")".
Sereja needs to answer *m* queries, each of them is described by two i... | ```python
s = input()
m = int(input())
queries = []
for i in range(m):
queries.append(map(int, input().split()))
for q in queries:
l, r = q
sub = s[l-1:r]
correct = 0
while sub.find("()") != -1:
correct += 2
sub = sub.replace("()", "", 1)
print(correct... | 0 | |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,665,191,335 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 202 | 18,227,200 | input()
elementos = list(map(int, input().split()))
maior_soma = 0
soma_esquerda = 0
soma_direita = 0
esquerda = 0
direita = len(elementos) - 1
controle_incremento = 0
while esquerda < direita:
if controle_incremento == 0:
soma_esquerda += elementos[esquerda]
soma_direita += elementos[direita]
... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
input()
elementos = list(map(int, input().split()))
maior_soma = 0
soma_esquerda = 0
soma_direita = 0
esquerda = 0
direita = len(elementos) - 1
controle_incremento = 0
while esquerda < direita:
if controle_incremento == 0:
soma_esquerda += elementos[esquerda]
soma_direita += elementos... | 3 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,532,246,839 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 0 | a=input()
c=0
for i in range(97,123):
x=a.count(chr(i))
if x>1:
c+=x-1
z=(26*(len(a)+1))-len(a)-c
print(z)
| Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
a=input()
c=0
for i in range(97,123):
x=a.count(chr(i))
if x>1:
c+=x-1
z=(26*(len(a)+1))-len(a)-c
print(z)
``` | 0 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,560,401,986 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | """
/*************************************************************
# by : mohamd abda alazez hashim #
# e-mail : [email protected] #
# problem : B. Queue at the School #
*************************************************************/
""... | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
"""
/*************************************************************
# by : mohamd abda alazez hashim #
# e-mail : [email protected] #
# problem : B. Queue at the School #
********************************************************... | 0 |
898 | C | Phone Numbers | PROGRAMMING | 1,400 | [
"implementation",
"strings"
] | null | null | Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friends. You will be given *n* strings — all entries from Vasya's phone books. Each entry starts with a f... | First line contains the integer *n* (1<=≤<=*n*<=≤<=20) — number of entries in Vasya's phone books.
The following *n* lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase E... | Print out the ordered information about the phone numbers of Vasya's friends. First output *m* — number of friends that are found in Vasya's phone books.
The following *m* lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each... | [
"2\nivan 1 00123\nmasha 1 00123\n",
"3\nkarl 2 612 12\npetr 1 12\nkatya 1 612\n",
"4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789\n"
] | [
"2\nmasha 1 00123 \nivan 1 00123 \n",
"3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 \n",
"2\ndasha 2 23 789 \nivan 4 789 123 2 456 \n"
] | none | 1,500 | [
{
"input": "2\nivan 1 00123\nmasha 1 00123",
"output": "2\nmasha 1 00123 \nivan 1 00123 "
},
{
"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612",
"output": "3\nkatya 1 612 \npetr 1 12 \nkarl 1 612 "
},
{
"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndash... | 1,551,265,164 | 2,064 | Python 3 | OK | TESTS | 59 | 109 | 0 | n = int(input())
book = {}
for _ in range(n):
toks = input().strip().split()
name = toks[0]
numbers = toks[2:]
book.setdefault(name,[])
book[name].extend(numbers)
print(len(book))
for k, v in book.items():
v.sort(key=lambda x: len(x))
new_v = []
for i in range(len(v)):
if any(v[j... | Title: Phone Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers.
Vasya decided to organize information about the phone numbers of friend... | ```python
n = int(input())
book = {}
for _ in range(n):
toks = input().strip().split()
name = toks[0]
numbers = toks[2:]
book.setdefault(name,[])
book[name].extend(numbers)
print(len(book))
for k, v in book.items():
v.sort(key=lambda x: len(x))
new_v = []
for i in range(len(v)):
... | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,643,619,084 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 60 | 0 | t=int(input())
for i in range(t):
x=int(input())
for i in range(3,x):
y=(i-2)*180
y=y/i
if(y>=x):
break
if(y==x):
print("YES")
else:
print("NO") | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
t=int(input())
for i in range(t):
x=int(input())
for i in range(3,x):
y=(i-2)*180
y=y/i
if(y>=x):
break
if(y==x):
print("YES")
else:
print("NO")
``` | -1 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,585,820,854 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
a=[int(x) for x in input().split()]
s=''
if n%3==0:
for i in range(0, n, 3):
s+=str(a[i:i+3])+'-'
elif n%2==0:
for i in range(0, n, 2):
s+=str(a[i:i+2])+'-'
else:
for i in range(0, n, 2):
if i is not n-1
s+=str(a[i:i+2])+'-'
else:
... | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
n=int(input())
a=[int(x) for x in input().split()]
s=''
if n%3==0:
for i in range(0, n, 3):
s+=str(a[i:i+3])+'-'
elif n%2==0:
for i in range(0, n, 2):
s+=str(a[i:i+2])+'-'
else:
for i in range(0, n, 2):
if i is not n-1
s+=str(a[i:i+2])+'-'
e... | -1 |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,695,039,665 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 92 | 0 | n = int(input())
l = list(map(int, input().split()))
a = l.index(max(l)) + l[::-1].index(min(l))
swaps = a - (a >= n)
print(swaps) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
l = list(map(int, input().split()))
a = l.index(max(l)) + l[::-1].index(min(l))
swaps = a - (a >= n)
print(swaps)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 0 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx... | 1,505,658,592 | 5,092 | Python 3 | SKIPPED | PRETESTS | 10 | 61 | 4,608,000 | s=input()
vowel=['a','e','i','o','u']
i=0
consc=0
spaces=[]
while(i<len(s)):
if s[i] not in vowel:
consc+=1
else:
consc=0
if consc==3:
consc=1
spaces.append(i)
i+=1
for i in range(0,len(spaces)):
if i==0:
continue
else:
spaces[i]+... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 2... | ```python
s=input()
vowel=['a','e','i','o','u']
i=0
consc=0
spaces=[]
while(i<len(s)):
if s[i] not in vowel:
consc+=1
else:
consc=0
if consc==3:
consc=1
spaces.append(i)
i+=1
for i in range(0,len(spaces)):
if i==0:
continue
else:
... | -1 | |
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the s... | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"outp... | 1,633,799,911 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 3,000 | 6,758,400 | import math
def main() -> None:
n = int(input())
ans = 0
for a in range(1, n + 1):
for b in range(a, n + 1):
c = int(math.sqrt(a ** 2 + b ** 2))
if c <= n and a ** 2 + b ** 2 == c ** 2:
ans += 1
print(ans)
if __name__ == '__main__':
... | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the squar... | ```python
import math
def main() -> None:
n = int(input())
ans = 0
for a in range(1, n + 1):
for b in range(a, n + 1):
c = int(math.sqrt(a ** 2 + b ** 2))
if c <= n and a ** 2 + b ** 2 == c ** 2:
ans += 1
print(ans)
if __name__ == '__main... | 0 | |
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,666,358,510 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | import math
# n=int(input())
# n,k=map(int,input().split())
# for _ in range(int(input())):
# coor,ap=map(int,input().split())
# s=(input());t=input()
# s,t=input().split()
# arr=list(map(int,input().split()))
# for _ in range(int(input())):
# n,q=map(int,input().split());s=(input())
money=mn=int(inp... | 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
import math
# n=int(input())
# n,k=map(int,input().split())
# for _ in range(int(input())):
# coor,ap=map(int,input().split())
# s=(input());t=input()
# s,t=input().split()
# arr=list(map(int,input().split()))
# for _ in range(int(input())):
# n,q=map(int,input().split());s=(input())
money=... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,696,442,193 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | k,n,w =map(int,input().split())
s=k*(w+1)*w/2
a=s-n
if a>0:
print(int(a))
else print (0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w =map(int,input().split())
s=k*(w+1)*w/2
a=s-n
if a>0:
print(int(a))
else print (0)
``` | -1 | |
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,695,740,286 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 28,262,400 | from math import ceil
a = int(input())
b = ceil(a / 5)
print(b)
| 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
from math import ceil
a = int(input())
b = ceil(a / 5)
print(b)
``` | 3 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,697,693,283 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 30 | 0 | p = list(input())
characters = ['H', 'Q', '9', '+']
for character in characters:
if character in p:
found = True
break
if found:
print("YES")
else:
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
p = list(input())
characters = ['H', 'Q', '9', '+']
for character in characters:
if character in p:
found = True
break
if found:
print("YES")
else:
print("NO")
``` | -1 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,676,729,466 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n=int(input())
l=[]
if n%2==1:
print(-1)
else:
for i in range(n-1):
l.append(i+2)
l=l[::-1]
l.append(1)
print(*l)
| Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
n=int(input())
l=[]
if n%2==1:
print(-1)
else:
for i in range(n-1):
l.append(i+2)
l=l[::-1]
l.append(1)
print(*l)
``` | 3 | |
514 | D | R2D2 and Droid Army | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"two pointers"
] | null | null | An army of *n* droids is lined up in one row. Each droid is described by *m* integers *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of details of the *i*-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has *m* weapons, the *i*-th weapon can aff... | The first line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=5, 0<=≤<=*k*<=≤<=109) — the number of droids, the number of detail types and the number of available shots, respectively.
Next *n* lines follow describing the droids. Each line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (0<=... | Print *m* space-separated integers, where the *i*-th number is the number of shots from the weapon of the *i*-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length.
If there are multiple optimal solutions, print any of them.
It is not necessary to make exactly *k* ... | [
"5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3\n",
"3 2 4\n1 2\n1 3\n2 2\n"
] | [
"2 2\n",
"1 3\n"
] | In the first test the second, third and fourth droids will be destroyed.
In the second test the first and second droids will be destroyed. | 2,000 | [
{
"input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3",
"output": "2 2"
},
{
"input": "3 2 4\n1 2\n1 3\n2 2",
"output": "1 3"
},
{
"input": "1 1 0\n0",
"output": "0"
},
{
"input": "1 1 0\n1",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "4 ... | 1,690,487,742 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1690487742.2009044")# 1690487742.200921 | Title: R2D2 and Droid Army
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An army of *n* droids is lined up in one row. Each droid is described by *m* integers *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of details of the *i*-th type in this droid's mechanism. R2-D2 wants to de... | ```python
print("_RANDOM_GUESS_1690487742.2009044")# 1690487742.200921
``` | 0 | |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,544,690,321 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | n,p,k=map(int,input().split())
s=''
for i in range(max(1,p-k),min(p+k+1,n+1)):
if i==p:
s=s+'('+str(i)+')'+' '
else:
s=s+str(i)+' '
if p-k>1:
s='<< '+s
if p+k<n:
s=s+'>>'
print(s)
| Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
n,p,k=map(int,input().split())
s=''
for i in range(max(1,p-k),min(p+k+1,n+1)):
if i==p:
s=s+'('+str(i)+')'+' '
else:
s=s+str(i)+' '
if p-k>1:
s='<< '+s
if p+k<n:
s=s+'>>'
print(s)
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,687,086,230 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 60 | 0 | n = int(input())
thexit = []
thent = []
for i in (range(n)):
mat = [int(n) for n in input().split()]
thexit.append(mat[0])
thent.append(mat[1])
ni = thent[0] - thexit[1]
num = ni + thent[1]
print(num) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n = int(input())
thexit = []
thent = []
for i in (range(n)):
mat = [int(n) for n in input().split()]
thexit.append(mat[0])
thent.append(mat[1])
ni = thent[0] - thexit[1]
num = ni + thent[1]
print(num)
``` | 0 | |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,607,664,005 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 108 | 0 | a,b,c,d=list(map(int,input().split()))
awin=a/b
aloss=1-(a/b)
bloss=1-(c/d)
ans=awin*(1/(1-(aloss*bloss)))
print("%.12f" % ans)
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d=list(map(int,input().split()))
awin=a/b
aloss=1-(a/b)
bloss=1-(c/d)
ans=awin*(1/(1-(aloss*bloss)))
print("%.12f" % ans)
``` | 3 | |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ... | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
... | 1,467,265,816 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 389 | 15,462,400 | n,m=map(int,input().split())
set3=set()
set1=set()
set2=set()
for i in range(m):
a,b=input().split()
if a in set1:
set2.add(b)
elif a in set2:
set1.add(b)
elif b in set1:
set2.add(a)
elif b in set2:
set1.add(a)
else:
set3.add((a,b))
for i... | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ... | ```python
n,m=map(int,input().split())
set3=set()
set1=set()
set2=set()
for i in range(m):
a,b=input().split()
if a in set1:
set2.add(b)
elif a in set2:
set1.add(b)
elif b in set1:
set2.add(a)
elif b in set2:
set1.add(a)
else:
set3.add((a,b)... | 0 | |
152 | B | Steps | PROGRAMMING | 1,300 | [
"binary search",
"implementation"
] | null | null | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangu... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*).
The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. ... | Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"4 5\n1 1\n3\n1 1\n1 1\n0 -2\n",
"10 10\n1 2\n1\n-1 0\n"
] | [
"4\n",
"0\n"
] | In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,... | 1,000 | [
{
"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2",
"output": "4"
},
{
"input": "10 10\n1 2\n1\n-1 0",
"output": "0"
},
{
"input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5",
"output": "13"
},
{
"input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n2... | 1,635,265,201 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 156 | 4,608,000 | n, m = map(int, input().split())
x, y = map(int, input().split())
e = 0
for i in range(int(input())):
dx, dy = map(int, input().split())
a, b = n, m
op1=(m - y)
op2=(y - 1)
op3=(n - x)
op4=(x - 1)
if dy > 0:
a = op1 // dy
elif dy < 0:
a = op2 // (- dy)
... | Title: Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ... | ```python
n, m = map(int, input().split())
x, y = map(int, input().split())
e = 0
for i in range(int(input())):
dx, dy = map(int, input().split())
a, b = n, m
op1=(m - y)
op2=(y - 1)
op3=(n - x)
op4=(x - 1)
if dy > 0:
a = op1 // dy
elif dy < 0:
a = op2 //... | 3 | |
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like... | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input"... | 1,667,052,132 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 512,000 | s=int(input())
s1=input()
o=s1.count("0")
o2=s1.count("1")
print(abs(o-o2)) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Cons... | ```python
s=int(input())
s1=input()
o=s1.count("0")
o2=s1.count("1")
print(abs(o-o2))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if ... | [
"3 0 0\n0 1\n-1 2\n1 2\n",
"4 1 -1\n0 0\n1 2\n2 0\n1 1\n"
] | [
"12.566370614359172464\n",
"21.991148575128551812\n"
] | In the first sample snow will be removed from that area: | 0 | [
{
"input": "3 0 0\n0 1\n-1 2\n1 2",
"output": "12.566370614359172464"
},
{
"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1",
"output": "21.991148575128551812"
},
{
"input": "3 0 0\n-1 1\n0 3\n1 1",
"output": "25.132741228718344928"
},
{
"input": "3 -4 2\n-3 2\n5 -5\n5 3",
"output": ... | 1,636,488,029 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 77 | 28,979,200 | from math import sqrt, pi
n, px, py = [int(x) for x in input().split()]
def dist(x, y):
return sqrt((px - x)**2 + (py - y)**2)
min_p = [float('inf'), 0, 0]
max_p = [0, 0, 0]
for i in range(n):
x, y = [int(a) for a in input().split()]
d = dist(x, y)
if d < min_p[0]:
min_p = [d, x, y]
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you ... | ```python
from math import sqrt, pi
n, px, py = [int(x) for x in input().split()]
def dist(x, y):
return sqrt((px - x)**2 + (py - y)**2)
min_p = [float('inf'), 0, 0]
max_p = [0, 0, 0]
for i in range(n):
x, y = [int(a) for a in input().split()]
d = dist(x, y)
if d < min_p[0]:
min_p = [d,... | 0 | |
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,585,647,033 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
def equivalent(s1, s2):
if s1 == s2:
return True
elif len(s1) == 1:
return False
left = slice(0, len(s1) // 2, 1)
right = slice(len(s1) // 2, len(s1), 1)
return (equivalent(s1[left], s2[left]) and equivalent(s1[right], s2[right])) or \
(equivalent(s1[left], s2[ri... | 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
def equivalent(s1, s2):
if s1 == s2:
return True
elif len(s1) == 1:
return False
left = slice(0, len(s1) // 2, 1)
right = slice(len(s1) // 2, len(s1), 1)
return (equivalent(s1[left], s2[left]) and equivalent(s1[right], s2[right])) or \
(equivalent(s1[le... | -1 | |
631 | A | Interview | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.
We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109).
The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). | Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. | [
"5\n1 2 4 3 2\n2 3 3 12 1\n",
"10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n"
] | [
"22",
"46"
] | Bitwise OR of two non-negative integers *a* and *b* is the number *c* = *a* *OR* *b*, such that each of its digits in binary notation is 1 if and only if at least one of *a* or *b* have 1 in the corresponding position in binary notation.
In the first sample, one of the optimal answers is *l* = 2 and *r* = 4, because *... | 500 | [
{
"input": "5\n1 2 4 3 2\n2 3 3 12 1",
"output": "22"
},
{
"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6",
"output": "46"
},
{
"input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 9... | 1,601,726,281 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int FrontIndex(vector<int> v, int n, int x){
for(int i = 0; i < n; i++){
if (x == v[i]){
return i;
}
}
return -1;
}
int BackIndex(vector<int> v, int n, int x){
for(int i = n -... | Title: Interview
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of... | ```python
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int FrontIndex(vector<int> v, int n, int x){
for(int i = 0; i < n; i++){
if (x == v[i]){
return i;
}
}
return -1;
}
int BackIndex(vector<int> v, int n, int x){
for(i... | -1 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,677,705,474 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | m='a'
v=input()
m=m+v
t=13
l=0
for i in range(len(m)-1):
diff=abs(ord(m[i])-ord(m[i+1]))
if diff>13:
h=diff-13
diff=t-h
l+=diff
print('l=',l)
print(int(l)) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
m='a'
v=input()
m=m+v
t=13
l=0
for i in range(len(m)-1):
diff=abs(ord(m[i])-ord(m[i+1]))
if diff>13:
h=diff-13
diff=t-h
l+=diff
print('l=',l)
print(int(l))
``` | 0 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,671,907,804 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | n = int(input())
if n%2==0: print(n-4, 4)
else: print(n-9, 9) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
n = int(input())
if n%2==0: print(n-4, 4)
else: print(n-9, 9)
``` | 3 | |
353 | D | Queue | PROGRAMMING | 2,000 | [
"constructive algorithms",
"dp"
] | null | null | There are *n* schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, simultaneously swap places with the girls (so that the girls could go closer to the beginni... | The first line contains a sequence of letters without spaces *s*1*s*2... *s**n* (1<=≤<=*n*<=≤<=106), consisting of capital English letters M and F. If letter *s**i* equals M, that means that initially, the line had a boy on the *i*-th position. If letter *s**i* equals F, then initially the line had a girl on the *i*-th... | Print a single integer — the number of seconds needed to move all the girls in the line in front of the boys. If the line has only boys or only girls, print 0. | [
"MFM\n",
"MMFF\n",
"FFMMM\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first test case the sequence of changes looks as follows: MFM → FMM.
The second test sample corresponds to the sample from the statement. The sequence of changes is: MMFF → MFMF → FMFM → FFMM. | 2,500 | [
{
"input": "MFM",
"output": "1"
},
{
"input": "MMFF",
"output": "3"
},
{
"input": "FFMMM",
"output": "0"
},
{
"input": "MMFMMFFFFM",
"output": "7"
},
{
"input": "MFFFMMFMFMFMFFFMMMFFMMMMMMFMMFFMMMFMMFMFFFMMFMMMFFMMFFFFFMFMFFFMMMFFFMFMFMFMFFFMMMMFMMFMMFFMMMMMMFFM",... | 1,555,323,064 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#def... | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes.
Each second all boys that stand right in front of girls, ... | ```python
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first.first
#define yy first.second
#define __V vector
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.re... | -1 | |
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,688,471,384 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
level = 0
kubik_level = 0
summa = 0
while summa<n:
level += 1
kubik_level = kubik_level + level
summa = summa + kubik_level
print(level,kubik_level,summa)
if summa == n:
print(level)
else:
print(level-1)
| Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
n = int(input())
level = 0
kubik_level = 0
summa = 0
while summa<n:
level += 1
kubik_level = kubik_level + level
summa = summa + kubik_level
print(level,kubik_level,summa)
if summa == n:
print(level)
else:
print(level-1)
``` | 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.