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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,559,202,066 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 307,200 | n, m = [int(i) for i in input().split()]
neigh = [[] for i in range(n)]
for i in range(m):
a, b = [int(i) for i in input().split()]
neigh[a - 1].append(b - 1)
neigh[b - 1].append(a - 1)
def search(a, b):
for i in a:
if a[i] == b:
return True
return False
def isRing(neighList):
indexesPassed... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
n, m = [int(i) for i in input().split()]
neigh = [[] for i in range(n)]
for i in range(m):
a, b = [int(i) for i in input().split()]
neigh[a - 1].append(b - 1)
neigh[b - 1].append(a - 1)
def search(a, b):
for i in a:
if a[i] == b:
return True
return False
def isRing(neighList):
ind... | 0 | |
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th... | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"... | 1,576,942,517 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 0 | n,s=[int(x) for x in input().split()]
l=[int(x) for x in input().split()]
l.sort()
print("YES" if sum(l[:-1])<=s else "NO")
| Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
n,s=[int(x) for x in input().split()]
l=[int(x) for x in input().split()]
l.sort()
print("YES" if sum(l[:-1])<=s else "NO")
``` | 3 | |
409 | A | The Great Game | PROGRAMMING | 1,700 | [
"*special"
] | null | null | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion. | The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team. | Output "TEAM 1 WINS" if the first team won, "TEAM 2 WINS" if the second team won, and "TIE" if there was a tie. | [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n"
] | [
"TEAM 2 WINS\n",
"TIE\n"
] | none | 0 | [
{
"input": "[]()[]8<\n8<[]()8<",
"output": "TEAM 2 WINS"
},
{
"input": "8<8<()\n[]8<[]",
"output": "TIE"
},
{
"input": "()\n[]",
"output": "TEAM 2 WINS"
},
{
"input": "()\n8<",
"output": "TEAM 1 WINS"
},
{
"input": "8<\n[]",
"output": "TEAM 1 WINS"
},
{
... | 1,624,998,642 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 139 | 409,600 | from collections import defaultdict, Counter
from math import sqrt, log10, log2, log, gcd, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import combinations, combinations_with_replacement
import sys, io, os
input=sys.stdin.readline
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).re... | Title: The Great Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. ... | ```python
from collections import defaultdict, Counter
from math import sqrt, log10, log2, log, gcd, floor, factorial
from bisect import bisect_left, bisect_right
from itertools import combinations, combinations_with_replacement
import sys, io, os
input=sys.stdin.readline
input=io.BytesIO(os.read(0,os.fstat(0).st... | 0 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,683,980,001 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 |
n = int(input())
l = [int(x) for x in input().split()]
one = l.count(1)
two = l.count(2)
thr = l.count(3)
fou = l.count(4)
six = l.count(6)
if two+thr != int(n/3) or one != int(n/3) or fou+six != int(n/3) : print(-1)
else:
for i in range(0,fou):
print("1 2 4")
for i in range(0,two-fou):
... | 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
n = int(input())
l = [int(x) for x in input().split()]
one = l.count(1)
two = l.count(2)
thr = l.count(3)
fou = l.count(4)
six = l.count(6)
if two+thr != int(n/3) or one != int(n/3) or fou+six != int(n/3) : print(-1)
else:
for i in range(0,fou):
print("1 2 4")
for i in range(0,t... | 0 | |
817 | B | Makes And The Product | PROGRAMMING | 1,500 | [
"combinatorics",
"implementation",
"math",
"sortings"
] | null | null | After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=<<=*j*<=<<=*k*), such that *a**i*·*a**j*·*a... | The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array. | Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible. | [
"4\n1 1 1 1\n",
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | 0 | [
{
"input": "4\n1 1 1 1",
"output": "4"
},
{
"input": "5\n1 3 2 3 4",
"output": "2"
},
{
"input": "6\n1 3 3 1 3 2",
"output": "1"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": ... | 1,519,612,585 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 233 | 14,438,400 | ##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
def list_input():
return list(map(int, input().split()))
n = int(input())
a = list_input()
a.sort()
s = list()
p = 0
while p < n:
q = p
while q < n and a[p] == a[q]:
q += 1
s.append(q-p)
... | Title: Makes And The Product
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular questi... | ```python
##n = int(input())
##a = list(map(int, input().split()))
##print(' '.join(map(str, res)))
def list_input():
return list(map(int, input().split()))
n = int(input())
a = list_input()
a.sort()
s = list()
p = 0
while p < n:
q = p
while q < n and a[p] == a[q]:
q += 1
s.app... | 3 | |
733 | D | Kostya the Sculptor | PROGRAMMING | 1,600 | [
"data structures",
"hashing"
] | null | null | Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has *n* stones which are rectang... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=105).
*n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109) — the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be co... | In the first line print *k* (1<=≤<=*k*<=≤<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n* — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data.
You can print th... | [
"6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n",
"7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n"
] | [
"1\n1\n",
"2\n1 5\n"
] | In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of ... | 2,000 | [
{
"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4",
"output": "1\n1"
},
{
"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7",
"output": "2\n1 5"
},
{
"input": "1\n1 1 1",
"output": "1\n1"
},
{
"input": "2\n2 3 1\n2 2 3",
"output": "2\n2 1"
},
{
... | 1,615,008,642 | 2,147,483,647 | PyPy 3 | OK | TESTS | 104 | 1,356 | 14,028,800 | n = int(input())
INF = 10**10
ind = 0
ans = 0
temp = 0
a = []
d = dict()
S = sorted([sorted(list(map(int, input().split())) , reverse = True) + [i + 1] for i in range(n)], reverse = True)
ans = S[0][2]
a = [S[0][-1]]
for i in range(1, n):
if S[i][0] == S[i-1][0] and S[i][1] == S[i-1][1]:
... | Title: Kostya the Sculptor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangu... | ```python
n = int(input())
INF = 10**10
ind = 0
ans = 0
temp = 0
a = []
d = dict()
S = sorted([sorted(list(map(int, input().split())) , reverse = True) + [i + 1] for i in range(n)], reverse = True)
ans = S[0][2]
a = [S[0][-1]]
for i in range(1, n):
if S[i][0] == S[i-1][0] and S[i][1] == S[i-1][... | 3 | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, 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. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,553,853,048 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 483 | 1,024,000 | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
j = None
r = 0
p = 0
for i in minp():
r += (int(i)%4 == 0)
if j != None:
if int(j+i) % 4 == 0:
r += p
p += 1
j = i
print(r) | Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
j = None
r = 0
p = 0
for i in minp():
r += (int(i)%4 == 0)
if j != None:
if int(j+i) % 4 == 0:
r += p
p += 1
j = i
pri... | 3 | |
25 | E | Test | PROGRAMMING | 2,200 | [
"hashing",
"strings"
] | E. Test | 2 | 256 | Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop... | There are exactly 3 lines in the input data. The *i*-th line contains string *s**i*. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105. | Output one number — what is minimal length of the string, containing *s*1, *s*2 and *s*3 as substrings. | [
"ab\nbc\ncd\n",
"abacaba\nabaaba\nx\n"
] | [
"4\n",
"11\n"
] | none | 0 | [
{
"input": "ab\nbc\ncd",
"output": "4"
},
{
"input": "abacaba\nabaaba\nx",
"output": "11"
},
{
"input": "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls",
"output": "100"
},
{
"input": "jwdezvgfm\nmdoqvylpuvyk\nqylld... | 1,627,243,243 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 15,564,800 | def fun(a,b):
x=0
for t in range(min(len(a),len(b))):
if b[0:t]+b[t] == a[-(t+1):-1] + a[-1]:
x = t+1
return x
s_1 = input()
s_2 = input()
s_3 = input()
def ful(a,b):
for t in range(len(b)):
if b[t:t+len(a)] == a:
return True
if ful(s_2,s_1) and... | Title: Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong an... | ```python
def fun(a,b):
x=0
for t in range(min(len(a),len(b))):
if b[0:t]+b[t] == a[-(t+1):-1] + a[-1]:
x = t+1
return x
s_1 = input()
s_2 = input()
s_3 = input()
def ful(a,b):
for t in range(len(b)):
if b[t:t+len(a)] == a:
return True
if ful(s_... | 0 |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,677,426,640 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 124 | 0 | n,m=map(int,input().split())
f=list(map(int,input().split()))
g=sorted(f)
x=g[0:n]
y=m-len(x)+1
z=[]
for i in range(y):
y=g[i:i+n]
z.append(y[-1]-y[0])
print(min(z))
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m=map(int,input().split())
f=list(map(int,input().split()))
g=sorted(f)
x=g[0:n]
y=m-len(x)+1
z=[]
for i in range(y):
y=g[i:i+n]
z.append(y[-1]-y[0])
print(min(z))
``` | 3 | |
957 | A | Tritonic Iridescence | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the co... | The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas.
The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted... | If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).
You can print each character in any case (upper or lower). | [
"5\nCY??Y\n",
"5\nC?C?Y\n",
"5\n?CYC?\n",
"5\nC??MM\n",
"3\nMMY\n"
] | [
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | For the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.
For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.
For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.
For the fourth example, no matter how th... | 500 | [
{
"input": "5\nCY??Y",
"output": "Yes"
},
{
"input": "5\nC?C?Y",
"output": "Yes"
},
{
"input": "5\n?CYC?",
"output": "Yes"
},
{
"input": "5\nC??MM",
"output": "No"
},
{
"input": "3\nMMY",
"output": "No"
},
{
"input": "15\n??YYYYYY??YYYY?",
"output"... | 1,521,907,367 | 1,667 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 77 | 7,065,600 | n = int(input())
s = input()
flag1 = True
num = 0
pre = s[0]
for i in range(1, n):
if s[i] == pre:
if s[i] != "?" and pre != "?":
flag1 = False
break
if s[i] == "?":
num += 1
pre = s[i]
if flag1 and num >= 2:
print("Yes")
elif flag1 and num == 1:
... | Title: Tritonic Iridescence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.
Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one... | ```python
n = int(input())
s = input()
flag1 = True
num = 0
pre = s[0]
for i in range(1, n):
if s[i] == pre:
if s[i] != "?" and pre != "?":
flag1 = False
break
if s[i] == "?":
num += 1
pre = s[i]
if flag1 and num >= 2:
print("Yes")
elif flag1 and ... | 0 | |
276 | D | Little Girl and Maximum XOR | PROGRAMMING | 1,700 | [
"bitmasks",
"dp",
"greedy",
"implementation",
"math"
] | null | null | A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). Your task is to find the maximum value among all considered ones.
Expression means applying bitw... | The single line contains space-separated integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | In a single line print a single integer — the maximum value of for all pairs of integers *a*, *b* (*l*<=≤<=*a*<=≤<=*b*<=≤<=*r*). | [
"1 2\n",
"8 16\n",
"1 1\n"
] | [
"3\n",
"31\n",
"0\n"
] | none | 2,000 | [
{
"input": "1 2",
"output": "3"
},
{
"input": "8 16",
"output": "31"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "506 677",
"output": "1023"
},
{
"input": "33 910",
"output": "1023"
},
{
"input": "36 94",
"output": "127"
},
{
"input": ... | 1,676,388,554 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 46 | 0 | a,b=map(int,input().split())
a=a^b
def setb(a):
for i in range(63,-1,-1):
if(a&(1<<i)):
return i+1
return 0
z=setb(a)
print((2**z)-1)
| Title: Little Girl and Maximum XOR
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little girl loves problems on bitwise operations very much. Here's one of them.
You are given two integers *l* and *r*. Let's consider the values of for all pairs of integers *a* and *b* (*l*<=≤<=*a*<=≤<... | ```python
a,b=map(int,input().split())
a=a^b
def setb(a):
for i in range(63,-1,-1):
if(a&(1<<i)):
return i+1
return 0
z=setb(a)
print((2**z)-1)
``` | 3 | |
145 | A | Lucky Conversion | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 500 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,585,853,999 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 342 | 7,372,800 | a = list(input())
b = list(input())
ans = 0
c4 = abs(a.count('4') - b.count('4'))
c7 = abs(a.count('7') - b.count('7'))
ans += c4
n =len(a)
count = 0
for i in range(n):
if a[i] != b[i]:
count += 1
ans += ((count - c4)//2)
print(ans)
| Title: Lucky Conversion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are no... | ```python
a = list(input())
b = list(input())
ans = 0
c4 = abs(a.count('4') - b.count('4'))
c7 = abs(a.count('7') - b.count('7'))
ans += c4
n =len(a)
count = 0
for i in range(n):
if a[i] != b[i]:
count += 1
ans += ((count - c4)//2)
print(ans)
``` | 3 | |
987 | C | Three displays | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation"
] | null | null | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ... | The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \... | If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$. | [
"5\n2 4 5 4 10\n40 30 20 10 40\n",
"3\n100 101 100\n2 4 5\n",
"10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n"
] | [
"90\n",
"-1\n",
"33\n"
] | In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | 1,250 | [
{
"input": "5\n2 4 5 4 10\n40 30 20 10 40",
"output": "90"
},
{
"input": "3\n100 101 100\n2 4 5",
"output": "-1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13",
"output": "33"
},
{
"input": "3\n1 2 3\n100000000 100000000 100000000",
"output": "300... | 1,569,436,275 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 124 | 1,228,800 | n, fonts, rents = int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' ')))
cache = [[[-1 for _ in range(n+1)] for i in range(n+1)] for j in range(4)]
def go(current, last, chosen, cost):
global cache
if(chosen == 3):
return cost
if(current == n):
return... | Title: Three displays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, ... | ```python
n, fonts, rents = int(input()), list(map(int, input().split(' '))), list(map(int, input().split(' ')))
cache = [[[-1 for _ in range(n+1)] for i in range(n+1)] for j in range(4)]
def go(current, last, chosen, cost):
global cache
if(chosen == 3):
return cost
if(current == n):
... | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,642,483,977 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 0 | n, k = map(int,input().split())
r = 0
for i in range(n):
a = input()
for j in range(k+1):
if str(j) in a:
b = 1
else:
b = 0
break
if b == 1:
r +=1
print(r) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = map(int,input().split())
r = 0
for i in range(n):
a = input()
for j in range(k+1):
if str(j) in a:
b = 1
else:
b = 0
break
if b == 1:
r +=1
print(r)
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,670,091,234 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | left, right = 0, int(input())-1
l = list(map(int, input().split()))
sree = 0
dima = 0
times = 1
while left<=right:
if times%2==0:
if l[left]<l[right]:
dima+=l[right]
right-=1
else:
dima+=l[left]
left+=1
else:
if l[left]<l[ri... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
left, right = 0, int(input())-1
l = list(map(int, input().split()))
sree = 0
dima = 0
times = 1
while left<=right:
if times%2==0:
if l[left]<l[right]:
dima+=l[right]
right-=1
else:
dima+=l[left]
left+=1
else:
if l[... | 3 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,635,660,358 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 18 | 92 | 5,017,600 | import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
minp = la... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
import sys
import os.path
if(os.path.exists('input.txt')) :
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
sys.stderr = open("error.txt", "w")
depth = 1000000
mod = 1000000007
lim = mod * mod
sys.setrecursionlimit(depth)
linp = lambda: list(minp())
... | -1 | |
248 | A | Cupboards | PROGRAMMING | 800 | [
"implementation"
] | null | null | One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house.
Karlsson's gaze immediately fell on *n* woode... | The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal... | In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. | [
"5\n0 1\n1 0\n0 1\n1 1\n0 1\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "5\n0 1\n1 0\n0 1\n1 1\n0 1",
"output": "3"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1\n1 1\n1 1",
"output": "1"
},
{
"input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0",
"output": "7"
},
{
"input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ... | 1,635,431,879 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 124 | 4,505,600 | n = int(input())
leftOpen, rightOpen = 0, 0
for i in range(n):
left, right = [int(x) for x in input().split()]
if left == 0:
leftOpen += 1
if right == 0:
rightOpen += 1
res = min(leftOpen, n - leftOpen) + min(rightOpen, n - rightOpen)
print(res) | Title: Cupboards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long... | ```python
n = int(input())
leftOpen, rightOpen = 0, 0
for i in range(n):
left, right = [int(x) for x in input().split()]
if left == 0:
leftOpen += 1
if right == 0:
rightOpen += 1
res = min(leftOpen, n - leftOpen) + min(rightOpen, n - rightOpen)
print(res)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,674,363,030 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | s=input()
f={}
d=0
for i in s:
if i in f:
f[i]+=1
else:
f[i]=1
for i in f:
if (f[i]>=2 and i!='l'):
d=1
break
if(d==1):
if(f['h']>0 and f['e']>0 and f['l']>1 and f['o']>0):
print('YES')
else:
print('NO')
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
s=input()
f={}
d=0
for i in s:
if i in f:
f[i]+=1
else:
f[i]=1
for i in f:
if (f[i]>=2 and i!='l'):
d=1
break
if(d==1):
if(f['h']>0 and f['e']>0 and f['l']>1 and f['o']>0):
print('YES')
else:
print('NO')
else:
print('NO'... | 0 |
550 | C | Divisibility by Eight | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"math"
] | null | null | You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a no... | The single line of the input contains a non-negative integer *n*. The representation of number *n* doesn't contain any leading zeroes and its length doesn't exceed 100 digits. | Print "NO" (without quotes), if there is no such way to remove some digits from number *n*.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number *n* in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any ... | [
"3454\n",
"10\n",
"111111\n"
] | [
"YES\n344\n",
"YES\n0\n",
"NO\n"
] | none | 1,000 | [
{
"input": "3454",
"output": "YES\n344"
},
{
"input": "10",
"output": "YES\n0"
},
{
"input": "111111",
"output": "NO"
},
{
"input": "8996988892",
"output": "YES\n8"
},
{
"input": "5555555555",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
... | 1,674,154,236 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | from itertools import combinations
def sol(num):
combs = []
for length in range(len(num) - 1, 0, -1):
combs += (list(combinations(num, length)))
for i in range(len(combs) - 1, -1, -1):
num = ""
for j in range(len(combs[i])):
num += combs[i][j]
... | Title: Divisibility by Eight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a non-negative integer *n*, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of t... | ```python
from itertools import combinations
def sol(num):
combs = []
for length in range(len(num) - 1, 0, -1):
combs += (list(combinations(num, length)))
for i in range(len(combs) - 1, -1, -1):
num = ""
for j in range(len(combs[i])):
num += combs[i]... | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,644,829,531 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 4,000 | 7,372,800 | n = int(input())
arr = list(map(int,input().split()))
m = int(input())
targets = list(map(int,input().split()))
count = 0
countb = 0
for i in range(n):
for j in range(m):
if targets[j] == arr[i]:
count = count + (i+1)
newarr = arr[::-1]
for i in range(n):
for j in range(m):
... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
arr = list(map(int,input().split()))
m = int(input())
targets = list(map(int,input().split()))
count = 0
countb = 0
for i in range(n):
for j in range(m):
if targets[j] == arr[i]:
count = count + (i+1)
newarr = arr[::-1]
for i in range(n):
for j in ran... | 0 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,698,226,288 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | def is_prime(n):
for i in range(2, n * n):
if i * i > n:
break
if n % i == 0:
return False
return True
n = int(input())
for i in range(1, 1001):
if (is_prime(n * i)):
print(i)
break | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
def is_prime(n):
for i in range(2, n * n):
if i * i > n:
break
if n % i == 0:
return False
return True
n = int(input())
for i in range(1, 1001):
if (is_prime(n * i)):
print(i)
break
``` | 0 | |
982 | A | Row | PROGRAMMING | 1,200 | [
"brute force",
"constructive algorithms"
] | null | null | You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule.
The seating is given as a string consisting of zeros and ones ($0$ means t... | The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs.
The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. | Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No".
You are allowed to print letters in whatever case you'd like (uppercase or lowercase). | [
"3\n101\n",
"4\n1011\n",
"5\n10001\n"
] | [
"Yes\n",
"No\n",
"No\n"
] | In sample case one the given seating is maximal.
In sample case two the person at chair three has a neighbour to the right.
In sample case three it is possible to seat yet another person into chair three. | 500 | [
{
"input": "3\n101",
"output": "Yes"
},
{
"input": "4\n1011",
"output": "No"
},
{
"input": "5\n10001",
"output": "No"
},
{
"input": "1\n0",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "100\n010100101010100101001001010100101010010... | 1,540,253,015 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | _, sa = input(), input()
print(
"No" if ("11" in sa or "000" in sa or sa.startswith("00") or sa.endswith("00")) and sa != "0" else "Yes")
| Title: Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold:
1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating th... | ```python
_, sa = input(), input()
print(
"No" if ("11" in sa or "000" in sa or sa.startswith("00") or sa.endswith("00")) and sa != "0" else "Yes")
``` | 0 | |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,436,889,016 | 2,416 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | #include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1000001;
int first[N] = {0};
int last[N] = {10000000};
int coun[N] = {0};
int arr[N];
int main()
{
int n, a;
cin >> n;
for(int i = 0; i < n... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
#include <iostream>
#include <iomanip>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1000001;
int first[N] = {0};
int last[N] = {10000000};
int coun[N] = {0};
int arr[N];
int main()
{
int n, a;
cin >> n;
for(int i ... | -1 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,689,794,780 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,k=map(int,input().split())
c=0
for i in range(n):
a=list(map(int,input()))
b=set(a)
if len(a)==len(b)==k+1 and all(0 <= x <= k for x in a):
c+=1
print(c)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n,k=map(int,input().split())
c=0
for i in range(n):
a=list(map(int,input()))
b=set(a)
if len(a)==len(b)==k+1 and all(0 <= x <= k for x in a):
c+=1
print(c)
``` | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,625,799,426 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 2,000 | 6,963,200 | n = int(input())
arr = list(map(int,input().rstrip().split()))
q = int(input())
find = list(map(int, input().rstrip().split()))
f = 0
e = 0
for i in range(q):
for j in range(n):
if find[i]==arr[j]:
f+=1
break
else:
f+=1
for i in range(q):
for j i... | Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
arr = list(map(int,input().rstrip().split()))
q = int(input())
find = list(map(int, input().rstrip().split()))
f = 0
e = 0
for i in range(q):
for j in range(n):
if find[i]==arr[j]:
f+=1
break
else:
f+=1
for i in range(q):
... | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,500,750,620 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 4,608,000 | T=input("")
T1=input("")
T2=""
for k in range(len(T)):
if(T[k]==T1[k]):
T2+="0"
else:
T2+="1"
print(T2)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
T=input("")
T1=input("")
T2=""
for k in range(len(T)):
if(T[k]==T1[k]):
T2+="0"
else:
T2+="1"
print(T2)
``` | 3.975917 |
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,505,387,594 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 307,200 | a = input();
b = len(a);
num_of_three = 0;
if (b % 2 == 0):
num_of_two = b / 2;
else:
num_of_three = 1;
num_of_two = (b - 3) / 2;
i = 0;
while (num_of_two != 0):
if ((num_of_three == 0)&(num_of_two ==1)):
print(a[i],end = '');
i+= 1;
print(a[i],end = '');
... | 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
a = input();
b = len(a);
num_of_three = 0;
if (b % 2 == 0):
num_of_two = b / 2;
else:
num_of_three = 1;
num_of_two = (b - 3) / 2;
i = 0;
while (num_of_two != 0):
if ((num_of_three == 0)&(num_of_two ==1)):
print(a[i],end = '');
i+= 1;
print(a[i],end =... | -1 |
203 | B | Game on Paper | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.
He took a checkered white square piece of paper, consisting of *n*<=×<=*n* cells. After that, he started to paint the white cells black one after the other. In total he painted *m* different cells ... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*m*<=≤<=*min*(*n*·*n*,<=105)) — the size of the squared piece of paper and the number of moves, correspondingly.
Then, *m* lines contain the description of the moves. The *i*-th line contains two integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*... | On a single line print the answer to the problem — the minimum number of the move after which the piece of paper has a black square with side 3. If no such move exists, print -1. | [
"4 11\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n3 3\n4 1\n",
"4 12\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n4 2\n4 1\n3 1\n"
] | [
"10\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 11\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n3 3\n4 1",
"output": "10"
},
{
"input": "4 12\n1 1\n1 2\n1 3\n2 2\n2 3\n1 4\n2 4\n3 4\n3 2\n4 2\n4 1\n3 1",
"output": "-1"
},
{
"input": "3 1\n1 3",
"output": "-1"
},
{
"input": "3 8\n1 3\n3 3\n2 2\n3 2\n1 1\n1 2\... | 1,571,223,350 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 1,964 | 4,812,800 | import math
from sys import stdin
from math import ceil
import sys
if __name__ == '__main__':
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
moves = [[0] * (n + 4) for _ in range(n + 4)]
for i in range(m):
listOfMoves = list(map(int, input().split()))
... | Title: Game on Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game.
He took a checkered white square piece of paper, consisting of *n*<=×<=*n* cells. After that, he s... | ```python
import math
from sys import stdin
from math import ceil
import sys
if __name__ == '__main__':
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
moves = [[0] * (n + 4) for _ in range(n + 4)]
for i in range(m):
listOfMoves = list(map(int, input().spl... | 3 | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,514,831,701 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 5,529,600 | import sys
stack = []
bracketType = {
'[': (0, ']'),
'(': (0, ')'),
'<': (0, '>'),
'{': (0, '}'),
']': (1,),
')': (1,),
'>': (1,),
'}': (1,)
}
res = 0
while True:
bracket = sys.stdin.read(1)
if bracketType.get(bracket) == None:
break
elif bracketType.get(bracket)[0] == 0:
stack.app... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
import sys
stack = []
bracketType = {
'[': (0, ']'),
'(': (0, ')'),
'<': (0, '>'),
'{': (0, '}'),
']': (1,),
')': (1,),
'>': (1,),
'}': (1,)
}
res = 0
while True:
bracket = sys.stdin.read(1)
if bracketType.get(bracket) == None:
break
elif bracketType.get(bracket)[0] == 0:
... | 0 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,698,063,354 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 93 | 1,331,200 | # trees = [int(x) for x in input().split()]
def make_tri(a,ind):
ind2 = a[ind]
ind3 = a[ind2]
if a[ind3] ==ind:
# print(a)
# print(ind,ind2,ind3)
return True
else:
return False
n = int(input())
a= [int(x)-1 for x in input().split()]
tri = False
for ind in range(len(a)):
... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
# trees = [int(x) for x in input().split()]
def make_tri(a,ind):
ind2 = a[ind]
ind3 = a[ind2]
if a[ind3] ==ind:
# print(a)
# print(ind,ind2,ind3)
return True
else:
return False
n = int(input())
a= [int(x)-1 for x in input().split()]
tri = False
for ind in range(... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,631,500,380 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 218 | 20,172,800 | import math
a,b,n=map(int,input().split())
temp,res=math.gcd(a,n),False
while n>temp:
n-=temp
temp=math.gcd(b,n) if not res else math.gcd(a,n)
res=not res
print(1 if res else 0)
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
a,b,n=map(int,input().split())
temp,res=math.gcd(a,n),False
while n>temp:
n-=temp
temp=math.gcd(b,n) if not res else math.gcd(a,n)
res=not res
print(1 if res else 0)
``` | 3 | |
147 | A | Punctuation | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to add spaces to the text by the following rules:
- if there is no punctuation mark between two word... | The input data contains of a single non-empty line — the text whose length is no more than 10000 characters. | Print the text, edited according to the rules. In this problem you should follow the output format very strictly. For example, extra space at the end of the output line is considered as wrong answer. Note that a newline character at the end of the line doesn't matter. | [
"galileo galilei was an italian physicist ,mathematician,astronomer\n",
"galileo was born in pisa\n"
] | [
"galileo galilei was an italian physicist, mathematician, astronomer\n",
"galileo was born in pisa\n"
] | none | 500 | [
{
"input": "galileo galilei was an italian physicist ,mathematician,astronomer",
"output": "galileo galilei was an italian physicist, mathematician, astronomer"
},
{
"input": "galileo was born in pisa",
"output": "galileo was born in pisa"
},
{
"input": "jkhksdfhsdfsf",
"outpu... | 1,600,230,066 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 218 | 307,200 | s = input().split()
punc = [".", ",", "!", "?"]
com_ind = [(x, y) for x, row in enumerate(s) for y, col in enumerate(row) if(col in punc)]
com_ind.sort(reverse = True, key = lambda x: x[1])
for (x, y) in com_ind:
if(y != len(s[x])-1):
s[x] = s[x][:y+1]+" "+s[x][y+1:]
for i in range(len(s)):
if(i < l... | Title: Punctuation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to ad... | ```python
s = input().split()
punc = [".", ",", "!", "?"]
com_ind = [(x, y) for x, row in enumerate(s) for y, col in enumerate(row) if(col in punc)]
com_ind.sort(reverse = True, key = lambda x: x[1])
for (x, y) in com_ind:
if(y != len(s[x])-1):
s[x] = s[x][:y+1]+" "+s[x][y+1:]
for i in range(len(s)):
... | 3 | |
900 | D | Unusual Sequences | PROGRAMMING | 2,000 | [
"bitmasks",
"combinatorics",
"dp",
"math",
"number theory"
] | null | null | Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answer modulo 109<=+<=7.
*gcd* here means the [greatest common divisor](https://en.wikipedia.org/wiki/Great... | The only line contains two positive integers *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=109). | Print the number of such sequences modulo 109<=+<=7. | [
"3 9\n",
"5 8\n"
] | [
"3\n",
"0\n"
] | There are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).
There are no suitable sequences in the second test. | 2,000 | [
{
"input": "3 9",
"output": "3"
},
{
"input": "5 8",
"output": "0"
},
{
"input": "2 12",
"output": "27"
},
{
"input": "1 8",
"output": "120"
},
{
"input": "1 9",
"output": "252"
},
{
"input": "1000000000 1000000000",
"output": "1"
},
{
"inp... | 1,513,240,998 | 2,298 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | from sympy import mobius, divisors
def a(n): return sum([mobius(n/d)*2**(d - 1) for d in divisors(n)])
x, y = map(int, input().split())
if (x % y != 0):
print(0)
quit()
n = x / y
print(a(n)) | Title: Unusual Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Count the number of distinct sequences *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*) consisting of positive integers such that *gcd*(*a*1,<=*a*2,<=...,<=*a**n*)<==<=*x* and . As this number could be large, print the answe... | ```python
from sympy import mobius, divisors
def a(n): return sum([mobius(n/d)*2**(d - 1) for d in divisors(n)])
x, y = map(int, input().split())
if (x % y != 0):
print(0)
quit()
n = x / y
print(a(n))
``` | -1 | |
386 | C | Diverse Substrings | PROGRAMMING | 2,000 | [
"dp",
"strings",
"two pointers"
] | null | null | String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3.
Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to ... | The input consists of a single line containing *s*. It contains only lowercase Latin letters, the length of *s* is from 1 to 3·105. | Print to the first line the value *d*(*s*). Print sequence *t*1,<=*t*2,<=...,<=*t**d*(*s*) to the following lines, where *t**i* is the number of substrings of *s* having diversity of exactly *i*. | [
"abca\n",
"aabacaabbad\n"
] | [
"3\n4\n3\n3\n",
"4\n14\n19\n28\n5\n"
] | Consider the first example.
We denote by *s*(*i*, *j*) a substring of "abca" with the indices in the segment [*i*, *j*].
- *s*(1, 1) = "a", *d*("a") = 1 - *s*(2, 2) = "b", *d*("b") = 1 - *s*(3, 3) = "c", *d*("c") = 1 - *s*(4, 4) = "a", *d*("a") = 1 - *s*(1, 2) = "ab", *d*("ab") = 2 - *s*(2, 3) = "bc", *d*... | 1,500 | [
{
"input": "abca",
"output": "3\n4\n3\n3"
},
{
"input": "aabacaabbad",
"output": "4\n14\n19\n28\n5"
},
{
"input": "a",
"output": "1\n1"
},
{
"input": "cabaccbcaa",
"output": "3\n12\n13\n30"
},
{
"input": "ccabaccbbb",
"output": "3\n15\n13\n27"
},
{
"in... | 1,695,129,592 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 307,200 | s = input()
dist = set(s)
print(len(dist))
resDict = dict()
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
curDist = len(set(s[i:j]))
if curDist in resDict:
resDict[curDist] += 1
else:
resDict[curDist] = 1
for val in sorted(resDict):
... | Title: Diverse Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3.
Given a string *s*, consisting of lowerca... | ```python
s = input()
dist = set(s)
print(len(dist))
resDict = dict()
for i in range(len(s)):
for j in range(i + 1, len(s) + 1):
curDist = len(set(s[i:j]))
if curDist in resDict:
resDict[curDist] += 1
else:
resDict[curDist] = 1
for val in sorted(resDi... | 0 | |
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,473,687,434 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 436 | 8,192,000 | n = int(input())
numbers = [int(x) for x in input().split()]
ans = [0] * n
ans[n-1] = numbers[n-1]
for i in reversed(range(n-1)):
ans[i] = numbers[i+1] + numbers[i]
for an in ans:
print(an, end=" ")
print() | 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())
numbers = [int(x) for x in input().split()]
ans = [0] * n
ans[n-1] = numbers[n-1]
for i in reversed(range(n-1)):
ans[i] = numbers[i+1] + numbers[i]
for an in ans:
print(an, end=" ")
print()
``` | 3 | |
361 | A | Levko and Table | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. | The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). | Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value.
If there are multiple suitable tables, you are allowed to print any of them. | [
"2 4\n",
"4 7\n"
] | [
"1 3\n3 1\n",
"2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n"
] | In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.
In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table... | 500 | [
{
"input": "2 4",
"output": "4 0 \n0 4 "
},
{
"input": "4 7",
"output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 "
},
{
"input": "1 8",
"output": "8 "
},
{
"input": "9 3",
"output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0... | 1,474,976,726 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 77 | 0 | if __name__ == '__main__':
n, k = str(input()).split()
n = int(n)
k = int(k)
for i in range(n):
line = list()
for j in range(i):
line.append('0')
line.append(str(k))
for j in range(i + 1, n):
line.append('0')
print(' '.join(line)... | Title: Levko and Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*.
Unfortun... | ```python
if __name__ == '__main__':
n, k = str(input()).split()
n = int(n)
k = int(k)
for i in range(n):
line = list()
for j in range(i):
line.append('0')
line.append(str(k))
for j in range(i + 1, n):
line.append('0')
print(' '.... | 3 | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,603,027,682 | 482 | Python 3 | OK | TESTS | 34 | 483 | 0 | import math
r, d = map(int, input().split())
n = int(input())
s = 0
for i in range(0, n):
x, y, r1 = map(int, input().split())
if math.sqrt(x**2 + y**2) >= r-d+r1 and math.sqrt(x**2 + y**2) + r1 <= r:
s+=1
print(s) | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
import math
r, d = map(int, input().split())
n = int(input())
s = 0
for i in range(0, n):
x, y, r1 = map(int, input().split())
if math.sqrt(x**2 + y**2) >= r-d+r1 and math.sqrt(x**2 + y**2) + r1 <= r:
s+=1
print(s)
``` | 3 | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,478,320,124 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | bangun = input().split(":")
lama_tidur = input().split(":")
menit = int(bangun[1]) - int(lama_tidur[1])
jam = int(bangun[0]) - int(lama_tidur[0])
if menit < 0:
menit += 60
jam -= 1
if jam < 0:
jam += 24
A = str(menit)
B = str(jam)
if len(A) < 2:
A = "0"+A
if len(B)<2:
B = "0"+B
print(B+":"+A)
... | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
bangun = input().split(":")
lama_tidur = input().split(":")
menit = int(bangun[1]) - int(lama_tidur[1])
jam = int(bangun[0]) - int(lama_tidur[0])
if menit < 0:
menit += 60
jam -= 1
if jam < 0:
jam += 24
A = str(menit)
B = str(jam)
if len(A) < 2:
A = "0"+A
if len(B)<2:
B = "0"+B
print(B+":"... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,668,341,708 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | from math import ceil
n, m, x = input().split(' ')
result = ceil((int(m) * int(n)) / (int(x) * int(x)))
if result % 2: result += 1
print(result) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
from math import ceil
n, m, x = input().split(' ')
result = ceil((int(m) * int(n)) / (int(x) * int(x)))
if result % 2: result += 1
print(result)
``` | 0 |
676 | C | Vasya and String | PROGRAMMING | 1,500 | [
"binary search",
"dp",
"strings",
"two pointers"
] | null | null | High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.
Vasya can change no more than *k* characters of the original strin... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change.
The second line contains the string, consisting of letters 'a' and 'b' only. | Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. | [
"4 2\nabba\n",
"8 1\naabaabaa\n"
] | [
"4\n",
"5\n"
] | In the first sample, Vasya can obtain both strings "aaaa" and "bbbb".
In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa". | 1,500 | [
{
"input": "4 2\nabba",
"output": "4"
},
{
"input": "8 1\naabaabaa",
"output": "5"
},
{
"input": "1 0\na",
"output": "1"
},
{
"input": "1 1\nb",
"output": "1"
},
{
"input": "1 0\nb",
"output": "1"
},
{
"input": "1 1\na",
"output": "1"
},
{
... | 1,578,052,603 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 307,200 | n, k = map(int, input().split())
s = input().rstrip()
a = [0]
b = [0]
for ch in s:
a.append(a[-1] + (ch == 'a'))
b.append(b[-1] + (ch == 'b'))
def maxSize(a):
ret = 0
first = [-1] * n
for i, val in enumerate(a):
if first[val] == -1:
first[val] = i
if val ... | Title: Vasya and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ... | ```python
n, k = map(int, input().split())
s = input().rstrip()
a = [0]
b = [0]
for ch in s:
a.append(a[-1] + (ch == 'a'))
b.append(b[-1] + (ch == 'b'))
def maxSize(a):
ret = 0
first = [-1] * n
for i, val in enumerate(a):
if first[val] == -1:
first[val] = i
... | -1 | |
633 | C | Spy Syndrome 2 | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the ciphe... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered wh... | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | 1,500 | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaa... | 1,456,511,036 | 4,136 | Python 3 | RUNTIME_ERROR | PRETESTS | 2 | 62 | 204,800 | # You lost the game.
n = int(input())
ch = str(input())
m = int(input())
T = [str(input()) for _ in range(m)]
def envers(mot):
resultat = ""
for lettre in mot:
resultat = lettre+resultat
return resultat
def minus(mot):
A = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r = ""
f... | Title: Spy Syndrome 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observati... | ```python
# You lost the game.
n = int(input())
ch = str(input())
m = int(input())
T = [str(input()) for _ in range(m)]
def envers(mot):
resultat = ""
for lettre in mot:
resultat = lettre+resultat
return resultat
def minus(mot):
A = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
r ... | -1 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,621,175,777 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 218 | 0 | m,n=input().split()
m=int(m)
n=int(n)
print(int((m*n)/2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=input().split()
m=int(m)
n=int(n)
print(int((m*n)/2))
``` | 3.9455 |
242 | A | Heads or Tails | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by t... | The single line contains four integers *x*,<=*y*,<=*a*,<=*b* (1<=≤<=*a*<=≤<=*x*<=≤<=100,<=1<=≤<=*b*<=≤<=*y*<=≤<=100). The numbers on the line are separated by a space. | In the first line print integer *n* — the number of possible outcomes of the game. Then on *n* lines print the outcomes. On the *i*-th line print a space-separated pair of integers *c**i*, *d**i* — the number of heads Vasya and Petya got in the *i*-th outcome of the game, correspondingly. Print pairs of integers (*c**i... | [
"3 2 1 1\n",
"2 4 2 2\n"
] | [
"3\n2 1\n3 1\n3 2\n",
"0\n"
] | none | 500 | [
{
"input": "3 2 1 1",
"output": "3\n2 1\n3 1\n3 2"
},
{
"input": "2 4 2 2",
"output": "0"
},
{
"input": "1 1 1 1",
"output": "0"
},
{
"input": "4 5 2 3",
"output": "1\n4 3"
},
{
"input": "10 6 3 4",
"output": "15\n5 4\n6 4\n6 5\n7 4\n7 5\n7 6\n8 4\n8 5\n8 6\n9... | 1,603,410,468 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | x,y,a,b=map(int,input().split())
c=x-a+x-b
print(c)
for i in range(c):
if(a<x ):
a+=1
print(a,b)
else:
if(b<a-1):
b+=1
print(a,b)
| Title: Heads or Tails
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin *x* times, then Petya tosses a coin *y* times. If the tossing player gets head, he score... | ```python
x,y,a,b=map(int,input().split())
c=x-a+x-b
print(c)
for i in range(c):
if(a<x ):
a+=1
print(a,b)
else:
if(b<a-1):
b+=1
print(a,b)
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,696,919,441 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import math
m=int(input())
n=int(input())
a=in(input())
FlagStoneSize=math.ceil(m/a)+math.ceil(n/a)
print(FlagStoneSize) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
m=int(input())
n=int(input())
a=in(input())
FlagStoneSize=math.ceil(m/a)+math.ceil(n/a)
print(FlagStoneSize)
``` | -1 |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,564,082,838 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | import math
r, x1, y1, x2, y2 = map(int, input().split())
d = 2 * r
dist = math.sqrt((x2-x1)**2 + (y2-y1)**2)
if dist % d == 0:
print(int(dist / d))
else:
print(int(dist / d) + 1) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
r, x1, y1, x2, y2 = map(int, input().split())
d = 2 * r
dist = math.sqrt((x2-x1)**2 + (y2-y1)**2)
if dist % d == 0:
print(int(dist / d))
else:
print(int(dist / d) + 1)
``` | 3 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,591,201,725 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 109 | 307,200 | n, a = map(int, input().split())
a -= 1
c = list(map(int, input().split()))
ans = 0
if c[a] == 1:
ans += 1
for i in range(1,n):
if a-i >= 0 and c[a-i] == 1 and a+i<=n-1 and c[a+i] == 1:
ans += 2
elif a-i < 0 and a+i<=n-1 and c[a+i] == 1:
ans += 1
elif a+i>n-1 and a-i >= 0 an... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
n, a = map(int, input().split())
a -= 1
c = list(map(int, input().split()))
ans = 0
if c[a] == 1:
ans += 1
for i in range(1,n):
if a-i >= 0 and c[a-i] == 1 and a+i<=n-1 and c[a+i] == 1:
ans += 2
elif a-i < 0 and a+i<=n-1 and c[a+i] == 1:
ans += 1
elif a+i>n-1 and a... | 3 | |
18 | A | Triangle | PROGRAMMING | 1,500 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined them with segments of straight lines, then he showed the triangle t... | The first input line contains 6 space-separated integers *x*1,<=*y*1,<=*x*2,<=*y*2,<=*x*3,<=*y*3 — coordinates of the triangle's vertices. All the coordinates are integer and don't exceed 100 in absolute value. It's guaranteed that the triangle is nondegenerate, i.e. its total area is not zero. | If the given triangle is right-angled, output RIGHT, if it is almost right-angled, output ALMOST, and if it is neither of these, output NEITHER. | [
"0 0 2 0 0 1\n",
"2 3 4 5 6 6\n",
"-1 0 2 0 0 1\n"
] | [
"RIGHT\n",
"NEITHER\n",
"ALMOST\n"
] | none | 0 | [
{
"input": "0 0 2 0 0 1",
"output": "RIGHT"
},
{
"input": "2 3 4 5 6 6",
"output": "NEITHER"
},
{
"input": "-1 0 2 0 0 1",
"output": "ALMOST"
},
{
"input": "27 74 85 23 100 99",
"output": "NEITHER"
},
{
"input": "-97 -19 17 62 30 -76",
"output": "NEITHER"
},... | 1,687,159,558 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 29 | 124 | 0 | def checkRightAngled(X1, Y1, X2,Y2, X3, Y3):
# Calculate the sides
A = (int(pow((X2 - X1), 2)) +
int(pow((Y2 - Y1), 2)))
B = (int(pow((X3 - X2), 2)) +
int(pow((Y3 - Y2), 2)))
C = (int(pow((X3 - X1), 2)) +
int(pow((Y3 - Y1), 2)))
# Check Pythagoras Formula
... | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer co... | ```python
def checkRightAngled(X1, Y1, X2,Y2, X3, Y3):
# Calculate the sides
A = (int(pow((X2 - X1), 2)) +
int(pow((Y2 - Y1), 2)))
B = (int(pow((X3 - X2), 2)) +
int(pow((Y3 - Y2), 2)))
C = (int(pow((X3 - X1), 2)) +
int(pow((Y3 - Y1), 2)))
# Check Pythagoras ... | 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,660,588,040 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 124 | 0 | n = int(input())
arr = input().split()
five = arr.count('5')
zero = arr.count('0')
five = five//9
if zero==0:
print(-1)
elif five==0:
print(0)
else:
print('5'*(five*9)+'0'*zero) | 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())
arr = input().split()
five = arr.count('5')
zero = arr.count('0')
five = five//9
if zero==0:
print(-1)
elif five==0:
print(0)
else:
print('5'*(five*9)+'0'*zero)
``` | 3 | |
638 | D | Three-dimensional Turtle Super Computer | PROGRAMMING | 1,800 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×<=1<=×<=1 cells, each cell contains exactly one CPU. Thus, each CPU can be simultaneously identified as a group of three numbe... | The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100) — the dimensions of the Super Computer.
Then *n* blocks follow, describing the current state of the processes. The blocks correspond to the layers of the Super Computer in the order from 1 to *n*. Each block consists of *m* lines,... | Print a single integer — the number of critical CPUs, that is, such that turning only this CPU off will disrupt some control. | [
"2 2 3\n000\n000\n\n111\n111\n",
"3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n",
"1 1 10\n0101010101\n"
] | [
"2\n",
"19\n",
"0\n"
] | In the first sample the whole first layer of CPUs is malfunctional. In the second layer when CPU (2, 1, 2) turns off, it disrupts the control by CPU (2, 1, 3) over CPU (2, 1, 1), and when CPU (2, 2, 2) is turned off, it disrupts the control over CPU (2, 2, 3) by CPU (2, 2, 1).
In the second sample all processors excep... | 2,000 | [
{
"input": "2 2 3\n000\n000\n\n111\n111",
"output": "2"
},
{
"input": "3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111",
"output": "19"
},
{
"input": "1 1 10\n0101010101",
"output": "0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 1 1\n1",
"... | 1,595,591,268 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 202 | 22,323,200 | def put():
return map(int, input().split())
def safe(x,y,z):
return x>=0 and y>=0 and z>=0 and x<n and y<m and z<p
def check(x,y,z):
if mat[x][y][z]=='0': return 0
tmp = [(0,0,1),(0,1,0),(1,0,0)]
move = [-1,1]
ori = [x,y,z]
cpy = ori.copy()
for i in range(3):
an... | Title: Three-dimensional Turtle Super Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A super computer has been built in the Turtle Academy of Sciences. The computer consists of *n*·*m*·*k* CPUs. The architecture was the paralellepiped of size *n*<=×<=*m*<=×<=*k*, split into 1<=×... | ```python
def put():
return map(int, input().split())
def safe(x,y,z):
return x>=0 and y>=0 and z>=0 and x<n and y<m and z<p
def check(x,y,z):
if mat[x][y][z]=='0': return 0
tmp = [(0,0,1),(0,1,0),(1,0,0)]
move = [-1,1]
ori = [x,y,z]
cpy = ori.copy()
for i in range(3):
... | -1 | |
195 | C | Try and Catch | PROGRAMMING | 1,800 | [
"expression parsing",
"implementation"
] | null | null | Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.
The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks:
1. The try oper... | The first line contains a single integer: *n* (1<=≤<=*n*<=≤<=105) the number of lines in the program. Next *n* lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces.
The program contains only operat... | Print the message the screen will show after the given program is executed. | [
"8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")\n",
"8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch(BE, \"BE in line 5\") \ncatch(AE,\"AE somewhere\")\n",
"8\ntry\... | [
"AE somewhere\n",
"AE in line 3\n",
"Unhandled Exception\n"
] | In the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(A... | 1,500 | [
{
"input": "8\ntry\n try\n throw ( AE ) \n catch ( BE, \"BE in line 3\")\n\n try\n catch(AE, \"AE in line 5\") \ncatch(AE,\"AE somewhere\")",
"output": "AE somewhere"
},
{
"input": "8\ntry\n try\n throw ( AE ) \n catch ( AE, \"AE in line 3\")\n\n try\n catch(BE,... | 1,694,082,029 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 37 | 1,278 | 10,240,000 | n = (int)(input())
stack = []
stack_len = 0
found = False
for _ in range(n) :
line = input()
if "try" in line :
stack.append(not found)
stack_len += 1
elif "throw" in line :
temp = line.split('throw')[1]
ex = ""
for ch in temp :
if ch == '(' o... | Title: Try and Catch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.
The exceptions are... | ```python
n = (int)(input())
stack = []
stack_len = 0
found = False
for _ in range(n) :
line = input()
if "try" in line :
stack.append(not found)
stack_len += 1
elif "throw" in line :
temp = line.split('throw')[1]
ex = ""
for ch in temp :
if c... | 0 | |
792 | D | Paths in a Complete Binary Tree | PROGRAMMING | 1,900 | [
"bitmasks",
"trees"
] | null | null | *T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So *n* is a number such t... | The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=1018, *q*<=≥<=1). *n* is such that *n*<=+<=1 is a power of 2.
The next 2*q* lines represent queries; each query consists of two consecutive lines. The first of these two lines contains *u**i* (1<=≤<=*u**i*<=≤<=*n*), the second contains non-empty st... | Print *q* numbers, *i*-th number must be the answer to the *i*-th query. | [
"15 2\n4\nUURL\n8\nLRLLLLLLLL\n"
] | [
"10\n5\n"
] | none | 0 | [
{
"input": "15 2\n4\nUURL\n8\nLRLLLLLLLL",
"output": "10\n5"
},
{
"input": "1 1\n1\nL",
"output": "1"
},
{
"input": "1 1\n1\nR",
"output": "1"
},
{
"input": "1 1\n1\nU",
"output": "1"
},
{
"input": "1 10\n1\nURLRLULUR\n1\nLRRRURULULL\n1\nLURURRUUUU\n1\nRRULLLRRUL\... | 1,559,168,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 409,600 | from collections import deque
root,q = map(int,input().split(' '))
# Problems
# We can't search for siblings When we don't have One
# We can't get the parent of the root
# I would Use deque(from collection) for fast pop,append operation...
# This func for getting The start item path
def find_path(root,x,deep,path):... | Title: Paths in a Complete Binary Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two ch... | ```python
from collections import deque
root,q = map(int,input().split(' '))
# Problems
# We can't search for siblings When we don't have One
# We can't get the parent of the root
# I would Use deque(from collection) for fast pop,append operation...
# This func for getting The start item path
def find_path(root,x,d... | 0 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,572,973,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | a = list(map(int, input().split()))
c = 0
b = a[0] + a[1]
if min(a) % 2 == 0:
c = b - 3
elif min(a) % 2 != 0:
c = b - 2
print(c)
| Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a = list(map(int, input().split()))
c = 0
b = a[0] + a[1]
if min(a) % 2 == 0:
c = b - 3
elif min(a) % 2 != 0:
c = b - 2
print(c)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,661,116,008 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | m, n = map(int, input().split())
if m % 2 == 0 and n % 2 == 0:
print((m//2)*n)
elif m % 2 == 0 and n % 2 != 0:
print((m//2)*n)
elif m % 2 != 0 and n % 2 != 0:
print(((m//2)*n)+n//2)
elif m % 2 != 0 and n % 2 == 0:
print(((m//2)*n)+n//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m, n = map(int, input().split())
if m % 2 == 0 and n % 2 == 0:
print((m//2)*n)
elif m % 2 == 0 and n % 2 != 0:
print((m//2)*n)
elif m % 2 != 0 and n % 2 != 0:
print(((m//2)*n)+n//2)
elif m % 2 != 0 and n % 2 == 0:
print(((m//2)*n)+n//2)
``` | 3.969 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,697,729,410 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n, h = [int(h) for h in input().split()]
x_values = []
for i in range(n):
x = list(map(int, input().split()))
x_values.extend(x)
a = 0
for i in range(len(x_values)):
if x_values[i] > h:
a = a + 1
print(a + n) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n, h = [int(h) for h in input().split()]
x_values = []
for i in range(n):
x = list(map(int, input().split()))
x_values.extend(x)
a = 0
for i in range(len(x_values)):
if x_values[i] > h:
a = a + 1
print(a + n)
``` | -1 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,560,356,785 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | n = list(map(int,input().split()))
l,r = n[0],n[1]
b = r-l
if b == 1:
print(-1)
elif b == 2 and l == 1:
print(1, 2, 3)
elif b == 2:
if l%2 == 0 :
print(l, l+1, l+2)
else:
print(-1)
else:
if l%2 == 0 :
print(l, l+1, l+2)
else:
print(l+1, l+2, l+3) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
n = list(map(int,input().split()))
l,r = n[0],n[1]
b = r-l
if b == 1:
print(-1)
elif b == 2 and l == 1:
print(1, 2, 3)
elif b == 2:
if l%2 == 0 :
print(l, l+1, l+2)
else:
print(-1)
else:
if l%2 == 0 :
print(l, l+1, l+2)
else:
print(l+1, l+2, l+3)
``` | 0 | |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,662,806,234 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 1,045 | 5,324,800 | n=1000
bhisop_board = [[0 for i in range(n)] for j in range(n)]
t = int(input())
for i in range(t):
x,y = map(int,input().split())
bhisop_board[x-1][y-1] = 1
total_attacks=0
for i in range(1,n):
curr_diag_bhisops_count=0
for j in range(i+1):
if bhisop_board[i-j][j]==1:
... | Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
n=1000
bhisop_board = [[0 for i in range(n)] for j in range(n)]
t = int(input())
for i in range(t):
x,y = map(int,input().split())
bhisop_board[x-1][y-1] = 1
total_attacks=0
for i in range(1,n):
curr_diag_bhisops_count=0
for j in range(i+1):
if bhisop_board[i-... | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integer — the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,544,209,478 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 109 | 0 | def olympiada(lst):
a = list()
if 0 not in lst:
return len(set(lst))
for elem in lst:
if elem != 0:
a.append(elem)
return len(set(a))
n = int(input())
b = [int(i) for i in input().split()]
print(olympiada(b))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
def olympiada(lst):
a = list()
if 0 not in lst:
return len(set(lst))
for elem in lst:
if elem != 0:
a.append(elem)
return len(set(a))
n = int(input())
b = [int(i) for i in input().split()]
print(olympiada(b))
``` | 3 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,572,869,068 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 0 | numWins = int(input().split(" ")[1])
numPlayers = input().split(" ")
player = int(numPlayers[0])
numPlayers.pop(0)
wins = 0
checker = int(numPlayers[0])
while wins < numWins:
initPlayer = int(numPlayers[0])
if player > initPlayer:
wins+=1
if wins == numWins:
print(player)... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
numWins = int(input().split(" ")[1])
numPlayers = input().split(" ")
player = int(numPlayers[0])
numPlayers.pop(0)
wins = 0
checker = int(numPlayers[0])
while wins < numWins:
initPlayer = int(numPlayers[0])
if player > initPlayer:
wins+=1
if wins == numWins:
pri... | 0 | |
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order... | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, som... | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
... | 1,617,878,352 | 2,147,483,647 | PyPy 3 | OK | TESTS | 150 | 124 | 1,433,600 | cases = int(input())
arr = []
while cases:
cases -= 1
a, b = map(int, input().split())
if a != b:
print("rated")
exit()
arr.append(a)
sor = sorted(arr, reverse=True)
if arr == sor:
print("maybe")
else:
print("unrated")
| Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number ... | ```python
cases = int(input())
arr = []
while cases:
cases -= 1
a, b = map(int, input().split())
if a != b:
print("rated")
exit()
arr.append(a)
sor = sorted(arr, reverse=True)
if arr == sor:
print("maybe")
else:
print("unrated")
``` | 3 | |
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,679,837,842 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 545 | 1,843,200 | import sys
sys.setrecursionlimit(3000)
def process_list(lst):
for i in range(len(lst)):
if lst[i] > 1:
x = lst[i]
lst.pop(i)
lst.insert(i, x // 2)
lst.insert(i + 1, x % 2)
lst.insert(i + 2, x // 2)
return process_list(lst)
return... | 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
import sys
sys.setrecursionlimit(3000)
def process_list(lst):
for i in range(len(lst)):
if lst[i] > 1:
x = lst[i]
lst.pop(i)
lst.insert(i, x // 2)
lst.insert(i + 1, x % 2)
lst.insert(i + 2, x // 2)
return process_list(lst)
... | -1 | |
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,568,135,523 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 13,516,800 | n = input()
li = list(map(int, input().split())); li2 = []; c = 0
for i in li:
if i in li2:
li2.remove(i)
else:
li2.append(i)
c = max(c, len(li2))
print(c) | 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 = input()
li = list(map(int, input().split())); li2 = []; c = 0
for i in li:
if i in li2:
li2.remove(i)
else:
li2.append(i)
c = max(c, len(li2))
print(c)
``` | 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,739,067 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | berland = input()
birland = input()
print((lambda: 'YES' if berland == birland[::-1] else '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
berland = input()
birland = input()
print((lambda: 'YES' if berland == birland[::-1] else 'NO')())
``` | 3.977 |
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,626,459,058 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,656,000 | x = str(input())
y = str(input())
reversed(x.begin(), x.end())
if x == y:
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 = str(input())
y = str(input())
reversed(x.begin(), x.end())
if x == y:
print("YES")
else: print("NO")
``` | -1 |
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other ... | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. 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 ... | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.pn... | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
... | 1,645,755,076 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 31 | 0 | a,b,c,d = list(map(int,input().split()))
e = abs(a-b)
f = abs(c+d)
print(e/f) | Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a strai... | ```python
a,b,c,d = list(map(int,input().split()))
e = abs(a-b)
f = abs(c+d)
print(e/f)
``` | 3 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,500,225,167 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 4,608,000 | n,m=map(int,input().split(' '))
i=1;k=0
while(i<=n):
j=1
while(j<=m):
if((i+j)%5==0):
k=k+1
j=j+1
i=i+1
print(k)
| Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n,m=map(int,input().split(' '))
i=1;k=0
while(i<=n):
j=1
while(j<=m):
if((i+j)%5==0):
k=k+1
j=j+1
i=i+1
print(k)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands *n* and 1. The center of each island contains an identical pedestal, and all but... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=200<=000) — the total number of islands.
The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=*n*<=-<=1) — the statue currently placed on the *i*-th island. If *a**i*<==<=0, then the island has no statue. It is guaranteed that the *a... | Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise. | [
"3\n1 0 2\n2 0 1\n",
"2\n1 0\n0 1\n",
"4\n1 2 3 0\n0 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample, the islanders can first move statue 1 from island 1 to island 2, then move statue 2 from island 3 to island 1, and finally move statue 1 from island 2 to island 3.
In the second sample, the islanders can simply move statue 1 from island 1 to island 2.
In the third sample, no sequence of movements... | 0 | [
{
"input": "3\n1 0 2\n2 0 1",
"output": "YES"
},
{
"input": "2\n1 0\n0 1",
"output": "YES"
},
{
"input": "4\n1 2 3 0\n0 3 2 1",
"output": "NO"
},
{
"input": "9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7",
"output": "NO"
},
{
"input": "4\n2 3 1 0\n2 0 1 3",
"output"... | 1,467,726,222 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 514 | 17,203,200 | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
A, B = [], []
i = a.index(1)
while len(A) < n:
if a[i]: A.append(a[i])
i = (i + 1) % n
i = b.index(1)
while len(B) < n:
if b[i]: B.append(b[i])
i = (i + 1) % n
ans = 'YES' if A == B else 'NO'
print(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connect... | ```python
read = lambda: map(int, input().split())
n = int(input())
a = list(read())
b = list(read())
A, B = [], []
i = a.index(1)
while len(A) < n:
if a[i]: A.append(a[i])
i = (i + 1) % n
i = b.index(1)
while len(B) < n:
if b[i]: B.append(b[i])
i = (i + 1) % n
ans = 'YES' if A == B else 'N... | 3 | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,614,160,200 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 307,200 | n,m=map(int,input().split(" "))
arr=list(map(int,input().split(" ")))
sum1=sum(arr)
brr=arr.copy()
s=s1=i=j=0
k=n
while (n!=0 and i!=m):
if i==m:
i=i%m
s=s+arr[i]
arr[i]-=1
n=n-1
if max(arr)==arr[i]:
pass
else:
i=i+1
brr.sort()
while (k!=0 and j!=m):
... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m=map(int,input().split(" "))
arr=list(map(int,input().split(" ")))
sum1=sum(arr)
brr=arr.copy()
s=s1=i=j=0
k=n
while (n!=0 and i!=m):
if i==m:
i=i%m
s=s+arr[i]
arr[i]-=1
n=n-1
if max(arr)==arr[i]:
pass
else:
i=i+1
brr.sort()
while (k!=0 and j... | 0 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,698,635,198 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 6,041,600 | n = int(input())
myString = input()
myList=[]
for char in myString:
x = 10 -int(char)
myNewString=myString
ch=''
for newChar in myNewString:
myDigit=int(newChar)+x
if myDigit>=10:
myDigit=abs(myDigit-10)
ch+=str(myDigit)
myList.appe... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
n = int(input())
myString = input()
myList=[]
for char in myString:
x = 10 -int(char)
myNewString=myString
ch=''
for newChar in myNewString:
myDigit=int(newChar)+x
if myDigit>=10:
myDigit=abs(myDigit-10)
ch+=str(myDigit)
m... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,653,295,193 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | m,n,a=map(int,input().split())
s=((m+a-1)/a)*((n+a-1)/a)
print(s) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
m,n,a=map(int,input().split())
s=((m+a-1)/a)*((n+a-1)/a)
print(s)
``` | 0 |
44 | A | Indian Summer | PROGRAMMING | 900 | [
"implementation"
] | A. Indian Summer | 2 | 256 | Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of leaves Alyona has found. The next *n* lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no mor... | Output the single number — the number of Alyona's leaves. | [
"5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green\n",
"3\noak yellow\noak yellow\noak yellow\n"
] | [
"4\n",
"1\n"
] | none | 0 | [
{
"input": "5\nbirch yellow\nmaple red\nbirch yellow\nmaple yellow\nmaple green",
"output": "4"
},
{
"input": "3\noak yellow\noak yellow\noak yellow",
"output": "1"
},
{
"input": "5\nxbnbkzn hp\nkaqkl vrgzbvqstu\nj aqidx\nhos gyul\nwefxmh tygpluae",
"output": "5"
},
{
"input"... | 1,671,872,997 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 154 | 0 | n_1=int(input())
arr_1=[]
for i in range(n_1):
s=input()
arr_1.append(s)
set_1=set(arr_1)
print(len(set_1))
| Title: Indian Summer
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the specie... | ```python
n_1=int(input())
arr_1=[]
for i in range(n_1):
s=input()
arr_1.append(s)
set_1=set(arr_1)
print(len(set_1))
``` | 3.9615 |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,671,082,257 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 468 | 0 | z=int(input())
y=list(map(int,input().split()))
arr=[]
for a in y:
count=0
for b in y:
if a<b:
count+=1
arr.append(count+1)
print(*arr)
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
z=int(input())
y=list(map(int,input().split()))
arr=[]
for a in y:
count=0
for b in y:
if a<b:
count+=1
arr.append(count+1)
print(*arr)
``` | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,699,459,839 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | import math
distance = int(input())
movement_counter = 0
while distance != 0:
if distance >= 5:
movement_counter += math.floor(distance / 5)
distance %= 5
else:
movement_counter += 1
distance = 0
print(movement_counter) | 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
import math
distance = int(input())
movement_counter = 0
while distance != 0:
if distance >= 5:
movement_counter += math.floor(distance / 5)
distance %= 5
else:
movement_counter += 1
distance = 0
print(movement_counter)
``` | 3 | |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th... | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n... | 1,488,009,091 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 62 | 4,608,000 | n=int(input())%6
x=int(input())
for i in range(n,0,-1):
if i%2 == 1 and x < 2:
x = 1 - x
elif i%2 == 0 and x > 0:
x = 3 - x
print(x)
| Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben... | ```python
n=int(input())%6
x=int(input())
for i in range(n,0,-1):
if i%2 == 1 and x < 2:
x = 1 - x
elif i%2 == 0 and x > 0:
x = 3 - x
print(x)
``` | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,675,683,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
for i in range (n):
word=input()
s=len(word)
if s>=10:
print(word[0]+str(s-2)+word[-1])
else:
print(word)
| 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):
word=input()
s=len(word)
if s>=10:
print(word[0]+str(s-2)+word[-1])
else:
print(word)
``` | 0 |
1,010 | A | Fly | PROGRAMMING | 1,500 | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted... | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct... | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu... | 500 | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2... | 1,613,119,053 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 57 | 280 | 10,240,000 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... | Title: Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ... | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # #... | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,588,238,760 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 108 | 307,200 | n=int(input())
arr = list(map(int, input().rstrip().split()))
arr.sort(reverse=True)
if n%2 == 1 :
print(arr[n//2])
else :
print(arr[n//2])
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n=int(input())
arr = list(map(int, input().rstrip().split()))
arr.sort(reverse=True)
if n%2 == 1 :
print(arr[n//2])
else :
print(arr[n//2])
``` | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The next line contains *n* uppercase letters without spaces — the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer – the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,409,066,090 | 4,490 | Python 3 | OK | TESTS | 41 | 202 | 1,228,800 | this=input()
hurry=this.split()
n=int(hurry[0])
k=int(hurry[1])
then=input()
thelist=[]
i=0
while i<len(then):
thelist.append(then[i])
i+=1
#print(thelist)
checked=[]
counts=[]
for item in thelist:
if item not in checked:
checked.append(item)
counts.append(thelist.count(ite... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
this=input()
hurry=this.split()
n=int(hurry[0])
k=int(hurry[1])
then=input()
thelist=[]
i=0
while i<len(then):
thelist.append(then[i])
i+=1
#print(thelist)
checked=[]
counts=[]
for item in thelist:
if item not in checked:
checked.append(item)
counts.append(thelist... | 3 | |
845 | G | Shortest Path Problem? | PROGRAMMING | 2,300 | [
"dfs and similar",
"graphs",
"math"
] | null | null | You are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). You have to find the minimum length of path betwe... | The first line contains two numbers *n* and *m* (1<=≤<=*n*<=≤<=100000, *n*<=-<=1<=≤<=*m*<=≤<=100000) — the number of vertices and the number of edges, respectively.
Then *m* lines follow, each line containing three integer numbers *x*, *y* and *w* (1<=≤<=*x*,<=*y*<=≤<=*n*, 0<=≤<=*w*<=≤<=108). These numbers denote an e... | Print one number — the minimum length of path between vertices 1 and *n*. | [
"3 3\n1 2 3\n1 3 2\n3 2 0\n",
"2 2\n1 1 3\n1 2 3\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 3\n1 2 3\n1 3 2\n3 2 0",
"output": "2"
},
{
"input": "2 2\n1 1 3\n1 2 3",
"output": "0"
},
{
"input": "10 20\n8 5 64\n5 6 48\n4 5 91\n10 1 2\n3 4 51\n8 2 74\n6 1 98\n3 10 24\n2 10 35\n8 7 52\n10 5 72\n5 9 25\n2 9 65\n7 4 69\n5 7 26\n7 2 44\n6 8 61\n3 5 43\n10 7 33\n4 2 28",... | 1,651,811,919 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 13 | 545 | 19,968,000 | from collections import deque
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(s), get_ro... | Title: Shortest Path Problem?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an undirected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, the... | ```python
from collections import deque
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
rs, rt = get_root(... | -1 | |
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,635,953,191 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 61 | 4,300,800 | n=int(input())
x=0
for i in range(1,n//2+1):
if n%i==0:
x=x+1
print(x) | 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())
x=0
for i in range(1,n//2+1):
if n%i==0:
x=x+1
print(x)
``` | 3 | |
858 | C | Did you mean... | PROGRAMMING | 1,500 | [
"dp",
"greedy",
"implementation"
] | 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 | 1,500 | [
{
"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,517,075,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 5,632,000 | s=input()
vowels=set(list('aeiou'))
chars=''
for i in range(len(s)):
if s[i] not in vowels:
if len(chars)==2:
if s[i] not in chars:
print(' ',end='')
chars=s[i]
else:
chars+=s[i]
else:
chars=''
print(s[i],end='') | Title: Did you mean...
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 (... | ```python
s=input()
vowels=set(list('aeiou'))
chars=''
for i in range(len(s)):
if s[i] not in vowels:
if len(chars)==2:
if s[i] not in chars:
print(' ',end='')
chars=s[i]
else:
chars+=s[i]
else:
chars=''
print(s[i],end='')
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,682,816,648 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 62 | 0 | n, m, a = map(int, input().split())
flag_ar = a*a
if (n <= a) & (m <= a):
print(1)
else:
r1 = n%a
r2 = m%a
if r1 == 0:
n = n+r1
else:
n = n + abs(a-r1)
if r2 == 0:
m = m+r2
else:
m = m+abs(a-r2)
thea_ar = n * m
print(int(round(t... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
flag_ar = a*a
if (n <= a) & (m <= a):
print(1)
else:
r1 = n%a
r2 = m%a
if r1 == 0:
n = n+r1
else:
n = n + abs(a-r1)
if r2 == 0:
m = m+r2
else:
m = m+abs(a-r2)
thea_ar = n * m
print(i... | 3.969 |
691 | A | Fashion in Berland | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with *n* buttons. Determine if it is fast... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of buttons on the jacket.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | [
"3\n1 0 1\n",
"3\n1 0 0\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 0 1",
"output": "YES"
},
{
"input": "3\n1 0 0",
"output": "NO"
},
{
"input": "3\n1 1 0",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n0 0 1",
"output": "NO"
},
{
"input": "3\n0 0 0",
"output": "NO"
}... | 1,538,515,266 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | n = int(input())
arr = list(map(int, input().split()))
fastenedCount = 0
for i in range(n):
if arr[i] == 1:
fastenedCount += 1
if n == 1:
if fastenedCount == 1:
print('YES')
else:
print('NO')
else:
if fastenedCount == n - 1:
print('YES')
else:
p... | Title: Fashion in Berland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened,... | ```python
n = int(input())
arr = list(map(int, input().split()))
fastenedCount = 0
for i in range(n):
if arr[i] == 1:
fastenedCount += 1
if n == 1:
if fastenedCount == 1:
print('YES')
else:
print('NO')
else:
if fastenedCount == n - 1:
print('YES')
else:
... | 3 | |
346 | B | Lucky Common Subsequence | PROGRAMMING | 2,000 | [
"dp",
"strings"
] | null | null | In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri... | The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters. | Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted.
If there is no valid common subsequence, output 0. | [
"AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n",
"AA\nA\nA\n"
] | [
"ORZ\n",
"0\n"
] | none | 1,000 | [
{
"input": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ",
"output": "ORZ"
},
{
"input": "AA\nA\nA",
"output": "0"
},
{
"input": "PWBJTZPQHA\nZJMKLWSROQ\nUQ",
"output": "WQ"
},
{
"input": "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCU... | 1,684,598,088 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 92 | 102,400 | def LCS(X, Y):
m = len(X)
n = len(Y)
c = [[0 for _ in range (n+1)]for _ in range(m+1)]
for i in range (1,m+1):
for j in range(1,n+1):
if X[i-1] == Y[j-1]:
c[i][j] = c[i-1][j-1] + 1
else:
c[i][j] = max(c[i-1][j], c[i][j-1])
r... | Title: Lucky Common Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequen... | ```python
def LCS(X, Y):
m = len(X)
n = len(Y)
c = [[0 for _ in range (n+1)]for _ in range(m+1)]
for i in range (1,m+1):
for j in range(1,n+1):
if X[i-1] == Y[j-1]:
c[i][j] = c[i-1][j-1] + 1
else:
c[i][j] = max(c[i-1][j], c[i][j-... | 0 | |
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"in... | 1,636,125,340 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 4,505,600 | a={}
s=input()
for c in s:
a[c]=a.get(c,0)+1
ans=0
for i in a.values():
ans+=i**2
print(ans) | Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbo... | ```python
a={}
s=input()
for c in s:
a[c]=a.get(c,0)+1
ans=0
for i in a.values():
ans+=i**2
print(ans)
``` | 3.960608 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,694,443,008 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | def mini(ts, li):
half = sum(li) / 2
rob = 0
n = 0
for i in li:
if rob > half:
break
else:
n += 1
rob += i
print(n)
ts = int(input())
li = list(map(int, input().split()))
mini(ts,li) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
def mini(ts, li):
half = sum(li) / 2
rob = 0
n = 0
for i in li:
if rob > half:
break
else:
n += 1
rob += i
print(n)
ts = int(input())
li = list(map(int, input().split()))
mini(ts,li)
``` | 0 | |
1,004 | C | Sonya and Robots | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi... | The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. | Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. | [
"5\n1 5 4 1 3\n",
"7\n1 2 1 1 1 3 2\n"
] | [
"9\n",
"7\n"
] | In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$).
In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$). | 1,500 | [
{
"input": "5\n1 5 4 1 3",
"output": "9"
},
{
"input": "7\n1 2 1 1 1 3 2",
"output": "7"
},
{
"input": "10\n2 2 4 4 3 1 1 2 3 2",
"output": "14"
},
{
"input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4",
"output": "20"
},
{
"input": "1\n1",
"output": "0"
}
] | 1,547,894,459 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 233 | 14,028,800 | n=int(input())
l=list(map(int,input().split()))
d={}
d1={-1}
s=set(l)
k=0
for x in l :
d[x]=d.get(x,0)+1
for x in l :
if x not in d1 :
if d[x]==1 :
s.remove(x)
k+=len(s)
d1.add(x)
d[x]-=1
else :
d[x]-=1
if d[x]==0 :
s.... | Title: Sonya and Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.
Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ... | ```python
n=int(input())
l=list(map(int,input().split()))
d={}
d1={-1}
s=set(l)
k=0
for x in l :
d[x]=d.get(x,0)+1
for x in l :
if x not in d1 :
if d[x]==1 :
s.remove(x)
k+=len(s)
d1.add(x)
d[x]-=1
else :
d[x]-=1
if d[x]==0 :
... | 3 | |
817 | B | Makes And The Product | PROGRAMMING | 1,500 | [
"combinatorics",
"implementation",
"math",
"sortings"
] | null | null | After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=<<=*j*<=<<=*k*), such that *a**i*·*a**j*·*a... | The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array. | Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible. | [
"4\n1 1 1 1\n",
"5\n1 3 2 3 4\n",
"6\n1 3 3 1 3 2\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first example Makes always chooses three ones out of four, and the number of ways to choose them is 4.
In the second example a triple of numbers (1, 2, 3) is chosen (numbers, not indices). Since there are two ways to choose an element 3, then the answer is 2.
In the third example a triple of numbers (1, 1, 2) ... | 0 | [
{
"input": "4\n1 1 1 1",
"output": "4"
},
{
"input": "5\n1 3 2 3 4",
"output": "2"
},
{
"input": "6\n1 3 3 1 3 2",
"output": "1"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": ... | 1,636,526,693 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 1,372 | 14,131,200 | from collections import Counter
import math
def main():
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
lst = list(set(nums))
lst.sort()
counter = Counter(nums)
if counter[lst[0]] >= 3:
print(comb(counter[lst[0]],3))
elif counter[lst[0]] == 2:
... | Title: Makes And The Product
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular questi... | ```python
from collections import Counter
import math
def main():
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
lst = list(set(nums))
lst.sort()
counter = Counter(nums)
if counter[lst[0]] >= 3:
print(comb(counter[lst[0]],3))
elif counter[lst[0]]... | 0 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,554,962,742 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 124 | 1,331,200 | n = int(int(input()))
parent = [0,0] + list(map(int, input().split()))
color = [0] + list(map(int, input().split()))
cnt = 1
for i in range(2,n+1,1):
if color[i] != color[parent[i]]:
cnt += 1
print(cnt) | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
n = int(int(input()))
parent = [0,0] + list(map(int, input().split()))
color = [0] + list(map(int, input().split()))
cnt = 1
for i in range(2,n+1,1):
if color[i] != color[parent[i]]:
cnt += 1
print(cnt)
``` | 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,694,335,541 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | p=int(input())
w=0
s=0
for i in range(p):
a,b=map(int,input().split())
w+=(-a+b)
if w>=s:
s=w
print(s) | 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
p=int(input())
w=0
s=0
for i in range(p):
a,b=map(int,input().split())
w+=(-a+b)
if w>=s:
s=w
print(s)
``` | 3 | |
606 | B | Testing Robots | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will be placed in cell (*x*0,<=*y*0) of a rectangular squared field of size *x*<=×<=*y*, after that a min... | The first line of the input contains four integers *x*, *y*, *x*0, *y*0 (1<=≤<=*x*,<=*y*<=≤<=500,<=1<=≤<=*x*0<=≤<=*x*,<=1<=≤<=*y*0<=≤<=*y*) — the sizes of the field and the starting coordinates of the robot. The coordinate axis *X* is directed downwards and axis *Y* is directed to the right.
The second line contains a... | Print the sequence consisting of (*length*(*s*)<=+<=1) numbers. On the *k*-th position, starting with zero, print the number of tests where the robot will run exactly *k* commands before it blows up. | [
"3 4 2 2\nUURDRDRL\n",
"2 2 2 2\nULD\n"
] | [
"1 1 0 1 1 1 1 0 6\n",
"1 1 1 1\n"
] | In the first sample, if we exclude the probable impact of the mines, the robot's route will look like that: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16bfda1e4f41cc00665c31f0a1d754d68cd9b4ab.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 1,000 | [
{
"input": "3 4 2 2\nUURDRDRL",
"output": "1 1 0 1 1 1 1 0 6"
},
{
"input": "2 2 2 2\nULD",
"output": "1 1 1 1"
},
{
"input": "1 1 1 1\nURDLUURRDDLLURDL",
"output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
},
{
"input": "15 17 8 9\nURRDLUULLDD",
"output": "1 1 1 1 1 1 0 1 1 1 ... | 1,450,709,362 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | field = [int(x) for x in input().split()]
commands = input()
X = field[0]
Y = field[1]
pos = [field[2], field[3]]
lastPos = [X+1, Y+1]
count = 0
flag = False
for c in commands:
if lastPos[0] == pos[0] and lastPos[1] == pos[1]:
print(0, end = " ")
flag = True
else:
print(1, end = " ")
count += 1
last... | Title: Testing Robots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Cybernetics Failures (CF) organisation made a prototype of a bomb technician robot. To find the possible problems it was decided to carry out a series of tests. At the beginning of each test the robot prototype will ... | ```python
field = [int(x) for x in input().split()]
commands = input()
X = field[0]
Y = field[1]
pos = [field[2], field[3]]
lastPos = [X+1, Y+1]
count = 0
flag = False
for c in commands:
if lastPos[0] == pos[0] and lastPos[1] == pos[1]:
print(0, end = " ")
flag = True
else:
print(1, end = " ")
count +... | 0 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,620,422,043 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 404 | 31,129,600 | n, d = map(int, input().split())
a = list(map(int, input().split()))
p = 0
ans = 0
for i in range(n):
while a[i] - a[p] > d:
p += 1
diff = i - p
ans += (diff * (diff - 1)) // 2
print(ans)
| Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
n, d = map(int, input().split())
a = list(map(int, input().split()))
p = 0
ans = 0
for i in range(n):
while a[i] - a[p] > d:
p += 1
diff = i - p
ans += (diff * (diff - 1)) // 2
print(ans)
``` | 3 | |
242 | C | King's Path | PROGRAMMING | 1,800 | [
"dfs and similar",
"graphs",
"hashing",
"shortest paths"
] | null | null | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the... | The first line contains four space-separated integers *x*0,<=*y*0,<=*x*1,<=*y*1 (1<=≤<=*x*0,<=*y*0,<=*x*1,<=*y*1<=≤<=109), denoting the initial and the final positions of the king.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=105), denoting the number of segments of allowed cells. Next *n* lines contai... | If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer — the minimum number of moves the king needs to get from the initial position to the final one. | [
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n",
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n"
] | [
"4\n",
"6\n",
"-1\n"
] | none | 1,500 | [
{
"input": "5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5",
"output": "4"
},
{
"input": "3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10",
"output": "6"
},
{
"input": "1 1 2 10\n2\n1 1 3\n2 6 10",
"output": "-1"
},
{
"input": "9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10... | 1,656,867,229 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 7 | 216 | 2,355,200 | X_MOVE_LIST = [0, 1, 0, -1, 1, -1, -1, 1]
Y_MOVE_LIST = [1, 0, -1, 0, -1, 1, -1, 1]
DIC_ALLOWED_POS_BY_ROWS = {}
DIC_VISITED = {}
MAX_POS = 1000000000
def verify_ends(num):
return num > 0 and num <= MAX_POS
def verify_pos(pos):
if verify_ends(pos[0]) and verify_ends(pos[1]):
allowed_pos = DIC_ALLO... | Title: King's Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with int... | ```python
X_MOVE_LIST = [0, 1, 0, -1, 1, -1, -1, 1]
Y_MOVE_LIST = [1, 0, -1, 0, -1, 1, -1, 1]
DIC_ALLOWED_POS_BY_ROWS = {}
DIC_VISITED = {}
MAX_POS = 1000000000
def verify_ends(num):
return num > 0 and num <= MAX_POS
def verify_pos(pos):
if verify_ends(pos[0]) and verify_ends(pos[1]):
allowed_pos ... | 0 | |
430 | B | Balls Game | PROGRAMMING | 1,400 | [
"brute force",
"two pointers"
] | null | null | Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color *x*. He can insert his ball at... | The first line of input contains three integers: *n* (1<=≤<=*n*<=≤<=100), *k* (1<=≤<=*k*<=≤<=100) and *x* (1<=≤<=*x*<=≤<=*k*). The next line contains *n* space-separated integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*k*). Number *c**i* means that the *i*-th ball in the row has color *c**i*.
It is guaranteed th... | Print a single integer — the maximum number of balls Iahub can destroy. | [
"6 2 2\n1 1 2 2 1 1\n",
"1 1 1\n1\n"
] | [
"6\n",
"0\n"
] | none | 1,000 | [
{
"input": "6 2 2\n1 1 2 2 1 1",
"output": "6"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 2 1\n2 1 2 2 1 2 2 1 1 2",
"output": "5"
},
{
"input": "50 2 1\n1 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 2 1 2 1 2 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 1 2 2 1 1 2",
"... | 1,674,035,734 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n, k, x = map(int, input().split())
a = list(map(int, input().split()))
maxim = 0
for i in range(n-1):
b = a.copy()
while len(b) > 2:
l = len(b)
for i in range(2, len(b)):
if b[i - 2] == b[i - 1] == b[i]:
k = i + 1
while k < len(b):
... | Title: Balls Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game?
There are *n* balls put in a row. Each ball is colored in one of *k* colors. Initially the row doesn't contain three or more conti... | ```python
n, k, x = map(int, input().split())
a = list(map(int, input().split()))
maxim = 0
for i in range(n-1):
b = a.copy()
while len(b) > 2:
l = len(b)
for i in range(2, len(b)):
if b[i - 2] == b[i - 1] == b[i]:
k = i + 1
while k < len(b):... | 0 | |
999 | D | Equalize the Remainders | PROGRAMMING | 1,900 | [
"data structures",
"greedy",
"implementation"
] | null | null | You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$.
Let's calculate $c_r$ ($0 \le r \le m-1)$ — the number of elements havin... | The first line of input contains two integers $n$ and $m$ ($1 \le n \le 2 \cdot 10^5, 1 \le m \le n$). It is guaranteed that $m$ is a divisor of $n$.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), the elements of the array. | In the first line, print a single integer — the minimum number of moves required to satisfy the following condition: for each remainder from $0$ to $m - 1$, the number of elements of the array having this remainder equals $\frac{n}{m}$.
In the second line, print any array satisfying the condition and can be obtained f... | [
"6 3\n3 2 0 6 10 12\n",
"4 2\n0 1 2 3\n"
] | [
"3\n3 2 0 7 10 14 \n",
"0\n0 1 2 3 \n"
] | none | 0 | [
{
"input": "6 3\n3 2 0 6 10 12",
"output": "3\n3 2 0 7 10 14 "
},
{
"input": "4 2\n0 1 2 3",
"output": "0\n0 1 2 3 "
},
{
"input": "1 1\n1000000000",
"output": "0\n1000000000 "
},
{
"input": "6 3\n3 2 0 6 10 11",
"output": "1\n3 2 0 7 10 11 "
},
{
"input": "100 25... | 1,634,721,516 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 3,000 | 40,448,000 | n, m = map(int,input().split())
k = n//m
def mod(x):
return x % m
A = list(map(int, input().split()))
a = []
for i in range(n):
a.append([A[i], i])
a = sorted(a, key=lambda x: mod(x[0]))
cnt = [0]*m
target = 0
ans = 0
for i in range(n):
x, y = a[i]
now = x%m
if cnt[now] < k:
cn... | Title: Equalize the Remainders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$.
In a single move, you can choose any position $i$ between $1$... | ```python
n, m = map(int,input().split())
k = n//m
def mod(x):
return x % m
A = list(map(int, input().split()))
a = []
for i in range(n):
a.append([A[i], i])
a = sorted(a, key=lambda x: mod(x[0]))
cnt = [0]*m
target = 0
ans = 0
for i in range(n):
x, y = a[i]
now = x%m
if cnt[now] < ... | 0 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,597,691,749 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 109 | 0 | n=input()
a=n[::-1]
if n==a:
print(n)
else:
print(n+a) | Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
n=input()
a=n[::-1]
if n==a:
print(n)
else:
print(n+a)
``` | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,676,210,179 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 108 | 9,011,200 | import math
from sys import stdin
from collections import Counter, defaultdict, deque, namedtuple
from bisect import bisect_right, bisect_left
from typing import List, DefaultDict
def readarray(typ):
return list(map(typ, stdin.readline().split()))
def readint():
return int(input())
a, b... | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
import math
from sys import stdin
from collections import Counter, defaultdict, deque, namedtuple
from bisect import bisect_right, bisect_left
from typing import List, DefaultDict
def readarray(typ):
return list(map(typ, stdin.readline().split()))
def readint():
return int(input())... | 3 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,653,002,165 | 2,147,483,647 | Python 3 | OK | TESTS | 178 | 46 | 0 | a,b,c=map(int,input().split())
if c==0 and a==b:
print("yes")
elif c!=0 and ((b-a)/c)==int((b-a)/c) and ((b-a)/c)>=0:
print("yes")
else:
print("no") | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a,b,c=map(int,input().split())
if c==0 and a==b:
print("yes")
elif c!=0 and ((b-a)/c)==int((b-a)/c) and ((b-a)/c)>=0:
print("yes")
else:
print("no")
``` | 3 | |
909 | A | Generate Login | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"sortings"
] | null | null | The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person.
You are given the first and ... | The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. | Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. | [
"harry potter\n",
"tom riddle\n"
] | [
"hap\n",
"tomr\n"
] | none | 500 | [
{
"input": "harry potter",
"output": "hap"
},
{
"input": "tom riddle",
"output": "tomr"
},
{
"input": "a qdpinbmcrf",
"output": "aq"
},
{
"input": "wixjzniiub ssdfodfgap",
"output": "wis"
},
{
"input": "z z",
"output": "zz"
},
{
"input": "ertuyivhfg v"... | 1,679,388,432 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | fn, ln = input().split()
login = fn[0]
for p in range(1, len(fn)):
if fn[p] < ln[0]:
login += fn[p]
else:
break
login += ln[0]
print(login)
| Title: Generate Login
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the fu... | ```python
fn, ln = input().split()
login = fn[0]
for p in range(1, len(fn)):
if fn[p] < ln[0]:
login += fn[p]
else:
break
login += ln[0]
print(login)
``` | 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,688,663,377 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n=int(input())
a=str()
for i in range(1,n+1):
x=(int(input()))
if x*3<180:
a=a+"NO"+" "
else:
a=a+"YES"+" "
#a=a.split()
a=a.replace(" ","\n")
print(a) | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
n=int(input())
a=str()
for i in range(1,n+1):
x=(int(input()))
if x*3<180:
a=a+"NO"+" "
else:
a=a+"YES"+" "
#a=a.split()
a=a.replace(" ","\n")
print(a)
``` | 0 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,693,209,225 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 93 | 102,400 | n = int(input())
nums = list(map(int, input().split()))
#nums = sorted(nums)
while len(nums) != 1:
nums = sorted(nums)[::-1]
nums.remove(nums[0])
#print(nums)
if (len(nums) == 1):
break
nums = sorted(nums)
nums.remove(nums[0])
#print(nums)
print(*nums) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
n = int(input())
nums = list(map(int, input().split()))
#nums = sorted(nums)
while len(nums) != 1:
nums = sorted(nums)[::-1]
nums.remove(nums[0])
#print(nums)
if (len(nums) == 1):
break
nums = sorted(nums)
nums.remove(nums[0])
#print(nums)
print(*nums)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.