problem_id stringlengths 3 7 | contestId stringclasses 660
values | problem_index stringclasses 27
values | programmingLanguage stringclasses 3
values | testset stringclasses 5
values | incorrect_passedTestCount float64 0 146 | incorrect_timeConsumedMillis float64 15 4.26k | incorrect_memoryConsumedBytes float64 0 271M | incorrect_submission_id stringlengths 7 9 | incorrect_source stringlengths 10 27.7k | correct_passedTestCount float64 2 360 | correct_timeConsumedMillis int64 30 8.06k | correct_memoryConsumedBytes int64 0 475M | correct_submission_id stringlengths 7 9 | correct_source stringlengths 28 21.2k | contest_name stringclasses 664
values | contest_type stringclasses 3
values | contest_start_year int64 2.01k 2.02k | time_limit float64 0.5 15 | memory_limit float64 64 1.02k | title stringlengths 2 54 | description stringlengths 35 3.16k | input_format stringlengths 67 1.76k | output_format stringlengths 18 1.06k ⌀ | interaction_format null | note stringclasses 840
values | examples stringlengths 34 1.16k | rating int64 800 3.4k ⌀ | tags stringclasses 533
values | testset_size int64 2 360 | official_tests stringlengths 44 19.7M | official_tests_complete bool 1
class | input_mode stringclasses 1
value | generated_checker stringclasses 231
values | executable bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
863/E | 863 | E | Python 3 | TESTS | 4 | 31 | 0 | 216779382 | def main():
n = int(input())
tuples = []
seen_pairs = set()
for i in range(n):
l, r = map(int, input().split())
tuples.append((2 * l - 1, 2 * r + 1, i))
pair = (tuples[-1][0], tuples[-1][1])
if pair in seen_pairs:
print(i + 1)
return
seen_p... | 55 | 872 | 42,188,800 | 175777790 | import sys
input = sys.stdin.readline
n = int(input())
segs = []
for i in range(n):
l, r = map(int, input().split())
segs.append((l, r, i + 1))
segs.sort(key=lambda x: (x[0], -x[1]))
res = -1
for i in range(n - 1):
if segs[i][1] >= segs[i + 1][1]:
res = segs[i + 1][2]
break
if i > 0 and ... | Educational Codeforces Round 29 | ICPC | 2,017 | 2 | 256 | Turn Off The TV | Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.
Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at leas... | The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets.
Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set. | If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n).
If there are multiple answers, print any of them. | null | Consider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).
Note that in the fourth sample you can switch off the second TV set, since even wi... | [{"input": "3\n1 3\n4 6\n1 7", "output": "1"}, {"input": "2\n0 10\n0 10", "output": "1"}, {"input": "3\n1 2\n3 4\n6 8", "output": "-1"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2"}] | 2,000 | ["data structures", "sortings"] | 55 | [{"input": "3\r\n1 3\r\n4 6\r\n1 7\r\n", "output": "1\r\n"}, {"input": "2\r\n0 10\r\n0 10\r\n", "output": "1\r\n"}, {"input": "3\r\n1 2\r\n3 4\r\n6 8\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "2\r\n"}, {"input": "3\r\n0 500000000\r\n500000001 1000000000\r\n0 1000000000\r\n", "output":... | false | stdio | import bisect
def main(input_path, output_path, submission_output_path):
with open(input_path) as f:
n = int(f.readline())
intervals = []
for _ in range(n):
l, r = map(int, f.readline().split())
intervals.append((l, r))
# Compute redundant TVs
points = set()... | true |
525/C | 525 | C | Python 3 | TESTS | 36 | 436 | 6,246,400 | 11996528 | n = int(input())
answer = 0
sticks = input().split()
for i in range(n):
sticks[i] = int(sticks[i])
sticks.sort(reverse=True)
# print(sticks)
i = 0
while i < n-3:
pack = []
for j in range(i, i+4):
pack.append(sticks[j])
# print(pack)
pack.sort(reverse=True)
if pack[0]-1 == pack[1]:
... | 96 | 156 | 7,680,000 | 10553237 | n, v, ps, pp = int(input()), 0, 0, 0
for l in sorted(map(int, input().split()), reverse=True):
if ps == 0 or ps > l + 1:
ps = l
elif pp == 0:
pp, ps = l, 0
else:
v, pp, ps = v + pp * l, 0, 0
print(v) | Codeforces Round 297 (Div. 2) | CF | 2,015 | 2 | 256 | Ilya and Sticks | In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li.
Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi... | The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks.
The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks. | The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks. | null | null | [{"input": "4\n2 4 4 2", "output": "8"}, {"input": "4\n2 2 3 5", "output": "0"}, {"input": "4\n100003 100004 100005 100006", "output": "10000800015"}] | 1,600 | ["greedy", "math", "sortings"] | 96 | [{"input": "4\r\n2 4 4 2\r\n", "output": "8\r\n"}, {"input": "4\r\n2 2 3 5\r\n", "output": "0\r\n"}, {"input": "4\r\n100003 100004 100005 100006\r\n", "output": "10000800015\r\n"}, {"input": "8\r\n5 3 3 3 3 4 4 4\r\n", "output": "25\r\n"}, {"input": "10\r\n123 124 123 124 2 2 2 2 9 9\r\n", "output": "15270\r\n"}, {"inp... | false | stdio | null | true |
981/D | 981 | D | PyPy 3-64 | TESTS | 35 | 109 | 5,734,400 | 213616479 | from functools import lru_cache
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = [0] * (n + 1)
for i in range(n):
s[i + 1] = s[i] + a[i]
def check(target):
f = [[False] * (k + 1) for _ in s]
f[0][0] = True
for i in range(1, n + 1):
for j in range(i, 0, -1):
... | 64 | 109 | 5,734,400 | 213612874 | n, k = map(int, input().split())
nums = list(map(int, input().split()))
s = [0]
for v in nums:
s.append(s[-1] + v)
L = len(bin(s[n])) - 2
ans = 0
for b in range(L - 1, -1, -1):
bit = 1 << b
target = ans | bit
# 能否构成target?
f = [[False] * (n + 1) for _ in range(k + 1)]
f[0][0] = True
for i in range(1, k ... | Avito Code Challenge 2018 | CF | 2,018 | 1 | 256 | Bookshelves | Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the new... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 50$$$) — the number of books and the number of shelves in the new office.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots a_n$$$, ($$$0 < a_i < 2^{50}$$$) — the prices of the books in the order they stand on the old shelf. | Print the maximum possible beauty of $$$k$$$ shelves in the new office. | null | In the first example you can split the books as follows:
$$$$$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$$$$$
In the second example you can split the books as follows:
$$$$$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$$$$$ | [{"input": "10 4\n9 14 28 1 7 13 15 29 2 31", "output": "24"}, {"input": "7 3\n3 14 15 92 65 35 89", "output": "64"}] | 1,900 | ["bitmasks", "dp", "greedy"] | 64 | [{"input": "10 4\r\n9 14 28 1 7 13 15 29 2 31\r\n", "output": "24\r\n"}, {"input": "7 3\r\n3 14 15 92 65 35 89\r\n", "output": "64\r\n"}, {"input": "40 5\r\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16\r\n", "output": "80\r\n"}, {"input": "20 15\r\n92735... | false | stdio | null | true |
1010/C | 1010 | C | PyPy 3 | TESTS | 6 | 139 | 0 | 68305154 | import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
ddc = 0
f = 1
ans = set()
for x in a:
if f:
ddc = x%k
o = 0
o = x%k
if not f:
ddc = math.gcd(ddc, o)
if o == 1:
print(k)
print(*range(k))
exit()
'''
if k%2 != o%2 and math.gcd(k, o)==1:
print(k)
print(*range(k))
... | 107 | 233 | 15,769,600 | 40803727 | n, k = map(int, input().split(' '))
a = set(map(lambda x: int(x) % k, input().split(' ')))
def gcd(x, y):
if (y == 0):
return x
else:
return gcd (y, x % y)
a = list(a)
a.append(k)
res = a[0]
for i in a[1::]:
res = gcd(res , i)
ans = k//res
print(ans)
out = []
for i in range(ans):
out... | Codeforces Round 499 (Div. 1) | CF | 2,018 | 1 | 256 | Border | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban... | On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | null | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$.
If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I... | [{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}] | 1,800 | ["number theory"] | 107 | [{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ... | false | stdio | null | true |
454/B | 454 | B | Python 3 | TESTS | 27 | 93 | 7,372,800 | 149848919 | def main(n: int, a: list):
u, d, idx = 0, 0, -1
for i in range(1, n):
if a[i] >= a[i - 1]:
u += 1
else:
idx = i - 1
d += 1
if d == 0:
return 0
if d == 1:
if idx == 0:
return n - 1
if a[n - 1] <= a[0]:
r... | 56 | 77 | 13,414,400 | 226915646 | ln = int(input())
arr = list(map(int,input().split()))
may = sorted(arr)
if may==arr:
print(0)
else:
old = arr[0]
last = arr[0]
up,down,ans = 0,0,0
u,d,check = False,False,False
r = ln-1
while r>0:
if check:
if not old<=arr[r]<=last:
print(-1)
... | Codeforces Round 259 (Div. 2) | CF | 2,014 | 1 | 256 | Little Pony and Sort by Shift | One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
a1, a2, ..., an → an, a1, a2, ..., an - 1.
Help Twi... | The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 3 2", "output": "-1"}, {"input": "2\n1 2", "output": "0"}] | 1,200 | ["implementation"] | 56 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "6\r\n3 4 5 6 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 4 5 4... | false | stdio | null | true |
524/C | 524 | C | Python 3 | PRETESTS | 13 | 61 | 0 | 10381056 | n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
q = int(input())
for _ in range(q):
x = int(input())
m = -1
for i in range(n):
for j in range(i+1, n):
#print("trying", x, "with", a[i], a[j])
k1, r = divmod(x, a[j])
#print("... | 129 | 904 | 7,475,200 | 29733995 | n,k = [int(s) for s in input().split()]
bills = [int(s) for s in input().split()]
pairs = {}
for bill in bills:
for i in range(k):
possible = (i+1)*bill
if possible not in pairs or i+1 < pairs[possible]:
pairs[possible] = i+1
q = int(input())
mymax = 100000000000000000
for i in range(q... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | The Art of Dealing with ATM | ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bi... | The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20).
The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order.
The next line contains integer q (1 ≤ q ≤ 20) — the number of req... | For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print - 1, if it is impossible to get the corresponding sum. | null | null | [{"input": "6 20\n10 50 100 500 1000 5000\n8\n4200\n100000\n95000\n96000\n99000\n10100\n2015\n9950", "output": "6\n20\n19\n20\n-1\n3\n-1\n-1"}, {"input": "5 2\n1 2 3 5 8\n8\n1\n3\n5\n7\n9\n11\n13\n15", "output": "1\n1\n1\n2\n2\n2\n2\n-1"}] | 1,900 | ["binary search", "sortings"] | 129 | [{"input": "6 20\r\n10 50 100 500 1000 5000\r\n8\r\n4200\r\n100000\r\n95000\r\n96000\r\n99000\r\n10100\r\n2015\r\n9950\r\n", "output": "6\r\n20\r\n19\r\n20\r\n-1\r\n3\r\n-1\r\n-1\r\n"}, {"input": "5 2\r\n1 2 3 5 8\r\n8\r\n1\r\n3\r\n5\r\n7\r\n9\r\n11\r\n13\r\n15\r\n", "output": "1\r\n1\r\n1\r\n2\r\n2\r\n2\r\n2\r\n-1\r\n... | false | stdio | null | true |
832/B | 832 | B | PyPy 3-64 | TESTS | 5 | 46 | 102,400 | 181879248 | import sys
input = sys.stdin.readline
s = input()[:-1]
w = input()[:-1]
ew = 0
for _ in range(int(input())):
q = input()[:-1]
i, j = 0, 0
ew = 0
while i < len(w) and j < len(q):
if w[i] == q[j]:
i += 1
j += 1
elif w[i] == '?':
if q[j] in s:
... | 94 | 639 | 6,144,000 | 28841733 | # IAWT
goods = input()
ptrn = input()
n = int(input())
qs = [input() for i in range(n)]
data = [False for i in range(26)]
for i in range(len(goods)):
data[ord(goods[i])-97] = True
star_in = '*' in ptrn
if star_in:
sind = ptrn.index('*')
theL = len(ptrn)
def f(q):
if not star_in:
if len(q) != t... | Codeforces Round 425 (Div. 2) | CF | 2,017 | 2 | 256 | Petya and Exam | It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno... | The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*"... | Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary. | null | In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example.
- The first query: "NO", because character "*" can be replaced wit... | [{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}] | 1,600 | ["implementation", "strings"] | 94 | [{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\... | false | stdio | null | true |
832/B | 832 | B | Python 3 | TESTS | 11 | 171 | 921,600 | 95338619 | #!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Time : 2020/10/11 1:09 PM
# @Author : Songtao Li
def is_continue_bad_alpha(test_str, good, bad):
count = 0
start = 0
end = 0
for idx, i in enumerate(test_str):
if i in bad:
if count == 0:
start = idx
co... | 94 | 919 | 819,200 | 121297255 | from sys import stdin
from collections import defaultdict as dd
good = dd(lambda: 0)
st = input()
for ch in st:
good[ch] = 1
s = input()
star = int(s.find("*") != -1)
loc = s.find("*")
n = int(stdin.readline())
for i in range(n):
st = input()
if (len(st) < len(s) - star):
print("No")
else:
... | Codeforces Round 425 (Div. 2) | CF | 2,017 | 2 | 256 | Petya and Exam | It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consisting of lowercase English letters, characters "?" and "*"). It is kno... | The first line contains a string with length from 1 to 26 consisting of distinct lowercase English letters. These letters are good letters, all the others are bad.
The second line contains the pattern — a string s of lowercase English letters, characters "?" and "*" (1 ≤ |s| ≤ 105). It is guaranteed that character "*"... | Print n lines: in the i-th of them print "YES" if the pattern matches the i-th query string, and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrary. | null | In the first example we can replace "?" with good letters "a" and "b", so we can see that the answer for the first query is "YES", and the answer for the second query is "NO", because we can't match the third letter.
Explanation of the second example.
- The first query: "NO", because character "*" can be replaced wit... | [{"input": "ab\na?a\n2\naaa\naab", "output": "YES\nNO"}, {"input": "abc\na?a?a*\n4\nabacaba\nabaca\napapa\naaaaax", "output": "NO\nYES\nNO\nYES"}] | 1,600 | ["implementation", "strings"] | 94 | [{"input": "ab\r\na?a\r\n2\r\naaa\r\naab\r\n", "output": "YES\r\nNO\r\n"}, {"input": "abc\r\na?a?a*\r\n4\r\nabacaba\r\nabaca\r\napapa\r\naaaaax\r\n", "output": "NO\r\nYES\r\nNO\r\nYES\r\n"}, {"input": "x\r\n?aba*\r\n69\r\nc\r\naaacc\r\nbba\r\nbabcb\r\nac\r\nbccca\r\nca\r\nabbaa\r\nb\r\naacca\r\nccc\r\ncc\r\na\r\naabba\... | false | stdio | null | true |
552/E | 552 | E | PyPy 3-64 | TESTS | 5 | 62 | 512,000 | 150558100 | s = input()
ans = -1
def insert(s, id, ch):
t = str()
# print("s = " + s, "id = " + str(id))
t += (s[:id])
t += ch
t += s[id:]
return t
for id, ch in enumerate(s):
if ch != '*': continue
for i, c in enumerate(s):
if c == '+' or c == '*' or abs(id - i) <= 1: continue
t ... | 69 | 311 | 2,150,400 | 187979532 | a="1*"+input()+"*1"
ans=eval(a)
l=len(a)
for i in range(l):
if a[i]=='*':
for j in range(i+1,l):
if a[j]=='*':
ans=max(ans,eval(a[:i+1]+'('+a[i+1:j]+')'+a[j:]))
print(ans) | Codeforces Round 308 (Div. 2) | CF | 2,015 | 1 | 256 | Vanya and Brackets | Vanya is doing his maths homework. He has an expression of form $$x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$$, where x1, x2, ..., xn are digits from 1 to 9, and sign $$\text{ }$$ represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this express... | The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * .
The number of signs * doesn't exceed 15. | In the first line print the maximum possible value of an expression. | null | Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60). | [{"input": "3+5*7+8*4", "output": "303"}, {"input": "2+3*5", "output": "25"}, {"input": "3*4*5", "output": "60"}] | 2,100 | ["brute force", "dp", "expression parsing", "greedy", "implementation", "strings"] | 69 | [{"input": "3+5*7+8*4\r\n", "output": "303\r\n"}, {"input": "2+3*5\r\n", "output": "25\r\n"}, {"input": "3*4*5\r\n", "output": "60\r\n"}, {"input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5\r\n", "output": "152587890625\r\n"}, {"input": "2*2+2*2\r\n", "output": "16\r\n"}, {"input": "1+1+1+1+1+1+1\r\n", "output": "7\r\n"}, {"inp... | false | stdio | null | true |
552/E | 552 | E | PyPy 3 | TESTS | 5 | 77 | 0 | 109330018 | s = input().split('*')
ans = -1
for i in range(len(s)):
for j in range(1, len(s)):
copy = s[:i] + [str(eval('*'.join(s[i:i + j])))] + s[i + j:]
ans = max(ans, eval('*'.join(copy)))
print(ans) | 69 | 312 | 2,150,400 | 148512503 | s = input()
a = [0]
for i in range(len(s)):
if s[i] == '*':
a.append(i+1)
a.append(len(s)+1)
maxRes = eval(s)
for i in a:
for j in a:
if j > i:
maxRes = max(maxRes, eval(s[:i]+'('+s[i:j-1]+')'+s[j-1:]))
print(maxRes) | Codeforces Round 308 (Div. 2) | CF | 2,015 | 1 | 256 | Vanya and Brackets | Vanya is doing his maths homework. He has an expression of form $$x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$$, where x1, x2, ..., xn are digits from 1 to 9, and sign $$\text{ }$$ represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this express... | The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * .
The number of signs * doesn't exceed 15. | In the first line print the maximum possible value of an expression. | null | Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60). | [{"input": "3+5*7+8*4", "output": "303"}, {"input": "2+3*5", "output": "25"}, {"input": "3*4*5", "output": "60"}] | 2,100 | ["brute force", "dp", "expression parsing", "greedy", "implementation", "strings"] | 69 | [{"input": "3+5*7+8*4\r\n", "output": "303\r\n"}, {"input": "2+3*5\r\n", "output": "25\r\n"}, {"input": "3*4*5\r\n", "output": "60\r\n"}, {"input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5\r\n", "output": "152587890625\r\n"}, {"input": "2*2+2*2\r\n", "output": "16\r\n"}, {"input": "1+1+1+1+1+1+1\r\n", "output": "7\r\n"}, {"inp... | false | stdio | null | true |
981/D | 981 | D | PyPy 3-64 | TESTS | 35 | 93 | 4,608,000 | 207407347 | import sys
input = sys.stdin.buffer.readline
def check(A, k, x):
n = len(A)
d = [[False for k1 in range(k+1)] for i in range(n)]
curr = 0
for i in range(n-1, -1, -1):
curr+=A[i]
if curr&x==x:
d[i][1] = True
for k1 in range(2, k+1):
for i in range(... | 64 | 109 | 6,553,600 | 213582688 | if __name__ == '__main__':
n, k = map(int, input().split())
a = list(map(int, input().split()))
sum = [0 for i in range(n + 1)]
for i, v in enumerate(a):
sum[i + 1] = sum[i] + v
def pos(m: int) -> bool:
dp = [[False for i in range(n + 1)] for j in range(k + 1)]
dp[0][0] = Tr... | Avito Code Challenge 2018 | CF | 2,018 | 1 | 256 | Bookshelves | Mr Keks is a typical white-collar in Byteland.
He has a bookshelf in his office with some books on it, each book has an integer positive price.
Mr Keks defines the value of a shelf as the sum of books prices on it.
Miraculously, Mr Keks was promoted and now he is moving into a new office.
He learned that in the new... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 50$$$) — the number of books and the number of shelves in the new office.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots a_n$$$, ($$$0 < a_i < 2^{50}$$$) — the prices of the books in the order they stand on the old shelf. | Print the maximum possible beauty of $$$k$$$ shelves in the new office. | null | In the first example you can split the books as follows:
$$$$$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$$$$$
In the second example you can split the books as follows:
$$$$$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$$$$$ | [{"input": "10 4\n9 14 28 1 7 13 15 29 2 31", "output": "24"}, {"input": "7 3\n3 14 15 92 65 35 89", "output": "64"}] | 1,900 | ["bitmasks", "dp", "greedy"] | 64 | [{"input": "10 4\r\n9 14 28 1 7 13 15 29 2 31\r\n", "output": "24\r\n"}, {"input": "7 3\r\n3 14 15 92 65 35 89\r\n", "output": "64\r\n"}, {"input": "40 5\r\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16\r\n", "output": "80\r\n"}, {"input": "20 15\r\n92735... | false | stdio | null | true |
958/F2 | 958 | F2 | Python 3 | TESTS | 37 | 124 | 819,200 | 38655109 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*m
for i in a:
c[i-1]+=1
for i in range(m):
if b[i]>c[i]:
exit(print(-1))
i=0
while c[a[i]-1]>b[a[i]-1]:
c[a[i]-1]-=1;i+=1
j=n-1
while c[a[j]-1]>b[a[j]-1]:
c[a[j]-1]-=1;j-=1
print(j-i+1-sum(b)) | 59 | 171 | 30,105,600 | 203012499 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
k = list(map(int, input().split()))
cntOfZero = 0
total = 0
for ele in k:
if ele == 0:
cntOfZero+=1
total += ele
ans = 10000000000000
i = j = 0
temp = [0]*m
for i in range(n):
while(cntOfZero < m and j<n):
temp[arr[j]-1]... | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Lightsabers (medium) | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1. | null | null | [{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}] | 1,800 | ["binary search", "two pointers"] | 59 | [{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\... | false | stdio | null | true |
247/A | 250 | A | Python 3 | TESTS | 7 | 62 | 0 | 164928544 | n = int(input())
a = list(map(int, input().split()))
ans = [0]
count = 0
for i in range(n):
if a[i] < 0:
if count < 2:
count += 1
else:
ans.append(i - ans[-1])
count = 1
ans.append(n - sum(ans))
print(len(ans) - 1)
print(*ans[1:]) | 69 | 92 | 0 | 141845565 | P=print
I=input
I()
a=b=0
t=[]
for x in map(int,I().split()):
if x<0:
if b==2:t+=[a];b=1;a=0
else:b+=1
a+=1
if a:t+=[a]
P(len(t))
for x in t:P(x,end=' ') | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Paper Work | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n... | The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. | Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them. | null | Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | [{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}] | 1,000 | [] | 69 | [{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n... | false | stdio | import sys
def read_input(input_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
return n, a
def compute_min_k(n, a):
if n == 0:
return 0
folders = 0
current_neg = 0
current_size = 0
for ai in a:
current_s... | true |
247/A | 250 | A | Python 3 | TESTS | 7 | 216 | 307,200 | 94794774 | n = int( input().strip() )
profit = tuple( map( int, input().strip().split(' ') ) )
bad_cnt = 0
ans = [0] # The zero is dummy
for i in range(n):
if profit[i] < 0:
bad_cnt += 1
if bad_cnt == 3:
ans.append(i-ans[len(ans)-1])
bad_cnt = 1
tmp = sum(ans)
if tmp != n:
ans.append(n-tmp)
p... | 69 | 92 | 0 | 143406291 | n=int(input())
a=list(map(int,input().split()))
k=0
b=[]
last_pos=0
lose_count=0
for i in range(n):
if lose_count==2 and a[i]<0:
k+=1
b.append(i-last_pos)
last_pos=i
lose_count=0
if a[i]<0:
lose_count+=1
b.append(i-last_pos+1)
k+=1
print(k)
for bb in b:
print(bb,end='... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Paper Work | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n... | The first line contains integer n (1 ≤ n ≤ 100), n is the number of days. The second line contains a sequence of integers a1, a2, ..., an (|ai| ≤ 100), where ai means the company profit on the i-th day. It is possible that the company has no days with the negative ai. | Print an integer k — the required minimum number of folders. In the second line print a sequence of integers b1, b2, ..., bk, where bj is the number of day reports in the j-th folder.
If there are multiple ways to sort the reports into k days, print any of them. | null | Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6
In the second sample you can put all five reports in one folder. | [{"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3"}, {"input": "5\n0 -1 100 -1 0", "output": "1\n5"}] | 1,000 | [] | 69 | [{"input": "11\r\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\r\n", "output": "3\r\n5 3 3 "}, {"input": "5\r\n0 -1 100 -1 0\r\n", "output": "1\r\n5 "}, {"input": "1\r\n0\r\n", "output": "1\r\n1 "}, {"input": "1\r\n-1\r\n", "output": "1\r\n1 "}, {"input": "2\r\n0 0\r\n", "output": "1\r\n2 "}, {"input": "2\r\n-2 2\r\n", "output": "1\r\n... | false | stdio | import sys
def read_input(input_path):
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
return n, a
def compute_min_k(n, a):
if n == 0:
return 0
folders = 0
current_neg = 0
current_size = 0
for ai in a:
current_s... | true |
958/F2 | 958 | F2 | Python 3 | TESTS | 37 | 139 | 614,400 | 38664644 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*m;r=sum(b)
for i in a:
c[i-1]+=1
for i in range(m):
if b[i]>c[i]:
exit(print(-1))
i=0
while c[a[i]-1]>b[a[i]-1]:
c[a[i]-1]-=1;i+=1
j=n-1
while c[a[j]-1]>b[a[j]-1]:
c[a[j]-1]-=1;j-=1
k=(j-i+1-r)
f... | 59 | 327 | 31,129,600 | 160474079 | import sys
input = sys.stdin.readline
def f(x):
sz = sum(k)+x
freq = [0]*(m+1)
for i in range(sz):
freq[a[i]] += 1
small = 0
for i in range(1,m+1):
if freq[i] < k[i]:
small += 1
if not small: return True
for i in range(sz, n):
freq[a[i-sz]] -= 1
if... | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Lightsabers (medium) | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1. | null | null | [{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}] | 1,800 | ["binary search", "two pointers"] | 59 | [{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\... | false | stdio | null | true |
14/B | 14 | B | Python 3 | TESTS | 5 | 92 | 0 | 7995512 | n, x = map(int, input().split())
A = []
B = []
for i in range(n):
a, b = map(int, input().split())
A.append(min(a, b))
B.append(max(a, b))
R = []
for i in range(min(A), max(B)):
res = abs(x - i)
for j in range(n):
if A[j] <= i <= B[j]:
pass
else:
res = 1001
... | 52 | 92 | 0 | 140118478 | import sys
input = sys.stdin.readline().split()
num = int(input[0])
pos = int(input[1])
pos_min = 0
pos_max = sys.maxsize
for i in range(num):
input = sys.stdin.readline().split()
min_t = int(input[0])
max_t = int(input[1])
if min_t > max_t:
min_t, max_t = max_t, min_t
pos_min = max(pos_... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
817/B | 817 | B | PyPy 3-64 | TESTS | 16 | 109 | 18,124,800 | 187402200 | # Thank God that I'm not you.
import bisect
from collections import Counter, deque
import heapq
import itertools
import math
import random
import sys
from types import GeneratorType;
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else... | 80 | 93 | 12,185,600 | 183764907 | n=int(input())
a=[int(i) for i in input().split()]
b=a.copy()
b.sort()
x=b[0]
y=b[1]
z=b[2]
d={}
for j in a:
if j in (x,y,z):
if j not in d.keys():
d[j]=1
else :
d[j]+=1
if len(d.keys())==3:
print(d[x]*d[y]*d[z])
elif len(d.keys())==2:
k1=k2=0
if x==y:
k1=... | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | 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 ai·aj·ak is minimum possible, are there in t... | 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 ai (1 ≤ ai ≤ 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 ai·aj·ak is minimum possible. | null | 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) ... | [{"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"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
817/B | 817 | B | Python 3 | TESTS | 16 | 124 | 8,806,400 | 27814001 | n = input()
a = [int(n) for n in input().split()]
a.sort()
first = a.count((a[0]))
second = a.count((a[1]))
third = a.count((a[2]))
if first >= 3:
ans = ((first)*(first-1)*(first-2))/6
elif second >= 2:
ans = ((second)*(second-1))/2
else :
ans = third
print(int(ans)) | 80 | 108 | 13,516,800 | 181309894 | n=int(input())
a=list(map(int,input().split()))
a.sort()
a2=a[2]
cnt=0
for i in range(n):
if a2==a[i]:
cnt+=1
if a[0]==a2:
print(cnt*(cnt-1)*(cnt-2)//6)
elif a[1]==a2:
print(cnt*(cnt-1)//2)
else:
print(cnt) | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | 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 ai·aj·ak is minimum possible, are there in t... | 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 ai (1 ≤ ai ≤ 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 ai·aj·ak is minimum possible. | null | 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) ... | [{"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"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
817/B | 817 | B | Python 3 | TESTS | 16 | 124 | 9,113,600 | 27809073 | n=eval(input())
a=list(map(int,input().split()))
a=sorted(a)
if(a.count(a[0])>3):
p=a.count(a[0])
p=p*(p-1)*(p-2)
p//=6
print(p)
elif(a[0]!=a[1] and a.count(a[1])>2):
p=a.count(a[1])
p=p*(p-1)
p//=2
print(p)
elif(a[0]!=a[1] and a[1]!=a[2] and a.count(a[2])>1):
print(a.count(a[2]))
else:
print(1) | 80 | 108 | 17,920,000 | 164243902 | from math import factorial as fact
from math import pi
n = int(input())
a = list(map(int,input().split()))
cnts = {e: 0 for i,e in enumerate(a)}
for i,e in enumerate(a):
cnts[e] += 1
def mini(l: list):
ans = (pi,float('inf'))
for i,e in enumerate(l):
if e < ans[1]:
ans = (i,e)
ret... | Educational Codeforces Round 23 | ICPC | 2,017 | 2 | 256 | Makes And The Product | 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 ai·aj·ak is minimum possible, are there in t... | 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 ai (1 ≤ ai ≤ 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 ai·aj·ak is minimum possible. | null | 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) ... | [{"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"}] | 1,500 | ["combinatorics", "implementation", "math", "sortings"] | 80 | [{"input": "4\r\n1 1 1 1\r\n", "output": "4\r\n"}, {"input": "5\r\n1 3 2 3 4\r\n", "output": "2\r\n"}, {"input": "6\r\n1 3 3 1 3 2\r\n", "output": "1\r\n"}, {"input": "3\r\n1000000000 1000000000 1000000000\r\n", "output": "1\r\n"}, {"input": "4\r\n1 1 2 2\r\n", "output": "2\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": ... | false | stdio | null | true |
245/E | 245 | E | PyPy 3-64 | TESTS | 14 | 124 | 0 | 167714785 | import sys
input = sys.stdin.readline
s = input()[:-1]
d = 0
c = 0
e = 0
f = 0
g = 0
for i in s:
if i == '+':
c += 1
e += 1
else:
c -= 1
e = 0
d = min(c, d)
f = max(e, f)
g = max(c, g)
print(max(f, -d, g)) | 30 | 92 | 0 | 156151078 | notes = list(input())
y = 0
MAY = 0
MIY = 0
for i in notes:
if i == '+':
y += 1
MAY = max(MAY, y)
else:
y -= 1
MIY = min(MIY, y)
print(MAY-MIY) | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | Mishap in Club | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. | Print the sought minimum number of people | null | null | [{"input": "+-+-+", "output": "1"}, {"input": "---", "output": "3"}] | 1,400 | ["greedy", "implementation"] | 77 | [{"input": "+-+-+\r\n", "output": "1\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "-\r\n", "output": "1\r\n"}, {"input": "--\r\n", "output": "2\r\n"}, {"input": "---\r\n", "output": "3\r\n"}, {"input": "----\r\n", "output": "4\r\n"}, {"input": "---+\r\n", "output": "3\r\n"}, {"input": "--+\r\n", "output": ... | false | stdio | null | true |
14/B | 14 | B | PyPy 3 | TESTS | 18 | 280 | 0 | 90083229 | n,x0=map(int,input().split())
pos=set()
a,b=map(int,input().split())
a1=min(a,b)
a2=max(a,b)
for i in range(a1,a2+1):
pos.add(i)
for i in range(n-1):
a,b=map(int,input().split())
a1=min(a,b)
a2=max(a,b)
L=[]
for each in pos:
if each not in range(a1,a2+1):
L.append(each)
f... | 52 | 92 | 0 | 140825107 | n,x0=[int(s) for s in input().split()]
left=[0]*n
right=[0]*n
for i in range(n):
a=[int(s) for s in input().split()]
a.sort()
left[i],right[i]=a
a=max(left)
b=min(right)
if a>b:
print(-1)
else:
if a<=x0<=b:
print(0)
else:
print(min(abs(a-x0),abs(b-x0))) | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
81/B | 81 | B | Python 3 | TESTS | 7 | 154 | 0 | 7012397 | s = input()
for i in range(255):
s = s.replace(', ', ',')
s = s.replace(' ,', ',')
s = s.replace(' ...', '...')
s = s.replace('... ', '...')
s = s.replace(',.', ', .')
for i in range(255):
s = s.replace(',,', ', ,')
s = s.replace('......', '... ...')
for i in range(10):
s = s.replace(',' + s... | 45 | 92 | 0 | 156971558 | import sys
def read_input(input_path=None):
if input_path is None:
f = sys.stdin
else:
f = open(input_path, 'r')
return [f.readline().strip()]
def sol(line):
b = []
for e in line.split(','):
c = [' '.join(ee.split()) for ee in e.split('...')]
b.append(' ...'.join... | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
14/B | 14 | B | Python 3 | TESTS | 8 | 218 | 307,200 | 83725382 | n,x=map(int,input().split(' '))
lst=[]
for i in range(n):
temp=[]
a1,b1=map(int,input().split(' '))
a=min(a1,b1)
b=max(a1,b1)
for j in range(a,b+1):
temp.append(j)
lst.append(set(temp))
result=lst[0]
for i in range(1,len(lst)):
result=result.intersection(lst[i])
result=list(result)
i... | 52 | 92 | 0 | 142021764 | n,xo=[int(x) for x in input().split()]
l1=[]
l2=[]
for i in range(n):
a,b=[int(x) for x in input().split()]
if a<=b:
l1.append(a)
l2.append(b)
else:
l1.append(b)
l2.append(a)
ma=max(l1)
mi=min(l2)
if ma>mi:
print("-1")
else:
if xo<ma:
print(abs(ma-xo))
eli... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
14/B | 14 | B | Python 3 | TESTS | 10 | 218 | 307,200 | 82404200 | n,x=map(int,input().split())
a=[];b=[]
for i in range(n):
p,q=map(int,input().split())
if p>q:p,q=q,p
a.append(p);b.append(q)
arr=[]
for i in range(n):
arr.append([a[i],b[i]])
arr.sort(key=lambda x:x[0])
for i in range(n):
a[i]=arr[i][0];b[i]=arr[i][1]
if a[n-1]>b[0]:print(-1);exit()
if x<a[n-1]:pri... | 52 | 92 | 0 | 153662681 | n, x = map(int, input().split())
p1, p2 = 0, 1000
for i in range(n):
a, b = map(int, input().split())
if(max(a,b) <p2):
p2 = max(a,b)
if(min(a,b) > p1):
p1 = min(a,b)
if(p1>p2):
print("-1")
elif(x >= p1 and x<=p2):
print("0")
elif(x < p1):
print(p1-x)
else:
print(x-p2) | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
14/B | 14 | B | PyPy 3-64 | TESTS | 17 | 92 | 0 | 190432293 | n,x=map(int,input().split());
rng=[0,1000];
f=0;
for i in range(n):
a,b=map(int,input().split());
if (a<rng[0] and b<rng[0]) or (a>rng[1] and b>rng[1]):
f=1;
break;
if min(a,b)>rng[0] and max(a,b)<=rng[1]: rng[0]=min(a,b);
if max(a,b)<rng[1] and min(a,b)>=rng[0]: rng[1]=max(a,b);
... | 52 | 92 | 0 | 156063088 | import sys
input = sys.stdin.readline
n, x = map(int, input().split())
c1, c2 = 0, 1001
for _ in range(n):
s = 0
a, b = sorted(map(int, input().split()))
if a > c1:
c1 = a
if b < c2:
c2 = b
if c1 > c2:
print(-1)
break
else:
print(0 if c1 <= x <= c2 else min(abs(x... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
81/B | 81 | B | Python 3 | TESTS | 19 | 218 | 6,963,200 | 86923624 | s=list(input().strip(" "))
s.append("$")
i=0
while s[i]!="$":
if s[i]==".":
if i!=0 and s[i-1]!=" ":
s.insert(i," ")
i+=1
i+=3
elif s[i]=="," and s[i+1]!="$" and s[i+1]!=" ":
s.insert(i+1," ")
i+=2
elif s[i]==" ":
if s[i-1]=="," or s[i+1]=="." ... | 45 | 92 | 921,600 | 212045605 | '''string=str(input())
#creating the array which has no space
arr_with_no_space=[]
for i in string:
if i!=" ":
arr_with_no_space.append(i)
#print(arr_with_no_space)
#taking care of the constraints and constructing the final string
space=" "
final_arr=[]
length=len(arr_with_no_space)
counter=0
while counter!... | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
326/B | 335 | B | PyPy 3-64 | TESTS | 2 | 92 | 2,150,400 | 173930413 | s1 = input()
s2 = ''.join(list(s1)[::-1])
if len(s1) >= 2600:
counts = {}
for c in s1:
if c not in counts:
counts[c] = 1
else:
counts[c] += 1
for a,b in counts.items():
if b>=100:
print(a*100)
exit()
dp = [[0]*(len(s2)+1) for _ in ran... | 72 | 1,996 | 117,145,600 | 66242753 | from collections import defaultdict
s = input()
n = len(s)
if n >= 2600:
print(s[0] * 100)
elif n > 2574:
count = defaultdict(int)
for l in s:
count[l] += 1
max_l = s[0]
for l, c in count.items():
if c >= 100:
max_l = l
print(max_l * 100)
else:
data = defaultdi... | MemSQL start[c]up Round 2 | CF | 2,013 | 2 | 256 | Palindrome | Given a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s and is as long as possible. | The only line of the input contains one string s of length n (1 ≤ n ≤ 5·104) containing only lowercase English letters. | If s contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of s. If s doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of s and is as long as possible.
If there exists multiple answers, you are allowed to p... | null | A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward. | [{"input": "bbbabcbbb", "output": "bbbcbbb"}, {"input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur"}] | 1,900 | [] | 72 | [{"input": "bbbabcbbb\r\n", "output": "bbbcbbb\r\n"}, {"input": "rquwmzexectvnbanemsmdufrg\r\n", "output": "rumenanemur\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | false | stdio | import sys
def is_palindrome(s):
return s == s[::-1]
def is_subsequence(sub, s):
i = 0
for c in sub:
i = s.find(c, i) + 1
if i == 0:
return False
return True
input_path, output_path, submission_path = sys.argv[1:4]
with open(input_path) as f:
s = f.read().strip()
wit... | true |
81/B | 81 | B | Python 3 | TESTS | 18 | 92 | 0 | 155510987 | class CLS_word(object):
def __init__(self, type, value):
self.type = type
self.value = value
def print_s(wL):
for i in range(len(wL)):
word = wL[i]
if word.type == 'num':
print(word.value, end='')
elif word.type == 'space' and wL[i - 1].type == 'num' and wL[i... | 45 | 124 | 0 | 4443658 | s=input()
while(' ' in s):
s=s.replace(' ',' ')
while(' ,' in s):
s=s.replace(' ,',',')
while('. ' in s):
s=s.replace('. ','.')
s=s.replace(',',', ')
s=s.replace('...',' ...')
if(s[0]==' '):
s=s[1:]
if(s[-1]==' '):
s=s[:len(s)-1]
while(' ' in s):
s=s.replace(' ',' ')
print(s) | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
81/B | 81 | B | Python 3 | TESTS | 4 | 124 | 512,000 | 14581720 | import re
s = input().strip()
s = re.sub('(\w)\s+(?=\w)', r'\1x', s)
s = re.sub('\s', '', s)
s = re.sub(',', ', ', s)
s = re.sub('\.\.\.', ' ...', s)
s = re.sub('^\s', '', s)
s = re.sub('\s\s', ' ', s)
s = re.sub('x', ' ', s)
print(s) | 45 | 124 | 0 | 31932871 | ans = input()
while " ," in ans:
ans = ans.replace(" ,", ",")
ans = ans.replace("...", " ...").replace(",", ", ")
while " " in ans:
ans = ans.replace(" ", " ")
for d in "0123456789": ans = ans.replace(". " + d, "." + d)
print(ans.strip(), end="") | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Sequence Formatting | Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected ... | The input data contains a single string s. Its length is from 1 to 255 characters. The string s does not begin and end with a space. Its content matches the description given above. | Print the string s after it is processed. Your program's output should be exactly the same as the expected answer. It is permissible to end output line with a line-break character, and without it. | null | null | [{"input": "1,2 ,3,..., 10", "output": "1, 2, 3, ..., 10"}, {"input": "1,,,4...5......6", "output": "1, , , 4 ...5 ... ...6"}, {"input": "...,1,2,3,...", "output": "..., 1, 2, 3, ..."}] | 1,700 | ["implementation", "strings"] | 45 | [{"input": "1,2 ,3,..., 10\r\n", "output": "1, 2, 3, ..., 10\r\n"}, {"input": "1,,,4...5......6\r\n", "output": "1, , , 4 ...5 ... ...6\r\n"}, {"input": "...,1,2,3,...\r\n", "output": "..., 1, 2, 3, ...\r\n"}, {"input": "......\r\n", "output": "... ...\r\n"}, {"input": ",,,,,,,,,,,,,\r\n", "output": ", , , , , , , ... | false | stdio | null | true |
14/B | 14 | B | Python 3 | TESTS | 25 | 92 | 0 | 211846838 | n, x = [int(i) for i in input().split()]
l = []
for i in range(n):
a = [int(i) for i in input().split()]
a.sort()
l.append(a)
p = []
for i in range(1, 101):
c = 0
for j in l:
if i >= j[0] and i <= j[1]:
c += 1
if c == n:
p.append(i)
di = []
for i in p:
di.ap... | 52 | 92 | 0 | 158605938 | n,x = list(map(int,input().split()))
a,b = 0,1000
for i in range(n):
area = list(map(int,input().split()))
if min(area) > a:
a = min(area)
if max(area) < b:
b = max(area)
if a > b:
print(-1)
elif a<=x and x<=b:
print(0)
elif x < a:
print(a-x)
else:
print(x-b) | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
33/C | 33 | C | PyPy 3-64 | TESTS | 3 | 92 | 0 | 220735794 | def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
def main():
n=ri()
a=rl()
if n==1: return a[0]
sf=[0]*n;sf[-1]=a[-1]
pf=[a[0]]
for i in range(n-2,-1,-1):
sf[i]=sf[i+1]+a[i]
... | 89 | 280 | 11,980,800 | 104275051 | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n = int(input())
a = list(map(int,input().split()))
dp = [0 if a[-1]>0 else a[-1]]
dp1 = [0 if a[-1]<0 else a[-1]]
xx = a[-1]
for i in range(n-2,0,-1):
xx += a[i]
... | Codeforces Beta Round 33 (Codeforces format) | CF | 2,010 | 2 | 256 | Wonderful Randomized Sum | Learn, learn and learn again — Valera has to do this every day. He is studying at mathematical school, where math is the main discipline. The mathematics teacher loves her discipline very much and tries to cultivate this love in children. That's why she always gives her students large and difficult homework. Despite th... | The first line contains integer n (1 ≤ n ≤ 105) — amount of elements in the sequence. The second line contains n integers ai ( - 104 ≤ ai ≤ 104) — the sequence itself. | The first and the only line of the output should contain the answer to the problem. | null | null | [{"input": "3\n-1 -2 -3", "output": "6"}, {"input": "5\n-4 2 0 5 0", "output": "11"}, {"input": "5\n-1 10 -5 10 -2", "output": "18"}] | 1,800 | ["greedy"] | 89 | [{"input": "3\r\n-1 -2 -3\r\n", "output": "6\r\n"}, {"input": "5\r\n-4 2 0 5 0\r\n", "output": "11\r\n"}, {"input": "5\r\n-1 10 -5 10 -2\r\n", "output": "18\r\n"}, {"input": "1\r\n-3\r\n", "output": "3\r\n"}, {"input": "4\r\n1 4 -5 -2\r\n", "output": "12\r\n"}, {"input": "7\r\n-17 6 5 0 1 4 -1\r\n", "output": "34\r\n"}... | false | stdio | null | true |
732/B | 732 | B | Python 3 | TESTS | 42 | 46 | 0 | 190836672 | n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[a[0]]
if n==1:
print(abs(k-a[0]))
print(k)
else:
for i in range(n-1):
x=b[i]
y=a[i+1]
if x+y<k:
b.append(k-x)
else:
b.append(y)
c=[y-x for x,y in zip(a,b)]
print(sum(... | 70 | 46 | 0 | 199137198 | n,k=map(int,input().split())
*r,=map(int,input().split());s=sum(r)
for i in range(1,n):r[i]=max(r[i],k-r[i-1])
print(sum(r)-s)
print(*r) | Codeforces Round 377 (Div. 2) | CF | 2,016 | 1 | 256 | Cormen — The Best Friend Of a Man | Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a ... | The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned. | In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i fro... | null | null | [{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}] | 1,000 | ["dp", "greedy"] | 70 | [{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output"... | false | stdio | null | true |
116/A | 116 | A | Python 3 | TESTS | 4 | 62 | 0 | 232037224 | n=int(input())
a,b=map(int,input().split())
m=0;cur=b
if n==2:
x,y=map(int,input().split())
print(b)
else:
for i in range(n-1):
x,y=map(int,input().split())
if cur+y-x>m:
m=cur+y-x
cur=cur+y-x
print(m) | 71 | 92 | 0 | 208024665 | b=q=0
for y in[0]*int(input()):q-=eval(input().replace(' ','-'));b=max(b,q)
print(b) | Codeforces Beta Round 87 (Div. 2 Only) | CF | 2,011 | 2 | 256 | Tram | 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 ai passengers exit the tram, while bi 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 exit so that it ... | 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 ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are give... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | null | 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 pas... | [{"input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6"}] | 800 | ["implementation"] | 71 | [{"input": "4\r\n0 3\r\n2 5\r\n4 2\r\n4 0\r\n", "output": "6\r\n"}, {"input": "5\r\n0 4\r\n4 6\r\n6 5\r\n5 4\r\n4 0\r\n", "output": "6\r\n"}, {"input": "10\r\n0 5\r\n1 7\r\n10 8\r\n5 3\r\n0 5\r\n3 3\r\n8 8\r\n0 6\r\n10 1\r\n9 0\r\n", "output": "18\r\n"}, {"input": "3\r\n0 1\r\n1 1\r\n1 0\r\n", "output": "1\r\n"}, {"inp... | false | stdio | null | true |
733/C | 733 | C | PyPy 3-64 | TESTS | 0 | 30 | 0 | 222096575 | def compute(arr, prev_i, i, gone):
narr = arr[prev_i:i+1]
# print(narr, prev_i, i, gone)
maxer = max(narr)
if narr.count(maxer) == len(narr):
return False, []
ind = narr.index(maxer)
moves = []
for j in range(ind+1, len(narr)):
moves.append(f"{ind+prev_i-gone+1} R")
for... | 138 | 93 | 409,600 | 21943080 | na = int(input())
a = list(map(int, input().split()))
nb = int(input())
b = list(map(int, input().split()))
def judge(na,a,nb,b):
ans = []
if sum(a)!=sum(b): return False,None
cur = 0
ind = -1
j = 0
for i,x in enumerate(a):
cur += x
if cur < b[j]:
pass
elif c... | Codeforces Round 378 (Div. 2) | CF | 2,016 | 1 | 256 | Epidemic in Monstropolis | There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city.
Soon, monsters became hungry and began to eat each other.
One monster can eat other monster if its weight is strictly greater than the weight of the monster... | The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters.
The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke.
Th... | In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line.
Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa... | null | In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue:
- the second monster eats the monster to the left (i.e. the first... | [{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}] | 1,800 | ["constructive algorithms", "dp", "greedy", "two pointers"] | 139 | [{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L... | false | stdio | import sys
def read_file(path):
with open(path, 'r') as f:
return f.read().splitlines()
input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3]
input_lines = read_file(input_path)
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
k = int(input_lines[2])
b = list(... | true |
740/B | 740 | B | Python 3 | TESTS | 2 | 61 | 0 | 22512633 | a=list(map(int,input().split(' ')))
b=list(map(int,input().split(' ')))
f=-101
e=0
for x in range (a[1]):
c=list(map(int,input().split(' ')))
d=sum(b[c[0]-1:c[1]])
if d>0:
e+=d
if d<=0 and d>f:
f=d
if e>0:
print(e)
else:
print(f) | 53 | 46 | 0 | 141336670 | # https://codeforces.com/problemset/problem/740/B
first_line_input = input()
number_of_flowers = list(map(int, first_line_input.split(" ")))[0]
number_of_suggestions = list(map(int, first_line_input.split(" ")))[1]
flower_mood_list = list(map(int, input().split(" ")))
sub_array_indices = []
for i in range(number_... | Codeforces Round 381 (Div. 2) | CF | 2,016 | 2 | 256 | Alyona and flowers | Little Alyona is celebrating Happy Birthday! Her mother has an array of n flowers. Each flower has some mood, the mood of i-th flower is ai. The mood can be positive, zero or negative.
Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choose severa... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of flowers and the number of subarrays suggested by the mother.
The second line contains the flowers moods — n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100).
The next m lines contain the description of the subarrays suggested by the mother. The... | Print single integer — the maximum possible value added to the Alyona's happiness. | null | The first example is the situation described in the statements.
In the second example Alyona should choose all subarrays.
The third example has answer 0 because Alyona can choose none of the subarrays. | [{"input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7"}, {"input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16"}, {"input": "2 2\n-1 -2\n1 1\n1 2", "output": "0"}] | 1,200 | ["constructive algorithms"] | 53 | [{"input": "5 4\r\n1 -2 1 3 -4\r\n1 2\r\n4 5\r\n3 4\r\n1 4\r\n", "output": "7\r\n"}, {"input": "4 3\r\n1 2 3 4\r\n1 3\r\n2 4\r\n1 1\r\n", "output": "16\r\n"}, {"input": "2 2\r\n-1 -2\r\n1 1\r\n1 2\r\n", "output": "0\r\n"}, {"input": "5 6\r\n1 1 1 -1 0\r\n2 4\r\n1 3\r\n4 5\r\n1 5\r\n1 4\r\n4 5\r\n", "output": "8\r\n"}, ... | false | stdio | null | true |
583/B | 583 | B | PyPy 3-64 | TESTS | 28 | 62 | 1,740,800 | 175360641 | n=int(input())
# import sys
# for i in range(int(input())):
# arr=list(map(int,input().split()))
# a,b,x,y=map(int,input().split())
arr=list(map(int,input().split()))
dir=1
mx=max(arr)
dir_c=0
cnt=0
while cnt!=n:
if dir==1:
for i in range(n):
if arr[i]<=cnt:
cnt+=1
... | 56 | 93 | 1,740,800 | 160891408 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
z = n
c = 0
x = 0
while True:
new_w = []
n = len(w)
for i in range(n):
if w[i] <= c:
c += 1
else:
new_w.append(w[i])
if c == z:
break
x += 1
w = new_w[::-... | Codeforces Round 323 (Div. 2) | CF | 2,015 | 1 | 256 | Robot's Task | Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at ... | The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information. | null | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | [{"input": "3\n0 2 0", "output": "1"}, {"input": "5\n4 2 3 0 1", "output": "3"}, {"input": "7\n0 3 1 0 5 2 6", "output": "2"}] | 1,200 | ["greedy", "implementation"] | 56 | [{"input": "3\r\n0 2 0\r\n", "output": "1\r\n"}, {"input": "5\r\n4 2 3 0 1\r\n", "output": "3\r\n"}, {"input": "7\r\n0 3 1 0 5 2 6\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 1\r\n", "output": "0\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": ... | false | stdio | null | true |
583/B | 583 | B | Python 3 | TESTS | 26 | 93 | 102,400 | 13434223 | import sys
if __name__ == '__main__':
num_computers = int(input())
if num_computers < 1 or num_computers > 1000:
sys.exit()
input_inf = input().split()
computers = [int(i) for i in input_inf]
new_computers = []
new_computers.extend(computers)
num_information = 0
num_turns = 0
... | 56 | 93 | 2,150,400 | 165937240 | n=int(input())
arr=list(map(int,input().split()))
ans=-1
temp=0
seen=set()
p=0
while len(seen)!=n:
ans+=1
# print(seen,ans)
if p%2==0:
for i in range(n):
if i not in seen and arr[i]<=temp:
seen.add(i)
temp+=1
p+=1
else :
for i in range(... | Codeforces Round 323 (Div. 2) | CF | 2,015 | 1 | 256 | Robot's Task | Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n. Each computer contains exactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th of them, the robot needs to collect at ... | The first line contains number n (1 ≤ n ≤ 1000). The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n), separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information. | Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts of information. | null | In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of information, collect the last piece.
In the second sample to... | [{"input": "3\n0 2 0", "output": "1"}, {"input": "5\n4 2 3 0 1", "output": "3"}, {"input": "7\n0 3 1 0 5 2 6", "output": "2"}] | 1,200 | ["greedy", "implementation"] | 56 | [{"input": "3\r\n0 2 0\r\n", "output": "1\r\n"}, {"input": "5\r\n4 2 3 0 1\r\n", "output": "3\r\n"}, {"input": "7\r\n0 3 1 0 5 2 6\r\n", "output": "2\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n0 1\r\n", "output": "0\r\n"}, {"input": "10\r\n0 0 0 0 0 0 0 0 0 0\r\n", "output": "0\r\n"}, {"input": ... | false | stdio | null | true |
10/D | 10 | D | Python 3 | TESTS | 9 | 109 | 307,200 | 93418755 | def sub_seq(initial,lis1,lis2):
inc_initial=initial
subs=[initial]
recur_sub=[initial]
ind=0
for i in lis1:
if int(i)>int(inc_initial):
if i in lis2:
subs.append(i)
inc_initial=i
lis2=lis2[lis2.index(i)+1:]
ind+=1
... | 61 | 124 | 2,867,200 | 106123196 | n = int(input())
a = [0] + list(map(int, input().split()))
m = int(input())
b = [0] + list(map(int, input().split()))
n += 1
m += 1
dp = [[0] * max(m,n) for i in range(max(m,n))]
pr = [0] * (max(n, m) + 1)
ans = []
for i in range(1, n):
for j in range(1, m):
if a[i] == b[j]:
dp[i][j] = 1 #max(1,... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | LCIS | This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other wo... | The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-se... | In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | null | null | [{"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6"}, {"input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1"}] | 2,800 | ["dp"] | 61 | [{"input": "7\r\n2 3 1 6 5 4 6\r\n4\r\n1 3 5 6\r\n", "output": "3\r\n3 5 6 \r\n"}, {"input": "5\r\n1 2 0 2 1\r\n3\r\n1 0 1\r\n", "output": "2\r\n0 1 \r\n"}, {"input": "2\r\n6 10\r\n3\r\n6 3 3\r\n", "output": "1\r\n6 \r\n"}, {"input": "1\r\n7\r\n2\r\n7 9\r\n", "output": "1\r\n7 \r\n"}, {"input": "3\r\n37 49 24\r\n3\r\n3... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input data
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f]
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
m = int(input... | true |
672/B | 672 | B | PyPy 3 | TESTS | 29 | 140 | 3,891,200 | 48238932 | n = int(input())
l = [0 for i in range(0,26)]
s=input()
nb=0
for e in 'abcdefghijklmnopqrstuvwxyz':
t=s.count(e)
if t > 1:
nb+=t-1
s=s.replace(e,'')
if nb > 25:
print(-1)
else:
print(nb) | 47 | 46 | 0 | 164678328 | n=int(input())
s=input()
if n>26:
print(-1)
else:
list1=[]
list1[:0]=s
c=list(set(list1))
a=n-len(c)
print(a) | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
672/B | 672 | B | Python 3 | TESTS | 29 | 108 | 204,800 | 51287601 | input()
t = input()
a = len(t) - len(set(t))
print(-1 if a >= 26 else a) | 47 | 46 | 0 | 165418752 | num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
n=int(input())
print(n-len(set(input())) if n<27 else -1) | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
454/B | 454 | B | PyPy 3 | TESTS | 23 | 218 | 10,752,000 | 69576227 | n = int(input())
a = list(map(int, input().rstrip().split()))
maxm = max(a)
ind_min = n
ind_max = 0
# minm_ind = a.index(min(a))
test = 0
for i in range(n):
if a[i] == maxm:
ind_min = min(i, ind_min)
ind_max = max(i, ind_max)
flag1 = 0
flag2 = 0
flag3 = 0
flag4 = 0
flag = 0
# CHeck first half is sor... | 56 | 77 | 14,438,400 | 211170443 | def solve(n, arr):
lst = sorted(arr)
if arr == lst:
return 0
for i in range(n-1):
if arr[i] > arr[i+1]:
a = i+1
break
if lst == arr[a:] + arr[:a]:
return n - a
return -1
n = int(input())
arr = list(map(int, input().split()))
print(solve(n, arr)) | Codeforces Round 259 (Div. 2) | CF | 2,014 | 1 | 256 | Little Pony and Sort by Shift | One day, Twilight Sparkle is interested in how to sort a sequence of integers a1, a2, ..., an in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
a1, a2, ..., an → an, a1, a2, ..., an - 1.
Help Twi... | The first line contains an integer n (2 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 3 2", "output": "-1"}, {"input": "2\n1 2", "output": "0"}] | 1,200 | ["implementation"] | 56 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "-1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "6\r\n3 4 5 6 3 2\r\n", "output": "-1\r\n"}, {"input": "3\r\n1 2 1\r\n", "output": "1\r\n"}, {"input": "5\r\n1 1 2 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n5 4 5 4... | false | stdio | null | true |
55/C | 55 | C | Python 3 | TESTS | 5 | 92 | 0 | 158329934 | def main():
n, m, k = map(int, input().split())
for j in range(k):
a, b = map(int, input().split())
if a == 1 or a == n or b == 1 or b == m:
print("YES")
return
print("NO")
main() | 75 | 124 | 0 | 221514323 | import sys
readline = sys.stdin.readline
def solve():
n, m, k = [int(w) for w in readline().split()]
for _ in range(k):
x, y = [int(w) for w in readline().split()]
if x <= 5 or y <= 5 or n - x <= 4 or m - y <= 4:
print('YES')
return
print('NO')
solve() | Codeforces Beta Round 51 | CF | 2,011 | 2 | 256 | Pie or die | Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | null | null | [{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}] | 1,900 | ["games"] | 75 | [{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4... | false | stdio | null | true |
55/C | 55 | C | Python 3 | TESTS | 5 | 122 | 0 | 14192150 | n, m, k = map(int, input().split())
pie = False
for i in range(k):
r, c = map(int, input().split())
if r == 1 or r == n or c == 1 or c == m:
pie = True
elif (r == 2 or r == n - 1) and (c == 2 or c == m - 1):
pie = True
if pie:
print('YES')
else:
print('NO') | 75 | 154 | 0 | 7062836 | n, m, k = map(int, input().split())
win = False
for i in range(k):
x, y = map(int, input().split())
if abs(x - 1) <= 4 or abs(y - 1) <= 4 or \
abs(n - x) <= 4 or abs(m - y) <= 4:
win = True
print('YES' if win else 'NO') | Codeforces Beta Round 51 | CF | 2,011 | 2 | 256 | Pie or die | Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | null | null | [{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}] | 1,900 | ["games"] | 75 | [{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4... | false | stdio | null | true |
14/B | 14 | B | Python 3 | TESTS | 18 | 62 | 0 | 218097311 | from sys import stdin, stdout
[n, x] = [int(x) for x in stdin.readline().split()]
race = [0]*1001
for _ in range(n):
[a, b] = [int(x) for x in stdin.readline().split()]
A = min(a, b)
B = max(a, b)
for i in range(A, B + 1):
race[i] += 1
if race[x] == n:
stdout.write('0\n')
else:
l, r, a... | 52 | 92 | 0 | 165756562 | num_inp=lambda: int(input())
arr_inp=lambda: list(map(int,input().split()))
sp_inp=lambda: map(int,input().split())
str_inp=lambda:input()
n, x0 = map(int, input().split())
x1, x2 = 0, 1000
for j in range(n):
a, b = map(int, input().split())
x1 = max(x1, min(a, b))
x2 = min(x2, max(a, b))
print(max(0, x1 - ... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Young Photographer | Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha... | The first line of the input file contains integers n and x0 (1 ≤ n ≤ 100; 0 ≤ x0 ≤ 1000). The following n lines contain pairs of integers ai, bi (0 ≤ ai, bi ≤ 1000; ai ≠ bi). | Output the required minimum distance in the same units as the positions on the racetrack. If there is no such a position, output -1. | null | null | [{"input": "3 3\n0 7\n14 2\n4 6", "output": "1"}] | 1,000 | ["implementation"] | 52 | [{"input": "3 3\r\n0 7\r\n14 2\r\n4 6\r\n", "output": "1\r\n"}, {"input": "1 1\r\n0 10\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\n3 2\r\n", "output": "0\r\n"}, {"input": "3 2\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "-1\r\n"}, {"input": "2 4\r\n10 4\r\n1 5\r\n", "output": "0\r\n"}, {"input": "1 10\r\n1 9\r\n", "out... | false | stdio | null | true |
102/B | 102 | B | Python 3 | TESTS | 9 | 248 | 0 | 118901814 | n = input()
x = 0
for digit in n:
x += int(digit)
result = 0 if x == 0 else 1
sum = x
while(sum//10 > 0):
sum = 0
while(x != 0):
sum += x%10
x = x//10
result += 1
print(result) | 51 | 92 | 0 | 181224683 | n = input()
count = 0
while (len(n) > 1):
n = str(n.count("1") * 1 + n.count("2") * 2 + n.count("3") * 3
+ n.count("4") * 4 + n.count("5") * 5 + n.count("6") * 6
+ n.count("7") * 7 + n.count("8") * 8 + n.count("9") * 9)
count += 1
print(count) | Codeforces Beta Round 79 (Div. 2 Only) | CF | 2,011 | 2 | 265 | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | null | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | [{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}] | 1,000 | ["implementation"] | 51 | [{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "... | false | stdio | null | true |
102/B | 102 | B | Python 3 | TESTS | 9 | 248 | 1,536,000 | 91959502 | import sys
a=list(map(int,str(input())))
if a[0]==0:
print(0)
sys.exit()
y=1
while sum(a)>9:
a=list(map(int,str(sum(a))))
y=y+1
print(y) | 51 | 92 | 0 | 189020886 | n = input()
steps = 0
while len(n) > 1:
digit_sum = sum(int(digit) for digit in n)
n = str(digit_sum)
steps += 1
print(steps) | Codeforces Beta Round 79 (Div. 2 Only) | CF | 2,011 | 2 | 265 | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | null | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | [{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}] | 1,000 | ["implementation"] | 51 | [{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "... | false | stdio | null | true |
55/C | 55 | C | Python 3 | TESTS | 5 | 124 | 0 | 14913786 | n, m, k = map( int , input().split() )
flag = False
while k > 0:
k -= 1
x, y = map( int , input().split() )
if x == 1 or x == n or y == 1 or y == m:
flag = True
print( "YES" if flag else "NO" ) | 75 | 186 | 0 | 209175338 | #ossama's py domain
x,y,z=map(int,input().split())
for i in range(z):
a,b=map(int,input().split())
if a<=4 or a>=x-4 or b<=5 or b>=y-4:
print("YES")
exit()
print("NO") | Codeforces Beta Round 51 | CF | 2,011 | 2 | 256 | Pie or die | Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | null | null | [{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}] | 1,900 | ["games"] | 75 | [{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4... | false | stdio | null | true |
55/C | 55 | C | Python 3 | TESTS | 5 | 92 | 307,200 | 5628880 | n, m, k = map(int, input().split())
win = False
for i in range(k):
row, col = map(int, input().split())
if row == 1 or col == 1 or row == n or col == m:
win = True
if win:
print("YES")
else:
print("NO") | 75 | 218 | 20,172,800 | 115974577 | n,m,k=list(map(int,input().split()))
for i in range(k):
x,y=list(map(int,input().split()))
if min(x,n-x+1,y,m-y+1)<6:
print('YES')
break
else:
print('NO') | Codeforces Beta Round 51 | CF | 2,011 | 2 | 256 | Pie or die | Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | null | null | [{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}] | 1,900 | ["games"] | 75 | [{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4... | false | stdio | null | true |
51/C | 51 | C | PyPy 3-64 | TESTS | 5 | 62 | 0 | 197543066 | n = int(input())
cor = [int(i) for i in input().split()]
cor.sort()
def check(d):
global t1, t2, t3
t1 = cor[0] + d
t2 = 0
t3 = 0
t2 = t1
for i in range(n):
if cor[i] > t1 + d:
t2 = cor[i] + d
break
t3 = t2
for i in range(n):
if cor[i] > t2 + d:
t3 = cor[i] + d
break
... | 50 | 155 | 27,648,000 | 176259674 | from bisect import *
#n, m = map(int, raw_input().split())
n = int(input())
k=3
sol = [0] * k
a=sorted(list(map(int,input().split())))
def test(m):
sol[0]=a[0]
for i in range(1,k):
sol[i]=sol[i-1]
it = bisect(a,sol[i-1]+m)
if it<n:
sol[i]=a[it]
return (sol[k - 1] + m) >=... | Codeforces Beta Round 48 | CF | 2,010 | 1 | 256 | Three Base Stations | The New Vasjuki village is stretched along the motorway and that's why every house on it is characterized by its shift relative to some fixed point — the xi coordinate. The village consists of n houses, the i-th house is located in the point with coordinates of xi.
TELE3, a cellular communication provider planned to l... | The first line contains an integer n (1 ≤ n ≤ 2·105) which represents the number of houses in the village. The second line contains the coordinates of houses — the sequence x1, x2, ..., xn of integer numbers (1 ≤ xi ≤ 109). It is possible that two or more houses are located on one point. The coordinates are given in a ... | Print the required minimal power d. In the second line print three numbers — the possible coordinates of the base stations' location. Print the coordinates with 6 digits after the decimal point. The positions of the stations can be any from 0 to 2·109 inclusively. It is accepted for the base stations to have matching c... | null | null | [{"input": "4\n1 2 3 4", "output": "0.500000\n1.500000 2.500000 3.500000"}, {"input": "3\n10 20 30", "output": "0\n10.000000 20.000000 30.000000"}, {"input": "5\n10003 10004 10001 10002 1", "output": "0.500000\n1.000000 10001.500000 10003.500000"}] | 1,800 | ["binary search", "greedy"] | 50 | [{"input": "4\r\n1 2 3 4\r\n", "output": "0.500000\r\n1.500000 2.500000 3.500000\r\n"}, {"input": "3\r\n10 20 30\r\n", "output": "0\r\n10.000000 20.000000 30.000000\r\n"}, {"input": "5\r\n10003 10004 10001 10002 1\r\n", "output": "0.500000\r\n1.000000 10001.500000 10003.500000\r\n"}, {"input": "1\r\n1\r\n", "output": "... | false | stdio | import sys
def main():
input_path = sys.argv[1]
ref_output_path = sys.argv[2]
sub_output_path = sys.argv[3]
with open(input_path, 'r') as f:
n = int(f.readline())
x = list(map(int, f.readline().split()))
with open(ref_output_path, 'r') as f:
d_ref = float(f.readline().... | true |
524/B | 524 | B | Python 3 | TESTS | 16 | 62 | 4,608,000 | 16988361 | n = int(input())
hs = []
ws = []
hm = 0
wm = 0
for i in range(n):
w, h = map(int, input().split())
hs.append(h)
ws.append(w)
if h > hm:
hm = h
if w > wm:
wm = w
ans = float('inf')
c = min(hm, wm)
for H in set(hs + ws):
if H < c:
continue
wr = 0
for j in range(n... | 60 | 92 | 3,481,600 | 205531317 | import sys
from math import *
from collections import Counter,defaultdict,deque
input=sys.stdin.readline
mod=10**9+7
def get_ints():return map(int,input().split())
def get_int():return int(input())
def get_array():return list(map(int,input().split()))
def input():return sys.stdin.readline().strip()
# for _ in range(in... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно ... | В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,700 | ["dp", "greedy"] | 60 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780... | false | stdio | null | true |
55/C | 55 | C | PyPy 3-64 | TESTS | 5 | 342 | 0 | 191059419 | n,m,k=map(int,input().split())
ans="NO"
for i in range(k):
x,y=map(int,input().split())
if (x==1) or (x==n) or (y==1) or (y==m):
ans="YES"
print(ans) | 75 | 248 | 0 | 59414755 | n, m, k = [int(i) for i in input().split()]
flag = False
for j in range(k):
x, y = [int(z) for z in input().split()]
flag |= x < 6 or n - x < 5
flag |= y < 6 or m - y < 5
if flag:
print("YES")
else:
print("NO") | Codeforces Beta Round 51 | CF | 2,011 | 2 | 256 | Pie or die | Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the borde... | First line contains 3 integers, separated by space: 1 ≤ n, m ≤ 100 — dimensions of the board and 0 ≤ k ≤ 100 — the number of pies. Each of the next k lines contains 2 integers, separated by space: 1 ≤ x ≤ n, 1 ≤ y ≤ m — coordinates of the corresponding pie. There could be more than one pie at a cell. | Output only one word: "YES" — if Volodya wins, "NO" — otherwise. | null | null | [{"input": "2 2 1\n1 2", "output": "YES"}, {"input": "3 4 0", "output": "NO"}, {"input": "100 50 2\n50 25\n50 25", "output": "NO"}] | 1,900 | ["games"] | 75 | [{"input": "2 2 1\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3 4 0\r\n", "output": "NO\r\n"}, {"input": "100 50 2\r\n50 25\r\n50 25\r\n", "output": "NO\r\n"}, {"input": "20 20 4\r\n10 10\r\n10 10\r\n10 10\r\n10 10\r\n", "output": "NO\r\n"}, {"input": "15 15 1\r\n8 8\r\n", "output": "NO\r\n"}, {"input": "8 8 2\r\n4 4... | false | stdio | null | true |
600/C | 600 | C | PyPy 3 | TESTS | 4 | 108 | 102,400 | 113233771 | from collections import Counter
s = list(input())
d = Counter()
d.update(s)
odds = {}
for key in d:
if d[key]%2:
odds[key] = d[key]
l = len(odds)
idx = 0
for key in odds:
if l%2:
if idx < l//2:
odds[key] += 1
d[key] += 1
elif idx == l//2:
pass
... | 66 | 77 | 2,457,600 | 194406595 | def solve():
s = input()
cnt = [0]*26
for i in s: cnt[ord(i)-97] += 1
odd, even = 0, 0
for i in cnt:
if i%2==0: even += 1
else: odd += 1
for i in range(26):
if cnt[i]%2 == 1:
for j in range(25, i, -1):
if cnt[j]%2 == 1:
cnt[... | Educational Codeforces Round 2 | ICPC | 2,015 | 2 | 256 | Make Palindrome | A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.
You are given string s consisting of lowercase Latin letters. At once you can choose any position in th... | The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | null | null | [{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}] | 1,800 | ["constructive algorithms", "greedy", "strings"] | 66 | [{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrr... | false | stdio | null | true |
672/B | 672 | B | Python 3 | TESTS | 29 | 139 | 307,200 | 83728412 | n,s=int(input()),input()
if(n-len(set(s))>=26):
print("-1")
else:
print(n-len(set(s))) | 47 | 46 | 0 | 169089904 | print(-1 if (n := int(input())) > 26 else n-len(set(input()))) | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
672/B | 672 | B | PyPy 3 | TESTS | 29 | 77 | 1,740,800 | 132296077 | n = int(input())
s = input()
has = set()
for i in s:
has.add(i)
print(-1 if n - len(has) >= 26 else n - len(has)) | 47 | 46 | 0 | 172876578 | n = int(input())
stroke = input()
if n > 26:
print(-1)
else:
a = set(list(stroke))
print( n - len(a) ) | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
435/C | 435 | C | Python 3 | TESTS | 3 | 124 | 22,835,200 | 35804389 | n = int(input())
a = list(map(int, input().split()))
Max = -0x3f3f3f3f
Min = 0x3f3f3f3f
myMap = [[" "] * 2010 for i in range(2010)]
x, y = 0, 1005
for i in range(n):
if i % 2 == 0:
for j in range(a[i]):
myMap[x][y] = "/"
x += 1
y -= 1
y += 1
else:
f... | 46 | 93 | 8,601,600 | 6755066 | n = int(input())
a = list(map(int, input().split()))
x = [0] * (n + 1)
y = [0] * (n + 1)
for i in range(1, n + 1):
x[i] = x[i - 1] + a[i - 1]
y[i] = y[i - 1]
if i % 2 == 0:
y[i] -= a[i - 1]
else:
y[i] += a[i - 1]
# print(x)
# print(y)
m = min(y)
if m < 0:
for i in range(n + 1):
y[i] -= m
# print(y... | Codeforces Round 249 (Div. 2) | CF | 2,014 | 1 | 256 | Cardiogram | In this problem, your task is to use ASCII graphics to paint a cardiogram.
A cardiogram is a polyline with the following corners:
$$(0;0),(a_{1};a_{1}),(a_{1}+a_{2};a_{1}-a_{2}),(a_{1}+a_{2}+a_{3};a_{1}-a_{2}+a_{3}),\ldots,(\sum_{i=1}^{n}a_{i};\sum_{i=1}^{n}(-1)^{i+1}a_{i}).$$
That is, a cardiogram is fully defined ... | The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000. | Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print $$\sum_{i=1}^{n}a_{i}$$ characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for ... | null | Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.
http://assets.codeforces.com/rounds/435/1.txt
http://assets.codeforces.com/rounds/435/2.txt | [{"input": "5\n3 1 2 5 1", "output": "/\n\\\n/\n\\\n/\n\\\n/\n\\\n/\n\\\n\\\n/"}, {"input": "3\n1 5 1", "output": "/\n\\\n\\\n\\\n\\\n\\\n/"}] | 1,600 | ["implementation"] | 46 | [{"input": "5\r\n3 1 2 5 1\r\n", "output": " /\\ \r\n /\\/ \\ \r\n / \\ \r\n/ \\ \r\n \\/\r\n"}, {"input": "3\r\n1 5 1\r\n", "output": "/\\ \r\n \\ \r\n \\ \r\n \\ \r\n \\/\r\n"}, {"input": "2\r\n1 1\r\n", "output": "/\\\r\n"}, {"input": "2\r\n2 1\r\n", "output":... | false | stdio | null | true |
672/B | 672 | B | PyPy 3-64 | TESTS | 29 | 124 | 4,812,800 | 162232516 | n = int(input())
s = input()
l = []
for i in s:
l.append(i)
k = len(l)-len(set(l))
if k>25:
print(-1)
else:
print(k) | 47 | 46 | 0 | 177392204 | n=int(input())
a=input()
k=len({*a})
print([n-k,-1][n>26]) | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
672/B | 672 | B | Python 3 | TESTS | 29 | 124 | 204,800 | 57753472 | n=int(input())
s=input()
a=set(s)
x=n-len(a)
if x<26:
print(x)
else:
print(-1) | 47 | 46 | 102,400 | 139370353 | import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
inp = lambda: list(map(int, sys.stdin.readline().rstrip("\r\n").split()))
n=int(input())
s=input()
if n>26:
print(-1)
else:
ans=0
c=[0]*26
for i in s:
k=ord(i)-ord("a")
if c[k]>=1:
ans+=1
c[k]+=1
print... | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
672/B | 672 | B | PyPy 3 | TESTS | 29 | 77 | 1,740,800 | 167724844 | n = int(input())
s = input()
k = len(s)-len(set(s))
if k>25: print(-1)
else:print(k) | 47 | 46 | 102,400 | 204523035 | import sys
def take_input():
return sys.stdin.readline().strip()
def main():
n = int(take_input())
s = take_input()
ss = set(s)
k = 26 - len(ss)
j = n - len(ss)
if k < j:
print("-1")
else:
print(j)
if __name__ == "__main__":
main() | Codeforces Round 352 (Div. 2) | CF | 2,016 | 2 | 256 | Different is Good | A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string s to be distinct. Substring is a string formed by some numb... | The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the length of the string s.
The second line contains the string s of length n consisting of only lowercase English letters. | If it's impossible to change the string s such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. | null | In the first sample one of the possible solutions is to change the first character to 'b'.
In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko". | [{"input": "2\naa", "output": "1"}, {"input": "4\nkoko", "output": "2"}, {"input": "5\nmurat", "output": "0"}] | 1,000 | ["constructive algorithms", "implementation", "strings"] | 47 | [{"input": "2\r\naa\r\n", "output": "1\r\n"}, {"input": "4\r\nkoko\r\n", "output": "2\r\n"}, {"input": "5\r\nmurat\r\n", "output": "0\r\n"}, {"input": "6\r\nacbead\r\n", "output": "1\r\n"}, {"input": "7\r\ncdaadad\r\n", "output": "4\r\n"}, {"input": "25\r\npeoaicnbisdocqofsqdpgobpn\r\n", "output": "12\r\n"}, {"input": ... | false | stdio | null | true |
718/A | 718 | A | Python 3 | TESTS | 13 | 202 | 5,017,600 | 20960481 | l, t = (int(i) for i in input().split())
x = input()
integ = 0
for d in x:
if d == '.':
break
integ += 1
n = [int(i) for i in x if i != '.']
earliest = [t+1] * len(n)
for i in range(l-3, integ-2, -1):
if n[i+1] > 4:
earliest[i] = 1
elif n[i+1] == 4:
earliest[i] = earliest[i+1]... | 90 | 109 | 24,473,600 | 221870739 | import sys
input = lambda: sys.stdin.readline().rstrip()
N,t = map(int, input().split())
S = input()
sign = 0
A = []
for i in range(N):
if S[i]=='.':
sign = 1
elif sign:
a = int(S[i])
if a>=5:
A = [c for c in S[:i+1]]
break
if not A:
exit(print(... | Codeforces Round 373 (Div. 1) | CF | 2,016 | 1 | 256 | Efim and Strange Grade | Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th... | The first line of the input contains two integers n and t (1 ≤ n ≤ 200 000, 1 ≤ t ≤ 109) — the length of Efim's grade and the number of seconds till the end of the break respectively.
The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least one digit after the... | Print the maximum grade that Efim can get in t seconds. Do not print trailing zeroes. | null | In the first two samples Efim initially has grade 10.245.
During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect.
In the third sample the optimal strategy is to not perform any rounding at all. | [{"input": "6 1\n10.245", "output": "10.25"}, {"input": "6 2\n10.245", "output": "10.3"}, {"input": "3 100\n9.2", "output": "9.2"}] | 1,700 | ["dp", "implementation", "math"] | 90 | [{"input": "6 1\r\n10.245\r\n", "output": "10.25\r\n"}, {"input": "6 2\r\n10.245\r\n", "output": "10.3\r\n"}, {"input": "3 100\r\n9.2\r\n", "output": "9.2\r\n"}, {"input": "12 5\r\n872.04488525\r\n", "output": "872.1\r\n"}, {"input": "35 8\r\n984227318.2031144444444444494637612\r\n", "output": "984227318.2031144445\r\n... | false | stdio | null | true |
721/B | 721 | B | Python 3 | TESTS | 13 | 46 | 0 | 153357837 | import math;
n, k = map(int, input().split());
l = {};
for i in range(n):
p = input();
if len(p) in l: l[len(p)]+=1;
else: l[len(p)] = 1;
ansL = len(input());
sum = 0;
best = 1;
for j in range(1, ansL):
if j in l:
sum+=l[j];
best+=(sum+math.floor(sum/k)*5);
worst = best+(math.floor((l[ansL]-1)/k... | 66 | 46 | 0 | 158543454 | n, k = list(map(int, input().split()))
count_len_password = [0] * 101 # length password != 0
for _ in range(n):
wrong_password = input()
count_len_password[len(wrong_password)] += 1
true_password = input()
best_case = 0
worst_case = 0
i = 1
while i < len(true_password):
best_case += count_len_password[... | Codeforces Round 374 (Div. 2) | CF | 2,016 | 2 | 256 | Passwords | Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar... | The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | null | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | [{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}] | 1,100 | ["implementation", "math", "sortings", "strings"] | 66 | [{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu... | false | stdio | null | true |
721/B | 721 | B | PyPy 3 | TESTS | 13 | 124 | 20,172,800 | 124658422 | n, k = list(map(int, input().split()))
a = []
for i in range(n):
l = input()
a.append(l)
pswd = input()
a = sorted(a, key=len)
time = 0
count = 0
for i in range(len(a)):
count += 1
if len(a[i]) < len(pswd):
if count < k:
time += 1
else:
time += 6
cou... | 66 | 46 | 0 | 159515681 | n, k = map(int, input().split())
cnt = [0] * 101
for _ in range(n):
s = input()
cnt[len(s)] += 1
password = input()
best_time = worst_time = 0
for i in range(len(password)):
best_time += cnt[i]
worst_time = best_time + cnt[len(password)] - 1
best_time += (best_time // k) * 5
worst_time += (worst_time /... | Codeforces Round 374 (Div. 2) | CF | 2,016 | 2 | 256 | Passwords | Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar... | The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | null | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | [{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}] | 1,100 | ["implementation", "math", "sortings", "strings"] | 66 | [{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu... | false | stdio | null | true |
721/B | 721 | B | PyPy 3-64 | TESTS | 13 | 62 | 0 | 174917062 | import sys
tokens = (token for token in sys.stdin.read().split())
N = int(next(tokens))
K = int(next(tokens))
ls = []
for _ in range(N):
ls.append(len(next(tokens)))
ans_len = len(next(tokens))
ls.sort()
index_of_first_ans = ls.index(ans_len)
index_of_last_ans = len(ls) - ls[::-1].index(ans_len) - 1
min_time... | 66 | 46 | 0 | 168885700 | n, k = map(int, input().split())
arr = [0] * 101
for i in range(n):
st = input()
arr[len(st)] += 1
st = input()
min = 0
for i in range(1, len(st)): min += arr[i]
print(min + 5 * (min // k) + 1, 5 * ((min + arr[len(st)] - 1) // k) + min + arr[len(st)]) | Codeforces Round 374 (Div. 2) | CF | 2,016 | 2 | 256 | Passwords | Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.
Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrar... | The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.
The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters a... | Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively. | null | Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he ente... | [{"input": "5 2\ncba\nabc\nbb1\nabC\nABC\nabc", "output": "1 15"}, {"input": "4 100\n11\n22\n1\n2\n22", "output": "3 4"}] | 1,100 | ["implementation", "math", "sortings", "strings"] | 66 | [{"input": "5 2\r\ncba\r\nabc\r\nbb1\r\nabC\r\nABC\r\nabc\r\n", "output": "1 15\r\n"}, {"input": "4 100\r\n11\r\n22\r\n1\r\n2\r\n22\r\n", "output": "3 4\r\n"}, {"input": "1 1\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "1 100\r\na1\r\na1\r\n", "output": "1 1\r\n"}, {"input": "2 1\r\nabc\r\nAbc\r\nAbc\r\n", "outpu... | false | stdio | null | true |
405/B | 405 | B | PyPy 3 | TESTS | 9 | 77 | 0 | 232790793 | n = int(input())
s = input()
l = []
for i in range(n):
if s[i] != ".":
l.append(i)
c = 0
for i in range(1, len(l) - 1):
if (l[i] - l[i - 1] - 1) % 2 != 0:
c += 1
if len(l) == 0:
c = n
else:
if s[l[0]] == "R":
c += l[0]
if s[l[-1]] == "L":
c += len(s) - l[-1] - 1
print(c) | 61 | 62 | 0 | 6108441 | n = int(input())
a = input().strip()
nextl = [-1] * n
lastr = [-1] * n
ll = -1
for i in range(n):
if a[i] == "R":
ll = i
if a[i] == "L":
ll = -1
lastr[i] = ll
nl = -1
for i in range(n - 1, -1, -1):
if a[i] == "L":
nl = i
if a[i] == "R":
nl = -1
nextl[i] = nl
ans =... | Codeforces Round 238 (Div. 2) | CF | 2,014 | 1 | 256 | Domino Effect | Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes... | The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to
- "L", if the i-th domino has been pushed to the left;
- "R", if the i-th domino has been pushed to the right;
- ".... | Output a single integer, the number of the dominoes that remain vertical at the end of the process. | null | The first example case is shown on the figure. The four pieces that remain standing vertically are highlighted with orange.
In the second example case, all pieces fall down since the first piece topples all the other pieces.
In the last example case, a single piece has not been pushed in either direction. | [{"input": "14\n.L.R...LR..L..", "output": "4"}, {"input": "5\nR....", "output": "0"}, {"input": "1\n.", "output": "1"}] | 1,100 | [] | 61 | [{"input": "14\r\n.L.R...LR..L..\r\n", "output": "4\r\n"}, {"input": "5\r\nR....\r\n", "output": "0\r\n"}, {"input": "1\r\n.\r\n", "output": "1\r\n"}, {"input": "1\r\nL\r\n", "output": "0\r\n"}, {"input": "1\r\nR\r\n", "output": "0\r\n"}, {"input": "2\r\nL.\r\n", "output": "1\r\n"}, {"input": "2\r\nRL\r\n", "output": "... | false | stdio | null | true |
101/A | 101 | A | Python 3 | TESTS | 45 | 186 | 409,600 | 171764000 | from collections import Counter
variableS = input()
strLen = len(variableS)
variableN = int(input())
finalUniqueChar = 0
if (variableN > len(variableS)):
print ("0")
else:
myCounter = Counter(variableS)
counterLen = len(myCounter)
finalUniqueChar = counterLen
#print (myCounter)
#print (cou... | 48 | 92 | 102,400 | 197661281 | # LUOGU_RID: 104929878
s = input()
k = int(input())
for c, ch in sorted([[s.count(x), x] for x in set(s)]):
if c <= k:
k -= c
s = s.replace(ch, '')
print(len(set(s)))
print(s) | Codeforces Beta Round 79 (Div. 1 Only) | CF | 2,011 | 2 | 256 | Homework | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to l... | The first input data line contains a string whose length is equal to n (1 ≤ n ≤ 105). The string consists of lowercase Latin letters. The second line contains the number k (0 ≤ k ≤ 105). | Print on the first line the only number m — the least possible number of different characters that could remain in the given string after it loses no more than k characters.
Print on the second line the string that Gerald can get after some characters are lost. The string should have exactly m distinct characters. The... | null | In the first sample the string consists of five identical letters but you are only allowed to delete 4 of them so that there was at least one letter left. Thus, the right answer is 1 and any string consisting of characters "a" from 1 to 5 in length.
In the second sample you are allowed to delete 4 characters. You cann... | [{"input": "aaaaa\n4", "output": "1\naaaaa"}, {"input": "abacaba\n4", "output": "1\naaaa"}, {"input": "abcdefgh\n10", "output": "0"}] | 1,200 | ["greedy"] | 48 | [{"input": "aaaaa\r\n4\r\n", "output": "1\r\naaaaa\r\n"}, {"input": "abacaba\r\n4\r\n", "output": "1\r\naaaa\r\n"}, {"input": "abcdefgh\r\n10\r\n", "output": "0\r\n\r\n"}, {"input": "aaaaaaaaaaaaaaaaaaaa\r\n19\r\n", "output": "1\r\naaaaaaaaaaaaaaaaaaaa\r\n"}, {"input": "abcdefghijjihgedcba\r\n0\r\n", "output": "10\r\na... | false | stdio | import sys
from collections import Counter
def is_subsequence(t, s):
it = iter(s)
try:
for c in t:
while next(it) != c:
pass
return True
except StopIteration:
return False
def compute_min_m(s, k):
total = len(s)
required_sum = total - k
if re... | true |
731/B | 731 | B | Python 3 | TESTS | 3 | 62 | 6,963,200 | 128937732 | # / *
#
# / \ | | / \ | | | |
# / __\ | | / __\ |--| | |
# / \ |__ | __ / \ | | \__ /
#
# __ __
# / \ | / | ) / \ | )
# / __\ |< |-< / __\ |-<
# / \ | \ |__) / \ | \
#
# * /
# / *
#
# / \ | | / \ | | | |
# ... | 79 | 124 | 18,022,400 | 203314706 | n = int(input())
col = [int(i) for i in input().split()] + [0]
ans = 'YES'
for i in range(n):
if col[i] % 2 != 0:
if col[i+1] > 0:
col[i+1] -= 1
else:
ans = 'NO'
break
print(ans) | Codeforces Round 376 (Div. 2) | CF | 2,016 | 1 | 256 | Coupons and Discounts | The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu... | The first line of input contains a single integer n (1 ≤ n ≤ 200 000) — the number of training sessions.
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 10 000) — the number of teams that will be present on each of the days. | If there is a way to order pizzas using only coupons and discounts and do not buy any extra pizzas on any of the days, then print "YES" (without quotes) in the only line of output. Otherwise, print "NO" (without quotes). | null | In the first sample, Sereja can use one coupon to buy one pizza on the first and the second days, one coupon to buy pizza on the second and the third days and one discount to buy pizzas on the fourth days. This is the only way to order pizzas for this sample.
In the second sample, Sereja can't use neither the coupon n... | [{"input": "4\n1 2 1 2", "output": "YES"}, {"input": "3\n1 0 1", "output": "NO"}] | 1,100 | ["constructive algorithms", "greedy"] | 79 | [{"input": "4\r\n1 2 1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n2 0 2\r\n", "output": "YES\r\n"}, {"input": "1\r\n179\r\n", "output": "NO\r\n"}, {"input": "10\r\n0 0 5 9 9 3 0 0 0 10\r\n", "output": "YES\r\n"}, {"inpu... | false | stdio | null | true |
732/B | 732 | B | PyPy 3-64 | TESTS | 4 | 77 | 0 | 232081108 | import heapq
from math import gcd,lcm
from collections import Counter
# Shortcut for input
def I(): return int(input())
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def S(): return ... | 70 | 46 | 0 | 210681332 | n,k=map(int,input().split())
l=list(map(int,input().split()))
added=0;x=0
for i in range(n-1):
if l[i]+l[i+1]<k:
added=k-(l[i]+l[i+1])
x+=added
l[i+1]+=added
print(x)
for i in l:
print(i,end=" ") | Codeforces Round 377 (Div. 2) | CF | 2,016 | 1 | 256 | Cormen — The Best Friend Of a Man | Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk.
Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a ... | The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days.
The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned. | In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days.
In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i fro... | null | null | [{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}] | 1,000 | ["dp", "greedy"] | 70 | [{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output"... | false | stdio | null | true |
426/B | 426 | B | Python 3 | TESTS | 9 | 46 | 0 | 197874420 | x,y=map(int,input().split())
if x%2!=0:
print(x)
else:
cnt=1
temp=[0]
for i in range(x):
temp.append(input())
temp+=[0]
while 2**cnt<=x:
flag = 1
weizhi1 = x //(2 * cnt)
weizhi2 = x // (2 * cnt) + 1
while flag and weizhi1 > 0:
if temp[weizhi1] ... | 65 | 62 | 0 | 10546155 | def f(c):
n = len(c)
if (n % 2 == 1):
return n
for i in range(n):
if c[i] != c[n - i - 1]:
return n
return f(c[:n // 2])
n, m = map(int, input().split())
c = [input() for i in range(n)]
print(f(c)) | Codeforces Round 243 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Mirroring | Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:
- the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;
- the lower half of matrix c (rows with number... | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | null | In the first test sample the answer is a 2 × 3 matrix b:
If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input: | [{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}] | 1,300 | ["implementation"] | 65 | [{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\... | false | stdio | null | true |
351/A | 351 | A | Python 3 | TESTS | 33 | 92 | 204,800 | 4710340 | k = 0
ans = 0
n = int(input())
a = input().split()
for i in range(2 * n):
s = float(a[i])
if s != int(s):
k+=1
ans += (int(s) + 1 - s)
if ans - int(ans) > 0.5:
p = int(ans) + 1
else:
p = int(ans)
if (p + n >= k):
print('%.3f'% abs(ans - p))
else:
print('%.3f'% abs(ans - k + n)) | 63 | 92 | 307,200 | 4669827 | from math import ceil, floor
N = int(input())
Nums = list(map(float, input().split()))
Zeros = 0
Sum = 0.0
for Num in Nums:
if Num - floor(Num) == 0:
Zeros += 1
else:
Sum += Num - floor(Num)
Best = float(10 ** 9)
for i in range(Zeros + 1):
Best = min(Best, abs(N - Zeros + i - Sum))
Best = s... | Codeforces Round 204 (Div. 1) | CF | 2,013 | 1 | 256 | Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai ... | The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | null | In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | [{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}] | 1,800 | ["dp", "greedy", "implementation", "math"] | 63 | [{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486.... | false | stdio | null | true |
351/A | 351 | A | Python 3 | TESTS | 33 | 124 | 307,200 | 4788928 | from sys import *
s1=stdin.readline().strip()
n=int(s1)
s1=stdin.readline().strip()
a=list(map(float,s1.split()))
b=[]
for i in range (2*n):
if int(a[i])!=a[i]:
b.append(a[i]-int(a[i]))
m=len(b)
r=0
for i in range (m):
r=r+b[i]
if m<=n:
if r>m:
r=r-m
else:
r=min(r-int(r),1-r+in... | 63 | 124 | 5,836,800 | 34803918 | n = int(input())
l = list(map(float, input().split()))
l = sorted([x - int(x) for x in l if x - int(x) != 0])
o = 2*n - len(l)
su = sum(l)
ans = 0xFFFFFFFFFFFFFFF
for i in range(n + 1):
if i + o >= n:
ans = min(ans, abs(i-su))
print("%.3f" % ans) | Codeforces Round 204 (Div. 1) | CF | 2,013 | 1 | 256 | Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai ... | The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | null | In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | [{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}] | 1,800 | ["dp", "greedy", "implementation", "math"] | 63 | [{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486.... | false | stdio | null | true |
351/A | 351 | A | Python 3 | TESTS | 33 | 92 | 307,200 | 4789002 | from sys import *
s1=stdin.readline().strip()
n=int(s1)
s1=stdin.readline().strip()
a=list(map(float,s1.split()))
b=[]
for i in range (2*n):
if int(a[i])!=a[i]:
b.append(round(1000*(a[i]-int(a[i]))))
m=len(b)
r=0
for i in range (m):
r=r+b[i]
if m<=n:
if r>=1000*m:
r=r-1000*m
else:
... | 63 | 154 | 1,945,600 | 217202135 | from math import ceil,floor
n = int(input())
total = 0
m = 0
answer = float('inf')
for a in map(float,input().split()):
if floor(a) == ceil(a):
m += 1
total += ceil(a)-a
for i in range(n-m,n+1):
answer = min(answer,abs(total-i))
print("{:.3f}".format(answer)) | Codeforces Round 204 (Div. 1) | CF | 2,013 | 1 | 256 | Jeff and Rounding | Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows:
- choose indexes i and j (i ≠ j) that haven't been chosen yet;
- round element ai ... | The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. | In a single line print a single real number — the required difference with exactly three digits after the decimal point. | null | In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25. | [{"input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250"}, {"input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279"}] | 1,800 | ["dp", "greedy", "implementation", "math"] | 63 | [{"input": "3\r\n0.000 0.500 0.750 1.000 2.000 3.000\r\n", "output": "0.250\r\n"}, {"input": "3\r\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896\r\n", "output": "0.279\r\n"}, {"input": "3\r\n673.674 9263.142 6780.000 9801.000 4640.000 8244.000\r\n", "output": "0.184\r\n"}, {"input": "3\r\n6470.649 8295.000 8486.... | false | stdio | null | true |
985/B | 985 | B | Python 3 | TESTS | 12 | 1,591 | 921,600 | 39611323 | n,m=map(int,input().split())
l=[]
for i in range(n):
s=input()
l.append(int(s,2))
number=2**m-1
k,flag=1,False
for i in range(1,n):
x=l[0]
for j in range(1,n):
if j==k:
continue
x=x|l[j]
if x==number:
flag=True
break
k+=1
if flag:
print('YES')
else:
print('NO') | 67 | 124 | 5,222,400 | 38520790 | input()
a = list(map(lambda s: int(s, 2), __import__('sys').stdin.readlines()))
t = T = 0
for x in a:
t |= T & x
T |= x
print(['YES', 'NO'][all(x & (x ^ t) for x in a)]) | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Switches and Lamps | You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are t... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.
The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.
It is guaranteed that if you press all... | Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. | null | null | [{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}] | 1,200 | ["implementation"] | 67 | [{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\... | false | stdio | null | true |
908/B | 908 | B | Python 3 | TESTS | 3 | 46 | 5,529,600 | 33840360 | from itertools import permutations
p = [[0, 1], [1, 0], [0, -1], [-1, 0]]
n, m = map(int, input().split())
a = [[False] * m] * n
s, e = [], []
for i in range(n):
for j, v in enumerate(input()):
if v == 'S':
s = [i, j]
elif v == 'E':
e = [i, j]
elif v == '.':
... | 46 | 46 | 0 | 151084604 | import itertools
n, m = map(int, input().rstrip().split())
mas = []
start = [0, 0]
end = [0, 0]
for i in range(n):
s = input()
for j in range(len(s)):
if s[j] == 'S':
start = [i, j]
elif s[j] == 'E':
end = [i, j]
mas.append(s)
k = input()
cou = 0
for i1, i2, i3, i4 ... | Good Bye 2017 | CF | 2,017 | 1 | 256 | New Year and Buggy Bot | Bob programmed a robot to navigate through a 2d maze.
The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.
There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single ex... | The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.
The next n lines will contain exactly m characters each, denoting the maze.
Each character of the maze will be '.', '#', 'S', or 'E'.
There will be exactly one 'S' and exactly one 'E' in the maze.
The las... | Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit. | null | For the first sample, the only valid mapping is $$0 \rightarrow D, 1 \rightarrow L, 2 \rightarrow U, 3 \rightarrow R$$, where D is down, L is left, U is up, R is right. | [{"input": "5 6\n.....#\nS....#\n.#....\n.#....\n...E..\n333300012", "output": "1"}, {"input": "6 6\n......\n......\n..SE..\n......\n......\n......\n01232123212302123021", "output": "14"}, {"input": "5 3\n...\n.S.\n###\n.E.\n...\n3", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 46 | [{"input": "5 6\r\n.....#\r\nS....#\r\n.#....\r\n.#....\r\n...E..\r\n333300012\r\n", "output": "1\r\n"}, {"input": "6 6\r\n......\r\n......\r\n..SE..\r\n......\r\n......\r\n......\r\n01232123212302123021\r\n", "output": "14\r\n"}, {"input": "5 3\r\n...\r\n.S.\r\n###\r\n.E.\r\n...\r\n3\r\n", "output": "0\r\n"}, {"input"... | false | stdio | null | true |
426/B | 426 | B | Python 3 | TESTS | 21 | 46 | 0 | 197871585 | hang,lie=(int(x) for x in input().split())
#print(hang,lie)
lst=[]
for i in range(hang):
lst.append([int(x) for x in input().split()])
'''
lst=[[0,0,1],[1,1,0],[1,1,0],[0,0,1]]
lst=[[0],[1],[1],[0],[0],[1],[1],[1]]
hang,lie=(8,1)'''
def solve(lst,hang,lie):
#print(lst)
if(hang%2==1):
print... | 65 | 62 | 0 | 30815882 | n,m=map(int,input().split())
arr=[input()for i in range(n)]
while n%2==0:
if arr[:n]==list(reversed(arr[:n])):n//=2
else:break
print(n) | Codeforces Round 243 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Mirroring | Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:
- the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;
- the lower half of matrix c (rows with number... | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | null | In the first test sample the answer is a 2 × 3 matrix b:
If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input: | [{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}] | 1,300 | ["implementation"] | 65 | [{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\... | false | stdio | null | true |
962/B | 962 | B | Python 3 | TESTS | 9 | 77 | 7,577,600 | 37291054 | count = 0
a = input().split()
totseats = int(a[0])
totprog = int(a[1])
totath = int(a[2])
sum = totath+totprog
for x in map(len , input().split('*')):
count = count +x
if(sum>count):
print(count)
elif(count>sum):
print(sum)
elif(count==sum):
print(sum) | 93 | 109 | 6,041,600 | 107164129 | n,a,b=map(int,input().split())
t=a+b
for x in map(len,input().split('*')):
if a<b:a,b=b,a
b-=min(b,x//2);a-=min(a,x-x//2)
print(t-a-b) | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Students in Railway Carriage | There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in t... | The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with len... | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | null | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, an... | [{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}] | 1,300 | ["constructive algorithms", "greedy", "implementation"] | 93 | [{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6... | false | stdio | null | true |
524/B | 524 | B | Python 3 | TESTS | 9 | 46 | 0 | 11364076 | n = int(input())
max_ = -1
sum_w = 0
sum_h = 0
max_w = -1
a = []
b = []
for i in range(n):
w,h = map(int,input().split())
a.append(w)
b.append(h)
if (w > max_w):
max_w = w
if (h > max_):
max_ = h
sum_w_1 = 0
sum_h_1 = 0
for i in range(len(a)):
if (b[i] <= max_):
if ((b[i]... | 60 | 155 | 2,150,400 | 97398123 | import sys
input = sys.stdin.readline
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
def lcm(a, b):
return (a * b) / gcd(a, b)
def main():
n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input().split())))
ans=float('inf')
for i in range(... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно ... | В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,700 | ["dp", "greedy"] | 60 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780... | false | stdio | null | true |
102/B | 102 | B | Python 3 | TESTS | 9 | 92 | 2,355,200 | 207448999 | x=str(input())
counter=1
for i in x:
sukm=sum([int(i) for i in x])
if(sukm==0):
print(0);
break
if(len(str(sukm))==1):
print(counter)
break
counter+=1
x=str(sukm) | 51 | 92 | 0 | 192450551 | n = input()
ans = 0
while len(n) > 1:
n = str(sum(map(int, n)))
ans += 1
print(ans) | Codeforces Beta Round 79 (Div. 2 Only) | CF | 2,011 | 2 | 265 | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | null | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | [{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}] | 1,000 | ["implementation"] | 51 | [{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "... | false | stdio | null | true |
102/B | 102 | B | PyPy 3-64 | TESTS | 9 | 92 | 2,662,400 | 156283864 | def SumOfNumber():
a = str(input())
sum = 0
count = 0
if(len(a)==1):
print(a)
return
while(len(a)!=1):
for x in a:
sum +=int(x)
a=str(sum)
sum=0
count+=1
print(count)
if __name__ == '__main__':
SumOfNumber() | 51 | 92 | 102,400 | 149083198 | num = input()
ans = 0
def getSum(n):
sum = 0
for digit in str(n):
sum += int(digit)
return sum
def c(n):
global ans
if len(str(n)) == 1:
return
ans += 1
c(getSum(n))
c(num)
print(ans) | Codeforces Beta Round 79 (Div. 2 Only) | CF | 2,011 | 2 | 265 | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | null | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | [{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}] | 1,000 | ["implementation"] | 51 | [{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "... | false | stdio | null | true |
102/B | 102 | B | PyPy 3-64 | TESTS | 9 | 122 | 1,740,800 | 226956248 | num= input().strip()
count= 0
if num!= '0':
numsum = sum(map(int,num))
count+= 1
while numsum > 9:
m = numsum
numsum = 0
while m != 0:
numsum += m % 10
m //= 10
count+= 1
print(count) | 51 | 92 | 102,400 | 207416987 | import math
import sys
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp(): # one integer input
return(int(input()))
def inlt(): # list input
return(list(map(int,input().split())))
def insr(): # string input
s = input()
return(list(s[:len(s) - 1]))
def invr(): # mul... | Codeforces Beta Round 79 (Div. 2 Only) | CF | 2,011 | 2 | 265 | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number n. How many times can Gerald put a spell on it until the number becomes one-di... | The first line contains the only integer n (0 ≤ n ≤ 10100000). It is guaranteed that n doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | null | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | [{"input": "0", "output": "0"}, {"input": "10", "output": "1"}, {"input": "991", "output": "3"}] | 1,000 | ["implementation"] | 51 | [{"input": "0\r\n", "output": "0\r\n"}, {"input": "10\r\n", "output": "1\r\n"}, {"input": "991\r\n", "output": "3\r\n"}, {"input": "99\r\n", "output": "2\r\n"}, {"input": "100\r\n", "output": "1\r\n"}, {"input": "123456789\r\n", "output": "2\r\n"}, {"input": "32\r\n", "output": "1\r\n"}, {"input": "86\r\n", "output": "... | false | stdio | null | true |
219/C | 219 | C | PyPy 3 | TESTS | 13 | 184 | 0 | 161633020 | import sys
input = sys.stdin.readline
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
def ch(cur,k):
global s
C=-1
for i in range(k):
if (s[i] not ... | 87 | 342 | 22,528,000 | 183600658 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, k = map(int, input().split())
s = list(input().rstrip())
if k == 2:
c = 0
for i in range(n):
c += (s[i] ^ i) & 1
m = min(n - c, c)
if 2 * c >= n:
ans = [chr((i % 2) + 65) for i in range(n)]
else:
... | Codeforces Round 135 (Div. 2) | CF | 2,012 | 2 | 256 | Color Stripe | A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells. | The first input line contains two integers n and k (1 ≤ n ≤ 5·105; 2 ≤ k ≤ 26). The second line contains n uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first k English letters may be used. Each letter represents the color of the corresponding ce... | Print a single integer — the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe. | null | null | [{"input": "6 3\nABBACC", "output": "2\nABCACA"}, {"input": "3 2\nBBB", "output": "1\nBAB"}] | 1,600 | ["brute force", "dp", "greedy"] | 87 | [{"input": "6 3\r\nABBACC\r\n", "output": "2\r\nABCACA\r\n"}, {"input": "3 2\r\nBBB\r\n", "output": "1\r\nBAB\r\n"}, {"input": "1 2\r\nA\r\n", "output": "0\r\nA\r\n"}, {"input": "1 26\r\nZ\r\n", "output": "0\r\nZ\r\n"}, {"input": "2 2\r\nAA\r\n", "output": "1\r\nAB\r\n"}, {"input": "2 2\r\nBA\r\n", "output": "0\r\nBA\r... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n, k = map(int, f.readline().split())
original = f.readline().strip()
with open(output_path) as f:
expected_count = int(f.readline().strip())
with open(submission_path) as f:
... | true |
532/E | 533 | E | Python 3 | TESTS | 18 | 109 | 307,200 | 81142199 | from math import *
n=int(input())
s=input()
t=input()
a=[]
for i in range(n):
if s[i]!=t[i]:
a.append([s[i],t[i]])
if len(a)==0:
print(26*(n+1))
elif len(a)==1:
print(2)
elif len(a)==2:
if(a[0][0]==a[1][0] or a[0][0]==a[1][1]):
print(1)
elif(a[0][1]==a[1][0] or a[0][1]==a[1][1]):
print(1)
else:
print(0)
... | 89 | 108 | 16,793,600 | 150151810 | n = int(input())
S = list(input())
T = list(input())
index = 0
for i in range(n):
if S[i] != T[i]:
index = i
break
S = S[index:]
T = T[index:]
n -= index
index = 0
for i in range(n-1, -1, -1):
if S[i] != T[i]:
index = i+1
break
S = S[0:index]
T = T[0:index]
answer = 0
equals = Tr... | VK Cup 2015 - Round 2 | CF | 2,015 | 2 | 256 | Correcting Mistakes | Analyzing the mistakes people make while typing search queries is a complex and an interesting work. As there is no guaranteed way to determine what the user originally meant by typing some query, we have to use different sorts of heuristics.
Polycarp needed to write a code that could, given two words, check whether t... | The first line contains integer n (1 ≤ n ≤ 100 000) — the length of words S and T.
The second line contains word S.
The third line contains word T.
Words S and T consist of lowercase English letters. It is guaranteed that S and T are distinct words. | Print a single integer — the number of distinct words W that can be transformed to S and T due to a typo. | null | In the first sample test the two given words could be obtained only from word "treading" (the deleted letters are marked in bold).
In the second sample test the two given words couldn't be obtained from the same word by removing one letter.
In the third sample test the two given words could be obtained from either wo... | [{"input": "7\nreading\ntrading", "output": "1"}, {"input": "5\nsweet\nsheep", "output": "0"}, {"input": "3\ntoy\ntry", "output": "2"}] | 1,800 | [] | 89 | [{"input": "7\r\nreading\r\ntrading\r\n", "output": "1\n"}, {"input": "5\r\nsweet\r\nsheep\r\n", "output": "0\n"}, {"input": "3\r\ntoy\r\ntry\r\n", "output": "2\n"}, {"input": "5\r\nspare\r\nspars\r\n", "output": "2\n"}, {"input": "1\r\na\r\nb\r\n", "output": "2\n"}, {"input": "1\r\nz\r\ny\r\n", "output": "2\n"}, {"inp... | false | stdio | null | true |
426/B | 426 | B | Python 3 | TESTS | 21 | 61 | 4,710,400 | 25696229 | line = input()
rows, cols = line.split()
rows, cols = int(rows), int(cols)
grid = []
for i in range(rows):
line = input()
a = [int(z) for z in line.split()]
grid.append(a)
if rows % 2 != 0:
print(rows)
else:
half = int(rows / 2)
row_count = rows
can_go = True
while can_go == True and ... | 65 | 62 | 0 | 228924635 | n, m = map(int, input().split())
a = [input() for i in range(n)]
while n%2 == 0 and a[:n] == list(reversed(a[:n])):
n = n // 2
print(n)# 1697806988.1422396 | Codeforces Round 243 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Mirroring | Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties:
- the upper half of matrix c (rows with numbers from 1 to x) exactly matches b;
- the lower half of matrix c (rows with number... | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | null | In the first test sample the answer is a 2 × 3 matrix b:
If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input: | [{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}] | 1,300 | ["implementation"] | 65 | [{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\... | false | stdio | null | true |
962/B | 962 | B | Python 3 | TESTS | 9 | 77 | 0 | 145149525 | n,a,b=map(int,input().split())
st=input()
num_of_pairs=min(a,b)
available_seats=0
for i in range(n):
if(st[i]=="."):
available_seats+=1
if(available_seats<=(2*num_of_pairs)):
print(available_seats)
else:
available_seats=available_seats-(2*num_of_pairs)
a-=num_of_pairs
b-=num_of_pairs
rem... | 93 | 109 | 8,704,000 | 37361365 | def Slove():
n,a,b=map(int,input().split())
ept=[]
for i in map(len,input().split('*')):
if(i>0):
ept.append(i)
s=a+b
for x in ept:
if a< b:
a,b=b,a
b-=min(b, x//2)
a-=min(a, x-x//2)
return s-(a+b)
print(Slove()) | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Students in Railway Carriage | There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in t... | The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with len... | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | null | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, an... | [{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}] | 1,300 | ["constructive algorithms", "greedy", "implementation"] | 93 | [{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6... | false | stdio | null | true |
962/B | 962 | B | Python 3 | TESTS | 13 | 93 | 8,089,600 | 37374753 | import sys
n, a, b = map(int, input().split())
s = list(map(str, input().split('*')))
# print (s)
k = 0
sum = a + b
if n == 200000 and a == 47626 and b == 150377:
print (147130)
sys.exit()
for i in s:
x = len(i) // 2
y = len(i) % 2
if a < b:
b -= (x + y)
a -= x
else:
b ... | 93 | 109 | 24,166,400 | 129281216 | n, a, b = map(int, input().split())
s = str(input())
X = []
cnt = 0
cur =s[0]
for c in s:
if c == cur:
cnt += 1
else:
if cur == '.':
X.append(cnt)
cur = c
cnt = 1
else:
if cur == '.' and cnt:
X.append(cnt)
#print(X)
ans = 0
for x in X:
m, l = x//2, x-x... | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Students in Railway Carriage | There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in t... | The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with len... | Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. | null | In the first example you can put all student, for example, in the following way: *.AB*
In the second example you can put four students, for example, in the following way: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, an... | [{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}] | 1,300 | ["constructive algorithms", "greedy", "implementation"] | 93 | [{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6... | false | stdio | null | true |
958/F2 | 958 | F2 | PyPy 3-64 | TESTS | 20 | 61 | 0 | 204183830 | n,m = map(int,input().split())
arr = list(map(int,input().split()))
colors = list(map(int,input().split()))
color_freq = [0]*(m+1)
subarr_freq = [0]*(m+1)
for i in range(m):
color_freq[i+1] = colors[i]
nonzeros = 0
for color in colors:
if color!=0:
nonzeros+=1
l,r = 0,0
cnt = 0
subarr_len = float("in... | 59 | 436 | 40,448,000 | 127420540 | from sys import stdin
class SegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [de... | Helvetic Coding Contest 2018 online mirror (teams allowed, unrated) | ICPC | 2,018 | 1 | 256 | Lightsabers (medium) | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains n (1 ≤ n ≤ 2·105) and m (1 ≤ m ≤ n). The second line contains n integers in the range {1, 2, ..., m} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains m integers k1, k2, ..., km (with $$1 \leq \sum_{i=1}^{m} k_i \leq n$$) – the desired co... | Output one number: the minimum number of Jedi Knights that need to be removed from the sequence so that, in what remains, there is an interval with the prescribed counts of lightsaber colors. If this is not possible, output - 1. | null | null | [{"input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1", "output": "1"}] | 1,800 | ["binary search", "two pointers"] | 59 | [{"input": "8 3\r\n3 3 1 2 2 1 1 3\r\n3 1 1\r\n", "output": "1\r\n"}, {"input": "6 5\r\n1 2 4 2 4 3\r\n0 0 1 0 0\r\n", "output": "0\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "2 1\r\n1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n1 2\r\... | false | stdio | null | true |
10/D | 10 | D | PyPy 3 | TESTS | 16 | 108 | 1,638,400 | 172957992 | from sys import stdin,stdout
from collections import defaultdict
#input=stdin.readline
#print=stdout.write
import math
import sys
#sys.setrecursionlimit(10**6)
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def modDivide(a,b,m):
a = a %... | 61 | 155 | 1,945,600 | 95059088 | def lcis(a, b):
n, m = len(a), len(b)
dp = [0]*m
best_seq, max_len = [], 0
for i in range(n):
current = 0
seq = []
for j in range(m):
if a[i] == b[j]:
f = seq + [a[i]]
if len(f) > max_len:
... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | LCIS | This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other wo... | The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-se... | In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | null | null | [{"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6"}, {"input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1"}] | 2,800 | ["dp"] | 61 | [{"input": "7\r\n2 3 1 6 5 4 6\r\n4\r\n1 3 5 6\r\n", "output": "3\r\n3 5 6 \r\n"}, {"input": "5\r\n1 2 0 2 1\r\n3\r\n1 0 1\r\n", "output": "2\r\n0 1 \r\n"}, {"input": "2\r\n6 10\r\n3\r\n6 3 3\r\n", "output": "1\r\n6 \r\n"}, {"input": "1\r\n7\r\n2\r\n7 9\r\n", "output": "1\r\n7 \r\n"}, {"input": "3\r\n37 49 24\r\n3\r\n3... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input data
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f]
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
m = int(input... | true |
10/D | 10 | D | PyPy 3-64 | TESTS | 4 | 46 | 0 | 213791149 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
dp = [0] * m
path = [-1] * m
for i in a:
now = 0
ind = -1
for j in range(m):
if b[j] < i:
if dp[j] > now:
now = dp[j]
ind = j
if b[j] == i:
... | 61 | 170 | 1,843,200 | 75066752 | """
s1=input()
s2=input()
n=len(s1)
m=len(s2)
dp=[]
for i in range(n+1):
h=[]
for j in range(m+1):
h.append(0)
dp.append(h)
for i in range(1,n+1):
for j in range(1,m+1):
if(s1[i-1]==s2[j-1]):
dp[i][j]=dp[i-1][j-1]+1
else:
dp[i][j]=max(dp[i-1][j],dp[i][j-1... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | LCIS | This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other wo... | The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-se... | In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | null | null | [{"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6"}, {"input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1"}] | 2,800 | ["dp"] | 61 | [{"input": "7\r\n2 3 1 6 5 4 6\r\n4\r\n1 3 5 6\r\n", "output": "3\r\n3 5 6 \r\n"}, {"input": "5\r\n1 2 0 2 1\r\n3\r\n1 0 1\r\n", "output": "2\r\n0 1 \r\n"}, {"input": "2\r\n6 10\r\n3\r\n6 3 3\r\n", "output": "1\r\n6 \r\n"}, {"input": "1\r\n7\r\n2\r\n7 9\r\n", "output": "1\r\n7 \r\n"}, {"input": "3\r\n37 49 24\r\n3\r\n3... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input data
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f]
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
m = int(input... | true |
10/D | 10 | D | Python 3 | TESTS | 12 | 108 | 307,200 | 76206747 | n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
d = [[0]*m for i in range(n)]
p = [[-1]*m for i in range(n)]
for i in range(n):
j1 = -1
for j in range(m):
if i==0:
if a[i]!=b[j]:
d[i][j] = 0
else:
... | 61 | 171 | 22,323,200 | 89312171 | n=int(input())
ar=list(map(int,input().split()))
m=int(input())
br=list(map(int,input().split()))
t=[0]*m
A=[[] for i in range(m)]
for i in range(n):
c=0
p=-1
for j in range(m):
if(ar[i]==br[j] and c+1>t[j]):
t[j]=c+1
A[j]=(A[p] if p!=-1 else []) +[ar[i]]
if(ar[i]>br[... | Codeforces Beta Round 10 | ICPC | 2,010 | 1 | 256 | LCIS | This problem differs from one which was on the online contest.
The sequence a1, a2, ..., an is called increasing, if ai < ai + 1 for i < n.
The sequence s1, s2, ..., sk is called the subsequence of the sequence a1, a2, ..., an, if there exist such a set of indexes 1 ≤ i1 < i2 < ... < ik ≤ n that aij = sj. In other wo... | The first line contains an integer n (1 ≤ n ≤ 500) — the length of the first sequence. The second line contains n space-separated integers from the range [0, 109] — elements of the first sequence. The third line contains an integer m (1 ≤ m ≤ 500) — the length of the second sequence. The fourth line contains m space-se... | In the first line output k — the length of the longest common increasing subsequence. In the second line output the subsequence itself. Separate the elements with a space. If there are several solutions, output any. | null | null | [{"input": "7\n2 3 1 6 5 4 6\n4\n1 3 5 6", "output": "3\n3 5 6"}, {"input": "5\n1 2 0 2 1\n3\n1 0 1", "output": "2\n0 1"}] | 2,800 | ["dp"] | 61 | [{"input": "7\r\n2 3 1 6 5 4 6\r\n4\r\n1 3 5 6\r\n", "output": "3\r\n3 5 6 \r\n"}, {"input": "5\r\n1 2 0 2 1\r\n3\r\n1 0 1\r\n", "output": "2\r\n0 1 \r\n"}, {"input": "2\r\n6 10\r\n3\r\n6 3 3\r\n", "output": "1\r\n6 \r\n"}, {"input": "1\r\n7\r\n2\r\n7 9\r\n", "output": "1\r\n7 \r\n"}, {"input": "3\r\n37 49 24\r\n3\r\n3... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input data
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f]
n = int(input_lines[0])
a = list(map(int, input_lines[1].split()))
m = int(input... | true |
613/A | 613 | A | Python 3 | TESTS | 37 | 452 | 409,600 | 90407765 | # from decimal import *
# getcontext().prec=16
# from math import sqrt
# from scipy.special import binom
# from collections import defaultdict
# from math import sin,pi,sqrt
from math import sqrt,hypot,pi
from collections import defaultdict
def dist(a, b, c):
return abs((c[1] - a[1])*b[0] - (c[0] - a[0])*b[1] + c[... | 60 | 624 | 13,312,000 | 194655416 | import math
n, px, py = map(int, input().split())
xs, ys, l = list(), list(), list()
for _ in range(n):
x, y = map(int, input().split())
xs.append(x - px)
ys.append(y - py)
x0, y0 = xs[-1], ys[-1]
for x, y in zip(xs, ys):
l.append(x * x + y * y)
dx, dy = x - x0, y - y0
if (x0 * dx + y0 * dy) * (x * dx + y * dy) <... | Codeforces Round 339 (Div. 1) | CF | 2,016 | 2 | 256 | Peter and Snow Blower | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon n ($$3 \leq n \leq 100\ 000$$), and coordinates of point P.
Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three ... | Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if $$\frac... | null | In the first sample snow will be removed from that area: | [{"input": "3 0 0\n0 1\n-1 2\n1 2", "output": "12.566370614359172464"}, {"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1", "output": "21.991148575128551812"}] | 1,900 | ["binary search", "geometry", "ternary search"] | 60 | [{"input": "3 0 0\r\n0 1\r\n-1 2\r\n1 2\r\n", "output": "12.566370614359172464\r\n"}, {"input": "4 1 -1\r\n0 0\r\n1 2\r\n2 0\r\n1 1\r\n", "output": "21.991148575128551812\r\n"}, {"input": "3 0 0\r\n-1 1\r\n0 3\r\n1 1\r\n", "output": "25.132741228718344928\r\n"}, {"input": "3 -4 2\r\n-3 2\r\n5 -5\r\n5 3\r\n", "output": ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path, 'r') as f:
ref_line = f.readline().strip()
try:
b = float(ref_line)
except:
print(0)
return
with open(submission_path, 'r') as f:
... | true |
985/B | 985 | B | Python 3 | TESTS | 12 | 1,747 | 26,419,200 | 38821504 | ## 985 B
(num_switches, num_lamps) = (int(_) for _ in input().split(' '))
a = []
for _ in range(num_switches):
a.append(list(input()))
switched_on_by = []
for lamp in range(num_lamps):
switched_on_by.append(sum([int(a[i][lamp]) for i in range(num_switches)]))
num_1 = sum(1 if x <= 1 else 0 for x in switched_o... | 67 | 139 | 1,228,800 | 71380413 | n, _ = map(int, input().split())
switches = [int(input(), 2) for _ in range(n)]
extra = lit = 0
for switch in switches:
extra |= lit & switch
lit |= switch
necessary = ~extra
print('NO' if all(switch & necessary for switch in switches) else 'YES') | Educational Codeforces Round 44 (Rated for Div. 2) | ICPC | 2,018 | 3 | 256 | Switches and Lamps | You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp.
Initially all m lamps are t... | The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps.
The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise.
It is guaranteed that if you press all... | Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch. | null | null | [{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}] | 1,200 | ["implementation"] | 67 | [{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\... | false | stdio | null | true |
186/A | 186 | A | Python 3 | TESTS | 37 | 154 | 409,600 | 119292685 | s1 = input()
s2 = input()
if len(s1) != len(s2):
print('NO')
else:
flag = False
d = {}
for i in range(len(s1)):
if s1[i] != s2[i]:
if not flag:
if not d:
d[s1[i]] = s2[i]
else:
if s2[i] in d and d[s2[i]] == s1[i... | 53 | 92 | 204,800 | 138952234 | x = input()
y = input()
if len(x) != len(y):
print('NO')
else:
flag = 0
n = len(x)
l = -1
r = -1
for i in range(n):
if x[i] != y[i] :
if flag == 0:
l = i
elif flag == 1:
r = i
else:
print('NO')
... | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
186/A | 186 | A | Python 3 | TESTS | 36 | 154 | 2,048,000 | 193781916 | genome1 = input().strip()
genome2 = input().strip()
if len(genome1) != len(genome2):
print("NO")
elif genome1 == genome2:
print("YES")
else:
differing_positions = []
for i in range(len(genome1)):
if genome1[i] != genome2[i]:
differing_positions.append(i)
if len(differing_positio... | 53 | 92 | 204,800 | 158938450 | s1 = input()
s2 = input()
if(len(s1)!=len(s2)):
print("NO")
else:
if(len(s1)==1):
print("NO")
else:
c=0
pos1=0
pos2=0
flag=0
for i in range(0,len(s1)):
if(s1[i]!=s2[i]):
c+=1
if(c==1):
pos1=i
... | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
747/D | 747 | D | PyPy 3 | TESTS | 30 | 280 | 18,227,200 | 55952919 | R = lambda: map(int, input().split())
n, k = R()
ts = list(R()) + [-1]
k -= sum(1 if t < 0 else 0 for t in ts[:n])
res = 0 if ts[0] >= 0 else 1
for i in range(1, n):
if ts[i - 1] < 0 and ts[i] >= 0 or ts[i - 1] >= 0 and ts[i] < 0:
res += 1
locs = [i for i, t in enumerate(ts) if t < 0]
ps = sorted((y - x - 1... | 59 | 139 | 23,040,000 | 213484055 | def rl():
return list(map(int,input().split()))
def ri():
return int(input())
def rs():
return input()
def rm():
return map(int,input().split())
def main():
n,k=rm()
a=rl()
b=[1 if a[0]>=0 else -1]
pos=1 if a[0]>=0 else 0
for i in range(1,n):
if int(a[i]<0)^pos: b[-1]+=(2*po... | Codeforces Round 387 (Div. 2) | CF | 2,016 | 1 | 256 | Winter Is Coming | The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of using it (regardless of the temperature of these days) the set of wint... | The first line contains two positive integers n and k (1 ≤ n ≤ 2·105, 0 ≤ k ≤ n) — the number of winter days and the number of days winter tires can be used. It is allowed to drive on winter tires at any temperature, but no more than k days in total.
The second line contains a sequence of n integers t1, t2, ..., tn ( ... | Print the minimum number of times Vasya has to change summer tires to winter tires and vice versa to drive safely during all winter. If it is impossible, print -1. | null | In the first example before the first winter day Vasya should change summer tires to winter tires, use it for three days, and then change winter tires to summer tires because he can drive safely with the winter tires for just three days. Thus, the total number of tires' changes equals two.
In the second example before... | [{"input": "4 3\n-5 20 -3 0", "output": "2"}, {"input": "4 2\n-5 20 -3 0", "output": "4"}, {"input": "10 6\n2 -5 1 3 0 0 -4 -3 1 0", "output": "3"}] | 1,800 | ["dp", "greedy", "sortings"] | 59 | [{"input": "4 3\r\n-5 20 -3 0\r\n", "output": "2\r\n"}, {"input": "4 2\r\n-5 20 -3 0\r\n", "output": "4\r\n"}, {"input": "10 6\r\n2 -5 1 3 0 0 -4 -3 1 0\r\n", "output": "3\r\n"}, {"input": "4 4\r\n-5 20 -3 0\r\n", "output": "1\r\n"}, {"input": "4 1\r\n-5 20 -3 0\r\n", "output": "-1\r\n"}, {"input": "1 0\r\n-13\r\n", "o... | false | stdio | null | true |
186/A | 186 | A | PyPy 3 | TESTS | 41 | 280 | 2,355,200 | 60299271 | import sys
s1 = sys.stdin.readline().strip()
s2 = sys.stdin.readline().strip()
def oneReplaced(s1,s2):
if len(s1)!=len(s2):
return 'NO'
anyPositions = []
for pos in range(len(s1)):
if s1[pos]!=s2[pos]:
anyPositions.append(pos)
if len(anyPositions)>3:
... | 53 | 92 | 204,800 | 210640979 | def solve(s1, s2):
if len(s1) != len(s2):
return False
anomaly = -1
for i in range(len(s1)):
if s1[i] != s2[i]:
if anomaly == -2:
return False
elif anomaly != -1:
if s1[anomaly] != s2[i] or s1[i] != s2[anomaly]:
re... | Codeforces Round 118 (Div. 2) | CF | 2,012 | 2 | 256 | Comparing Strings | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | null | - First example: you can simply swap two letters in string "ab". So we get "ba".
- Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | [{"input": "ab\nba", "output": "YES"}, {"input": "aa\nab", "output": "NO"}] | 1,100 | ["implementation", "strings"] | 53 | [{"input": "ab\r\nba\r\n", "output": "YES\r\n"}, {"input": "aa\r\nab\r\n", "output": "NO\r\n"}, {"input": "a\r\nza\r\n", "output": "NO\r\n"}, {"input": "vvea\r\nvvae\r\n", "output": "YES\r\n"}, {"input": "rtfabanpc\r\natfabrnpc\r\n", "output": "YES\r\n"}, {"input": "mt\r\ntm\r\n", "output": "YES\r\n"}, {"input": "qxolm... | false | stdio | null | true |
401/B | 401 | B | Python 3 | TESTS | 40 | 296 | 0 | 190271955 | a,b=map(int,input().split())
c=[]
m=[]
if b==0:
if a%2==0:
print(a//2,a-1)
else:
print(a//2+1,a-1)
else:
for i in range(b):
e=[int(j) for j in input().split()]
if len(e)==3:
c=c+[e[1]]+[e[2]]
if len(e)==2:
c=c+[e[1]]
for i in range(1,a):
... | 47 | 46 | 0 | 159723543 | I = lambda: map(int, input().split())
x, k = I()
R = [0, x]
for _ in range(k):
_, *r = I()
R += r
R.sort()
max_ = min_ = 0
for i in range(len(R)-1):
min_ += (R[i+1]-R[i]) // 2
max_ += R[i+1]-R[i]-1
print(min_, max_) | Codeforces Round 235 (Div. 2) | CF | 2,014 | 1 | 256 | Sereja and Contests | Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds.
Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot... | The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in.
Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding l... | Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed. | null | In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round.
The maximum number of rounds equals 3. ... | [{"input": "3 2\n2 1\n2 2", "output": "0 0"}, {"input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3"}, {"input": "10 0", "output": "5 9"}] | 1,200 | ["greedy", "implementation", "math"] | 47 | [{"input": "3 2\r\n2 1\r\n2 2\r\n", "output": "0 0"}, {"input": "9 3\r\n1 2 3\r\n2 8\r\n1 4 5\r\n", "output": "2 3"}, {"input": "10 0\r\n", "output": "5 9"}, {"input": "10 2\r\n1 1 2\r\n1 8 9\r\n", "output": "3 5"}, {"input": "9 3\r\n1 4 5\r\n1 1 2\r\n1 6 7\r\n", "output": "2 2"}, {"input": "7 2\r\n2 3\r\n1 5 6\r\n", "... | false | stdio | null | true |
451/B | 451 | B | Python 3 | TESTS | 73 | 78 | 12,800,000 | 214386230 | n=int(input())
a1=list(map(int,input().split()))
i=0
start=0
j=1
ans=[]
flag=True
while(j<n):
# print(j,n)
if(a1[j-1]<a1[j]):
j+=1
pass
else:
start=j
# print("start",start)
while(j<n and a1[j-1]>=a1[j]):
# print(j,n)
j+=1
# j+=1
... | 76 | 77 | 8,089,600 | 195570608 | n = int(input())
s=list(map(int, input().split()))
s1= sorted(s)
g = 0
q = 0
d=0
for i in range(len(s1)):
if s[i]!=s1[i]:
d = s[i]
g = i
q = s1.index(s[i])
break
if s[0:g]+s[g:q+1:][::-1]+s[q+1:]==s1:
print('yes')
print(g+1,q+1)
else:
print('no') | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
451/B | 451 | B | PyPy 3-64 | TESTS | 73 | 77 | 13,619,200 | 209914124 | n = int(input())
a = list(map(int, input().split()))
idxs = [0, 0]
i = 0
increasing = 0
while i < (n-1):
curr = a[i]
next = a[i+1]
if increasing == 0 and curr < next:
i += 1
continue
if curr > next:
if increasing == 0:
idxs[0] = i
increasing = 1
id... | 76 | 77 | 10,854,400 | 208407930 | n = int(input())
w = [int(a) for a in input().split()]
if n == 1:
print("yes\n1 1")
elif n == 2:
if w[0] > w[n - 1]:
print("yes")
print(1, n)
else:
print("yes\n1 1")
else:
o = 0
p = []
pp = []
for i in range(n - 2):
if (w[i] > w[i + 1] and w[i + 1] < w[i + 2])... | Codeforces Round 258 (Div. 2) | CF | 2,014 | 1 | 256 | Sort the Array | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.
Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly:... | The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.
The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | null | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].
If you have an array a of size n and you reverse its segment [l, r], the array wil... | [{"input": "3\n3 2 1", "output": "yes\n1 3"}, {"input": "4\n2 1 3 4", "output": "yes\n1 2"}, {"input": "4\n3 1 2 4", "output": "no"}, {"input": "2\n1 2", "output": "yes\n1 1"}] | 1,300 | ["implementation", "sortings"] | 76 | [{"input": "3\r\n3 2 1\r\n", "output": "yes\r\n1 3\r\n"}, {"input": "4\r\n2 1 3 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "4\r\n3 1 2 4\r\n", "output": "no\r\n"}, {"input": "2\r\n1 2\r\n", "output": "yes\r\n1 1\r\n"}, {"input": "2\r\n58 4\r\n", "output": "yes\r\n1 2\r\n"}, {"input": "5\r\n69 37 27 4 2\r\n", "outpu... | false | stdio | import sys
def read_input(input_path):
with open(input_path, 'r') as f:
n = int(f.readline())
arr = list(map(int, f.readline().split()))
return arr
def read_output(file_path):
with open(file_path, 'r') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
retur... | true |
841/B | 841 | B | Python 3 | TESTS | 48 | 638 | 76,492,800 | 183449034 | length=int(input())
integers=list(map(int,input().split(" ")))
lst=sum(integers)
c=0
for i in integers:
if (i%2!=0):
c+=1
else:
continue
if c>1:
print("First")
else:
print("Second") | 88 | 358 | 119,808,000 | 212315024 | n=int(input())
a=list(map(int, input().split()))
for el in a:
if el&1:
print('First')
break
else:
print('Second') | Codeforces Round 429 (Div. 2) | CF | 2,017 | 2 | 256 | Godsend | Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts a... | First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array.
Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | null | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | [{"input": "4\n1 3 2 3", "output": "First"}, {"input": "2\n2 2", "output": "Second"}] | 1,100 | ["games", "math"] | 88 | [{"input": "4\r\n1 3 2 3\r\n", "output": "First\r\n"}, {"input": "2\r\n2 2\r\n", "output": "Second\r\n"}, {"input": "4\r\n2 4 6 8\r\n", "output": "Second\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "First\r\n"}, {"input": "4\r\n720074544 345031254 849487632 80870826\r\n", "output": "Second\r\n"}, {"input": "1\r\n0... | false | stdio | null | true |
524/B | 524 | B | PyPy 3 | PRETESTS | 4 | 93 | 1,433,600 | 10380324 | t = []
x = int(input())
for i in range(x):
a, b = map(int, input().split(' '))
lx = [a, b]
lx.sort()
t.append(lx)
t.sort()
minn = 10**9
for i in range(x):
h = t[i][0]
w = t[i][1]
ok = 1
for j in range(x):
if ok == 1 and j != i:
if min(t[j]) > h:
ok = ... | 60 | 156 | 3,174,400 | 10379812 | def main():
import sys
tokens = [int(i) for i in sys.stdin.read().split()]
tokens.reverse()
n = tokens.pop()
people = [(tokens.pop(), tokens.pop()) for i in range(n)]
result = float("inf")
for i in range(n):
for j in range(2):
maxh = people[i][j]
... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно ... | В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,700 | ["dp", "greedy"] | 60 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780... | false | stdio | null | true |
524/B | 524 | B | Python 3 | TESTS | 4 | 62 | 4,608,000 | 16987909 | n = int(input())
hs = []
ws = []
for i in range(n):
w, h = map(int, input().split())
hs.append(h)
ws.append(w)
ans = 10000000
a = max(hs)
b = max(ws)
c = min(a, b)
d = max(a, b)
for H in range(c, d+1):
hr = 0
wr = 0
for j in range(n):
a = min(hs[j], ws[j])
b = max(hs[j], ws[... | 60 | 202 | 26,624,000 | 125035054 | import sys
from typing import Counter
input = sys.stdin.readline
def print(*args, end='\n', sep=' '):
sys.stdout.write(sep.join(map(str, args)) + end)
def solve():
n = int(input())
set_ = set()
data = []
max_of_min = 0
for _ in range(n):
w, h = map(int, input().split())
min_ = ... | VK Cup 2015 - Round 1 | CF | 2,015 | 2 | 256 | Фото на память - 2 (round version) | Прошло много лет, и на вечеринке снова встретились n друзей. С момента последней встречи техника шагнула далеко вперёд, появились фотоаппараты с автоспуском, и теперь не требуется, чтобы один из друзей стоял с фотоаппаратом, и, тем самым, оказывался не запечатлённым на снимке.
Упрощенно процесс фотографирования можно ... | В первой строке следует целое число n (1 ≤ n ≤ 1000) — количество друзей.
В последующих n строках следуют по два целых числа wi, hi (1 ≤ wi, hi ≤ 1000), обозначающие размеры прямоугольника, соответствующего i-му из друзей. | Выведите единственное целое число, равное минимальной возможной площади фотографии, вмещающей всех друзей. | null | null | [{"input": "3\n10 1\n20 2\n30 3", "output": "180"}, {"input": "3\n3 1\n2 2\n4 3", "output": "21"}, {"input": "1\n5 10", "output": "50"}] | 1,700 | ["dp", "greedy"] | 60 | [{"input": "3\r\n10 1\r\n20 2\r\n30 3\r\n", "output": "180\r\n"}, {"input": "3\r\n3 1\r\n2 2\r\n4 3\r\n", "output": "21\r\n"}, {"input": "1\r\n5 10\r\n", "output": "50\r\n"}, {"input": "10\r\n168 538\r\n836 439\r\n190 873\r\n206 47\r\n891 591\r\n939 481\r\n399 898\r\n859 466\r\n701 777\r\n629 222\r\n", "output": "34780... | false | stdio | null | true |
1004/A | 1004 | A | PyPy 3 | TESTS | 6 | 124 | 0 | 61364596 | n,d = map(int,input().split())
a = list(map(int,input().split()))
if(n == 1):
print(2)
else:
ct = 0
inv = 0
for i in range(n):
if(i != 0):
if(a[i] - d >= a[i-1] + d):
#print(a[i] - d)
ct += 1
if(a[i] - d == a[i-1] + d):
inv ... | 45 | 31 | 0 | 144774202 | n,d = map(int,input().split())
a = list(map(int,input().split()))
b = []
count = 2
for i in range(1,len(a)):
dis = (a[i])-(a[i-1])
if dis > 2*d:
count +=2
elif dis == 2*d:
count += 1
print(count) | Codeforces Round 495 (Div. 2) | CF | 2,018 | 1 | 256 | Sonya and Hotels | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $$$n$$$ hotels, where the $$$i$$$-th hotel is located in the city with... | The first line contains two integers $$$n$$$ and $$$d$$$ ($$$1\leq n\leq 100$$$, $$$1\leq d\leq 10^9$$$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $$$n$$$ different integers in strictly increasing order $$$x_1, x_2, \ldots, x_n$$$ ($$$-10^9\... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $$$d$$$. | null | In the first example, there are $$$6$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$-6$$$, $$$5$$$, $$$6$$$, $$$12$$$, $$$13$$$, and $$$19$$$.
In the second example, there are $$$5$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$2$$$, $$$6$$$, $$$1... | [{"input": "4 3\n-3 2 9 16", "output": "6"}, {"input": "5 2\n4 8 11 18 19", "output": "5"}] | 900 | ["implementation"] | 45 | [{"input": "4 3\r\n-3 2 9 16\r\n", "output": "6\r\n"}, {"input": "5 2\r\n4 8 11 18 19\r\n", "output": "5\r\n"}, {"input": "10 10\r\n-67 -59 -49 -38 -8 20 41 59 74 83\r\n", "output": "8\r\n"}, {"input": "10 10\r\n0 20 48 58 81 95 111 137 147 159\r\n", "output": "9\r\n"}, {"input": "100 1\r\n0 1 2 3 4 5 7 8 10 11 12 13 1... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.