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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
81/C | 81 | C | Python 3 | TESTS | 1 | 186 | 0 | 52296065 | import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
n = mint()
a, b = mints()
t = list(mints())
c = [0]*n
for i in range(n):
c[i] = (t[i], -i if a<b else i)
c.sort(reverse=a<b)
f = [0]*n
for i in range(a):
f[a... | 48 | 342 | 11,264,000 | 111814198 | n=int(input())
a,b=list(map(int,input().split()))
c=list(map(int,input().split()))
if a<b:
d=[1 for i in range(n)]
e=[[] for i in range(5)]
for i in range(n):
e[c[i]-1].append(i)
e=e[::-1]
for i in range(5):
e1=len(e[i])
if e1>a or a==0:
for j in range(a,e1):
... | Yandex.Algorithm Open 2011: Qualification 1 | CF | 2,011 | 2 | 256 | Average Score | After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it'... | The first line contains an integer n (2 ≤ n ≤ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 ≤ a, b ≤ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 ≤ ti ≤ 5), they are Polycarp's marks. | Print the sequence of integers f1, f2, ..., fn, where fi (1 ≤ fi ≤ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically l... | null | In the first sample the average score in the first subject is equal to 4, and in the second one — to 4.5. The total average score is 8.5. | [{"input": "5\n3 2\n4 4 5 4 4", "output": "1 1 2 1 2"}, {"input": "4\n2 2\n3 5 4 5", "output": "1 1 2 2"}, {"input": "6\n1 5\n4 4 4 5 4 4", "output": "2 2 2 1 2 2"}] | 1,700 | ["greedy", "math", "sortings"] | 48 | [{"input": "5\r\n3 2\r\n4 4 5 4 4\r\n", "output": "1 1 2 1 2 "}, {"input": "4\r\n2 2\r\n3 5 4 5\r\n", "output": "1 1 2 2 "}, {"input": "6\r\n1 5\r\n4 4 4 5 4 4\r\n", "output": "2 2 2 1 2 2 "}, {"input": "4\r\n2 2\r\n2 1 3 3\r\n", "output": "1 1 2 2 "}, {"input": "9\r\n3 6\r\n4 5 4 1 2 2 2 4 5\r\n", "output": "1 1 2 2 2... | false | stdio | null | true |
352/A | 352 | A | PyPy 3 | TESTS | 39 | 218 | 21,606,400 | 124000833 | import math
n = int(input())
a = list(map(int,input().rstrip().split()))
count_9=0
count_0=0
for i in a:
#print(i)
if i == 5:
count_9+=1
else:
count_0+=1
#print(count_0,count_9)
if(count_0 == 0):
print(-1)
elif(count_9<=9):
print(0)
else:
c = math.floor(count_9/9)*9
for i ... | 42 | 92 | 0 | 4659095 | n = int(input())
s = list(map(int, input().split()))
k = 0
m = 0
for i in range(len(s)):
if s[i] == 0:
k += 1
else:
m += 1
if k == 0:
print(-1)
elif m < 9:
print(0)
else:
x = m // 9
print('5' * 9 * x + '0' * k) | Codeforces Round 204 (Div. 2) | CF | 2,013 | 1 | 256 | Jeff and Digits | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number ... | The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | null | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | [{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}] | 1,000 | ["brute force", "implementation", "math"] | 42 | [{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out... | false | stdio | null | true |
352/A | 352 | A | Python 3 | TESTS | 39 | 124 | 6,963,200 | 130287755 | size = int(input(""))
StrDigits = input("").replace(" ","")
def index_of(val, in_list):
try:
return in_list.index(val)
except ValueError:
return -1
if index_of("0",StrDigits) == -1:
print("-1")
elif index_of("5",StrDigits) == -1:
print("0")
else:
indexes = [i for i, j in e... | 42 | 92 | 0 | 4659186 | n, cards = int(input()), sorted(input().split())
print(int(max(('555555555' * (cards.count('5') // 9) + '0' * cards.count('0')) * (cards.count('0') != 0), '-1'))) | Codeforces Round 204 (Div. 2) | CF | 2,013 | 1 | 256 | Jeff and Digits | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number ... | The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | null | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | [{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}] | 1,000 | ["brute force", "implementation", "math"] | 42 | [{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out... | false | stdio | null | true |
352/A | 352 | A | Python 3 | TESTS | 39 | 92 | 0 | 167373384 | t=int(input())
L=list(map(int,input().split(" ")))
def count(L,a):
times=0
for i in range(len(L)):
if L[i]==a:
times+=1
return times
if count(L,0)==0:
print(-1)
elif count(L,5) <= 9:
print(0)
else:
sum1=count(L,5)//9
sum2=count(L,5)%9
M=[]
for i in range(sum1*9):
... | 42 | 92 | 0 | 4664682 | while(1):
try:
n=int(input())
a=list(map(int,input().split()))
count5=a.count(5)
count0=a.count(0)
if count5//9==0 and count0!=0:
print(0)
elif count0==0:
print(-1)
else:
print((count5//9)*9*'5'+count0*'0')
except EOFEr... | Codeforces Round 204 (Div. 2) | CF | 2,013 | 1 | 256 | Jeff and Digits | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number ... | The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | null | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | [{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}] | 1,000 | ["brute force", "implementation", "math"] | 42 | [{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out... | false | stdio | null | true |
1010/C | 1010 | C | Python 3 | TESTS | 3 | 77 | 7,372,800 | 131072968 | def gcd(a,b):
if b == 0:
return a
return gcd(b,a%b)
n,k=map(int, input().split())
a=[int(v) for v in input().split()]
f=[0]*100010
g=0
for i in a:
g=gcd(g,i)
print(k//g)
for i in range(k):
if i%g==0:
print(i, end=' ') | 107 | 249 | 10,956,800 | 68313952 | def gcd(a, b):
if (a < b):
a, b = b, a
if (b == 0):
return a
return gcd(b, a % b)
n, k = map(int, input().split())
l = list(map(int, input().split()))
gcdd = k
for i in range(n):
gcdd = gcd(gcdd, l[i])
if (gcdd == 0):
print(1)
print(0)
else:
print(k // gcdd)
ans = []
for i in range(1, k // gcdd + 1):
a... | 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 |
609/A | 609 | A | Python 3 | TESTS | 6 | 108 | 0 | 60194147 | a=int(input())
b=int(input())
k=[]
for i in range(a):
k.append(int(input()))
tot=sum(k)
tot1=sum(k)
if tot==b:
print(a)
while k!=[]:
minIndex = k.index(min(k))
tot=tot1
tot1=tot1-min(k)
k.pop(minIndex)
if tot1<b:
print(len(k)+1)
break | 34 | 46 | 0 | 14877746 | n = int(input())
m = int(input())
flash = []
for i in range(n):
flash.append(int(input()))
flash.sort(key = lambda x : -x)
prefix = 0
for i in range(n):
prefix += flash[i]
if m <= prefix:
print(i+1)
break
else:
print('?') | Educational Codeforces Round 3 | ICPC | 2,015 | 2 | 256 | USB Flash Drives | Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives.
The second line contains positive integer m (1 ≤ m ≤ 105) — the size of Sean's file.
Each of the next n lines contains positive integer ai (1 ≤ ai ≤ 1000) — the sizes of USB flash drives in megabytes.
It is guaranteed that the... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | null | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | [{"input": "3\n5\n2\n1\n3", "output": "2"}, {"input": "3\n6\n2\n3\n2", "output": "3"}, {"input": "2\n5\n5\n10", "output": "1"}] | 800 | ["greedy", "implementation", "sortings"] | 34 | [{"input": "3\r\n5\r\n2\r\n1\r\n3\r\n", "output": "2\r\n"}, {"input": "3\r\n6\r\n2\r\n3\r\n2\r\n", "output": "3\r\n"}, {"input": "2\r\n5\r\n5\r\n10\r\n", "output": "1\r\n"}, {"input": "5\r\n16\r\n8\r\n1\r\n3\r\n4\r\n9\r\n", "output": "2\r\n"}, {"input": "10\r\n121\r\n10\r\n37\r\n74\r\n56\r\n42\r\n39\r\n6\r\n68\r\n8\r\n... | false | stdio | null | true |
701/C | 701 | C | Python 3 | TESTS | 11 | 342 | 409,600 | 198887170 | # Implementé el hint, y si lo logro es gracias al análisis de MF
num_flats = int(input())
flats = input()
distinct_pokemon = set(flats)
num_pokemon = len(distinct_pokemon)
'''
El siguiente código es una implementación de:
Hay varias formas de hacerlo, una de las más simple consiste en mantener un rango
en... | 80 | 78 | 6,860,800 | 169665755 | import sys
input = sys.stdin.readline
n = int(input())
s = input()[:-1]
x = len(set(s))
d = dict()
j = 0
ew = 1e9
c = 0
for i in range(n):
if d.get(s[i], 0) == 0:
c += 1
d[s[i]] = 1
if c == x:
ew = min(ew, i-j+1)
while c == x:
d[s[j]] -= 1
... | Codeforces Round 364 (Div. 2) | CF | 2,016 | 2 | 256 | They Are Everywhere | Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on... | The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | null | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | [{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}] | 1,500 | ["binary search", "strings", "two pointers"] | 80 | [{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ... | false | stdio | null | true |
701/C | 701 | C | PyPy 3 | TESTS | 74 | 186 | 4,812,800 | 103463088 | n = int(input())
slov = dict()
strin = input()
a = len(set(list(strin)))
i, j = 0, 0
m = 0
answ = n
while True:
while m < a:
i += 1
if i == n:
break
if strin[i] not in slov:
m += 1
slov[strin[i]] = 1
else:
slov[strin[i]] += 1
if i =... | 80 | 93 | 921,600 | 210313707 | def ans():
n=int(input())
s=input()
a=list(s)
d={}
j=0
k=len(set(a))
m=1e18
for i in range(n):
while(j<n and len(d)<k):
if(a[j] not in d):
d[a[j]]=0
d[a[j]]+=1
j+=1
if(len(d)==k):
m=min(m,j-i)
d[a[i]]-=1
... | Codeforces Round 364 (Div. 2) | CF | 2,016 | 2 | 256 | They Are Everywhere | Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on... | The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | null | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | [{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}] | 1,500 | ["binary search", "strings", "two pointers"] | 80 | [{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ... | false | stdio | null | true |
701/C | 701 | C | PyPy 3 | TESTS | 74 | 327 | 5,222,400 | 112626706 | def bs(l, h):
while l < h:
m = (l + h) // 2
if gf(m):
h = m
else:
l = m + 1
return l
def gf(x):
d = {}
for i in range(x):
if s[i] in d:
d[s[i]] += 1
else:
d[s[i]] = 1
for i in range(x, n):
if s[i] in d:
... | 80 | 93 | 3,072,000 | 180451638 | #!/usr/bin/env python3
import math
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip("\r\n")
def test_case():
n = int(input())
a = input()
curr = {}
for i in range(n):
if a[i] not in curr:
curr[a[i]] = 0
k = len(curr)
ans = float("inf"... | Codeforces Round 364 (Div. 2) | CF | 2,016 | 2 | 256 | They Are Everywhere | Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is on... | The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house.
The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | null | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | [{"input": "3\nAaA", "output": "2"}, {"input": "7\nbcAAcbc", "output": "3"}, {"input": "6\naaBCCe", "output": "5"}] | 1,500 | ["binary search", "strings", "two pointers"] | 80 | [{"input": "3\r\nAaA\r\n", "output": "2\r\n"}, {"input": "7\r\nbcAAcbc\r\n", "output": "3\r\n"}, {"input": "6\r\naaBCCe\r\n", "output": "5\r\n"}, {"input": "1\r\nA\r\n", "output": "1\r\n"}, {"input": "1\r\ng\r\n", "output": "1\r\n"}, {"input": "52\r\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n", "output": ... | false | stdio | null | true |
524/C | 524 | C | Python 3 | TESTS | 0 | 46 | 204,800 | 26886689 | params = [int(x) for x in input().split()]
n = params[0]
k = params[1]
bills = [int(x) for x in input().split()]
bills.sort()
bills = bills[::-1]
request = [int(x) for x in input().split()][0]
amounts = []
hashset = set()
for i in bills:
hashset.add(i)
for i in range(request):
t = int(input())
amounts.appen... | 129 | 358 | 11,878,400 | 231037855 | f = lambda: map(int, input().split())
n, k = f()
t = list(f())
d = {0: 0}
for q in t:
for i in range(1, k + 1): d[q * i] = i
for j in range(int(input())):
a = int(input())
p = [i + d[a - b] for b, i in d.items() if a - b in d]
print(min(p) if p and min(p) <= k else -1) | 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 |
204/B | 204 | B | Python 3 | TESTS | 4 | 122 | 0 | 29509392 | n = int(input())
x = n // 2 + n % 2
m1, m2, m = {}, {}, {}
for i in range(n):
a, b = map(int, input().split())
if a in m1:
m1[a] += 1
else:
m1[a] = 1
if not b in m1:
m1[b] = 0
if b in m2:
m2[b] += 1
else:
m2[b] = 1
if not a in m2:
m2[a] = 0
if not a in m:
m[a] = 1
if not b ... | 90 | 1,622 | 26,009,600 | 163171542 | import collections
n = int(input())
front, back, both, st = [], [], [], set()
for j in range(n):
f, b = map(int, input().split())
if f == b:
both.append(f)
else:
front.append(f)
back.append(b)
st.add(f)
st.add(b)
front = collections.Counter(front)
back = collections.Counter... | Codeforces Round 129 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Cards | The Little Elephant loves to play with color cards.
He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elephant can turn any card to the other side. The Little Elephant thinks... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of the cards. The following n lines contain the description of all cards, one card per line. The cards are described by a pair of positive integers not exceeding 109 — colors of both sides. The first number in a line is the color of the front of the ... | On a single line print a single integer — the sought minimum number of moves. If it is impossible to make the set funny, print -1. | null | In the first sample there initially are three cards lying with colors 4, 4, 7. Since two of the three cards are of the same color 4, you do not need to change anything, so the answer is 0.
In the second sample, you can turn the first and the fourth cards. After that three of the five cards will be of color 7. | [{"input": "3\n4 7\n4 7\n7 4", "output": "0"}, {"input": "5\n4 7\n7 4\n2 11\n9 7\n1 1", "output": "2"}] | 1,500 | ["binary search", "data structures"] | 90 | [{"input": "3\r\n4 7\r\n4 7\r\n7 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 7\r\n7 4\r\n2 11\r\n9 7\r\n1 1\r\n", "output": "2\r\n"}, {"input": "1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "7\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n", "output": "-1\r\n... | false | stdio | null | true |
870/B | 870 | B | PyPy 3 | TESTS | 22 | 265 | 10,752,000 | 78778160 | n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=l.copy()
l1.sort()
if k==1:
print(min(l))
elif k==2:
a,b=10**10,10**10
c,d=0,0
for j in range(n):
a=min(a,l[j])
b=min(b,l[n-1-j])
c=max(c,a)
d=max(d,b)
print(max(c,d))
else:
print(max(l)) | 55 | 62 | 12,902,400 | 205897179 | I = lambda: map(int, input().split())
_, k = I()
A = list(I())
print(min(A) if k<2 else max(A) if k>2 else max(A[0], A[-1])) | Technocup 2018 - Elimination Round 2 | CF | 2,017 | 1 | 256 | Maximum of Maximums of Minimums | You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
D... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. | null | A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array ... | [{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}] | 1,200 | ["greedy"] | 55 | [{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {... | false | stdio | null | true |
870/B | 870 | B | PyPy 3-64 | TESTS | 22 | 93 | 17,510,400 | 164911401 | n, k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
print(min(a))
if k >= 3:
print(max(a))
if k == 2:
min_suffix = [0] * n
min_suffix[-1] = a[-1]
min_prefix = [a[0]]
for i in range(1, n):
min_prefix.append(min(min_prefix[i - 1], a[i]))
for i in range(n -... | 55 | 77 | 8,089,600 | 155585834 | n, k = map(int, input().split())
a = list(map(int, input().split()))
if k >= 3:print(max(a))
elif k==2:print(max(a[0], a[-1]))
else:print(min(a)) | Technocup 2018 - Elimination Round 2 | CF | 2,017 | 1 | 256 | Maximum of Maximums of Minimums | You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
D... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. | null | A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array ... | [{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}] | 1,200 | ["greedy"] | 55 | [{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {... | false | stdio | null | true |
40/D | 40 | D | PyPy 3 | TESTS | 5 | 498 | 14,745,600 | 61002317 | d = {1: {(2, 13)}}
for j in range(2, 600):
d[j] = set()
big = 10**302
h = -1
for i in range(1, 600):
ok = 0
for a, b in d[i]:
c = 12*a
if c <= big:
ok = 1
d[i+1].add((b, c))
c = 13*b - 12*a
if c <= big:
ok = 1
d[i+1].add((b, c))
if not ok:
h = i
break
n = int(input())
g = set()
for i in ran... | 74 | 622 | 14,028,800 | 67613326 | a = int(input())
ans = set()
def work(i, z, y):
z.add(y)
# print(">>", i, y)
if y == a:
ans.add(i)
if len(z) > 1000:
z.remove(max(z))
pos = [set(), set([2])]
for i in range(2):
for x in pos[i]:
if x == a:
ans.add(i)
def dfs(i, last, cur):
if i > 988:
... | Codeforces Beta Round 39 | CF | 2,010 | 3 | 256 | Interesting Sequence | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros. | On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO.
If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separate... | null | null | [{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}] | 2,600 | ["math"] | 74 | [{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r... | false | stdio | null | true |
40/D | 40 | D | PyPy 3-64 | TESTS | 5 | 124 | 28,979,200 | 135224326 | A = int(input())
s = set()
def dfs(i, a, b):
assert(a <= b and a > 0 and b > 0)
if a > A:
return
if (i, a, b) in s:
return
s.add((i, a, b))
dfs(i + 1, b, 12 * a)
dfs(i + 1, b, 13 * b - 12 * a)
dfs(1, 2, 13)
a = set()
for p in s:
if p[1] == A:
a.add(p[0])
v =... | 74 | 810 | 307,200 | 102980351 | A=int(input())
res=[]
for i in range(300):
for j in range(300):
if(pow(12,i)+pow(12,j)==A):
res.append([i,j])
if(len(res)==0):
print("NO")
quit()
print("YES")
print(1)
sm=sum(res[0])
print(sm+1)
print(sm//2)
for i in range(sm//2,-1,-1):
V=pow(12,i)+pow(12,sm-i)
if(V!=A):
... | Codeforces Beta Round 39 | CF | 2,010 | 3 | 256 | Interesting Sequence | Berland scientists noticed long ago that the world around them depends on Berland population. Due to persistent research in this area the scientists managed to find out that the Berland chronology starts from the moment when the first two people came to that land (it is considered to have happened in the first year). A... | The first line contains integer A (1 ≤ A < 10300). It is guaranteed that the number doesn't contain leading zeros. | On the first output line print YES, if there could be a year in which the total population of the country equaled A, otherwise print NO.
If the answer is YES, then you also have to print number k — the number of years in which the population could equal A. On the next line you have to output precisely k space-separate... | null | null | [{"input": "2", "output": "YES\n1\n1\n0"}, {"input": "3", "output": "NO"}, {"input": "13", "output": "YES\n1\n2\n0"}, {"input": "1729", "output": "YES\n1\n4\n1\n156"}] | 2,600 | ["math"] | 74 | [{"input": "2\r\n", "output": "YES\r\n1\r\n1\r\n0\r\n"}, {"input": "3\r\n", "output": "NO\r\n"}, {"input": "13\r\n", "output": "YES\r\n1\r\n2\r\n0\r\n"}, {"input": "1729\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n156\r\n"}, {"input": "1\r\n", "output": "NO\r\n"}, {"input": "156\r\n", "output": "YES\r\n1\r\n4\r\n1\r\n1729\r... | false | stdio | null | true |
873/B | 873 | B | PyPy 3 | TESTS | 21 | 124 | 8,601,600 | 111692468 | import math,sys
#from itertools import permutations, combinations;import heapq,random;
from collections import defaultdict,deque
import bisect as bi
def yes():print('YES')
def no():print('NO')
#sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(sys.stdin.readline()))
def In():return(... | 53 | 77 | 8,908,800 | 144828894 | n = int(input())
s = input()
d = dict()
d[0] = -1
count0 = 0
count1 = 0
res = 0
for i in range(n):
if s[i] == "0":
count0 += 1
else:
count1 += 1
if d.get(count1 - count0) is not None:
res = max(res, i - d[count1 - count0])
else:
d[count1 - count0] = i
print(res) | Educational Codeforces Round 30 | ICPC | 2,017 | 1 | 256 | Balanced Substring | You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanc... | The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s.
The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s. | If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring. | null | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | [{"input": "8\n11010111", "output": "4"}, {"input": "3\n111", "output": "0"}] | 1,500 | ["dp", "implementation"] | 53 | [{"input": "8\r\n11010111\r\n", "output": "4\r\n"}, {"input": "3\r\n111\r\n", "output": "0\r\n"}, {"input": "11\r\n00001000100\r\n", "output": "2\r\n"}, {"input": "10\r\n0100000000\r\n", "output": "2\r\n"}, {"input": "13\r\n0001000011010\r\n", "output": "6\r\n"}, {"input": "14\r\n00000100101011\r\n", "output": "10\r\n"... | false | stdio | null | true |
873/B | 873 | B | Python 3 | TESTS | 20 | 124 | 204,800 | 170838816 | class Solution:
def balancedSubstring(self, n: int, s: str) -> int:
ones, zeroes = s.count('1'), s.count('0')
if not ones or not zeroes:
return 0
elif ones == zeroes:
return n
elif ones < zeroes:
small = ['1', ones]
else:
small ... | 53 | 77 | 11,264,000 | 218024631 | n = int(input())
s = input()
d = dict()
d[0] = -1
c,ans = 0,0
for i in range(n):
if s[i] == '0':
c -= 1
else:
c += 1
if c not in d:
d[c] = i
else:
ans = max(i - d[c], ans)
print(ans) | Educational Codeforces Round 30 | ICPC | 2,017 | 1 | 256 | Balanced Substring | You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanc... | The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s.
The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s. | If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring. | null | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | [{"input": "8\n11010111", "output": "4"}, {"input": "3\n111", "output": "0"}] | 1,500 | ["dp", "implementation"] | 53 | [{"input": "8\r\n11010111\r\n", "output": "4\r\n"}, {"input": "3\r\n111\r\n", "output": "0\r\n"}, {"input": "11\r\n00001000100\r\n", "output": "2\r\n"}, {"input": "10\r\n0100000000\r\n", "output": "2\r\n"}, {"input": "13\r\n0001000011010\r\n", "output": "6\r\n"}, {"input": "14\r\n00000100101011\r\n", "output": "10\r\n"... | false | stdio | null | true |
113/B | 113 | B | PyPy 3 | TESTS | 41 | 872 | 7,680,000 | 182935692 | import random
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def is_Prime(n):
if n == 1:
return False
for i in range(2, min(int(n ** (1 / 2)) + 2, n)):
if n % i == 0:
return False
return True
def random_mod():
mod = random.randint(5 * pow(10... | 88 | 186 | 5,734,400 | 27989136 | def calc_lcp(s, sa):
rank = [0 for _ in range(len(s))]
for i in range(len(s)):
rank[sa[i]] = i
lcp = [0 for _ in range(len(s) - 1)]
h = 0
for i in range(len(s)):
if rank[i] < len(s) - 1:
while max(i, sa[rank[i] + 1]) + h < len(s) and s[i + h] == s[sa[rank[i] + 1] + h]:
... | Codeforces Beta Round 86 (Div. 1 Only) | CF | 2,011 | 2 | 256 | Petr# | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings... | The input file consists of three lines. The first line contains string t. The second and the third lines contain the sbegin and send identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. | Output the only number — the amount of different substrings of t that start with sbegin and end with send. | null | In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab.
In the fourth sample identificators intersect. | [{"input": "round\nro\nou", "output": "1"}, {"input": "codeforces\ncode\nforca", "output": "0"}, {"input": "abababab\na\nb", "output": "4"}, {"input": "aba\nab\nba", "output": "1"}] | 2,000 | ["brute force", "data structures", "hashing", "strings"] | 88 | [{"input": "round\r\nro\r\nou\r\n", "output": "1\r\n"}, {"input": "codeforces\r\ncode\r\nforca\r\n", "output": "0\r\n"}, {"input": "abababab\r\na\r\nb\r\n", "output": "4\r\n"}, {"input": "aba\r\nab\r\nba\r\n", "output": "1\r\n"}, {"input": "abcdefghijklmnopqrstuvwxyz\r\nabc\r\nxyz\r\n", "output": "1\r\n"}, {"input": "a... | false | stdio | null | true |
985/B | 985 | B | Python 3 | TESTS | 8 | 2,355 | 4,710,400 | 38626650 | n,m = [int(i) for i in input().split()]
l = []
for i in range(n):
l.append(input())
cnt = m*[0]
for i in range(m):
for j in range(n):
cnt[i]+=int(l[j][i])
ans = 'NO'
#print(*cnt)
t = 0
for i in range(m):
if cnt[i]>=2:
t+=1
if t >= 2:
ans = 'YES'
print(ans) | 67 | 202 | 38,809,600 | 193544688 | import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################... | 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 |
870/B | 870 | B | Python 3 | TESTS | 22 | 109 | 15,155,200 | 131116810 | n, k = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
if k >= 3:
result = max(nums)
elif k == 1:
result = min(nums)
else:
mins = [0 for i in range(n)]
a = 0
b = n - 1
minA = max(nums)
minB = max(nums)
for i in range((n // 2) + 1):
# arr1 = nums[0:i]
... | 55 | 77 | 8,089,600 | 194728295 | n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
minv = 10000000000000000
maxv = -1*minv
if k == 2:
if a[0] > a[n-1]:
print(a[0])
else:
print(a[n-1])
elif k == 1:
for i in a:
if i < minv:
minv = i
print(minv)
else:
for i in a:
... | Technocup 2018 - Elimination Round 2 | CF | 2,017 | 1 | 256 | Maximum of Maximums of Minimums | You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
D... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. | null | A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array ... | [{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}] | 1,200 | ["greedy"] | 55 | [{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {... | false | stdio | null | true |
540/A | 540 | A | PyPy 3 | TESTS | 6 | 108 | 0 | 106247003 | n = int(input())
a = input()
b = input()
cnt = 0
for i in range(n):
if int(a[i])==0 and int(b[i])>5:
cnt+=(10-int(b[i]))
elif int(a[i])==1 and int(b[i])>6:
cnt+=(11-int(b[i]))
elif int(a[i])==2 and int(b[i])>7:
cnt+=(12 - int(b[i]))
elif int(a[i])==3 and int(b[i])>8:
cnt+... | 43 | 31 | 0 | 144843909 | n = int(input())
n1 = input()
n2 = input()
hsl = 0
for i in range(n):
smtr = abs(int(n1[i]) - int(n2[i]))
hsl += min(smtr,10-smtr)
print(hsl) | Codeforces Round 301 (Div. 2) | CF | 2,015 | 2 | 256 | Combination Lock | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn so... | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of disks on the combination lock.
The second line contains a string of n digits — the original state of the disks.
The third line contains a string of n digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | null | In the sample he needs 13 moves:
- 1 disk: $$8 \rightarrow 7 \rightarrow 6$$
- 2 disk: $$2 \rightarrow 3 \rightarrow 4$$
- 3 disk: $$1 \rightarrow 0 \rightarrow 9 \rightarrow 8 \rightarrow 7$$
- 4 disk: $$9 \rightarrow 0 \rightarrow 1 \rightarrow 2$$
- 5 disk: $$5 \rightarrow 4 \rightarrow 3$$ | [{"input": "5\n82195\n64723", "output": "13"}] | 800 | ["implementation"] | 43 | [{"input": "5\r\n82195\r\n64723\r\n", "output": "13\r\n"}, {"input": "12\r\n102021090898\r\n010212908089\r\n", "output": "16\r\n"}, {"input": "1\r\n8\r\n1\r\n", "output": "3\r\n"}, {"input": "2\r\n83\r\n57\r\n", "output": "7\r\n"}, {"input": "10\r\n0728592530\r\n1362615763\r\n", "output": "27\r\n"}, {"input": "100\r\n4... | false | stdio | null | true |
54/A | 54 | A | Python 3 | TESTS | 2 | 62 | 0 | 166321718 | n, k = list(map(int, input().split(' ')))
holidays = [int(item) for item in input().split(' ')]
ans = set()
i = 0
for i in range(i + k, n + 1, k):
ans.add(i)
for j in range(1, len(holidays)):
if holidays[j] <= n:
ans.add(holidays[j])
print(len(ans)) | 65 | 124 | 0 | 149684856 | w=list(map(int,input().split()))
holl=list(map(int,input().split()))[1:]
tr=0
q=w[1]
for e in range(1,w[0]+1):
if e==q :
tr+=1
q+=w[1]
elif e in holl :
tr+=1
q=e+w[1]
else:
pass
print(tr) | Codeforces Beta Round 50 | CF | 2,011 | 2 | 256 | Presents | The Hedgehog likes to give presents to his friend, but no less he likes to receive them.
Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c... | The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N).
The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating ... | Print a single number — the minimal number of presents the Hedgehog will receive over the following N days. | null | null | [{"input": "5 2\n1 3", "output": "3"}, {"input": "10 1\n3 6 7 8", "output": "10"}] | 1,300 | ["implementation"] | 65 | [{"input": "5 2\r\n1 3\r\n", "output": "3"}, {"input": "10 1\r\n3 6 7 8\r\n", "output": "10"}, {"input": "5 5\r\n1 3\r\n", "output": "1"}, {"input": "10 3\r\n3 3 6 9\r\n", "output": "3"}, {"input": "5 2\r\n0\r\n", "output": "2"}, {"input": "1 1\r\n0\r\n", "output": "1"}, {"input": "5 1\r\n0\r\n", "output": "5"}, {"inpu... | false | stdio | null | true |
873/B | 873 | B | Python 3 | TESTS | 20 | 218 | 6,348,800 | 78076706 | from sys import stdin
def entrada():
arr = stdin.read().split("\n")
n = int(arr[0])
S = arr[1]
return n,S
def encontrar_resultado(lista):
if len(lista)==0:
return 0
lista.sort()
c = 1
maximo = 0
for i in range(1,len(lista)):
if lista[i] == lista[i-1]+1:
... | 53 | 77 | 11,264,000 | 222700134 | digitToValMap = {
"1": 1,
"0": -1,
}
def process(nums: str) -> int:
prevRate = {0: -1}
rate = 0
maxLen = 0
for i, num in enumerate(nums):
rate += digitToValMap[num]
if rate in prevRate:
currLen = i - prevRate[rate]
maxLen = max(maxLen, currLen)
i... | Educational Codeforces Round 30 | ICPC | 2,017 | 1 | 256 | Balanced Substring | You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.
You have to determine the length of the longest balanc... | The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s.
The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s. | If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring. | null | In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.
In the second example it's impossible to find a non-empty balanced substring. | [{"input": "8\n11010111", "output": "4"}, {"input": "3\n111", "output": "0"}] | 1,500 | ["dp", "implementation"] | 53 | [{"input": "8\r\n11010111\r\n", "output": "4\r\n"}, {"input": "3\r\n111\r\n", "output": "0\r\n"}, {"input": "11\r\n00001000100\r\n", "output": "2\r\n"}, {"input": "10\r\n0100000000\r\n", "output": "2\r\n"}, {"input": "13\r\n0001000011010\r\n", "output": "6\r\n"}, {"input": "14\r\n00000100101011\r\n", "output": "10\r\n"... | false | stdio | null | true |
730/H | 730 | H | Python 3 | TESTS | 10 | 62 | 204,800 | 21705792 | num_files, num_delete = map(int, input().split(' '))
files = []
while num_files > 0:
files.append( input() )
num_files -= 1
indices_del = list( map(lambda x: x - 1, map(int, input().split(' '))) )
ind = 0
to_del = []
to_leave = []
for i in indices_del:
if len(to_del) > 0 and len(files[i]) != len(to_del[0]):
pri... | 74 | 62 | 0 | 21713468 | n = int(input().split()[0])
all_files = [str(input()) for i in range(n)]
index_to_del = [int(i) - 1 for i in (input().split())]
def find_pattern(all_files, index_to_del):
for i in index_to_del[1:]:
if len(all_files[i]) != len(all_files[index_to_del[0]]):
return "No"
pattern = ''
for ... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
269/A | 269 | A | PyPy 3-64 | TESTS | 6 | 92 | 0 | 210816812 | import sys
input = lambda: sys.stdin.readline().rstrip()
N = int(input())
A = []
for _ in range(N):
k,a = map(int, input().split())
A.append([k,a])
A.sort()
for i in range(1,N):
k,a = A[i-1]
while A[i][0]>k:
k+=1
a=(a-1)//4+1
if a>A[i][1]:
A[i][1] = a
k,a = A[-1]
#... | 46 | 748 | 0 | 111792956 | import math
n,o=int(input()),0
for i in range(n):
r,t=map(int,input().split())
r+=math.ceil(math.log(t,4))
r+=t==1
o=max(o,r)
print(o) | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
269/A | 269 | A | PyPy 3 | TESTS | 13 | 716 | 6,348,800 | 12918784 | from sys import stdin
input = stdin.readline
n = int(input())
res = 1
for i in range(n):
k, a = (int(x) for x in input().split())
i = 0
x = 1
while a > x:
i += 1
x *= 4
res = max(res, k + i)
print(res) | 46 | 748 | 0 | 111797021 | from math import *
n,o=int(input()),0
for i in range(n):
r,t=map(int,input().split())
r+=ceil(log(t,4))
r+=t==1
o=max(o,r)
print(o) | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
730/H | 730 | H | Python 3 | TESTS | 4 | 62 | 6,963,200 | 123789653 | # _
#####################################################################################################################
def fileNamePattern(nNamesToDelete, storage):
name_sLength = len(storage[0])
for i in range(1, nNamesToDelete):
if name_sLength != len(storage[i]):
return 'No'
patt... | 74 | 62 | 0 | 22210542 | n, m = [int(x) for x in input().split()]
slova = []
for i in range(n):
slova.append(input())
na_zmazanie = [int(x)-1 for x in input().split()]
dlzka_zmazanych = len(slova[na_zmazanie[0]])
for i in na_zmazanie:
if len(slova[i]) != dlzka_zmazanych:
print("No")
exit(0)
zmaz = [False] * n
for i in... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
730/H | 730 | H | Python 3 | TESTS | 4 | 61 | 0 | 21701920 | m,n=list(map(int,input().split()))
s=[input().strip() for i in range(m)]
a=list(map(lambda x:int(x)-1,input().split()))
stmpl=s[a[0]]
f=1
def peres(s1,s2):
return ''.join([i if i==j else '?' for i,j in zip(s1,s2)])
for i in a:
if len(stmpl)!=len(s[i]):
f=0
break
stmpl=peres(stmpl,s[i])
#~ for i,e in enumerate(s)... | 74 | 62 | 307,200 | 21706638 | __author__ = 'Think'
def check(s, password):
if len(s)!=len(password):
return False
for i in range(len(password)):
if password[i]!="?":
if password[i]!=s[i]:
return False
return True
n, m=[int(i) for i in input().split()]
filenames=[]
for i in range(n):
filenames.append(input())
deleted_indices=[int(i)-... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
305/A | 305 | A | PyPy 3-64 | TESTS | 34 | 124 | 0 | 175507893 | #list(map(int,input().split()))
#for times in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
ans = []
l.sort()
if 0 in l:
ans+=[0]
l.pop(0)
if 100 in l:
ans+=[100]
l.pop(-1)
f=0
for i in l:
if i<9:
ans+=[i]
f=1
break
for j in l:
if j>9 and j%10==0:
ans+=[j]
f=1
break
if not f... | 35 | 78 | 102,400 | 3742418 | input()
a = list(map(int, input().split()))
d = []
for i in a:
if i in range(1, 10):
d += [i]
break
for i in a:
if i in range(10, 100, 10):
d += [i]
break
if len(d) == 0:
for i in a:
if i not in (0, 100):
d += [i]
break
if 100 in a:
d += [100]
if 0 in a:
d += [0]
print(len(d))
... | Codeforces Round 184 (Div. 2) | CF | 2,013 | 2 | 256 | Strange Addition | Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.
Vasya wants to choose some integers ... | The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.
The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). | In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | null | null | [{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}] | 1,600 | ["brute force", "constructive algorithms", "implementation"] | 35 | [{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ... | false | stdio | import sys
def mask(num):
s = f"{num:03d}"
mask = 0
if s[0] != '0':
mask |= 4
if s[1] != '0':
mask |= 2
if s[2] != '0':
mask |= 1
return mask
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
k = int(li... | true |
305/A | 305 | A | PyPy 3-64 | TESTS | 23 | 92 | 0 | 200589628 | N = int(input())
A = list(map(int, input().split()))
ans = []
if 0 in A:
ans.append(0)
if 100 in A:
ans.append(100)
B = []
C = []
D = []
for a in A:
if a>0 and a<10:
B.append(a)
elif a>=10 and a<100 and a%10==0:
C.append(a)
elif a>0 and a<100:
D.append(a)
if B:
a... | 35 | 78 | 102,400 | 3745423 | import re
import itertools
from collections import Counter, deque
class Task:
numbers = []
answer = set()
def getData(self):
input()
self.numbers = [int(x) for x in input().split(' ')]
#inFile = open('input.txt', 'r')
#inFile.readline().rstrip()
#self.childs = inFi... | Codeforces Round 184 (Div. 2) | CF | 2,013 | 2 | 256 | Strange Addition | Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.
Vasya wants to choose some integers ... | The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.
The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). | In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | null | null | [{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}] | 1,600 | ["brute force", "constructive algorithms", "implementation"] | 35 | [{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ... | false | stdio | import sys
def mask(num):
s = f"{num:03d}"
mask = 0
if s[0] != '0':
mask |= 4
if s[1] != '0':
mask |= 2
if s[2] != '0':
mask |= 1
return mask
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
k = int(li... | true |
870/B | 870 | B | Python 3 | TESTS | 22 | 265 | 15,360,000 | 88280825 | a,b=map(int,input().split())
if b==1:print(min(list(map(int,input().split()))))
elif b>2:print(max(list(map(int,input().split()))))
else:
z=list(map(int,input().split()))
pre=[z[0]]
for i in range(1,a):
pre+=[min(pre[-1],z[i])]
suff=[10000000000]*a
suff[-1]=z[-1]
for i in range(a-2,-1,-1... | 55 | 77 | 8,089,600 | 196395078 | n,m = map(int,input().split())
l = list(map(int,input().split()))
if m == 1:
print(min(l))
elif m == 2:
print(max(l[0],l[-1]))
else:
print(max(l)) | Technocup 2018 - Elimination Round 2 | CF | 2,017 | 1 | 256 | Maximum of Maximums of Minimums | You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
D... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. | null | A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array ... | [{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}] | 1,200 | ["greedy"] | 55 | [{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {... | false | stdio | null | true |
305/A | 305 | A | Python 3 | TESTS | 18 | 218 | 0 | 117996616 | num = int(input())
arr = input().split(' ')
nums = []
for i in range(0, len(arr)):
nums.append(int(arr[i]))
ans = []
case = [0, 0, 0, 0]
if 100 in nums:
ans.append(100)
case[0] = 1
if 0 in nums:
ans.append(0)
case[3] = 1
for i in nums:
if i % 10 == 0 and i < 100 and i != 0:
ans.append... | 35 | 92 | 0 | 142038096 | k = int(input())
d = input().split()
for i in range(len(d)):
d[i] = int(d[i])
cnt = [0, 0, 0, 0, 0]
ans = []
for i in range(len(d)):
if d[i] == 0:
cnt[0] = 1
continue
if d[i]==100:
cnt[1] = 1
continue
if d[i]%10 == 0:
cnt[2] = d[i]
continue
if d[... | Codeforces Round 184 (Div. 2) | CF | 2,013 | 2 | 256 | Strange Addition | Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.
Vasya wants to choose some integers ... | The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.
The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). | In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | null | null | [{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}] | 1,600 | ["brute force", "constructive algorithms", "implementation"] | 35 | [{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ... | false | stdio | import sys
def mask(num):
s = f"{num:03d}"
mask = 0
if s[0] != '0':
mask |= 4
if s[1] != '0':
mask |= 2
if s[2] != '0':
mask |= 1
return mask
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
k = int(li... | true |
870/B | 870 | B | PyPy 3 | TESTS | 22 | 202 | 12,288,000 | 220990062 | n,k = map(int,input().split())
L = list(map(int,input().split()))
if k == 1:
print(min(L))
elif k == 2:
m1 = [0 for i in range(n)]
m2 = [0 for i in range(n)]
m1[0] = L[0]
m2[-1] = L[-1]
for i in range(1,n):
m1[i] = min(m1[i-1],L[i])
for i in range(-2,-n-1,-1):
m2[i] = min(L[... | 55 | 77 | 8,089,600 | 196399477 | n,k=map(int,input().split())
z=list(map(int,input().split()))
if(k>=3):
print(max(z))
elif(k==2):
print(max(z[0],z[-1]))
else:
print(min(z)) | Technocup 2018 - Elimination Round 2 | CF | 2,017 | 1 | 256 | Maximum of Maximums of Minimums | You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
D... | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109). | Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. | null | A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array ... | [{"input": "5 2\n1 2 3 4 5", "output": "5"}, {"input": "5 1\n-4 -5 -3 -2 -1", "output": "-5"}] | 1,200 | ["greedy"] | 55 | [{"input": "5 2\r\n1 2 3 4 5\r\n", "output": "5\r\n"}, {"input": "5 1\r\n-4 -5 -3 -2 -1\r\n", "output": "-5\r\n"}, {"input": "10 2\r\n10 9 1 -9 -7 -9 3 8 -10 5\r\n", "output": "10\r\n"}, {"input": "10 4\r\n-8 -1 2 -3 9 -8 4 -3 5 9\r\n", "output": "9\r\n"}, {"input": "1 1\r\n504262064\r\n", "output": "504262064\r\n"}, {... | false | stdio | null | true |
837/F | 837 | F | PyPy 3 | TESTS | 3 | 187 | 33,996,800 | 89636297 | s = input().split()
n = int(s[0]); k = int(s[1])
s = input().split()
a = [1]
for i in range(1, n + 1):
a.append(int(s[i - 1]))
for i in range(1, n + 1):
if (a[i] >= k):
print(0); exit(0)
def C(nn, kk):
global k
prod = 1
kk = min(kk, nn - kk)
# print(nn, nn - kk + 1)
for i in range(1, kk + 1):
# print("///"... | 40 | 140 | 28,569,600 | 190057489 | N,K=map(int,input().split())
A=list(map(int,input().split()))
if max(A) >= K:
print(0)
exit()
A.reverse()
while A[-1] == 0: A.pop()
if len(A) <= 3:
def check(K,A,x):
val = 0
for i in range(len(A)):
if i == 0: val += A[i]
elif i == 1: val += A[i]*x
elif i... | Educational Codeforces Round 26 | ICPC | 2,017 | 1 | 256 | Prefix Sums | Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m).
You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i ≥ 1 Ai = p(Ai - 1). Als... | The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k ≤ 1018). n is the size of array A0.
The second line contains n integers A00, A01... A0n - 1 — the elements of A0 (0 ≤ A0i ≤ 109). At least two elements of A0 are positive. | Print the minimum i such that Ai contains a number which is larger or equal than k. | null | null | [{"input": "2 2\n1 1", "output": "1"}, {"input": "3 6\n1 1 1", "output": "2"}, {"input": "3 1\n1 0 1", "output": "0"}] | 2,400 | ["binary search", "brute force", "combinatorics", "math", "matrices"] | 40 | [{"input": "2 2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3 6\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "3 1\r\n1 0 1\r\n", "output": "0\r\n"}, {"input": "3 1000000000000000000\r\n5 4 5\r\n", "output": "632455531\r\n"}, {"input": "4 1000000000000000000\r\n0 4 4 5\r\n", "output": "707106780\r\n"}, {"input": "5 1000... | false | stdio | null | true |
670/D2 | 670 | D2 | Python 3 | TESTS | 119 | 592 | 9,728,000 | 163467949 | def check(x, a, b, k):
bi = list(b)
count = 0
for i in range(len(a)):
if a[i]*x > bi[i]:
count += a[i] * x - bi[i]
else:
bi[i] -= a[i] * x
if count > k:
return False
return count <= k
n, k = map(int, input().split())
a = list(map(i... | 150 | 108 | 19,865,600 | 196271948 | import sys
input = sys.stdin.readline
print = sys.stdout.write
n,k = map(int,input().split())
required = list(map(int,input().split()))
has = list(map(int,input().split()))
left=0
right = 10**16
def check(x,k):
for i in range(n):
val = has[i]-required[i]*x
if val>=0:
continue
val... | Codeforces Round 350 (Div. 2) | CF | 2,016 | 1 | 256 | Magic Powder - 2 | The term of this problem is the same as the previous one, the only exception — increased restrictions. | The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bak... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | null | null | [{"input": "1 1000000000\n1\n1000000000", "output": "2000000000"}, {"input": "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1", "output": "0"}, {"input": "3 1\n2 1 4\n11 3 16", "output": "4"}, {"input": "4 3\n4 3 5 6\n11 12 14 20",... | 1,500 | ["binary search", "implementation"] | 150 | [{"input": "1 1000000000\r\n1\r\n1000000000\r\n", "output": "2000000000\r\n"}, {"input": "10 1\r\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n"}, {"input": "3 1\r\n2 1 4\r\n11 3 16\r\n", "output": "4\r\n"}, {"... | false | stdio | null | true |
352/A | 352 | A | Python 3 | TESTS | 7 | 62 | 0 | 178026220 | n = int(input())
a = [int(x) for x in input().split()]
a = sorted(a)
a = a[::-1]
x = sum(a)
if x ==0:
print(0)
elif x/5 == n and x!=45:
print(-1)
else:
if sum(a)%9 == 0:
ans = ''.join([str(x) for x in a])
print(ans)
else:
h = int(sum(a)/5)
if h<9:
print(0)
... | 42 | 92 | 0 | 4666538 | n=int(input())
m=list(map(int,input().split()))
if 0 in m :
if 5 in m:
k=0
l=0
for i in range(n):
k+=m[i]
if m[i]==0:
l+=1
p=k//9
#print(p)
p1=p//5
#print(p1)
if p1 !=0:
print('5'*p1*9+'0'*l)
... | Codeforces Round 204 (Div. 2) | CF | 2,013 | 1 | 256 | Jeff and Digits | Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that number ... | The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | null | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | [{"input": "4\n5 0 5 0", "output": "0"}, {"input": "11\n5 5 5 5 5 5 5 5 0 5 5", "output": "5555555550"}] | 1,000 | ["brute force", "implementation", "math"] | 42 | [{"input": "4\r\n5 0 5 0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 5 5 5 5 5 5 5 0 5 5\r\n", "output": "5555555550\r\n"}, {"input": "7\r\n5 5 5 5 5 5 5\r\n", "output": "-1\r\n"}, {"input": "1\r\n5\r\n", "output": "-1\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "11\r\n5 0 5 5 5 0 0 5 5 5 5\r\n", "out... | false | stdio | null | true |
830/A | 830 | A | PyPy 3 | TESTS | 7 | 312 | 31,846,400 | 105081001 | import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key;
def pi():
return(int(input()))
def pl():
return(int(input(), 16))
def ti():
return(list(map(int,input().split())))
def ts():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
... | 59 | 140 | 3,072,000 | 197513749 | o=lambda:[int(f)for f in input().split()]
n,k,p=o()
a=sorted(o())
b=sorted(o())
print(min(max(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1))) | Codeforces Round 424 (Div. 1, rated, based on VK Cup Finals) | CF | 2,017 | 2 | 256 | Office Keys | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arb... | Print the minimum time (in seconds) needed for all n to reach the office with keys. | null | In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is... | [{"input": "2 4 50\n20 100\n60 10 40 80", "output": "50"}, {"input": "1 2 10\n11\n15 7", "output": "7"}] | 1,800 | ["binary search", "brute force", "dp", "greedy", "sortings"] | 59 | [{"input": "2 4 50\r\n20 100\r\n60 10 40 80\r\n", "output": "50\r\n"}, {"input": "1 2 10\r\n11\r\n15 7\r\n", "output": "7\r\n"}, {"input": "2 5 15\r\n10 4\r\n29 23 21 22 26\r\n", "output": "23\r\n"}, {"input": "3 10 1500\r\n106 160 129\r\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163\r\n", "output": "1394\r\n"}, {"... | false | stdio | null | true |
734/C | 734 | C | PyPy 3-64 | TESTS | 2 | 62 | 0 | 218777015 | n, m, k = map(int, input().split())
x, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
type1 = [[a[t], b[t]] for t in range(m)]
type2 = [[c[t], d[t]] for t in range(k)]
def printx(matrix):
... | 119 | 1,107 | 27,340,800 | 22242203 | n, m, k = map(int, input().split())
x, s = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
ans = n * x
for i in range(m):
l = 0
r = k
while (r - l > 1):
mid = l + (r - l) // 2
... | Codeforces Round 379 (Div. 2) | CF | 2,016 | 4 | 256 | Anton and Making Potions | Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.
1. Spells of t... | The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the i... | Print one integer — the minimum time one has to spent in order to prepare n potions. | null | In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints... | [{"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80", "output": "20"}, {"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800", "output": "200"}] | 1,600 | ["binary search", "dp", "greedy", "two pointers"] | 119 | [{"input": "20 3 2\r\n10 99\r\n2 4 3\r\n20 10 40\r\n4 15\r\n10 80\r\n", "output": "20\r\n"}, {"input": "20 3 2\r\n10 99\r\n2 4 3\r\n200 100 400\r\n4 15\r\n100 800\r\n", "output": "200\r\n"}, {"input": "10 3 3\r\n10 33\r\n1 7 6\r\n17 25 68\r\n2 9 10\r\n78 89 125\r\n", "output": "10\r\n"}, {"input": "94 1 1\r\n26 324\r\n... | false | stdio | null | true |
305/A | 305 | A | PyPy 3 | TESTS | 18 | 280 | 20,172,800 | 86191763 | x=int(input())
a=input().split()
b=[]
l=0
p=0
q=0
r=0
s=0
for i in a:
if int(i)==0 or int(i)==100:
b.append(i)
elif(int(i)<10 and int(i)>0):
p=p+1
if(p==1):
b.append(i)
elif int(i)>=10 and int(i)<100 and int(i)%10==0:
q=q+1
if(q==1):
b.append(i... | 35 | 92 | 0 | 151210649 | input()
d=[*map(int,input().split())]
cnt=[0]*5
q=[]
for i in d:
if i==0:
cnt[0]=1
elif i==100:
cnt[1]=1
elif i<10:
cnt[2]=i
elif i%10==0:
cnt[3]=i
else:
cnt[4]=i
if cnt[0]:
q+=[0]
if cnt[1]:
q+=[100]
if cnt[2]:
q+=[cnt[2]]
if cnt[3]:
q+=[cnt[3... | Codeforces Round 184 (Div. 2) | CF | 2,013 | 2 | 256 | Strange Addition | Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.
Vasya wants to choose some integers ... | The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.
The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100). | In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | null | null | [{"input": "4\n100 10 1 0", "output": "4\n0 1 10 100"}, {"input": "3\n2 70 3", "output": "2\n2 70"}] | 1,600 | ["brute force", "constructive algorithms", "implementation"] | 35 | [{"input": "4\r\n100 10 1 0\r\n", "output": "4\r\n0 1 10 100 "}, {"input": "3\r\n2 70 3\r\n", "output": "2\r\n2 70 "}, {"input": "39\r\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29\r\n", "output": "4\r\n0 6 30 100 "}, {"input": "50\r\n20 67 96 6 75 ... | false | stdio | import sys
def mask(num):
s = f"{num:03d}"
mask = 0
if s[0] != '0':
mask |= 4
if s[1] != '0':
mask |= 2
if s[2] != '0':
mask |= 1
return mask
def main(input_path, output_path, submission_path):
with open(input_path) as f:
lines = f.readlines()
k = int(li... | true |
230/A | 230 | A | Python 3 | TESTS | 9 | 62 | 0 | 229368050 | s,n=map(int,input().split())
x,y=[],[]
d={}
for i in range(n):
a,b=map(int,input().split())
x.append(a)
y.append(b)
for i in range(n):
d[x[i]]=i
x.sort()
z=[]
for i in range(n):
#if x[i] == d[x[i]]:
z.append(y[d[x[i]]])
#print(x,z)
breaker=False
for i in range(n):
if s > x[i]:
s +... | 54 | 92 | 0 | 230358278 | s, n = map(int, input().split())
dragons = []
for i in range(n):
x, y = map(int, input().split())
dragons.append((x, y))
dragons.sort()
for dragon in dragons:
if s > dragon[0]:
s += dragon[1]
else:
print("NO")
break
else:
print("YES") | Codeforces Round 142 (Div. 2) | CF | 2,012 | 2 | 256 | Dragons | Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'... | The first line contains two space-separated integers s and n (1 ≤ s ≤ 104, 1 ≤ n ≤ 103). Then n lines follow: the i-th line contains space-separated integers xi and yi (1 ≤ xi ≤ 104, 0 ≤ yi ≤ 104) — the i-th dragon's strength and the bonus for defeating it. | On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. | null | In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level.
In the second sample Kirito's strength ... | [{"input": "2 2\n1 99\n100 0", "output": "YES"}, {"input": "10 1\n100 100", "output": "NO"}] | 1,000 | ["greedy", "sortings"] | 54 | [{"input": "2 2\r\n1 99\r\n100 0\r\n", "output": "YES\r\n"}, {"input": "10 1\r\n100 100\r\n", "output": "NO\r\n"}, {"input": "123 2\r\n78 10\r\n130 0\r\n", "output": "YES\r\n"}, {"input": "999 2\r\n1010 10\r\n67 89\r\n", "output": "YES\r\n"}, {"input": "2 5\r\n5 1\r\n2 1\r\n3 1\r\n1 1\r\n4 1\r\n", "output": "YES\r\n"},... | false | stdio | null | true |
830/A | 830 | A | PyPy 3 | TESTS | 9 | 373 | 34,201,600 | 116498092 | np,nk,d=[int(i) for i in input().split()]
lp=[int(i) for i in input().split()]
lk=[int(i) for i in input().split()]
lp.sort()
lk.sort()
dp=[[float('inf') for i in range(len(lp)+1)] for j in range(len(lk)+1)]
dp[0][0]=0
for i in range(1,len(lk)+1):
for j in range(1,len(lp)+1):
if dp[i-1][j-1]!=float('inf'):
... | 59 | 140 | 10,956,800 | 116481593 | import sys
input = sys.stdin.readline
n, k, p = map(int, input().split())
A = sorted(map(int, input().split()))
B = [0] + sorted(map(int, input().split()))
dp = [[0] * (k + 1) for _ in range(n + 1)]
for i, a in enumerate(A, 1):
for j in range(k - n + i, i - 1, -1):
dp[i][j] = max(dp[i - 1][j - 1], abs(a - ... | Codeforces Round 424 (Div. 1, rated, based on VK Cup Finals) | CF | 2,017 | 2 | 256 | Office Keys | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arb... | Print the minimum time (in seconds) needed for all n to reach the office with keys. | null | In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is... | [{"input": "2 4 50\n20 100\n60 10 40 80", "output": "50"}, {"input": "1 2 10\n11\n15 7", "output": "7"}] | 1,800 | ["binary search", "brute force", "dp", "greedy", "sortings"] | 59 | [{"input": "2 4 50\r\n20 100\r\n60 10 40 80\r\n", "output": "50\r\n"}, {"input": "1 2 10\r\n11\r\n15 7\r\n", "output": "7\r\n"}, {"input": "2 5 15\r\n10 4\r\n29 23 21 22 26\r\n", "output": "23\r\n"}, {"input": "3 10 1500\r\n106 160 129\r\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163\r\n", "output": "1394\r\n"}, {"... | false | stdio | null | true |
114/B | 114 | B | Python 3 | TESTS | 13 | 156 | 307,200 | 21891166 | import math
from operator import itemgetter
var=input("")
var=var.split(" ")
n=int(var[0])
m=int(var[1])
L=[]
for i in range(n):
name=input("")
L.append(name)
if m==0:
L.sort()
print(len(L))
for i in range(len(L)):
print(L[i])
else:
d={}
K=[]
L1=[]
for i in range(m):
... | 61 | 404 | 23,756,800 | 87839604 | def GSB(x):
counter=0
while x!=0:
counter+=1
x=x>>1
return counter
def friends(checker,enemy):
for i in range(len(enemy)):
if enemy[i][0] in checker and enemy[i][1] in checker:
return 0
return 1
people,conflict=[int(x) for x in input().split()]
person=[]
enemy=[]
highest=-1
highestarray=[]
for i in rang... | Codeforces Beta Round 86 (Div. 2 Only) | CF | 2,011 | 2 | 256 | PFAST Inc. | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m ($$0 \leq m \leq \frac{n(n-1)}{2}$$) — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters).... | The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team. | null | null | [{"input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya", "output": "2\nMasha\nPetya"}, {"input": "3 0\nPasha\nLesha\nVanya", "output": "3\nLesha\nPasha\nVanya"}] | 1,500 | ["bitmasks", "brute force", "graphs"] | 61 | [{"input": "3 1\r\nPetya\r\nVasya\r\nMasha\r\nPetya Vasya\r\n", "output": "2\r\nMasha\r\nPetya\r\n"}, {"input": "3 0\r\nPasha\r\nLesha\r\nVanya\r\n", "output": "3\r\nLesha\r\nPasha\r\nVanya\r\n"}, {"input": "7 12\r\nPasha\r\nLesha\r\nVanya\r\nTaras\r\nNikita\r\nSergey\r\nAndrey\r\nPasha Taras\r\nPasha Nikita\r\nPasha A... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
input_lines = [line.strip() for line in f.readlines()]
if not input_lines:
print(0)
return
n, m = map(int, input_l... | true |
747/D | 747 | D | Python 3 | TESTS | 5 | 77 | 4,812,800 | 23192739 | n, k = [int(i) for i in input().split(' ')]
w = [int(i) for i in input().split(' ')]
f = 0
while f < n and w[f] >= 0:
f += 1
if f == n:
print(0)
exit()
b = n - 1
while b >= 0 and w[b] >= 0:
b -= 1
if n == b - f + 1:
print(1)
exit()
inv = []
ps = 0
ns = 0
for i in range(f, b):
if w[i] >=... | 59 | 343 | 13,824,000 | 41284906 | _, k = map(int, input().split())
val = [0] + list(map(int, input().split()))
n = len(val)
pls = []
cur, i, sm = 0, 0, 0
while i < n:
if val[i] >= 0:
cur += 1
else:
if cur > 0:
pls.append(cur)
cur = 0
i += 1
sm = sum(p for p in pls)
pls = pls[1:]
if cur > 0:
one = ... | 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 |
830/A | 830 | A | PyPy 3-64 | TESTS | 9 | 62 | 3,174,400 | 190105592 | import sys
# sys.stdin, sys.stdout = open("input.txt", "r"), open("output.txt", "w")
def main():
n, k, p = map(int, input().split())
done = [0 for i in range(k)]
idx = [-1 for i in range(n)]
a = [int(a) for a in input().split()]
b = [int(a) for a in input().split()]
a.sort()
b.sort()
d... | 59 | 155 | 921,600 | 192593426 | import copy
import random
import heapq
import math
import sys
import bisect
import datetime
from functools import lru_cache
from collections import deque
from collections import Counter
from collections import defaultdict
from itertools import combinations
from itertools import permutations
from types import GeneratorT... | Codeforces Round 424 (Div. 1, rated, based on VK Cup Finals) | CF | 2,017 | 2 | 256 | Office Keys | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | The first line contains three integers n, k and p (1 ≤ n ≤ 1 000, n ≤ k ≤ 2 000, 1 ≤ p ≤ 109) — the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — positions in which people are located initially. The positions are given in arb... | Print the minimum time (in seconds) needed for all n to reach the office with keys. | null | In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is... | [{"input": "2 4 50\n20 100\n60 10 40 80", "output": "50"}, {"input": "1 2 10\n11\n15 7", "output": "7"}] | 1,800 | ["binary search", "brute force", "dp", "greedy", "sortings"] | 59 | [{"input": "2 4 50\r\n20 100\r\n60 10 40 80\r\n", "output": "50\r\n"}, {"input": "1 2 10\r\n11\r\n15 7\r\n", "output": "7\r\n"}, {"input": "2 5 15\r\n10 4\r\n29 23 21 22 26\r\n", "output": "23\r\n"}, {"input": "3 10 1500\r\n106 160 129\r\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163\r\n", "output": "1394\r\n"}, {"... | false | stdio | null | true |
837/F | 837 | F | PyPy 3 | TESTS | 3 | 124 | 11,264,000 | 183465893 | import io
import os
import math
from itertools import accumulate
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
i = 0
while a[i] == 0:
i += 1
a = a[i:]
n = len(a)
if max(a) >= k:
... | 40 | 155 | 29,593,600 | 197846856 | from io import BytesIO, IOBase
import sys
import os
# import time
import bisect
# import functools
# import math
# import random
# import re
# from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
# from heapq import heapify, heappop, heappush... | Educational Codeforces Round 26 | ICPC | 2,017 | 1 | 256 | Prefix Sums | Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that yi is equal to the sum of first i elements of array x (0 ≤ i ≤ m).
You have an infinite sequence of arrays A0, A1, A2..., where A0 is given in the input, and for each i ≥ 1 Ai = p(Ai - 1). Als... | The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k ≤ 1018). n is the size of array A0.
The second line contains n integers A00, A01... A0n - 1 — the elements of A0 (0 ≤ A0i ≤ 109). At least two elements of A0 are positive. | Print the minimum i such that Ai contains a number which is larger or equal than k. | null | null | [{"input": "2 2\n1 1", "output": "1"}, {"input": "3 6\n1 1 1", "output": "2"}, {"input": "3 1\n1 0 1", "output": "0"}] | 2,400 | ["binary search", "brute force", "combinatorics", "math", "matrices"] | 40 | [{"input": "2 2\r\n1 1\r\n", "output": "1\r\n"}, {"input": "3 6\r\n1 1 1\r\n", "output": "2\r\n"}, {"input": "3 1\r\n1 0 1\r\n", "output": "0\r\n"}, {"input": "3 1000000000000000000\r\n5 4 5\r\n", "output": "632455531\r\n"}, {"input": "4 1000000000000000000\r\n0 4 4 5\r\n", "output": "707106780\r\n"}, {"input": "5 1000... | false | stdio | null | true |
743/A | 743 | A | PyPy 3 | TESTS | 26 | 155 | 512,000 | 76717828 | n,a,b=list(map(int,input().strip().split()))
s=input()
t=s[a-1]
count=b-1
c=0
while count>=0 and s[count]!=t:
c+=1
count-=1
c2=0
count=b-1
while count<n and s[count]!=t:
c2+=1
count+=1
t2=s[b-1]
count=a-1
c3=0
while count>=0 and s[count]!=t2:
c3+=1
count-=1
c4=0
count=a-1
while count<n and s[cou... | 56 | 46 | 0 | 178822352 | n, a, b = map(int, input().split())
s = input()
a -= 1
b -= 1
print((ord(s[a]) - ord('0')) ^ (ord(s[b]) - ord('0'))) | Codeforces Round 384 (Div. 2) | CF | 2,016 | 2 | 256 | Vladik and flights | Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.
Vladik knows n airports. All the airports are located on a straight line. Each airport has uni... | The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.
The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th char... | Print single integer — the minimum cost Vladik has to pay to get to the olympiad. | null | In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th... | [{"input": "4 1 4\n1010", "output": "1"}, {"input": "5 5 2\n10110", "output": "0"}] | 1,200 | ["constructive algorithms", "greedy", "implementation"] | 56 | [{"input": "4 1 4\r\n1010\r\n", "output": "1"}, {"input": "5 5 2\r\n10110\r\n", "output": "0"}, {"input": "10 9 5\r\n1011111001\r\n", "output": "1"}, {"input": "7 3 7\r\n1110111\r\n", "output": "0"}, {"input": "1 1 1\r\n1\r\n", "output": "0"}, {"input": "10 3 3\r\n1001011011\r\n", "output": "0"}, {"input": "1 1 1\r\n0\... | false | stdio | null | true |
888/C | 888 | C | PyPy 3-64 | TESTS | 21 | 623 | 6,041,600 | 173912688 | s = input()
if len(s) == 1:
print(1)
exit()
def f(size):
for l in 'abcdefghijklmnopqrstuvwxyz':
found = {}
for i in range(size):
if s[i] not in found:
found[s[i]] = 1
else:
found[s[i]] += 1
i = 0
if l not in found:
... | 51 | 62 | 8,396,800 | 174648962 | import sys
input = sys.stdin.buffer.readline
def process(s):
n = len(s)
c = [[-1] for i in range(26)]
for i in range(n):
c[ord(s[i])-ord('a')].append(i)
for i in range(26):
c[i].append(n)
answer = n
for i in range(26):
entry = 0
for j in range(len(c[i])-1):
... | Educational Codeforces Round 32 | ICPC | 2,017 | 2 | 256 | K-Dominant Character | You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character. | The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). | Print one number — the minimum value of k such that there exists at least one k-dominant character. | null | null | [{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}] | 1,400 | ["binary search", "implementation", "two pointers"] | 51 | [{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o... | false | stdio | null | true |
888/C | 888 | C | Python 3 | TESTS | 31 | 202 | 3,276,800 | 81990379 | from collections import defaultdict
s=input()
d={}
d=defaultdict(lambda:[0],d)
d1={}
d1=defaultdict(lambda:-1,d1)
k=1
for i in s:
d1[i]=max(k-d[i][-1],d1[i])
d[i].append(k)
k+=1
#print(d)
#print(d1)
ans=[]
for i in d.keys():
d1[i]=max(len(s)-d[i][-1]+1,d1[i])
for i in d1.keys():
if len(d[i])... | 51 | 77 | 1,228,800 | 32163369 | '''input
abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy... | Educational Codeforces Round 32 | ICPC | 2,017 | 2 | 256 | K-Dominant Character | You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character. | The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). | Print one number — the minimum value of k such that there exists at least one k-dominant character. | null | null | [{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}] | 1,400 | ["binary search", "implementation", "two pointers"] | 51 | [{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o... | false | stdio | null | true |
888/C | 888 | C | PyPy 3 | TESTS | 31 | 187 | 24,371,200 | 88443044 | st = input()
l = len(st)
ls = list(set(st))
dt = dict()
for i in range(l):
for j in range(i+1, l):
if(st[i]==st[j]):
if(st[i] in dt):
dt[st[i]] = max(j-i, dt[st[i]])
else:
dt[st[i]] = j-i
break
for k in ls:
if k not in dt.keys():
... | 51 | 77 | 6,860,800 | 32638483 | s = str(input())
set_str = set(s)
distance = []
for i in set_str:
distance.append(max(map(len, s.split(i))))
print(min(distance)+1) | Educational Codeforces Round 32 | ICPC | 2,017 | 2 | 256 | K-Dominant Character | You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character. | The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000). | Print one number — the minimum value of k such that there exists at least one k-dominant character. | null | null | [{"input": "abacaba", "output": "2"}, {"input": "zzzzz", "output": "1"}, {"input": "abcde", "output": "3"}] | 1,400 | ["binary search", "implementation", "two pointers"] | 51 | [{"input": "abacaba\r\n", "output": "2\r\n"}, {"input": "zzzzz\r\n", "output": "1\r\n"}, {"input": "abcde\r\n", "output": "3\r\n"}, {"input": "bcaccacaaabaacaabaaabcbbcbcaacacbcbaaaacccacbbcbaabcbacaacbabacacacaccbbccbcbacbbbbccccabcabaaab\r\n", "output": "8\r\n"}, {"input": "daabcdabbabbacacbaacabacbcaabaacac\r\n", "o... | false | stdio | null | true |
662/D | 662 | D | Python 3 | TESTS | 3 | 374 | 8,499,200 | 65890807 | base = 1989
d = {}
for x in range(base, 100000):
x = str(x)
n = len(x)
for i in range(-1, -(n+1), -1):
if x[i:] not in d:
d[x[i:]] = x
break
T = int(input())
for _ in range(T):
x = input()[4:]
n = len(x)
cur_d = {}
for i in... | 45 | 46 | 0 | 230902958 | for i in range(int(input())):
t = input()[4:]
q, d = int(t), 10 ** len(t)
while q < 1988 + d // 9: q += d
print(q) | CROC 2016 - Final Round [Private, For Onsite Finalists Only] | CF | 2,016 | 1 | 256 | International Olympiad | International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Amo... | The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.
Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits. | For each abbreviation given in the input, find the year of the corresponding Olympiad. | null | null | [{"input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0", "output": "2015\n12015\n1991\n1989\n1990"}, {"input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999", "output": "1989\n1999\n2999\n9999"}] | 2,000 | ["constructive algorithms", "greedy", "implementation", "math"] | 45 | [{"input": "5\r\nIAO'15\r\nIAO'2015\r\nIAO'1\r\nIAO'9\r\nIAO'0\r\n", "output": "2015\r\n12015\r\n1991\r\n1989\r\n1990\r\n"}, {"input": "4\r\nIAO'9\r\nIAO'99\r\nIAO'999\r\nIAO'9999\r\n", "output": "1989\r\n1999\r\n2999\r\n9999\r\n"}, {"input": "1\r\nIAO'111110\r\n", "output": "1111110\r\n"}, {"input": "2\r\nIAO'0\r\nIAO... | false | stdio | null | true |
78/A | 78 | A | Python 3 | TESTS | 7 | 216 | 0 | 84403055 | a = []
for _ in range(3):
d = 0
k = input().split(" ")
for i in k:
for x in i:
if x == "a" or x == "i" or x == "e" or x == "o" or x == "u":
d += 1
a.append(d)
print("NO" if a[0] != a[2] != 5 or a[1] != 7 else "YES") | 40 | 62 | 0 | 148649468 | line1 = input()
line2 = input()
line3 = input()
count1 = 0
count2 = 0
count3 = 0
for i in range(0,len(line1)):
if(line1[i] == 'a' or line1[i] == 'e' or line1[i] == 'i' or line1[i] == 'o' or line1[i] == 'u'):
count1 = count1+1
for i in range(0,len(line2)):
if(line2[i] == 'a' or line2[i] == 'e' or line2[... | Codeforces Beta Round 70 (Div. 2) | CF | 2,011 | 2 | 256 | Haiku | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing sp... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | null | null | [{"input": "on codeforces\nbeta round is running\na rustling of keys", "output": "YES"}, {"input": "how many gallons\nof edo s rain did you drink\ncuckoo", "output": "NO"}] | 800 | ["implementation", "strings"] | 40 | [{"input": "on codeforces \r\nbeta round is running\r\n a rustling of keys \r\n", "output": "YES"}, {"input": "how many gallons\r\nof edo s rain did you drink\r\n cuckoo\r\n", "output": "NO"}, {"input": " hatsu shigure\r\n saru mo komino wo\r\nhoshige nari\r\n", "output": "Y... | false | stdio | null | true |
774/L | 774 | L | Python 3 | TESTS | 3 | 61 | 5,529,600 | 26498638 | from sys import exit
n=0
k=0
s=""
for i in input().split():
if n==0:
n=int(i)
else:
k=int(i)
s=str(input())
node=[]
for i in range(len(s)):
if s[int(i)]=='0':
node.append(i+1)
node.append(1000000000)
def check(dis):
current=0
num=k-2
point=[]
point.append(node[0])
... | 81 | 171 | 25,702,400 | 26155064 | def check(p):
cur = k - 2
p+=1
lastfree = 0
lasteat = 0
for i in range(1, n-1):
if tm[i] == '0':
lastfree = i
if i - lasteat >= p:
if lasteat == lastfree or cur <= 0:
return False
lasteat = lastfree
cur -= 1
return T... | VK Cup 2017 - Wild Card Round 1 | ICPC | 2,017 | 2 | 256 | Bars | Polycarp's workday lasts exactly $$$n$$$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $$$k$$$ bars at the beginning of the workday.
In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he... | The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 200\,000$$$, $$$2 \le k \le n$$$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday.
The second line contains the string with length $$$n$$$ consisting of zeros and ones. I... | Print the minimum possible break in minutes between eating chocolate bars. | null | In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute.
In the second example Polycarp will eat bars in the minutes $$$1$$$ and $$$8$$$ anyway, also he needs to eat the chocolate bar in the minute $$$5$$$, so that the time of the maximum break wi... | [{"input": "3 3\n010", "output": "1"}, {"input": "8 3\n01010110", "output": "3"}] | 2,000 | ["*special", "binary search"] | 81 | [{"input": "3 3\r\n010\r\n", "output": "1\r\n"}, {"input": "8 3\r\n01010110\r\n", "output": "3\r\n"}, {"input": "9 5\r\n001100110\r\n", "output": "2\r\n"}, {"input": "2 2\r\n00\r\n", "output": "0\r\n"}, {"input": "3 2\r\n010\r\n", "output": "1\r\n"}, {"input": "3 2\r\n000\r\n", "output": "1\r\n"}, {"input": "3 3\r\n000... | false | stdio | null | true |
763/C | 763 | C | Python 3 | TESTS | 12 | 217 | 8,089,600 | 46056934 | def pow_mod(a,b,c):
n = 1
m = a
v = b
if a == 1:
return 1
while v > 0:
if v%2 == 1:
n *= m%c
n %= c
m *= m
m %= c
v //= 2
return n%c
def pow(a,b):
n = 1
m = a
v = b
if a == 1:
return 1
while v > 0:
... | 62 | 155 | 20,275,200 | 230897323 | def solve(n, m, a):
if n == 0:
return 0, 1
if n == 1:
return a[0], 1
d = (a[1]-a[0]) % m
if d < 0: d += m
st = set(a)
cnt = 0
for v in a:
cnt += ((v + d) % m) in st
cnt = n-cnt
d = (d * pow(cnt, m-2, m)) % m
now = a[0]
while (now + m - d) % m in st:
... | Codeforces Round 395 (Div. 1) | CF | 2,017 | 2 | 256 | Timofey and remoduling | Little Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime m. Also, Timofey likes to look for arithmetical progressions everywhere.
One of his birthday presents was a sequence of distinct integers a1, a2, ..., an. ... | The first line contains two integers m and n (2 ≤ m ≤ 109 + 7, 1 ≤ n ≤ 105, m is prime) — Timofey's favorite prime module and the length of the sequence.
The second line contains n distinct integers a1, a2, ..., an (0 ≤ ai < m) — the elements of the sequence. | Print -1 if it is not possible to rearrange the elements of the sequence so that is will be an arithmetical progression modulo m.
Otherwise, print two integers — the first element of the obtained progression x (0 ≤ x < m) and its difference d (0 ≤ d < m).
If there are multiple answers, print any of them. | null | null | [{"input": "17 5\n0 2 4 13 15", "output": "13 2"}, {"input": "17 5\n0 2 4 13 14", "output": "-1"}, {"input": "5 3\n1 2 3", "output": "3 4"}] | 2,600 | ["brute force", "implementation", "math", "number theory"] | 62 | [{"input": "17 5\r\n0 2 4 13 15\r\n", "output": "13 2\r\n"}, {"input": "17 5\r\n0 2 4 13 14\r\n", "output": "-1\r\n"}, {"input": "5 3\r\n1 2 3\r\n", "output": "3 4\r\n"}, {"input": "17 8\r\n7 9 11 13 15 1 3 5\r\n", "output": "1 2\r\n"}, {"input": "13 2\r\n0 11\r\n", "output": "0 11\r\n"}, {"input": "3 1\r\n0\r\n", "out... | false | stdio | import sys
def read_answer(line):
line = line.strip()
if line == '-1':
return (-1, None)
parts = line.split()
if len(parts) != 2:
return (None, None)
try:
x = int(parts[0])
d = int(parts[1])
return (x, d)
except:
return (None, None)
def main(inpu... | true |
247/A | 250 | A | Python 3 | TESTS | 11 | 216 | 307,200 | 85791938 | n = int(input())
s = [int(i) for i in input().split()]
d = []
l,r = 0,0
cnt = 0
while r<n:
if (cnt==2 and s[r]<0) or r==n-1:
if r<n-1:
d.append(s[l:r])
cnt = 1
l=r
r+=1
else:
d.append(s[l:r+1])
r+=1
else:
if s[r]<0:
cnt+=1
r+=1
print(len(d))
s = [len(i) for i in d]
print(*s) | 69 | 92 | 0 | 160205997 | n = int(input())
days = list(map(int, input().split()))
result = []
count = 0
negatives = 0
for day in days:
if day >= 0:
count += 1
elif negatives < 2:
count += 1
negatives += 1
else:
result.append(count)
count = 1
negatives = 1
if count > 0:
result.append(count)
print(len(result))
f... | 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 |
63/B | 63 | B | PyPy 3-64 | TESTS | 3 | 92 | 0 | 153559304 | # @Chukamin ICPC_TRAIN
def main():
n, k = map(int, input().split())
cnt = [0] * (k + 1)
data = list(map(int, input().split()))
for i in range(n):
cnt[data[i]] += 1
ans = 0
while True:
ans += 1
for i in range(k, 0, -1):
if cnt[i - 1] != 0:
cnt[... | 37 | 92 | 0 | 139892376 | n,k=map(int,input().split())
l=list(map(int,list(input().split())))
l=sorted(l)
x=-1
i=0
count=0
while(l.count(k)!=n):
for i in range(n):
if x!=l[i]:
x=l[i]
if l[i]<k:
l[i]=l[i]+1
l=sorted(l)
x=-1
count=count+1
print(count) | Codeforces Beta Round 59 (Div. 2) | CF | 2,011 | 2 | 256 | Settlers' Training | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc... | The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai... | Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. | null | In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | [{"input": "4 4\n1 2 2 3", "output": "4"}, {"input": "4 3\n1 1 1 1", "output": "5"}] | 1,200 | ["implementation"] | 37 | [{"input": "4 4\r\n1 2 2 3\r\n", "output": "4"}, {"input": "4 3\r\n1 1 1 1\r\n", "output": "5"}, {"input": "3 3\r\n1 2 3\r\n", "output": "2"}, {"input": "1 1\r\n1\r\n", "output": "0"}, {"input": "1 5\r\n1\r\n", "output": "4"}, {"input": "1 5\r\n4\r\n", "output": "1"}, {"input": "2 6\r\n2 5\r\n", "output": "4"}, {"input... | false | stdio | null | true |
819/B | 819 | B | Python 3 | TESTS | 5 | 61 | 5,529,600 | 28102959 | n=int(input())
A=list(map(int,input().strip().split(' ')))
for i in range(len(A)):
A[i]-=1
ans=0
pos=0
neg=0
change=[0 for i in range(len(A))]
for i in range(len(A)):
ans+=abs(A[i]-i)
if A[i]-i>0:
pos+=1
else:
neg+=1
if A[i]-i>0:
change[i]=A[i]-i
else:
chang... | 80 | 1,138 | 96,153,600 | 28091016 | n = int(input())
p = [int(i) - 1 for i in input().split()]
chd = [0] * (n + 2)
dev = 0
dd = 0
for i in range(n):
shi = p[i] - i
dev += abs(shi)
if p[i] <= i:
dd += 1
shi = n + shi
chd[shi] += 2
else:
dd -= 1
chd[shi] += 2
bdev = dev
bsh = 0
for i in range(1, n... | Codeforces Round 421 (Div. 1) | CF | 2,017 | 2 | 256 | Mister B and PR Shifts | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | First line contains single integer n (2 ≤ n ≤ 106) — the length of the permutation.
The second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — the elements of the permutation. It is guaranteed that all elements are distinct. | Print two integers: the minimum deviation of cyclic shifts of permutation p and the id of such shift. If there are multiple solutions, print any of them. | null | In the first sample test the given permutation p is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
In the second sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) ... | [{"input": "3\n1 2 3", "output": "0 0"}, {"input": "3\n2 3 1", "output": "0 1"}, {"input": "3\n3 2 1", "output": "2 1"}] | 1,900 | ["data structures", "implementation", "math"] | 80 | [{"input": "3\r\n1 2 3\r\n", "output": "0 0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0 1\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0 0\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0 1\r\n"}, {"input": "10\r\n10 1 9 2 8 3 7 4 6 5\r\n", "output": "24 7\r\n"}, {"inpu... | false | stdio | null | true |
733/D | 733 | D | Python 3 | TESTS | 59 | 748 | 37,376,000 | 156270315 | n = int(input())
stones = dict()
ans = 0
gift = []
for i in range(n):
stone = list(map(int, input().split()))
if min(stone[0], stone[1], stone[2]) > ans:
ans = min(stone[0], stone[1], stone[2])
gift = [i+1]
pattern = (min(stone[0], stone[1]), max((stone[0], stone[1])))
length = stone[2]
... | 104 | 405 | 61,747,200 | 210182633 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
N = int(input())
A = []
cur = 0
ans = None
for i in range(N):
b = list(map(int, input().split()))
b.sort(reverse=True)
A.append(b)
if b[-1]>cur:
cur = b[-1]
ans = [i]
lib = defaultdict(lis... | Codeforces Round 378 (Div. 2) | CF | 2,016 | 3 | 256 | Kostya the Sculptor | Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has n stones which are rectangula... | The first line contains the integer n (1 ≤ n ≤ 105).
n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. | In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.
You can print the stones in ar... | null | In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
- 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
- 2 and 6, the size of the... | [{"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1"}, {"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5"}] | 1,600 | ["data structures", "hashing"] | 104 | [{"input": "6\r\n5 5 5\r\n3 2 4\r\n1 4 1\r\n2 1 3\r\n3 2 4\r\n3 3 4\r\n", "output": "1\r\n1\r\n"}, {"input": "7\r\n10 7 8\r\n5 10 3\r\n4 2 6\r\n5 5 5\r\n10 2 8\r\n4 2 1\r\n7 7 7\r\n", "output": "2\r\n1 5\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n2 3 1\r\n2 2 3\r\n", "output": "2\r\n2 1... | false | stdio | import sys
import os
from collections import defaultdict
EPS = 1e-9
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
stones = []
for _ in range(n):
a, b, c = map(int, f.readline().split())
... | true |
691/A | 691 | A | Python 3 | TESTS | 13 | 46 | 4,608,000 | 28699333 | n = int(input())
string = input()
if list(map(int, string.split())).count(0) == 1:
print("YES")
elif n == 1:
print("YES")
else:
print("NO") | 83 | 46 | 0 | 138255838 | # -*- coding: utf-8 -*-
"""
Created on Mon Dec 6 19:41:26 2021
@author: Lai Phuc
"""
N = int(input())
button = list(map(int, input().split(" ")))
count = 0
for i in range(len(button)):
if button[i] == 0:
count += 1
if count == 1 and N > 1 :
print("YES")
elif count == 0 and N == 1:
print("YES")
el... | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
691/A | 691 | A | Python 3 | TESTS | 13 | 61 | 0 | 31328235 | a=int(input())
b=input()
b=b.split()
if a==1:
if b[0]==1:
print("NO")
else:
print("YES")
else:
z=b.count("0")
if z==1:
print("YES")
else:
print("NO") | 83 | 46 | 0 | 146650254 | n=int(input())
m=input()
sum=0
l=list(map(int,m.split()))
if(n==1):
if(l[0]==1):
print("YES")
else:
print("NO")
elif(n>1):
for item in l:
if item==1:
sum=sum+1
if(sum==n-1):
print("YES")
else:
print("NO") | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
691/A | 691 | A | PyPy 3-64 | TESTS | 13 | 62 | 0 | 209911123 | n = int(input())
a = input().split().count('1')
if a==n-1 or (n==1 and n==a):
print("YES")
else:
print("NO") | 83 | 46 | 0 | 146663519 | n=int(input())
s=list(input().split())
sum=0
if n==1:
if int(s[0])==1:
print("YES")
else:
print("NO")
else:
for i in s:
sum+=int(i)
if sum==n-1:
print("YES")
else:
print("NO") | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
847/D | 847 | D | PyPy 3 | TESTS | 11 | 78 | 0 | 163071239 | from heapq import heappush, heappop
E = input().split(' ')
N,T = [int(i) for i in E]
E = input().split(' ')
t = [int(i) for i in E]
# priority queue
queue = []
sol = 0
for i in range(N):
heappush(queue, -(t[i] + i))
while(len(queue) > 0 and -queue[0] >= T - (i + 1)):
heappop(queue)
last = t[i]... | 151 | 358 | 20,684,800 | 163136780 | from heapq import heappush, heappop
# read input
E = input().split(' ')
N,T = [int(i) for i in E]
E = input().split(' ')
t = [int(i) for i in E]
# priority queue
queue = []
# move the dog to the position of the first bowl
T -= 1
sol = 0
for i in range(N):
# if the dog arrives at the second T or later to a posi... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 2 | 256 | Dog Show | A new dog show on TV is starting next week. On the show dogs are required to demonstrate bottomless stomach, strategic thinking and self-preservation instinct. You and your dog are invited to compete with other participants and naturally you want to win!
On the show a dog needs to eat as many bowls of dog food as poss... | Two integer numbers are given in the first line - n and T (1 ≤ n ≤ 200 000, 1 ≤ T ≤ 2·109) — the number of bowls of food and the time when the dog is stopped.
On the next line numbers t1, t2, ..., tn (1 ≤ ti ≤ 109) are given, where ti is the moment of time when the i-th bowl of food is ready for eating. | Output a single integer — the maximum number of bowls of food the dog will be able to eat in T seconds. | null | In the first example the dog should skip the second bowl to eat from the two bowls (the first and the third). | [{"input": "3 5\n1 5 3", "output": "2"}, {"input": "1 2\n1", "output": "1"}, {"input": "1 1\n1", "output": "0"}] | 2,200 | ["constructive algorithms", "data structures", "greedy"] | 151 | [{"input": "3 5\r\n1 5 3\r\n", "output": "2\r\n"}, {"input": "1 2\r\n1\r\n", "output": "1\r\n"}, {"input": "1 1\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1\r\n2\r\n", "output": "0\r\n"}, {"input": "2 2\r\n2 3\r\n", "output": "0\r\n"}, {"input": "2 3\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3 3\r\n2 3 2\r\n", "outp... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS1 | 35 | 62 | 6,656,000 | 31572283 | #python 3.5.2
n = int(input())
kata = input()
pos = []
muncul = set()
for i,x in zip(range(n),kata):
if (x == '*'):
pos.append(i)
else:
muncul.add(x)
m = int(input())
belum = []
for i in range(m):
kata = input()
yay = set()
cancel = False
for x in pos:
if (kata[x] in m... | 50 | 62 | 5,529,600 | 31560251 | n = int(input())
s = input()
lr = []
r = []
w = set()
for i in range(len(s)):
if s[i] == '*':
lr.append(i)
else:
r.append(i)
w.add(s[i])
m = int(input())
k = None
for i in range(m):
e = input()
f = False
for j in lr:
if e[j] in w:
f = True
break
for j in r:
if e[j] != s[j]:
f = True
break
... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
691/A | 691 | A | Python 3 | TESTS | 13 | 62 | 0 | 20476485 | n = int(input())
if n <= 1:
print("YES")
else:
print(["NO","YES"][input().split().count("0") == 1]) | 83 | 46 | 0 | 149067535 | n = int(input())
l = input().split()
if min(1, n-1) == l.count('0'):
print("YES")
else:
print("NO") | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS1 | 35 | 77 | 5,529,600 | 31558627 | c = input()
s = input()
star = []
no_star = []
for i in range(len(s)):
if s[i] == '*':
star.append(i)
else:
no_star.append(i)
n = int(input())
d = {}
skip = 0
for i in range(n):
s1 = input()
ext = 0
for i in star:
if s1[i] in s:
ext = 1
break
if ... | 50 | 62 | 6,041,600 | 31576883 | n = int(input())
word = input()
ast = word.count('*')
mas = [i for i in range(n) if word[i] == '*']
mas1 = [i for i in range(n) if word[i] != '*']
st = [word[i] for i in range(n) if word[i] != '*']
m = int(input())
Mas = list()
for i in range(m):
temp = input()
f = True
for j in mas1:
if temp[j] !... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS | 51 | 109 | 6,451,200 | 32634858 | import string
n=int(input())
s=input()
p=set(i for i in s if i!='*')
ans=set(string.ascii_lowercase)
for i in range(int(input())):
t=input()
T=1
for i in range(n):
if s[i]=='*'and t[i] in p:T=0
if T:ans&=set(t)-p
print(len(ans)) | 95 | 77 | 0 | 31865765 | n, word = int(input()), input()
stars_index, lttr_index = [], []
lttrs = set()
for i in range(len(word)):
if word[i] == '*':
stars_index.append(i)
else:
lttr_index.append(i)
lttrs.add(word[i])
m = int(input())
pssbl_lttrs = None
for i in range(m):
p_word = input()
f = False
for j in stars_index:
if p_wor... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
101/A | 101 | A | Python 3 | TESTS | 10 | 278 | 7,065,600 | 86631005 | def solve():
str0 = input()
k = int(input())
# print("str0 = ", str0)
# print("k = ", k)
if len(str0) < int(k):
print(0)
print()
exit()
dict = {}
for each in str0:
if each not in dict.keys():
dict[each] = 1
else:
dict[each] += ... | 48 | 92 | 204,800 | 159867499 | s=input("")
d=dict()
k=int(input())
b=s
setS=set()
for i in s:
if i not in setS:
d.update({i:s.count(i)})
setS.update(i)
cnt=0
del_cnt=0
l=list(d.items())
l.sort(key=lambda a: a[1])
for i,j in l:
if del_cnt+j<=k:
b=b.replace(i,"")
del_cnt+=j
cnt=len(set(b))
print(cnt)
print(b) | 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 |
883/E | 883 | E | PyPy 3-64 | TESTS | 51 | 140 | 8,601,600 | 229407232 | from collections import Counter
n=int(input())
w=set(Counter(input().replace('*','')).items())
m=int(input())
mw=[set(Counter(input()).items()) for _ in range(m)]
words =[]
w_simple = set(list(map(lambda x: x[0], w)))
for x in mw:
dif = set(list(map(lambda x: x[0],set.difference(x, w))))
if not set.intersectio... | 95 | 77 | 102,400 | 154875297 | from collections import *
input()
w, m, c, n = input(), int(input()), Counter(), 0
for _ in range(m):
q = input()
if any(a!='*' and a!=b or a=='*' and b in w for a, b in zip(w, q)):
continue
c.update(set(l for i, l in enumerate(q) if w[i]=='*'))
n += 1
print(len([l for l, x in c.items() if x==n])) | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
733/D | 733 | D | PyPy 3 | TESTS | 58 | 1,981 | 75,571,200 | 117401611 | n = int(input())
y = []
d = {}
ans = -1
pos1 = -1
pos2 = -1
for i in range(n):
a,b,c = tuple(map(int,input().split()))
y.append(sorted([a,b,c]))
if(str(min(a,b))+" "+str(max(a,b)) not in d):
d[str(min(a,b))+" "+str(max(a,b))] = [[c,i+1]]
else:
d[str(min(a,b))+" "+str(max(a,b))].append([... | 104 | 483 | 23,347,200 | 157129294 | n = int(input())
stones = []
d = {}
resradius = 0
res = []
for _ in range(n):
stones.append(list(map(int, input().split())))
for i in range(len(stones)):
stones[i].sort()
stone = stones[i]
key = (stone[1], stone[2])
if key in d:
val, index = d[key]
glued = min(val + stone[0], stone[1... | Codeforces Round 378 (Div. 2) | CF | 2,016 | 3 | 256 | Kostya the Sculptor | Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has n stones which are rectangula... | The first line contains the integer n (1 ≤ n ≤ 105).
n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. | In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data.
You can print the stones in ar... | null | In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1
- 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.
- 2 and 6, the size of the... | [{"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4", "output": "1\n1"}, {"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7", "output": "2\n1 5"}] | 1,600 | ["data structures", "hashing"] | 104 | [{"input": "6\r\n5 5 5\r\n3 2 4\r\n1 4 1\r\n2 1 3\r\n3 2 4\r\n3 3 4\r\n", "output": "1\r\n1\r\n"}, {"input": "7\r\n10 7 8\r\n5 10 3\r\n4 2 6\r\n5 5 5\r\n10 2 8\r\n4 2 1\r\n7 7 7\r\n", "output": "2\r\n1 5\r\n"}, {"input": "1\r\n1 1 1\r\n", "output": "1\r\n1\r\n"}, {"input": "2\r\n2 3 1\r\n2 2 3\r\n", "output": "2\r\n2 1... | false | stdio | import sys
import os
from collections import defaultdict
EPS = 1e-9
def main(input_path, output_path, submission_output_path):
# Read input
with open(input_path) as f:
n = int(f.readline())
stones = []
for _ in range(n):
a, b, c = map(int, f.readline().split())
... | true |
847/E | 847 | E | PyPy 3 | TESTS | 2 | 62 | 0 | 196910320 | n = (int)(input())
s = input()
l = 0
r = 2 * n
ans = -1
while l <= r :
mid = (l + r) // 2
temp = []
packman = []
time = []
for _ in range(n) :
if s[_] == '*' :
temp.append(_)
elif s[_] == 'P' :
packman.append(_)
time.append(mid)
index... | 77 | 124 | 7,372,800 | 121279454 | '''
pacman->food
pacman->food->food :hmmge:
larges smaller val
smallest larger val
'''
def check(mid,p,f):
u=0
for i in range(len(p)):
left=p[i]-f[u]
left=max(0,left)
if mid<left:
return 0
right=max(mid-2*left,0)
right=max(right,(mid-left)//2)
while u<len(f) and (f[u]<=p[i]+right): #bich mai fas ra
... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 1 | 256 | Packmen | A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.
Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.
In the initial mome... | The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field.
The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is... | Print minimum possible time after which Packmen can eat all asterisks. | null | In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ... | [{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}] | 1,800 | ["binary search", "dp"] | 77 | [{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP.... | false | stdio | null | true |
101/A | 101 | A | Python 3 | TESTS | 10 | 498 | 921,600 | 94957640 | import collections
s=input()
k=int(input())
d=dict()
for i in s:
if i in d:d[i]+=1
else:d[i]=1
d=sorted(d.items(), key=lambda x: x[1])
A=set()
ans=0
for i in d:
if k-i[1]>0:
A.add(i[0])
k-=i[1]
ans+=1
print(len(d)-ans)
for i in s:
if i not in A:
print(i,end="") | 48 | 124 | 204,800 | 5480672 | s, t, n = 0, input(), int(input())
p = {i: 0 for i in 'abcdefghijklmnopqrstuvwxyz'}
for i in t: p[i] += 1
p = {i: p[i] for i in p if p[i]}
q = sorted((k, i) for i, k in p.items())
for k, i in q:
if n < k: break
t = t.replace(i, '')
n -= k
s += 1
print(len(p) - s)
print(t) | 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 |
101/A | 101 | A | Python 3 | TESTS | 10 | 374 | 819,200 | 10548608 | import sys
import math
st = (sys.stdin.readline())
k = int(sys.stdin.readline())
d = dict()
alla = 0
for i in range(len(st) - 1):
if st[i] in d:
d[st[i]] += 1
else:
d[st[i]] = 1
alla += 1
f = sorted(d.items(), key = lambda x: x[1])
v = []
p = 0
for i in f:
if(k - i[1] > 0):
... | 48 | 124 | 204,800 | 172606582 | s=input()
k=int(input())
a=[]
for x in set(s):
a.append([s.count(x),x])
a.sort()
for z in a:
if z[0]>k:
break
k-=z[0]
s=s.replace(z[1],'')
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 |
673/B | 673 | B | PyPy 3 | TESTS | 18 | 140 | 0 | 79789593 | #n=int(input())
#n,m=map(int,input().split())
#arr=list(map(int,input().split()))\
#for i in range(m):
n,m=map(int,input().split())
if m==n:
print(0)
exit()
var=1
ans=n
for i in range(m):
u,v=map(int,input().split())
if u>v:u,v=v,u
var=max(u,var)
ans=min(v,ans)
print(max(0,ans-var)) | 51 | 155 | 9,625,600 | 164568818 | import sys
input = sys.stdin.readline
n, m = map(int, input().split())
small = 0
large = n+1
s = set(range(1, n+1))
for i in range(m):
a, b = sorted(map(int, input().split()))
if a > small:
small = a
if b < large:
large = b
s -= {a, b}
if small >= large:
print(0)
bre... | Codeforces Round 351 (VK Cup 2016 Round 3, Div. 2 Edition) | CF | 2,016 | 2 | 256 | Problems for Round | There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset of eac... | The first line of the input contains two integers n and m (2 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following m lines contains a pair of similar problems ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi). It's guaranteed,... | Print one integer — the number of ways to split problems in two divisions. | null | In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sa... | [{"input": "5 2\n1 4\n5 2", "output": "2"}, {"input": "3 3\n1 2\n2 3\n1 3", "output": "0"}, {"input": "3 2\n3 1\n3 2", "output": "1"}] | 1,300 | ["greedy", "implementation"] | 51 | [{"input": "5 2\r\n1 4\r\n5 2\r\n", "output": "2\r\n"}, {"input": "3 3\r\n1 2\r\n2 3\r\n1 3\r\n", "output": "0\r\n"}, {"input": "3 2\r\n3 1\r\n3 2\r\n", "output": "1\r\n"}, {"input": "2 0\r\n", "output": "1\r\n"}, {"input": "2 1\r\n1 2\r\n", "output": "1\r\n"}, {"input": "3 0\r\n", "output": "2\r\n"}, {"input": "3 1\r\... | false | stdio | null | true |
634/A | 634 | A | Python 3 | TESTS | 26 | 265 | 23,552,000 | 16823232 | N = int(input()) #количество островов
A = list(map(int,input().split()))
B = list(map(int,input().split()))
flag = True
A.remove(0)
B.remove(0)
ind_b = B.index(A[0])
i = 0
while ind_b + i < len(B):
if A[i] != B[ind_b + i]:
i = len(B) + ind_b # работает как флаг выхода из циклов
flag = False
i +=... | 61 | 77 | 6,348,800 | 158696931 | input()
f=lambda:(' '+input()).replace(' 0','')
a,b=f(),f()
print('YES' if a in b+b else 'NO') | 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) | CF | 2,016 | 2 | 256 | Island Puzzle | A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one o... | The first line contains a single integer n (2 ≤ n ≤ 200 000) — the total number of islands.
The second line contains n space-separated integers ai (0 ≤ ai ≤ n - 1) — the statue currently placed on the i-th island. If ai = 0, then the island has no statue. It is guaranteed that the ai are distinct.
The third line cont... | Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise. | null | In the first sample, the islanders can first move statue 1 from island 1 to island 2, then move statue 2 from island 3 to island 1, and finally move statue 1 from island 2 to island 3.
In the second sample, the islanders can simply move statue 1 from island 1 to island 2.
In the third sample, no sequence of movements... | [{"input": "3\n1 0 2\n2 0 1", "output": "YES"}, {"input": "2\n1 0\n0 1", "output": "YES"}, {"input": "4\n1 2 3 0\n0 3 2 1", "output": "NO"}] | 1,300 | ["constructive algorithms", "implementation"] | 61 | [{"input": "3\r\n1 0 2\r\n2 0 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 0\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n1 2 3 0\r\n0 3 2 1\r\n", "output": "NO\r\n"}, {"input": "9\r\n3 8 4 6 7 1 5 2 0\r\n6 4 8 5 3 1 2 0 7\r\n", "output": "NO\r\n"}, {"input": "4\r\n2 3 1 0\r\n2 0 1 3\r\n", "output": "NO\r\n"},... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS1 | 35 | 93 | 6,144,000 | 31556876 | N = int(input())
p = input()
M = int(input())
words = [input() for _ in range(M)]
cnt = 0
letters = [set() for _ in range(M)]
used = set()
for c in p:
used.add(c)
fail = [False]*M
for i, w in enumerate(words):
for j, c in enumerate(w):
if p[j] == '*':
letters[i].add(c)
if c in u... | 50 | 77 | 5,529,600 | 31565251 | n = int(input())
S = input()
HaveLetters = set(list(S))
m = int(input())
words = []
CanLetters = set([chr(i) for i in range(ord("a"), ord("z") + 1)]) - HaveLetters
for _ in range(m):
Word = input()
for i in range(n):
if S[i] == "*":
if Word[i] in HaveLetters:
break
el... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS | 51 | 93 | 1,536,000 | 32062050 | import sys
from collections import Counter
H = int(next(sys.stdin))
ast = next(sys.stdin).strip()
M = int(next(sys.stdin))
def filter_ast(w, ast):
return set(c for i, c in enumerate(w) if ast[i] == "*")
def is_compatible(w, ast):
seen = set(c for i, c in enumerate(w) if ast[i] != "*")
unseen = set(c fo... | 95 | 77 | 5,529,600 | 31624255 | n = int(input())
s = input()
already = set()
for i in s:
if i != '*':
already.add(i)
ans = [chr(ord('a') + i) for i in range(26)]
ans = set(ans)
for i in range(int(input())):
cur = input()
can = True
clos = set() #should be closed
for j in range(n):
if s[j] == '*':
clos.a... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
691/A | 691 | A | PyPy 3-64 | TESTS | 13 | 46 | 0 | 209911133 | n = int(input())
a = input().split().count('1')
if a==n-1 or n==1:
print("YES")
else:
print("NO") | 83 | 46 | 0 | 150067193 | n = int(input())
s = sum([int(x) for x in input().split(" ")])
if n == 1:
if n==s:
print("YES")
else:
print("NO")
else:
if s == n-1:
print("YES")
else:
print("NO") | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
691/A | 691 | A | Python 3 | TESTS | 13 | 46 | 4,300,800 | 134559425 | #!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-07 16:18:22
LastEditTime: 2021-11-07 16:22:56
Description: Fashion in Berland
FilePath: CF691A.py
'''
def func():
n = int(input())
buttons = list(map(int, input().strip().split()))
if n == 1 and sum(buttons) == 1:
print("YES")
... | 83 | 46 | 0 | 154972244 | input()
n = list(map(int , input().split()))
if n.count(0)==1 and len(n)>1:
print("YES")
elif n.count(0)==0 and len(n)==1:
print("YES")
else:
print("NO") | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
401/A | 401 | A | Python 3 | TESTS | 9 | 109 | 0 | 68895197 | n,x=map(int,input().split())
y=[int(q) for q in input().split()]
s=sum(y)
l=0
d=abs(s)
if n==1:
print(1)
else:
for i in range(x,1,-1):
while (d)>0:
d-=x
l+=1
print(l) | 47 | 46 | 0 | 141317869 | n,m=map(int,input().split())
l=list(map(int,input().split()))
s=0
for i in l:
s+=i
s=abs(s)
if(s%m==0):
print(s//m)
else :
print((s//m)+1) | Codeforces Round 235 (Div. 2) | CF | 2,014 | 1 | 256 | Vanya and Cards | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time pla... | The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. | Print a single number — the answer to the problem. | null | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | [{"input": "3 2\n-1 1 2", "output": "1"}, {"input": "2 3\n-2 -2", "output": "2"}] | 800 | ["implementation", "math"] | 47 | [{"input": "3 2\r\n-1 1 2\r\n", "output": "1\r\n"}, {"input": "2 3\r\n-2 -2\r\n", "output": "2\r\n"}, {"input": "4 4\r\n1 2 3 4\r\n", "output": "3\r\n"}, {"input": "2 2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "15 5\r\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\r\n", "output": "4\r\n"}, {"input": "15 16\r\n-15 -5 -15... | false | stdio | null | true |
498/A | 498 | A | PyPy 3 | TESTS | 32 | 311 | 6,553,600 | 56373152 | import math
import sys,string,bisect
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
def line(l,p):
d=(l[0]*p[0]+l[1]*p[1]+l[2])
if(d>0):
return 1
... | 51 | 61 | 0 | 9249983 | def town():
x1, y1= [int(i) for i in input().split()]
x2, y2= [int(i) for i in input().split()]
n= int(input())
ans= 0
for i in range(n):
a, b, c= [int(k) for k in input().split()]
if (a*x1 + b*y1 + c< 0 and a*x2 + b*y2 + c> 0) or (a*x1 + b*y1 + c> 0 and a*x2 + b*y2 + c< 0):
... | Codeforces Round 284 (Div. 1) | CF | 2,014 | 1 | 256 | Crazy Town | Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the po... | The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — th... | Output the answer to the problem. | null | Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors): | [{"input": "1 1\n-1 -1\n2\n0 1 0\n1 0 0", "output": "2"}, {"input": "1 1\n-1 -1\n3\n1 0 0\n0 1 0\n1 1 -3", "output": "2"}] | 1,700 | ["geometry"] | 51 | [{"input": "1 1\r\n-1 -1\r\n2\r\n0 1 0\r\n1 0 0\r\n", "output": "2\r\n"}, {"input": "1 1\r\n-1 -1\r\n3\r\n1 0 0\r\n0 1 0\r\n1 1 -3\r\n", "output": "2\r\n"}, {"input": "841746 527518\r\n595261 331297\r\n10\r\n-946901 129987 670374\r\n-140388 -684770 309555\r\n-302589 415564 -387435\r\n-565799 -72069 -395358\r\n-523453 -... | false | stdio | null | true |
883/E | 883 | E | PyPy 3 | TESTS | 51 | 202 | 1,126,400 | 40848706 | n = int(input())
s = str(input())
chosenLetters = set(s) - {'*'}
unknownIndexes = [i for i in range(n) if s[i] == '*']
dictSize = int(input())
dictionary = [str(input()) for i in range(dictSize)]
answerSet = set("abcdefghijklmnopqrstuvwxyz") - chosenLetters
for word in dictionary:
possibleLetters = set(word[i] for ... | 50 | 77 | 6,041,600 | 31561707 | n = int(input())
s = input()
a = []
m = int(input())
for i in range(m):
line = input()
st = set()
flag = False # 无效
for i in range(n):
if s[i] == '*':
st.add(line[i])
elif s[i] != line[i]:
flag = True
for i in range(n):
if s[i] in st:
flag ... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
1004/A | 1004 | A | PyPy 3-64 | TESTS | 5 | 46 | 0 | 177426457 | n, d = list(map(int, input().split()))
hotels = list(map(int, input().split())) # inceasing order
distances = set()
for index, coord in enumerate(hotels):
left = coord-d
right = coord+d
if index != n-1:
if abs(hotels[index+1]-left) < d:
left = None
if abs(hotels[index+1]-r... | 45 | 31 | 0 | 163025028 | R=lambda:map(int,input().split())
n,d=R()
a=[*R()]
print(2+sum((y-x>=d*2)+(y-x>d*2)for x,y in zip(a,a[1:]))) | 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 |
691/A | 691 | A | Python 3 | TESTS | 13 | 46 | 0 | 203181171 | n = int(input())
if n == 1:
input()
print("YES")
exit(0)
if input().count('0') - 1:
print("NO")
else:
print("YES") | 83 | 46 | 0 | 154972332 | print('YES' if (input()!='1')==input().count('0') else 'NO') | Educational Codeforces Round 14 | ICPC | 2,016 | 1 | 256 | Fashion in Berland | According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.
You are given a jacket with n buttons. Determine if it is fasten... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket.
The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1. | In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". | null | null | [{"input": "3\n1 0 1", "output": "YES"}, {"input": "3\n1 0 0", "output": "NO"}] | 1,000 | ["implementation"] | 83 | [{"input": "3\r\n1 0 1\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 1 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 1 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 0 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r... | false | stdio | null | true |
301/A | 301 | A | PyPy 3-64 | TESTS | 14 | 92 | 0 | 226238446 | import sys
input=sys.stdin.buffer.readline
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%2==1:
b=[abs(i) for i in a]
return sum(b)
ps,ng,zr=[... | 49 | 92 | 0 | 206380138 | n = int(input())
a = list(map(int, input().split()))
b = 0
for i in a:
if i < 0:
b += 1
c = list(map(abs, a))
if b & 1 and n + 1 & 1:
print(sum(c) - 2 * min(c))
else:
print(sum(c)) | Codeforces Round 182 (Div. 1) | CF | 2,013 | 2 | 256 | Yaroslav and Sequence | Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1.
Yaroslav is now wondering: what maximum sum of array elements c... | The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. | In a single line print the answer to the problem — the maximum sum that Yaroslav can get. | null | In the first sample you do not need to change anything. The sum of elements equals 150.
In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100. | [{"input": "2\n50 50 50", "output": "150"}, {"input": "2\n-1 -100 -1", "output": "100"}] | 1,800 | ["constructive algorithms"] | 49 | [{"input": "2\r\n50 50 50\r\n", "output": "150\r\n"}, {"input": "2\r\n-1 -100 -1\r\n", "output": "100\r\n"}, {"input": "3\r\n-959 -542 -669 -513 160\r\n", "output": "2843\r\n"}, {"input": "4\r\n717 473 344 -51 -548 703 -869\r\n", "output": "3603\r\n"}, {"input": "5\r\n270 -181 957 -509 -6 937 -175 434 -625\r\n", "outpu... | false | stdio | null | true |
883/E | 883 | E | Python 3 | TESTS | 51 | 78 | 5,529,600 | 31618297 | n=int(input())
s=input()
mask=0
unknownPos=[]
for i in range(n):
if s[i] != '*':
mask|=1<<(ord(s[i])-97)
else:
unknownPos.append(i)
m=int(input())
ans = (1<<26)-1
for i in range(m):
words=input()
umask=0
for pos in unknownPos:
umask|=1<<(ord(words[pos])-97)
if umask&mask:... | 95 | 78 | 0 | 31943887 | def f(t):
for i in range(n):
if s[i] != '*' and s[i] != t[i]:
return 0
if s[i] == '*':
if t[i] in fam:
return 0
return 1
n = int(input())
s = input()
fam = set(s)
m = int(input())
a = [input() for i in range(m)]
flag = 0
ans = set()
for t in a:
if f(t... | 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,017 | 3 | 256 | Field of Wonders | Polycarpus takes part in the "Field of Wonders" TV show. The participants of the show have to guess a hidden word as fast as possible. Initially all the letters of the word are hidden.
The game consists of several turns. At each turn the participant tells a letter and the TV show host responds if there is such letter ... | The first line contains one integer n (1 ≤ n ≤ 50) — the length of the hidden word.
The following line describes already revealed letters. It contains the string of length n, which consists of lowercase Latin letters and symbols "*". If there is a letter at some position, then this letter was already revealed. If the ... | Output the single integer — the number of letters Polycarpus can tell so that the TV show host definitely reveals at least one more letter. It is possible that this number is zero. | null | In the first example Polycarpus can tell letters "b" and "c", which assuredly will be revealed.
The second example contains no letters which can be told as it is not clear, which of the letters "v" or "s" is located at the third position of the hidden word.
In the third example Polycarpus exactly knows that the hidde... | [{"input": "4\na**d\n2\nabcd\nacbd", "output": "2"}, {"input": "5\nlo*er\n2\nlover\nloser", "output": "0"}, {"input": "3\na*a\n2\naaa\naba", "output": "1"}] | 1,500 | ["implementation", "strings"] | 95 | [{"input": "4\r\na**d\r\n2\r\nabcd\r\nacbd\r\n", "output": "2\r\n"}, {"input": "5\r\nlo*er\r\n2\r\nlover\r\nloser\r\n", "output": "0\r\n"}, {"input": "3\r\na*a\r\n2\r\naaa\r\naba\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\na\r\n", "output": "1\r\n"}, {"input": "1\r\n*\r\n1\r\nz\r\n", "output": "1\r\n"}, {"input... | false | stdio | null | true |
351/A | 351 | A | Python 3 | TESTS | 4 | 60 | 0 | 140421375 | import math
def main():
n = input()
num_list = input().split(" ")
diff = 0
for i in range(0, len(num_list)):
num_list[i] = float(num_list[i])
if(diff >= 0):
new_num = math.floor(num_list[i])
diff = diff + (new_num - num_list[i])
else:
new_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 |
808/G | 808 | G | Python 3 | TESTS | 55 | 2,885 | 1,024,000 | 27717157 | def look(t, i):
so = s[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return False
so[j] = t[j]
s[i:i + t_len] = so
return True
def rlook(t, i):
so = rs[i:i + t_len]
for j in range(t_len):
if not so[j] in [t[j], '?']:
return F... | 69 | 186 | 25,804,800 | 130296324 | import sys
input = sys.stdin.readline
def z_algorithm(w):
m = len(w)
z = [0] * m
z[0] = m
i, j = 1, 0
while i < m:
while i + j < m and w[j] == w[i + j]:
j += 1
z[i] = j
if not j:
i += 1
continue
l = 1
while l < j and l + z[... | Educational Codeforces Round 21 | ICPC | 2,017 | 3 | 256 | Anthem of Berland | Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | The first line contains string of small Latin letters and question marks s (1 ≤ |s| ≤ 105).
The second line contains string of small Latin letters t (1 ≤ |t| ≤ 105).
Product of lengths of strings |s|·|t| won't exceed 107. | Output the maximum number of occurrences of string t you can achieve by replacing all the question marks in string s with small Latin letters. | null | In the first example the resulting string s is "winlosewinwinlwinwin"
In the second example the resulting string s is "glorytoreorand". The last letter of the string can be arbitrary.
In the third example occurrences of string t are overlapping. String s with maximal number of occurrences of t is "abcabcab". | [{"input": "winlose???winl???w??\nwin", "output": "5"}, {"input": "glo?yto?e??an?\nor", "output": "3"}, {"input": "??c?????\nabcab", "output": "2"}] | 2,300 | ["dp", "strings"] | 69 | [{"input": "winlose???winl???w??\r\nwin\r\n", "output": "5\r\n"}, {"input": "glo?yto?e??an?\r\nor\r\n", "output": "3\r\n"}, {"input": "??c?????\r\nabcab\r\n", "output": "2\r\n"}, {"input": "ddddd\r\nd\r\n", "output": "5\r\n"}, {"input": "ww?ww\r\nw\r\n", "output": "5\r\n"}, {"input": "?????\r\nn\r\n", "output": "5\r\n"... | false | stdio | null | true |
730/H | 730 | H | Python 3 | TESTS | 4 | 61 | 4,915,200 | 23564210 | import sys
n,m = map(int, input().split())
s = [input() for i in range(n)]
d=list(map(lambda x:int(x)-1,input().split()))
ans = list(s[d[0]]);
for i in range(1,m):
if len(s[d[i]]) != len(ans):
print("No")
sys.exit(0)
for o in range(0, max([len(ans), len(s[d[i]])])):
if ans[o] != '?' and... | 74 | 62 | 307,200 | 22197583 | from sys import stdin, stdout
n, m = map(int, stdin.readline().split())
strings = []
for i in range(n):
f = stdin.readline().strip()
strings.append(f)
ans = []
challengers = []
used = set()
for a in list(map(int, stdin.readline().split())):
challengers.append(strings[a - 1])
used.add(a - 1)
challengers... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
269/A | 269 | A | PyPy 3-64 | TESTS | 3 | 92 | 0 | 194568146 | import sys
input = sys.stdin.readline
n = int(input())
c = 0
g = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n):
if i != n-1:
a = g[i+1][0]-g[i][0]
if a > 15:
continue
else:
x = max(0, g[i][1] - 4**a * g[i+1][1])
g[i+1][1] +... | 46 | 810 | 7,987,200 | 163199666 | import sys
input = sys.stdin.readline
test = False
mod1, mod2 = 10 ** 9 + 7, 998244353
inf = 10 ** 18 + 5
lim = 2 * 10 ** 5 + 5
def test_case():
n = int(input())
a = []
for i in range(n):
k, c = map(int, input().split())
a.append((k, c))
a.sort()
req = 0
for k, c in a:... | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
219/A | 219 | A | PyPy 3 | TESTS | 13 | 154 | 0 | 136072786 | t=int(input())
s=input()
dic={}
for i in s:
if i not in dic:
dic[i]=1
else:
dic[i]+=1
for i in dic.values():
if i<t:
print("-1")
break
else:
d=""
for i in dic.keys():
d+=(i*(dic[i]//t))
print(d*t) | 42 | 92 | 0 | 136243124 | n=int(input())
s=sorted(input())
x=s[::n]*n
if sorted(x)==s:
print("".join(x))
else:print(-1) | Codeforces Round 135 (Div. 2) | CF | 2,012 | 2 | 256 | k-String | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, ... | The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s. | Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | null | null | [{"input": "2\naazz", "output": "azaz"}, {"input": "3\nabcabcabz", "output": "-1"}] | 1,000 | ["implementation", "strings"] | 42 | [{"input": "2\r\naazz\r\n", "output": "azaz\r\n"}, {"input": "3\r\nabcabcabz\r\n", "output": "-1\r\n"}, {"input": "1\r\na\r\n", "output": "a\r\n"}, {"input": "2\r\nabba\r\n", "output": "abab\r\n"}, {"input": "2\r\naaab\r\n", "output": "-1\r\n"}, {"input": "7\r\nabacaba\r\n", "output": "-1\r\n"}, {"input": "5\r\naaaaa\r... | false | stdio | null | true |
101/A | 101 | A | Python 3 | TESTS | 10 | 216 | 819,200 | 10545556 | import sys
import math
st = (sys.stdin.readline())
k = int(sys.stdin.readline())
d = dict()
for i in range(len(st) - 1):
if st[i] in d:
d[st[i]] += 1
else:
d[st[i]] = 1
f = sorted(d.items(), key = lambda x: x[1])
v = []
for i in f:
if(k - i[1] > 0):
v.append(i[0])
k -= i[... | 48 | 154 | 0 | 144238519 | I=input
s=I()
C={}
for x in set(s):C[x]=s.count(x)
k=int(I())
t=sorted(set(s),key=lambda x:C[x])
while t and C[t[0]]<=k:k-=C[t[0]];s=s.replace(t[0],'');t=t[1:]
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 |
967/A | 967 | A | PyPy 3 | TESTS | 23 | 124 | 21,504,000 | 37709720 | ok = [True for _ in range(26 * 60)]
n, s = map(int, input().split())
for _ in range(n):
h, m = map(int, input().split())
for t in range(h * 60 + m - s, h * 60 + m + s + 1):
ok[t] = False
for t in range(len(ok)):
if ok[t]:
print("%d %d" % (t // 60, t % 60))
break | 34 | 46 | 0 | 159258678 | y=lambda:map(int,input().split())
n,s=y()
r=0
for f in[0]*n:
h,m=y();t=60*h+m
if t>r+s:break
r=t+s+1
print(r//60,r%60) | Codeforces Round 477 (rated, Div. 2, based on VK Cup 2018 Round 3) | CF | 2,018 | 1 | 256 | Mind the Gap | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$... | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$,... | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | null | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to inser... | [{"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1"}, {"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50"}, {"input": "3 17\n0 30\n1 0\n12 0", "output": "0 0"}] | 1,100 | ["implementation"] | 34 | [{"input": "6 60\r\n0 0\r\n1 20\r\n3 21\r\n5 0\r\n19 30\r\n23 40\r\n", "output": "6 1\r\n"}, {"input": "16 50\r\n0 30\r\n1 20\r\n3 0\r\n4 30\r\n6 10\r\n7 50\r\n9 30\r\n11 10\r\n12 50\r\n14 30\r\n16 10\r\n17 50\r\n19 30\r\n21 10\r\n22 50\r\n23 59\r\n", "output": "24 50\r\n"}, {"input": "3 17\r\n0 30\r\n1 0\r\n12 0\r\n",... | false | stdio | null | true |
101/A | 101 | A | PyPy 3-64 | TESTS | 10 | 124 | 5,734,400 | 218647817 | from collections import defaultdict
import sys
import math
s = input()
n = len(s)
k = int(input())
m = {}
for c in s:
m[c] = m.get(c, 0) + 1
m = dict(sorted(m.items(), key=lambda x: x[1]))
for c, v in m.items():
if v < k:
s = s.replace(c, '')
else:
break
k -= v
print(len(set(s)))
print(s... | 48 | 154 | 3,174,400 | 155240740 | s = input()
n = int(input())
x = len(s)
if x<=n:
print(0,"\n")
else:
dic = {}
for i in s:
dic[i] = dic.get(i,0) + 1
dic = {k: v for k, v in sorted(dic.items(), key=lambda item: item[1])}
c = 0
m = []
for i,j in dic.items():
c+=j
if c>n:
m.append(... | 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 |
63/B | 63 | B | PyPy 3-64 | TESTS | 4 | 122 | 0 | 166893404 | """
Cases:
1 1 1 1
1 1 1 2
1 1 2 3
1 2 3 3
2 3 3 3
3 3 3 3
1 1 1 1
1 1 1 2
1 1 2 3
1 2 3 4
2 3 4 4
3 4 4 4
4 4 4 4
"""
n,k = map(int,input().split())
l = list(map(int,input().split()))
i = 0
while(i>=0):
flag = 1
j = 0
m = []
while(j<n-1):
if(l[j] != l[j+1]):
if(l[j]<k):
... | 37 | 92 | 0 | 177853637 | #t = int(input())
t = 1
for tc in range(1,t+1):
#n = int(input())
n,k = map(int,input().split())
lvls = list(map(int,input().split()))
a = [0]*(k+1)
for i in range(len(lvls)):
a[lvls[i]]+=1
ans = 0
while a[k]!=n:
ans+=1
cur = 0
for i in range(k+1):
... | Codeforces Beta Round 59 (Div. 2) | CF | 2,011 | 2 | 256 | Settlers' Training | In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either inc... | The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai... | Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. | null | In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins. | [{"input": "4 4\n1 2 2 3", "output": "4"}, {"input": "4 3\n1 1 1 1", "output": "5"}] | 1,200 | ["implementation"] | 37 | [{"input": "4 4\r\n1 2 2 3\r\n", "output": "4"}, {"input": "4 3\r\n1 1 1 1\r\n", "output": "5"}, {"input": "3 3\r\n1 2 3\r\n", "output": "2"}, {"input": "1 1\r\n1\r\n", "output": "0"}, {"input": "1 5\r\n1\r\n", "output": "4"}, {"input": "1 5\r\n4\r\n", "output": "1"}, {"input": "2 6\r\n2 5\r\n", "output": "4"}, {"input... | false | stdio | null | true |
995/A | 995 | A | PyPy 3 | PRETESTS | 7 | 187 | 2,355,200 | 39612230 | import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,k=map(int,input().split())
cars=[list(map(int,input().split())) for _ in range(4)]
out=[]
for _ in range(1000):
for i in range(n):
if cars[1][i]==0: continue
if cars[1][i]==cars[0][i]:
out.append([cars[1][i],0,i])
... | 57 | 77 | 7,577,600 | 129459082 | def main():
n, k = map(int, input().split())
a, b, c, d = (list(map(int, input().split())) for _ in 'abcd')
ss, tt, n2, res = [*b, *c[::-1]], [*a, *d[::-1]], n * 2, []
yx = [*[(2, i + 1) for i in range(n)], *[(3, i) for i in range(n, 0, -1)]]
def park():
for i, s, t, (y, x) in zip(range(n2... | Codeforces Round 492 (Div. 1) [Thanks, uDebug!] | CF | 2,018 | 3 | 256 | Tesla | Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be repres... | The first line of the input contains two space-separated integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 50$$$, $$$1 \le k \le 2n$$$), representing the number of columns and the number of cars, respectively.
The next four lines will contain $$$n$$$ integers each between $$$0$$$ and $$$k$$$ inclusive, representing the ini... | If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $$$20000$$$ car moves, then print $$$m$$$, the number of moves, on the first line. On the following $$$m$$$ lines, print the moves (one move per line) in the format $$$i$$$ $$$r$$$ $$$c$$$, which corresponds to Allen movin... | null | In the first sample test case, all cars are in front of their spots except car $$$5$$$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $$$20000$$$ will be accepted.
In the second sample test case, there is only one column, a... | [{"input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3", "output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2"}, {"input": "1 2\n1\n2\n1\n2", "output": "-1"}, {"input": "1 2\n1\n1\n2\n2", "output": "2\n1 1 1\n2 4 1"}] | 2,100 | ["constructive algorithms", "implementation"] | 57 | [{"input": "4 5\r\n1 2 0 4\r\n1 2 0 4\r\n5 0 0 3\r\n0 5 0 3\r\n", "output": "6\r\n1 1 1\r\n2 1 2\r\n4 1 4\r\n3 4 4\r\n5 3 2\r\n5 4 2\r\n"}, {"input": "1 2\r\n1\r\n2\r\n1\r\n2\r\n", "output": "-1\r\n"}, {"input": "1 2\r\n1\r\n1\r\n2\r\n2\r\n", "output": "2\r\n1 1 1\r\n2 4 1\r\n"}, {"input": "2 2\r\n1 0\r\n0 2\r\n0 1\r\n... | 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())
grid = []
for _ in range(4):
grid.append(list(map(int, f.readline().split())))
initial = {}
target = {}
for row_idx in [1, 2]:
fo... | true |
592/D | 592 | D | Python 3 | TESTS | 3 | 1,091 | 30,720,000 | 14075150 | def tolist(graph):
res = [[] for i in range(n + 1)]
for l in graph:
res[l[0]].append(l[1])
res[l[1]].append(l[0])
return res
# ������� ��� rebuild
# ������� ��� ����� �� ������ ����� - �� �������
def dfs(s):
global graph
global regraph
global checked
good = False
... | 89 | 1,808 | 33,280,000 | 98656360 | from collections import deque
from sys import stdin
from sys import exit
#parsea una línea
def parser():
return map(int, stdin.readline().split())
#Método usado para obtener los vértices por los que debe pasar Super M
def DFS_Discriminiting():
visited=[False for x in range(n)]
visited[numbers_of_attacked_... | Codeforces Round 328 (Div. 2) | CF | 2,015 | 2 | 256 | Super M | Ari the monster is not an ordinary monster. She is the hidden identity of Super M, the Byteforces’ superhero. Byteforces is a country that consists of n cities, connected by n - 1 bidirectional roads. Every road connects exactly two distinct cities, and the whole road system is designed in a way that one is able to go ... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 123456) - the number of cities in Byteforces, and the number of cities being attacked respectively.
Then follow n - 1 lines, describing the road system. Each line contains two city numbers ui and vi (1 ≤ ui, vi ≤ n) - the ends of the road i.
The l... | First print the number of the city Super M should teleport to. If there are many possible optimal answers, print the one with the lowest city number.
Then print the minimum possible time needed to scare all humans in cities being attacked, measured in Krons.
Note that the correct answer is always unique. | null | In the first sample, there are two possibilities to finish the Super M's job in 3 krons. They are:
$$2 \rightarrow 1 \rightarrow 3 \rightarrow 7$$ and $$7 \rightarrow 3 \rightarrow 1 \rightarrow 2$$.
However, you should choose the first one as it starts in the city with the lower number. | [{"input": "7 2\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n2 7", "output": "2\n3"}, {"input": "6 4\n1 2\n2 3\n2 4\n4 5\n4 6\n2 4 5 6", "output": "2\n4"}] | 2,200 | ["dfs and similar", "dp", "graphs", "trees"] | 89 | [{"input": "7 2\r\n1 2\r\n1 3\r\n1 4\r\n3 5\r\n3 6\r\n3 7\r\n2 7\r\n", "output": "2\r\n3\r\n"}, {"input": "6 4\r\n1 2\r\n2 3\r\n2 4\r\n4 5\r\n4 6\r\n2 4 5 6\r\n", "output": "2\r\n4\r\n"}, {"input": "2 1\r\n2 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "1 1\r\n1\r\n", "output": "1\r\n0\r\n"}, {"input": "10 2\r\n6 9\... | false | stdio | null | true |
257/C | 257 | C | PyPy 3 | TESTS | 20 | 592 | 9,932,800 | 51366900 | import sys
def input():
return sys.stdin.readline().strip()
def print(*x, sep=' ', end='\n'):
return sys.stdout.write(sep.join(map(str, x)) + end)
def read():
return sys.stdin.read()
def main():
from math import atan2, degrees
q1 = []
q2 = []
q3 = []
q4 = []
n = int(input())
... | 56 | 218 | 9,216,000 | 165938408 | import sys
input = sys.stdin.readline
from math import atan2
from math import pi
n = int(input())
pos = []
for _ in range(n):
x, y = map(int, input().split())
pos.append(atan2(x, y))
if n == 1:
print(0)
else:
pos.sort()
best = pos[-1] - pos[0]
for i in range(n - 1):
best = min(best, 2*p... | Codeforces Round 159 (Div. 2) | CF | 2,013 | 2 | 256 | View Angle | Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this a... | The first line contains a single integer n (1 ≤ n ≤ 105) — the number of mannequins.
Next n lines contain two space-separated integers each: xi, yi (|xi|, |yi| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins ... | Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10 - 6. | null | Solution for the first sample test is shown below:
Solution for the second sample test is shown below:
Solution for the third sample test is shown below:
Solution for the fourth sample test is shown below: | [{"input": "2\n2 0\n0 2", "output": "90.0000000000"}, {"input": "3\n2 0\n0 2\n-2 2", "output": "135.0000000000"}, {"input": "4\n2 0\n0 2\n-2 0\n0 -2", "output": "270.0000000000"}, {"input": "2\n2 1\n1 2", "output": "36.8698976458"}] | 1,800 | ["brute force", "geometry", "math"] | 56 | [{"input": "2\r\n2 0\r\n0 2\r\n", "output": "90.0000000000\r\n"}, {"input": "3\r\n2 0\r\n0 2\r\n-2 2\r\n", "output": "135.0000000000\r\n"}, {"input": "4\r\n2 0\r\n0 2\r\n-2 0\r\n0 -2\r\n", "output": "270.0000000000\r\n"}, {"input": "2\r\n2 1\r\n1 2\r\n", "output": "36.8698976458\r\n"}, {"input": "1\r\n1 1\r\n", "output... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
sub_path = sys.argv[3]
# Read correct output
try:
with open(output_path, 'r') as f:
correct_lines = f.readlines()
if len(correct_lines) != 1:
print(0)
return
... | true |
465/B | 465 | B | PyPy 3 | TESTS | 8 | 139 | 0 | 73292266 | n=int(input())
v = [int(s) for s in input().split()]
resultado=0
cont=0
g=1
contadora=0;
inicio=0
fim=0
cont2=0
if(1 in v):
for x in range(n):
if(v[x]==1) and (cont2==0):
inicio=x
cont2=cont2+1
elif(v[x]==1) and (cont2!=0):fim=x
contado... | 44 | 46 | 0 | 149791659 | I=lambda: map(int,input().split())
n=int(input())
a=list(I())
s=int(a[0]==1)*2
for i in range(1,n):
if a[i]==1 and a[i-1]==1:
s=s+1
elif a[i]==1:
s=s+2
print((s-1)*int(s>0)) | Codeforces Round 265 (Div. 2) | CF | 2,014 | 1 | 256 | Inbox (100500) | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows... | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox.
The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | null | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already... | [{"input": "5\n0 1 0 1 0", "output": "3"}, {"input": "5\n1 1 0 0 1", "output": "4"}, {"input": "2\n0 0", "output": "0"}] | 1,000 | ["implementation"] | 44 | [{"input": "5\r\n0 1 0 1 0\r\n", "output": "3\r\n"}, {"input": "5\r\n1 1 0 0 1\r\n", "output": "4\r\n"}, {"input": "2\r\n0 0\r\n", "output": "0\r\n"}, {"input": "9\r\n1 0 1 0 1 0 1 0 1\r\n", "output": "9\r\n"}, {"input": "5\r\n1 1 1 1 1\r\n", "output": "5\r\n"}, {"input": "14\r\n0 0 1 1 1 0 1 1 1 0 1 1 1 0\r\n", "outpu... | false | stdio | null | true |
730/H | 730 | H | PyPy 3-64 | TESTS | 4 | 46 | 0 | 167175679 | x,_ = map(int,input().split())
ans = ""
l = []
a = []
for _ in range(x): l.append(input())
for e in map(int,input().split()): a.append(l[e-1])
s = sorted(a)
if len(s[0]) != len(s[-1]):
print("No")
quit()
a = [e for e in zip(*a)]
for e in a:
s = sorted(e)
if s[0] == s[-1]:
ans+=s[0]
else:
... | 74 | 62 | 307,200 | 108535215 | n, m = map(int, input().split())
f = [input() for _ in range(n)]
d = set(map(int, input().split()))
c = {}
l = 0
for x in d:
l = len(f[x - 1])
c[l] = 1
if len(c) > 1:
print('No')
else:
t = ['?'] * l
for i in range(l):
c = {}
ch = ''
for x in d:
ch = f[x - 1][i]
c[ch] = 1
if 1 == le... | 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) | ICPC | 2,016 | 2 | 512 | Delete Them | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the patte... | The first line of the input contains two integers n and m (1 ≤ m ≤ n ≤ 100) — the total number of files and the number of files to be deleted.
The following n lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The len... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | null | null | [{"input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?"}, {"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?"}, {"input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No"}, {"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???"}] | 1,300 | ["constructive algorithms", "implementation"] | 74 | [{"input": "3 2\r\nab\r\nac\r\ncd\r\n1 2\r\n", "output": "Yes\r\na?\r\n"}, {"input": "5 3\r\ntest\r\ntezt\r\ntest.\r\n.est\r\ntes.\r\n1 4 5\r\n", "output": "Yes\r\n?es?\r\n"}, {"input": "4 4\r\na\r\nb\r\nc\r\ndd\r\n1 2 3 4\r\n", "output": "No\r\n"}, {"input": "6 3\r\n.svn\r\n.git\r\n....\r\n...\r\n..\r\n.\r\n1 2 3\r\n"... | false | stdio | null | true |
269/A | 269 | A | Python 3 | TESTS | 10 | 124 | 0 | 111787761 | import math
I=lambda:map(int,input().split())
n=int(input())
r,t=I()
for i in range(n-1):
w,e=I()
if r-w<math.log(e/t,2):r,t=w,e
r+=t==1
while t>1:t/=4;r+=1
print(r) | 46 | 842 | 0 | 78797690 | import math
t=int(input())
ans=-1
maxi=-1
for i in range(t):
k,a=map(int,input().split())
h=k+math.ceil(math.log(a,4))
ans=max(ans,h)
maxi=max(maxi,k)
print(max(ans,maxi+1)) | Codeforces Round 165 (Div. 1) | CF | 2,013 | 2 | 256 | Magical Boxes | Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes.
From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a... | The first line of input contains an integer n (1 ≤ n ≤ 105), the number of different sizes of boxes Emuskald has. Each of following n lines contains two integers ki and ai (0 ≤ ki ≤ 109, 1 ≤ ai ≤ 109), which means that Emuskald has ai boxes with side length 2ki. It is guaranteed that all of ki are distinct. | Output a single integer p, such that the smallest magical box that can contain all of Emuskald’s boxes has side length 2p. | null | Picture explanation. If we have 3 boxes with side length 2 and 5 boxes with side length 1, then we can put all these boxes inside a box with side length 4, for example, as shown in the picture.
In the second test case, we can put all four small boxes into a box with side length 2. | [{"input": "2\n0 3\n1 5", "output": "3"}, {"input": "1\n0 4", "output": "1"}, {"input": "2\n1 10\n2 2", "output": "3"}] | 1,600 | ["greedy", "math"] | 46 | [{"input": "2\r\n0 3\r\n1 5\r\n", "output": "3\r\n"}, {"input": "1\r\n0 4\r\n", "output": "1\r\n"}, {"input": "2\r\n1 10\r\n2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n0 1\r\n", "output": "1\r\n"}, {"input": "1\r\n1000000000 1000000000\r\n", "output": "1000000015\r\n"}, {"input": "1\r\n0 16\r\n", "output": "2\r\n"}, ... | false | stdio | null | true |
351/A | 351 | A | Python 3 | TESTS | 20 | 124 | 5,632,000 | 34803595 | n = int(input())
l = list(map(float, input().split()))
l = sorted([x - int(x) for x in l])
su = sum(l)
print("%.3f" % abs(round(su) - su)) | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.