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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
750/B | 750 | B | PyPy 3-64 | TESTS | 0 | 30 | 0 | 222621675 | def is_valid_journey(n, instructions):
current_position = 0 # Start at the North Pole
for i in range(n):
t, dir_i = instructions[i]
# Update the current position based on the direction
if dir_i == "North":
current_position += t
elif dir_i == "South":
cu... | 140 | 62 | 4,710,400 | 23432135 | q=int(input())
s=20000
z=['North', 'South']
x=['West', 'East']
b=True
for j in range(0,q):
a=list(input().split())
if b:
a[0]=int(a[0])
if ((s==0)|(s==20000))&(a[1] in x):
b=False
elif (s==20000)&(a[1]=='North'):
b=False
elif (s==0)&(a[1]=='South'):
... | Good Bye 2016 | CF | 2,016 | 2 | 256 | New Year and North Pole | In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the N... | The first line of the input contains a single integer n (1 ≤ n ≤ 50).
The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the... | Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes. | null | Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. | [{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input... | 1,300 | ["geometry", "implementation"] | 140 | [{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 Sout... | false | stdio | null | true |
818/E | 818 | E | PyPy 3 | TESTS | 2 | 171 | 409,600 | 56769782 | import math
from math import gcd
# A function to print all prime factors of
# a given number n
def primeFactors(n,seti):
# Print the number of two's that divide n
while n % 2 == 0:
seti.append(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for ... | 135 | 373 | 31,744,000 | 127711452 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
ans.append... | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
797/B | 797 | B | Python 3 | TESTS | 16 | 61 | 0 | 117353977 | # cook your dish here
n=int(input())
ar=list(map(int,input().split()))
se=0
so=0
minop=10000
maxon=-10000
cnt=0
for i in range(n):
if(ar[i]%2==0 and ar[i]>0):
se+=ar[i]
elif(ar[i]%2 and ar[i]>0):
so+=ar[i]
minop=min(minop,ar[i])
cnt+=1
elif(ar[i]%2 and ar[i]<0):
max... | 126 | 93 | 7,270,400 | 132392463 | n = int(input())
sum_all_pos = 0
numbers = list(map(int, input().split()))
for num in numbers:
if num > 0:
# Directly return all positive numbers sum if odd
sum_all_pos += num
def isOdd(val):
return val % 2
if isOdd(sum_all_pos):
print(sum_all_pos)
else:
# even - odd = odd
# Remo... | Educational Codeforces Round 19 | ICPC | 2,017 | 1 | 256 | Odd sum | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | The first line contains integer number n (1 ≤ n ≤ 105).
The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | null | In the first example sum of the second and the fourth elements is 3. | [{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}] | 1,400 | ["dp", "greedy", "implementation"] | 126 | [{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {... | false | stdio | null | true |
797/B | 797 | B | PyPy 3 | TESTS | 16 | 92 | 0 | 153709682 | n = int(input())
a = [int(x) for x in input().split()]
odd = []
even = 0
m = -10**8
for x in a:
if x % 2 == 0 and x > 0:
even += x
if x % 2 == 1 and x > 0:
odd.append(x)
if x % 2 == 1 and x > m:
m = x
if len(odd) > 0:
if len(odd) % 2 == 1:
print(sum(odd) + even)
else:... | 126 | 93 | 13,107,200 | 204420316 | n = int(input())
a = list(map(int, input().split()))
count_nech = 0
prev_nech = None
ans = 0
a.sort(reverse=True)
for i in a:
if i > 0:
if i % 2 == 0:
ans += i
else:
if count_nech == 0:
ans += i
elif count_nech % 2 == 0:
ans += prev... | Educational Codeforces Round 19 | ICPC | 2,017 | 1 | 256 | Odd sum | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | The first line contains integer number n (1 ≤ n ≤ 105).
The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | null | In the first example sum of the second and the fourth elements is 3. | [{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}] | 1,400 | ["dp", "greedy", "implementation"] | 126 | [{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {... | false | stdio | null | true |
797/B | 797 | B | PyPy 3 | TESTS | 16 | 93 | 0 | 117496190 | from sys import stdin
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
number_odd = 0
biggest_odd = float("-inf")
smallest_odd = float("inf")
for i in a:
if i % 2 == 0:
if i > 0:
ans += i
else:
if i > 0:
number_odd += 1
sm... | 126 | 93 | 13,312,000 | 219027901 | n = int(input())
a = [int(_) for _ in input().split()]
c = []
b = []
ans = 0
for elem in a:
if elem>=0:
ans+=elem
if elem%2!=0:
if elem>0:
c.append(elem)
else:
b.append(elem)
if len(c)%2!=0:
print(ans)
else:
if len(b)==0:
print(ans-min(c))
elif... | Educational Codeforces Round 19 | ICPC | 2,017 | 1 | 256 | Odd sum | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | The first line contains integer number n (1 ≤ n ≤ 105).
The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | null | In the first example sum of the second and the fourth elements is 3. | [{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}] | 1,400 | ["dp", "greedy", "implementation"] | 126 | [{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {... | false | stdio | null | true |
797/B | 797 | B | Python 3 | TESTS | 16 | 46 | 0 | 197491325 | n=int(input())
l=list(map(int,input().split()))
ev=[]
od=[]
s=0
so=0
mmo=-10000000000
mino=123456789
for i in l:
if i%2==1:
if i>0:
so+=i;
mino=min(mino,i);
else:
mmo=max(mmo,i);
else:
if i>0:
s+=i
if so>0:
print(max(so-(mino*(so%2==0)),mmo)+s)
else:
print(mmo+s) | 126 | 93 | 13,516,800 | 167714511 | n=int(input())
a=list(map(int,input().split()))
sp=0
mx=1<<33
for i in a:
if i>0:sp+=i
if i&1:
mx=min(mx,abs(i))
if not sp&1:
sp-=mx
print(sp) | Educational Codeforces Round 19 | ICPC | 2,017 | 1 | 256 | Odd sum | You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequence by deletin... | The first line contains integer number n (1 ≤ n ≤ 105).
The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | null | In the first example sum of the second and the fourth elements is 3. | [{"input": "4\n-2 2 -3 1", "output": "3"}, {"input": "3\n2 -5 -3", "output": "-1"}] | 1,400 | ["dp", "greedy", "implementation"] | 126 | [{"input": "4\r\n-2 2 -3 1\r\n", "output": "3\r\n"}, {"input": "3\r\n2 -5 -3\r\n", "output": "-1\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n-1\r\n", "output": "-1\r\n"}, {"input": "15\r\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046\r\n", "output": "53507\r\n"}, {... | false | stdio | null | true |
818/E | 818 | E | Python 3 | TESTS | 1 | 46 | 4,608,000 | 28145165 | read = lambda: map(int, input().split())
n, k = read()
a = list(read())
p = 1
ans = 0
r = 0
for i in range(n):
r = max(r, i)
if r == i: p = a[i]
while r + 1 < n and p % k:
p *= a[r + 1]
r += 1
if p % k == 0: ans += n - r
print(ans) | 135 | 1,809 | 14,950,400 | 90465157 | def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
n,k = [int(x) for x in input().split()]
a = [gcd(int(x),k) for x in input().split()]
if k == 1:
print(((n+1)*(n+2))//2-n-1)
else:
s = 0
e = 0
total = ((n+1)*(n+2))//2-1-n
#print(total)
#extra = {}
c = 1
while e < n:
flag = False
wh... | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
750/B | 750 | B | Python 3 | TESTS | 8 | 31 | 0 | 223789315 | flag=True
north=0
south=0
for _ in range(int(input())):
t,s=map(str,input().split())
if south-north==20000:
if s!="North":
flag=False
if north-south==0 or (north==0 and south==0):
if s!="South":
flag=False
if s=="North":
north+=int(t)
if s=="South":
... | 140 | 62 | 4,710,400 | 23433068 | tmp=0
flag=True
for i in range(int(input())):
a,b=input().split()
if b=="South":
tmp+=int(a)
if tmp>20000:
flag=False
elif b=="North":
tmp-=int(a)
if tmp<0:
flag=False
elif tmp==0 or tmp == 20000:
flag=False
if flag ... | Good Bye 2016 | CF | 2,016 | 2 | 256 | New Year and North Pole | In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the N... | The first line of the input contains a single integer n (1 ≤ n ≤ 50).
The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the... | Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes. | null | Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. | [{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input... | 1,300 | ["geometry", "implementation"] | 140 | [{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 Sout... | false | stdio | null | true |
858/E | 858 | E | Python 3 | TESTS | 2 | 77 | 819,200 | 31102053 | import random
def genTemp():
sl = ""
firstTime = True
while firstTime or sl in pre or sl in post:
sl = ""
firstTime = False
for i in range(6):
sl += chr(random.randint(ord("a"), ord("z")))
return sl
n = int(input())
e = 0
pre = set()
post = set()
for i in range(n):... | 165 | 295 | 27,136,000 | 230751905 | n = int(input())
t = [1] + [0] * n
b, a = d = [], []
h, s = [], []
for i in range(n):
f, k = input().split()
d[int(k)].append(f)
m = len(a)
for i in a:
if i.isdigit() and i[0] != '0':
j = int(i)
if 0 < j <= m:
t[j] = 1
elif m < j <= n:
t[j] = -1
else... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 2 | 256 | Tests Renumeration | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.
n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. ... | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | null | null | [{"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"}, {"input": "2\n1 0\n2 1", "output": "3\nmove 1 3\nmove 2 1\nmove 3 2"}, {"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0", "output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3"}] | 2,200 | ["greedy", "implementation"] | 165 | [{"input": "5\r\n01 0\r\n2 1\r\n2extra 0\r\n3 1\r\n99 0\r\n", "output": "4\r\nmove 3 1\r\nmove 01 5\r\nmove 2extra 4\r\nmove 99 3\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 dytuig\r\nmove 2 1\r\nmove dytuig 2\r\n"}, {"input": "5\r\n1 0\r\n11 1\r\n111 0\r\n1111 1\r\n11111 0\r\n", "output": "5\r\nmove... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
files = []
type1_count = 0
for _ in range(n):
line = f.readline().strip()
name, typ = line.s... | true |
818/E | 818 | E | PyPy 3 | TESTS | 2 | 155 | 1,740,800 | 93169752 | import sys
def get_primes(n: int):
from itertools import chain
from array import array
primes = {2, 3}
is_prime = (array('b', (0, 0, 1, 1, 0, 1, 0)) +
array('b', (1, 0, 0, 0, 1, 0))*((n-1)//6))
for i in chain.from_iterable((range(5, n+1, 6), range(7, n+1, 6))):
if is_prime... | 135 | 77 | 13,414,400 | 170114604 | R,G=lambda:map(int,input().split()),range
n,k=R();a=[0]+[*R()];z,l,p=0,1,1
for r in G(1,n+1):
p=p*a[r]%k
if p==0:
p=1;i=r
while p*a[i]%k:p=p*a[i]%k;i-=1
z+=(n-r+1)*(i-l+1);l=i+1
print(z) | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
818/E | 818 | E | PyPy 3 | TESTS | 2 | 124 | 0 | 66638926 | n,k=map(int,input().split())
l=list(map(int,input().split()))
pf=[]
needed=[]
i=2
while (i*i)<=k:
if k%i==0:
pf.append(i)
c=0
while k%i==0:
k//=i
c+=1
needed.append(c)
i+=1
if k>1:
pf.append(k)
needed.append(1)
pfl=len(pf)
cnt=[[0]*n for i in range(pfl)]
for i in range(n):
for j in range(len(pf)):
... | 135 | 373 | 31,744,000 | 127711452 | import bisect
import sys
input = sys.stdin.readline
def prime_factorize(n):
ans = []
for i in range(2, int(n ** (1 / 2)) + 1):
while True:
if n % i:
break
ans.append(i)
n //= i
if n == 1:
break
if not n == 1:
ans.append... | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
818/E | 818 | E | PyPy 3-64 | TESTS | 2 | 77 | 0 | 181886867 | def fact(n):
res=n
a=[]
i=2
while i*i<=res:
if res%i==0:
cnt=0
while res%i==0:
cnt+=1
res//=i
a.append((i,cnt))
i+=1
if res!=1:
a.append((res,1))
return a
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==1:
print((n+1)*(n+2)//2)
exit()
d... | 135 | 1,809 | 14,950,400 | 90465157 | def gcd(a,b):
if a == 0:
return b
return gcd(b%a,a)
n,k = [int(x) for x in input().split()]
a = [gcd(int(x),k) for x in input().split()]
if k == 1:
print(((n+1)*(n+2))//2-n-1)
else:
s = 0
e = 0
total = ((n+1)*(n+2))//2-1-n
#print(total)
#extra = {}
c = 1
while e < n:
flag = False
wh... | Educational Codeforces Round 24 | ICPC | 2,017 | 2 | 256 | Card Game Again | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number ai is written on the i-th card in the deck.
After receiving th... | The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers written on the cards. | Print the number of ways to choose x and y so the resulting deck is valid. | null | In the first example the possible values of x and y are:
1. x = 0, y = 0;
2. x = 1, y = 0;
3. x = 2, y = 0;
4. x = 0, y = 1. | [{"input": "3 4\n6 2 8", "output": "4"}, {"input": "3 6\n9 1 14", "output": "1"}] | 1,900 | ["binary search", "data structures", "number theory", "two pointers"] | 135 | [{"input": "3 4\r\n6 2 8\r\n", "output": "4\r\n"}, {"input": "3 6\r\n9 1 14\r\n", "output": "1\r\n"}, {"input": "5 1\r\n1 3 1 3 1\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 5 5 5 5\r\n", "output": "15\r\n"}, {"input": "5 1\r\n5 4 4 4 4\r\n", "output": "15\r\n"}, {"input": "100 1\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1... | false | stdio | null | true |
858/E | 858 | E | Python 3 | TESTS | 0 | 46 | 204,800 | 30954475 | n = int(input())
s = {}
for i in range(n):
name, test = tuple(input().split())
s[name] = test
ex = []
us = []
kol_1 = list(s.values()).count('1')
for name, test in s.items():
if test == '1':
if name.isdigit() and name[0] != '0' and int(name) in range(1, kol_1 + 1):
ex.append(name)
... | 165 | 295 | 27,136,000 | 230751905 | n = int(input())
t = [1] + [0] * n
b, a = d = [], []
h, s = [], []
for i in range(n):
f, k = input().split()
d[int(k)].append(f)
m = len(a)
for i in a:
if i.isdigit() and i[0] != '0':
j = int(i)
if 0 < j <= m:
t[j] = 1
elif m < j <= n:
t[j] = -1
else... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 2 | 256 | Tests Renumeration | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.
n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. ... | In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6. | null | null | [{"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0", "output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3"}, {"input": "2\n1 0\n2 1", "output": "3\nmove 1 3\nmove 2 1\nmove 3 2"}, {"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0", "output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3"}] | 2,200 | ["greedy", "implementation"] | 165 | [{"input": "5\r\n01 0\r\n2 1\r\n2extra 0\r\n3 1\r\n99 0\r\n", "output": "4\r\nmove 3 1\r\nmove 01 5\r\nmove 2extra 4\r\nmove 99 3\r\n"}, {"input": "2\r\n1 0\r\n2 1\r\n", "output": "3\r\nmove 1 dytuig\r\nmove 2 1\r\nmove dytuig 2\r\n"}, {"input": "5\r\n1 0\r\n11 1\r\n111 0\r\n1111 1\r\n11111 0\r\n", "output": "5\r\nmove... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path) as f:
n = int(f.readline())
files = []
type1_count = 0
for _ in range(n):
line = f.readline().strip()
name, typ = line.s... | true |
789/B | 789 | B | PyPy 3 | TESTS | 14 | 218 | 10,752,000 | 92449543 | import math
b1,q,l,m=list(map(int,input().split()))
a=list(map(int,input().split()))
if abs(b1)>l:
print(0)
elif b1==0:
if b1 in a:
print(0)
else:
print('inf')
elif q==1:
if b1 in a:
print(0)
else:
print('inf')
elif q==-1:
if b1 in a and -b1 in a:
print(0)... | 116 | 93 | 12,902,400 | 25933157 | b, q, l, m = list(map(int, input().split()))
a = set(list(map(int, input().split())))
ans = 0
boo = False
i = 0
while (i < 34) and (abs(b) <= l):
if (b not in a):
ans += 1
if i > 31:
boo = True
b *= q
i += 1
if boo:
print('inf')
else:
print(ans) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
750/B | 750 | B | PyPy 3-64 | TESTS | 28 | 61 | 0 | 207347320 | def main():
n = int(input().strip())
north = 0
verdict = None
for _ in range(n):
dir = input().strip().split()
s = int(dir[0])
dir = dir[1]
if verdict is not None:
continue
if north % 40000 == 0 and dir != "South":
verdict = "NO"
... | 140 | 62 | 4,710,400 | 23434950 | """
Author : Arif Ahmad
Date :
Algo :
Difficulty :
"""
def main():
n = int(input())
ans = "YES"
pos = 0
for i in range(n):
t, direction = input().split()
t = int(t)
if (pos==0 and direction!='South') or (pos==20000 and direction!='North'):
ans = "NO"
break
if direction == 'East' or dir... | Good Bye 2016 | CF | 2,016 | 2 | 256 | New Year and North Pole | In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the N... | The first line of the input contains a single integer n (1 ≤ n ≤ 50).
The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, $${ dir } _ { i } \in \{ \mathrm { N o r t h, ~ S o u t h, ~ W e s t, ~ E a s t } \}$$) — the length and the direction of the i-th part of the journey, according to the... | Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes. | null | Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. | [{"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "output": "YES"}, {"input": "2\n15000 South\n4000 East", "output": "NO"}, {"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "output": "YES"}, {"input": "3\n20000 South\n10 East\n20000 North", "output": "NO"}, {"input... | 1,300 | ["geometry", "implementation"] | 140 | [{"input": "5\r\n7500 South\r\n10000 East\r\n3500 North\r\n4444 West\r\n4000 North\r\n", "output": "YES\r\n"}, {"input": "2\r\n15000 South\r\n4000 East\r\n", "output": "NO\r\n"}, {"input": "5\r\n20000 South\r\n1000 North\r\n1000000 West\r\n9000 North\r\n10000 North\r\n", "output": "YES\r\n"}, {"input": "3\r\n20000 Sout... | false | stdio | null | true |
808/D | 808 | D | PyPy 3-64 | TESTS | 44 | 155 | 27,136,000 | 168410800 | from collections import defaultdict
from bisect import bisect_left
def values():return tuple(map(int,input().split()))
def inlst():return list(map(int,input().split()))
def inp():return int(input())
def solve(n,l,s):
st = set()
t=s//2
d=defaultdict(int)
d2 = defaul... | 115 | 108 | 18,022,400 | 166889423 | n = int(input())
arr = list(map(int, input().split()))
def solve(n, a):
s = sum(a)
if n == 1 or s & 1:
print('NO')
return
half = s // 2
def judge(a):
pre, st = 0, {0}
for num in a:
st.add(num)
pre += num
if pre - half in st: return True... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
671/A | 671 | A | PyPy 3-64 | TESTS | 51 | 966 | 50,278,400 | 144871073 | import sys
input = sys.stdin.buffer.readline
def dist(r1, r2, s1, s2):
distance = (r1-s1)**2+(r2-s2)**2
return distance**0.5
def process(ax, ay, bx, by, tx, ty, A):
n = len(A)
answer = 0
maybe1 = []
maybe2 = []
for i in range(n):
x, y = A[i]
answer+=2*dist(tx, ty, x, y)
... | 148 | 608 | 36,352,000 | 225170582 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
alph = 'abcdefghijklmnopqrstuvwxyz'
#pow(x,mod-2,mod)
def cal(a,b):
return (ab... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
997/A | 997 | A | Python 3 | TESTS | 10 | 140 | 1,024,000 | 112276250 | n,x,y=map(int,input().split())
s=input()
c=0
ans1,ans2=0,0
for i in range(n-1):
if s[i]=='0' and s[i+1]=='1':
c+=1
ans1=x*c+y
ans2=c*y
if s[n-1]=='0':
ans2+=y
print(min(ans1,ans2)) | 115 | 62 | 2,457,600 | 205180262 | '''
https://codeforces.com/problemset/problem/997/A
输入 n(1≤n≤3e5) x(0≤x≤1e9) y(0≤y≤1e9) 和长为 n 的 01 字符串 s。
你可以执行任意次操作,每次选择其中一种操作执行。
1. 花费 x,reverse s 的一个子串,例如 1110 -> 0111。
2. 花费 y,flip s 的一个子串,例如 1110 -> 0001。
目标:使 s 中只有 1。
输出最少花费。
输入
5 1 10
01000
输出
11
输入
5 10 1
01000
输出
2
输入
7 2 3
1111111
输出
0
'''
def _n():
... | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
671/A | 671 | A | Python 3 | TESTS | 48 | 763 | 5,529,600 | 26649746 | from math import sqrt
ax, ay, bx, by, tx, ty = map(int, input().split())
n = int(input())
d = 0
mina = (2*10**9,0,0)
mina2 = (2*10**9,0,0)
minb = (2*10**9,0,0)
minb2 = (2*10**9,0,0)
for _ in range(n):
x, y = map(int, input().split())
dt = sqrt((x-tx)**2+(y-ty)**2)
d += 2*dt
da = sqrt((ax-x)**2+(ay-y)**2)
dat... | 148 | 685 | 12,902,400 | 179410672 | ax,ay,bx,by,tx,ty=map(int,input().split())
n=int(input())
a,b=[],[]
res=0
for i in range(n):
x, y=map(int, input().split())
lt=((tx-x)*(tx-x)+(ty-y)*(ty-y))**0.5
la=((ax-x)*(ax-x)+(ay-y)*(ay-y))**0.5
lb=((bx-x)*(bx-x)+(by-y)*(by-y))**0.5
a+=[(la-lt,i)]
b+=[(lb-lt,i)]
res+=lt
a.sort();b.sort(... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
789/B | 789 | B | Python 3 | TESTS | 13 | 77 | 15,564,800 | 28802508 | import sys
def ans(n):
print(n)
sys.exit()
def check(n):
global w
return ((abs(n) <= l) and (n not in w))
b1, q, l, m = map(int, input().split())
w = set(map(int, input().split()))
inf = 'inf'
#possiblity for answering inf
if b1 == 0:
if (0 not in w):
ans(inf)
else:
ans(0)
... | 116 | 93 | 13,004,800 | 28874811 | b,q,l,m=map(int,input().split())
a=set(list(map(int,input().split())))
c=0
for i in range(100):
if abs(b)>l: break
if b not in a: c+=1
b*=q
if c<32:
print (c)
else:
print('inf') | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
997/A | 997 | A | Python 3 | TESTS | 30 | 233 | 1,433,600 | 84404889 | n,h,m=list(map(int,input().split()))
s = input()
if h<m:
p=0
for i in range(n-1):
if s[i]=='0' and s[i+1]=='1':
p+=1
if s[i]=='1' and s[i+1]=='0':
p+=1
if s.count('0')>0:
print((p//2)*h+m)
else:
print((p//2)*h)
else:
k=0
p=0
for i in ra... | 115 | 77 | 1,433,600 | 205174627 | n, x, y = map(int, input().split())
s = '1'+input().strip()
c = s.count('10')
print(0 if c == 0 else y * c if y <= x else (x * c + y - x)) | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
814/A | 814 | A | Python 3 | TESTS | 19 | 93 | 6,963,200 | 89375436 | n,k=map(int,input().split())
lsta=list(map(int,input().split()))
lstb=list(map(int,input().split()))
lst=[]
for i in lsta:
if(i not in lst):
lst.append(i)
else:
if(i!=0):
print("NO")
exit()
lst=[]
for i in lstb:
if (i not in lst):
lst.append(i)
else:
... | 96 | 46 | 0 | 136176990 | n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
if a.count(0)>=2:
print('YES')
else:
a[a.index(0)]=b[0]
if sorted(a)==a:
print('NO')
else:
print('YES') | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
814/A | 814 | A | Python 3 | TESTS | 19 | 62 | 0 | 27765647 | # x = input().split()
n , k = map(int , input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
hitcresce = 1
if k > 1:
print('Yes')
exit()
x.append(999)
aux = 0
for i in range(1,n):
if x[i-1]!= 0:
aux = x[i-1]
if x[i] != 0 and x[i] < aux :
hitcresce = 0
break
i... | 96 | 46 | 0 | 146234207 | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if k == 1:
i = a.index(0)
a[i] = b[0]
x = sorted(a)
if a == x:
print("NO")
else:
print("YES")
else:
b = sorted(b, reverse=True)
x = 0
for i in range(0, n):
if ... | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
789/B | 789 | B | Python 3 | PRETESTS | 13 | 108 | 15,564,800 | 25903897 | b, q, l, m = map(int, input().split())
A = set(map(int, input().split()))
if b == 0:
print(0 if 0 in A else "inf")
elif q == 0:
if 0 in A:
print(1 if b not in A and abs(b) <= l else 0)
else:
print("inf")
elif q == 1:
print(0 if b in A or abs(b) > l else 'inf')
elif q == -1:
print(0 ... | 116 | 93 | 13,824,000 | 25912881 | import sys
def solve():
b1, q, L, m = map(int, input().split())
a = [int(i) for i in input().split()]
a = set(a)
if b1 == 0:
print(0 if b1 in a else 'inf')
return
if q == 1:
if abs(b1) > L or b1 in a:
print(0)
else:
print('inf')
elif q ... | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
868/C | 868 | C | Python 3 | TESTS | 27 | 452 | 512,000 | 32357058 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
"""
created by shhuan at 2017/10/5 15:00
"""
N, K = map(int, input().split())
problems = collections.defaultdict(set)
for i in range(N):
row = tuple([int(x) for x in input().split()])
k = sum(row)
... | 143 | 109 | 4,812,800 | 187539064 | import sys
readline=sys.stdin.readline
N,K=map(int,readline().split())
cnt=[0]*(1<<K)
lst=[]
for n in range(N):
bit=0
for i,b in enumerate(list(map(int,readline().split()))):
if b:
bit|=1<<i
cnt[bit]+=1
if cnt[bit]<=2:
lst.append(bit)
le=len(lst)
ans="NO"
if 0 in lst:
an... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
828/B | 828 | B | PyPy 3 | TESTS | 92 | 155 | 102,400 | 57581086 | from sys import stdin,stdout
n,m = (int(i) for i in stdin.readline().split())
x1,x2,y1,y2 = 10**6,0,0,0
c = 0
flag = False
for i in range(n):
st = stdin.readline()
if st.count('B') > 0:
c += st.count('B')
if not(flag):
y1 = i
flag = True
if x1 > st.index('B'):
... | 128 | 46 | 0 | 162978311 | n, m = map(int, input().split(' '))
x_min, x_max, y_min, y_max = n, -1, m, -1
B_cnt = 0
for i in range(n):
s = input()
for j in range(m):
if s[j]=='B':
B_cnt += 1
x_max, x_min = max(x_max, i), min(x_min, i)
y_max, y_min = max(y_max, j), min(y_min, j)
num = max((y_max... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
616/A | 616 | A | Python 3 | TESTS | 19 | 109 | 10,137,600 | 86735086 | from sys import stdin,stdout
# from collections import deque,Counter,defaultdict
# from itertools import permutations,combinations,combinations_with_replacement
# from operator import itemgetter
# import heapq
# from functools import reduce
def ii():return int(stdin.readline())
def mi():return map(int,stdin.readline().... | 120 | 46 | 3,584,000 | 176467571 | a,b=input(),input()
m=max(len(a),len(b))
a,b=a.zfill(m),b.zfill(m)
print('>' if a>b else ('<' if a<b else '=')) | Educational Codeforces Round 5 | ICPC | 2,016 | 2 | 256 | Comparing Two Long Integers | You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge... | The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". | null | null | [{"input": "9\n10", "output": "<"}, {"input": "11\n10", "output": ">"}, {"input": "00012345\n12345", "output": "="}, {"input": "0123\n9", "output": ">"}, {"input": "0123\n111", "output": ">"}] | 900 | ["implementation", "strings"] | 120 | [{"input": "9\r\n10\r\n", "output": "<\r\n"}, {"input": "11\r\n10\r\n", "output": ">\r\n"}, {"input": "00012345\r\n12345\r\n", "output": "=\r\n"}, {"input": "0123\r\n9\r\n", "output": ">\r\n"}, {"input": "0123\r\n111\r\n", "output": ">\r\n"}, {"input": "9\r\n9\r\n", "output": "=\r\n"}, {"input": "0\r\n0000\r\n", "outpu... | false | stdio | null | true |
616/A | 616 | A | Python 3 | TESTS | 19 | 46 | 3,174,400 | 154828326 | import sys
input = sys.stdin.readline
a,b=[input().rjust(10**6,'0') for i in range(2)]
print ('>' if a > b else '<' if a<b else '=') | 120 | 46 | 3,993,600 | 201632626 | exec('a, b = '+ 2 * 'input().rjust(10 ** 6, "0"),')
print('<>='[(a == b) + (a >= b)]) | Educational Codeforces Round 5 | ICPC | 2,016 | 2 | 256 | Comparing Two Long Integers | You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge... | The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 106 digits. | Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". | null | null | [{"input": "9\n10", "output": "<"}, {"input": "11\n10", "output": ">"}, {"input": "00012345\n12345", "output": "="}, {"input": "0123\n9", "output": ">"}, {"input": "0123\n111", "output": ">"}] | 900 | ["implementation", "strings"] | 120 | [{"input": "9\r\n10\r\n", "output": "<\r\n"}, {"input": "11\r\n10\r\n", "output": ">\r\n"}, {"input": "00012345\r\n12345\r\n", "output": "=\r\n"}, {"input": "0123\r\n9\r\n", "output": ">\r\n"}, {"input": "0123\r\n111\r\n", "output": ">\r\n"}, {"input": "9\r\n9\r\n", "output": "=\r\n"}, {"input": "0\r\n0000\r\n", "outpu... | false | stdio | null | true |
808/D | 808 | D | PyPy 3 | TESTS | 33 | 389 | 33,382,400 | 77057737 | # |
# _` | __ \ _` | __| _ \ __ \ _` | _` |
# ( | | | ( | ( ( | | | ( | ( |
# \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_|
import sys
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.s... | 115 | 109 | 17,920,000 | 166893879 | '''
https://codeforces.com/problemset/problem/808/D
输入 n(≤1e5) 和长为 n 的数组 a(1≤a[i]≤1e9)。
你可以选择一个 a[i],将其移除并插入到 a 的任意位置。
你能否在执行至多一次上述操作的限制下,将 a 划分成左右两部分,且这两部分的元素和相等?
能则输出 YES,不能则输出 NO。
输入
3
1 3 2
输出 YES
解释 把 3 移到末尾,得到 [1,2,3],sum([1,2]) = sum([3]) = 3
输入
5
1 2 3 4 5
输出 NO
输入
5
2 2 3 4 5
输出 YES
解释 把 4 往左移一位,得到 [2,2,4,3... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 54 | 421 | 9,625,600 | 50763092 | n = int(input())
l = input()
a = []
yes = False
for i in l.split():
a.append(int(i))
x = 0
b = []
ma = []
mb = []
for i in range(len(a)):
x += a[i]
b.append(x)
if not(ma == []):
if ma[-1] < a[i]:
ma.append(a[i])
else:
ma += [ma[-1]]
else:
ma += [a[0]]
if not(mb == []):
if mb[-1] < a[n-i-1]:
... | 115 | 124 | 18,841,600 | 166882089 | import collections
import os
import sys
from collections import Counter
# print(sys.hexversion)
# if os.getenv('LOCALCFTEST'):
# sys.stdin = open('cfinput.txt')
# else:
# input = sys.stdin.readline
if sys.hexversion == 50924784:
sys.stdin = open('cfinput.txt')
else:
input = sys.stdin.readline
MOD = 10 *... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
828/B | 828 | B | PyPy 3 | TESTS | 50 | 156 | 1,843,200 | 69073928 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m=map(int,input().split())
a=[]
for i in range(n):
t=input()
a.append(t)
L=m
R=0
U=n
D=0
for i in range(n):
for j in range(m):
if a[i][j]=='B':
L=min(L,j)
R=max(R,j)
U=min(U,i)
D=max(D,i)
len=D-U+1
wid=R... | 128 | 46 | 0 | 167514035 | n, m = map(int, input().split(' '))
min_j, max_j, min_i, max_i = m, -1, n, -1
count = 0
for i in range(n):
s = input()
for j in range(m):
if s[j]=='B':
count += 1
min_j = min(min_j, j)
max_j = max(max_j, j)
min_i = min(min_i, i)
max_i = max(ma... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
895/A | 895 | A | Python 3 | TESTS | 51 | 139 | 6,860,800 | 32759875 | n=int(input())
vals=list(map(int,input().split()))
print(min([360]+[abs(360-2*sum(vals[j:j+i])) for i in range(n//2+1) for j in range(n)])) | 93 | 46 | 0 | 168430109 | n = int(input())
l = list(map(int,input().split()))
l1 = []
for j in range(n):
tot=0
i = j-1
while i>-2:
i+=1
tot += l[i]
if tot>=180:
if (abs(180-tot))>(abs(180-(tot-l[i]))):
tot-=l[i]
break
if i==n-1:
i=-1
l1.append(ab... | Codeforces Round 448 (Div. 2) | CF | 2,017 | 1 | 256 | Pizza Separation | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece... | The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | null | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | [{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 93 | [{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ... | false | stdio | null | true |
868/C | 868 | C | Python 3 | TESTS | 128 | 624 | 307,200 | 31020889 | from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
used = {}
sze = 2 ** k
for i in range(n):
values = list(map(int, stdin.readline().split()))
if ''.join(list(map(str, values))) in used:
used[''.join(list(map(str, values)))] += 1
else:
used[''.join(list(map(str, ... | 143 | 124 | 3,891,200 | 211054545 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations
from bisect import *
from heapq import *
from math import ceil,gcd,lcm,floor,comb
N,M = map(int,input().split())
s = set()
for _ in range(N):
S = input().split(... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 46 | 1,357 | 8,806,400 | 70497527 | def bs(a, be, en, v):
while be + 1 < en:
mid = (be + en) // 2
if a[mid] == v:
return True
elif a[mid] < v:
be = mid
else:
en = mid
return False
def solve(inp, ps, n):
su = ps[-1]
if su % 2:
return False
su //= 2
if bs(p... | 115 | 124 | 19,763,200 | 166889527 | from itertools import accumulate
if __name__=='__main__':
n=int(input())
nums=list(map(int,input().split()))
total=sum(nums)
if total & 1:
print('NO')
quit()
s=0
presum={v:i for i,v in enumerate(accumulate(nums))}
for i,n in enumerate(nums):
l=total//2-n
... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
814/A | 814 | A | PyPy 3 | TESTS | 31 | 514 | 11,878,400 | 77459847 | import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
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())
d=defaultdict(list)
n,k=M()
a=L()
b=L()
m=max(a)
mi=min(a)
p... | 96 | 46 | 0 | 154074711 | def read(): return map(int, input().split())
n, k = read()
a = list(read())
b = list(sorted(read()))
for i in range(n):
if a[i] == 0:
a[i] = b.pop()
print("No" if sorted(a) == a else "Yes") | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
127/B | 127 | B | PyPy 3 | TESTS | 72 | 93 | 0 | 219386243 | n = int(input())
l = list(map(int, input().split()))
s, a = list(set(l)), []
f = 0
for i in range(len(s)):
c = l.count(s[i])
f += (c // 4)
if c % 4 != 0 and c > 1:
a.append((c % 4) // 2)
for i in range(len(a) - 1):
m = min(a[i], a[i + 1])
f += m
a[i + 1] -= m
print(f) | 93 | 46 | 0 | 139822547 | n = int(input())
arr = input().split()
final = []
for i in arr:
final.append(int(i))
npairs = 0
for i in set(final):
count = final.count(i)
npairs += count // 2
print(npairs // 2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
868/C | 868 | C | PyPy 3 | TESTS | 54 | 858 | 29,491,200 | 90725810 | from collections import defaultdict
One = {
0: [1],
1: [0]
}
Two = {
0: [1,2,3],
1: [0,2],
2: [0,1],
3: [0]
}
Three = {
0:[1,2,3,4,5,6,7],
1:[0,2,4,6],
2:[0,1,4,5],
3:[0,4],
4:[0,1,2,3],
5:[0,2],
6:[0,1],
7:[0]
}
Four = {
0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... | 143 | 124 | 5,120,000 | 209526956 | import sys
class FastIO:
def __init__(self):
return
@staticmethod
def _read():
return sys.stdin.readline().strip()
def read_int(self):
return int(self._read())
def read_float(self):
return float(self._read())
def read_ints(self):
return map(int, self... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
868/C | 868 | C | PyPy 3 | TESTS | 54 | 936 | 35,020,800 | 123839267 | from collections import Counter
def f(g):
st=Counter(g)
l=list(st.keys())
for i in range(len(l)):
c=0
if st[l[i]]>=2:
c=1
for j in range(i+c):
t=list(map(lambda x,y:x+y,l[i],l[j]))
if max(t)==2:
continue
else:
return "YES"
return "NO"
n,k=map(int,input().strip().split())
g=[]
for i in ran... | 143 | 140 | 0 | 212247968 | n,m=map(int,input().split())
l=set()
z="NO"
for i in range(n):
l.add(("".join(input().split())))
l=list(l)
r=len(l)
for i in range(1,(1<<r)):#subset
freq=[0]*m
y=0
for j in range(r):#chack sub
if i&(1<<j):
y+=1
for k in range(m):
freq[k]+=int(l[j][k])
... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 21 | 62 | 0 | 29677001 | # If the path be beautiful, let us not ask where it leads.
[n, m] = [int(x) for x in input().split()]
maximum = []
first, last, count = -1, -1, 0
for i in range(n):
line = input()
if 'B' in line:
count += line.count('B')
maximum.append(line.rindex('B') - line.index('B') + 1)
if first =... | 128 | 62 | 307,200 | 29962376 | def main():
(n, m) = (int(x) for x in input().split())
L = [None] * n
for i in range(n):
L[i] = input()
print(solver(n, m, L))
def solver(n, m, L):
tr = topRow(n, m, L)
if tr == -1:
return 1
br = bottomRow(n, m, L)
lc = leftCol(n, m, L)
rc = rightCol(n, m, L)
colSize = rc - lc + 1
rowSize = br - tr + 1
... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
814/A | 814 | A | Python 3 | TESTS | 27 | 62 | 5,632,000 | 34001933 | l1=input()
l1=l1.split()
n=int(l1[0])
k=int(l1[1])
a=input()
a=a.split()
b=input()
b=b.split()
for i in range(n):
a[i]=int(a[i])
for i in range(k):
b[i]=int(b[i])
def Increasing(a):
fb='NO'
fp="NO"
for i in range(len(a)-1):
if a[i]>a[i+1]:
fb='YES'
if a[i]<a[i+1]:
... | 96 | 46 | 0 | 161548968 | a_length, b_length = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort(reverse=True)
j = 0
for i in range(a_length):
if a[i] == 0:
a[i] = b[j]
j += 1
if a == sorted(a):
print('NO')
else:
print('YES') | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
127/B | 127 | B | Python 3 | TESTS | 69 | 78 | 204,800 | 121238118 | from collections import defaultdict
n = int(input())
arr = list(map(int,input().split()))
dict = defaultdict(int)
flag = False
ans = 0
for x in arr:
dict[x]+=1
if (dict[x]==2 or dict[x]==4) and flag==True:
ans+=1
flag=False
dict[x] = 0
if dict[x]==2 and flag==False:
flag=True... | 93 | 46 | 0 | 142645114 | n=int(input())
ch=str(input())
l=[]
l2=ch.split()
for i in range (n) :
l.append(l2[i])
s=set(l2)
c=[]
for i in s :
c.append(l.count(i))
cpt=0
for i in range (len(c)) :
cpt+=c[i]//2
print(cpt//2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 21 | 61 | 307,200 | 109625291 | n, m = list(map(int, input().split()))
sheet = []
for i in range(n):
sheet.append(input())
min_row = 101
max_row = -1
min_col = 101
max_col = -1
for i in range(n):
for j in range(m):
if sheet[i][j] == 'B':
min_row = min(min_row, i)
max_row = max(max_row, i)
min_col =... | 128 | 62 | 4,608,000 | 28722692 | n, m = map(int, input().split())
a = [input() for i in range(n)]
x1 = y1 = 10 ** 10
x2 = y2 = -1
cnt = 0
for i in range(n):
for j in range(m):
if a[i][j] == 'B':
x1 = min(x1, i)
x2 = max(x2, i)
y1 = min(y1, j)
y2 = max(y2, j)
cnt += 1
dx = x2 - x1 ... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
127/B | 127 | B | Python 3 | TESTS | 40 | 78 | 7,065,600 | 38907404 | n = int(input())
a = list(map(int,input().split()))
hm = [0]*110
for i in a:
hm[i]+=1
c = 0
for i in range(110):
if(hm[i]>=4):
c+=hm[i]//4
hm[i]-=c*hm[i]
elif(hm[i]>=2):
for j in range(i+1,110):
if(hm[j]>=2 and hm[j]<4):
c+=1
hm[i]-=2
... | 93 | 46 | 0 | 148727054 | n = int(input())
L = list(map(int,input().split()))
izmeri= {}
atbildes = 0
for skaitlis in L:
if skaitlis in izmeri:
izmeri[skaitlis] +=1
else:
izmeri[skaitlis] = 1
for x in izmeri :
atbildes += izmeri[x]//2
print(atbildes//2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 21 | 62 | 5,529,600 | 28438413 | n, m = map(int, input().split())
f = [input() for _ in range(n)]
first, last = (n + 1, m + 1), (-1, -1)
black = 0
for i in range(n):
for j in range(m):
if f[i][j] == "B":
first = min(first, (i, j))
last = max(last, (i, j))
black += 1
h = last[0] - first[0] + 1
w = la... | 128 | 62 | 4,608,000 | 28781017 | (n, m) = (int(i) for i in input().split())
top = -1
left = 101
right = -1
down = -1
cnt = 0
for i in range(n):
read = input()
for j in range(m):
cur = read[j]=='B'
if not cur: continue
cnt += 1
if top==-1:
top = i
if j<left:
left = j
if j>right:
right = j
down = i
stor = max(down-top, righ... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
962/A | 962 | A | Python 3 | TESTS | 10 | 171 | 19,660,800 | 37295648 | numberOfDays = input()
numberOfProblems = [int(x) for x in input().split()]
sumOfnumberOfProblemsArray = sum(numberOfProblems)
if sumOfnumberOfProblemsArray % 2 == 0:
halfSize = sumOfnumberOfProblemsArray / 2
else:
halfSize = sumOfnumberOfProblemsArray / 2 + 1
halfSize = round(halfSize)
helper = 0
for i in ra... | 106 | 93 | 13,516,800 | 138027483 | n = int(input())
a = [*map(int, input().split())]
S = sum(a); s = 0
for i in range(n):
s += a[i]
if 2*s >= S:
print(i+1)
break | Educational Codeforces Round 42 (Rated for Div. 2) | ICPC | 2,018 | 2 | 256 | Equator | Polycarp has created his own training plan to prepare for the programming contests. He will train for $$$n$$$ days, all days are numbered from $$$1$$$ to $$$n$$$, beginning from the first.
On the $$$i$$$-th day Polycarp will necessarily solve $$$a_i$$$ problems. One evening Polycarp plans to celebrate the equator. He ... | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of days to prepare for the programming contests.
The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$), where $$$a_i$$$ equals to the number of problems, which Polycarp will solve on the $$... | Print the index of the day when Polycarp will celebrate the equator. | null | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $$$4$$$ out of $$$7$$$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to th... | [{"input": "4\n1 3 2 1", "output": "2"}, {"input": "6\n2 2 2 2 2 2", "output": "3"}] | 1,300 | ["implementation"] | 106 | [{"input": "4\r\n1 3 2 1\r\n", "output": "2\r\n"}, {"input": "6\r\n2 2 2 2 2 2\r\n", "output": "3\r\n"}, {"input": "1\r\n10000\r\n", "output": "1\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "1\r\n"}, {"input": "2\r\n1 3\r\n", "output": "2\r\n"}, {"input": "4\r\n2 1 1 3\r\n", "output": "3\r\n"}, {"input": "3\r\n1 1 3\r... | false | stdio | null | true |
356/C | 356 | C | Python 3 | TESTS | 65 | 405 | 10,649,600 | 5635395 | n = int(input())
A = [0, 0, 0, 0, 0]
B = map(int, input().split(' '))
for i in B:
A[i] += 1
res = min(A[1], A[2])
A[1] -= res
A[2] -= res
res += 2 * (A[1] // 3)
A[3] += A[1] // 3
A[1] %= 3
res += 2 * (A[2] // 3)
A[3] += 2 * (A[2] // 3)
A[2] %= 3
assert(A[1] == 0 or A[2] == 0)
if (A[1] == 1):
if (A[3] > 0):
re... | 141 | 607 | 14,745,600 | 42135284 | #! /usr/bin/env python
n = int(input())
counts = [0] * 5
nums = [int(x) for x in input().split()]
for x in nums:
counts[x] += 1
s = sum(nums)
if s > 2 and s != 5:
ans = 0
if counts[1] >= counts[2]:
ans += counts[2]
counts[3] += counts[2]
counts[1] -= counts[2]
ans += 2 * (c... | Codeforces Round 207 (Div. 1) | CF | 2,013 | 1 | 256 | Compartments | A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge... | The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train. | If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places. | null | null | [{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}] | 2,100 | ["combinatorics", "constructive algorithms", "greedy", "implementation"] | 141 | [{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"... | false | stdio | null | true |
814/A | 814 | A | PyPy 3 | TESTS | 14 | 155 | 0 | 67440550 | n,k = map(int,input().split())
a=[int(i)for i in input().split()]
b=[int(i)for i in input().split()]
b.sort()
if k>1 :
print("Yes")
elif k==1:
for q, i in enumerate(a):
if i == 0:
a[q] = b[0]
if (a.index(max(a)) -a.index(min(a)))==n-1:
print("No")
else:
print("Yes") | 96 | 46 | 0 | 168484105 | a,b=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
y.sort()
j=b-1
#print
for i in range(a):
if x[i]==0:
x[i]=y[j]
j=j-1
t=sorted(x)
c=0
for i in range(a):
if t[i]!=x[i]:
print("Yes")
c=1
break
if(c==0):
print("No... | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
895/A | 895 | A | Python 3 | TESTS | 50 | 124 | 0 | 58705023 | n = int(input())
s = list(map(int,input().split()))
s.extend(s)
r = 360
a = 0
b1,b2 = 0,0
for i in range(2*n):
a+=s[i]
b2+=1
if a<180:
r = min(r,abs(a-180))
elif a==180:
r = 0
break
else:
a -=s[b1]
r = min(r,abs(a-180))
b1+=1
print(r*2) | 93 | 46 | 0 | 227768233 | def main():
N = 1000
SUMA = 0
NUMEROS = [0] * N
tam = int(input())
ANSI = 365
# Read numbers from one line, split by spaces, and convert each to an integer
input_values = list(map(int, input().split()))
for i in range(1, tam + 1):
NUMEROS[i] = input_values[i - 1]
for i in... | Codeforces Round 448 (Div. 2) | CF | 2,017 | 1 | 256 | Pizza Separation | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece... | The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | null | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | [{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 93 | [{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ... | false | stdio | null | true |
682/B | 682 | B | Python 3 | TESTS | 66 | 186 | 7,270,400 | 68034178 | import sys
#n = int(input())
#a = list(input().split())
#a.sort()
#m = []
#for x in a:
# for y in x:
# m.append(y)
#
#
#for i in range(len(m) + 1):
# try:
#
# if len(m) == 1:
# del m[i]
# m.insert(i, str(1))
# break
#
#
# if int(m[i + 1]) - int(m[i]) >= 2:
# ... | 127 | 93 | 11,571,200 | 177394199 | n=int(input())
a=[int(s) for s in input().split()]
k=1
a=sorted(a)
for i in range(n):
if k<=a[i]:
k+=1
print(k) | Codeforces Round 358 (Div. 2) | CF | 2,016 | 1 | 256 | Alyona and Mex | Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | null | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | [{"input": "5\n1 3 3 3 6", "output": "5"}, {"input": "2\n2 1", "output": "3"}] | 1,200 | ["sortings"] | 127 | [{"input": "5\r\n1 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "2\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1 3\r\n", "output"... | false | stdio | null | true |
814/A | 814 | A | PyPy 3 | TESTS | 16 | 93 | 20,172,800 | 128382571 | def possible(n,k,a,b):
i = 0
j = 0
while i < n:
if a[i] == 0:
a[i] = b[j]
j += 1
i += 1
if a == sorted(a):
return False
else:
return True
def reversepossible(n,k,a,b):
b.reverse()
i = 0
j = 0
while i < n:
if a[i] == 0:
... | 96 | 46 | 0 | 174774083 | isValid = False
x1 = list(map(int, input().split()))
x2 = list(map(int, input().split()))
x3 = list(map(int, input().split()))
for i in range(len(x2)):
if(i<len(x2)-1):
if(x2[i] > x2[i+1] and x2[i] != 0):
if(x2[i] != 0 and x2[i+1] != 0):
isValid = True
break
... | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
789/B | 789 | B | Python 3 | TESTS | 19 | 92 | 13,107,200 | 25917516 | b, q, l, m = map(int, input().split())
b = abs(b)
q = abs(q)
a = set(list(map(int, input().split())))
if (b == 0):
print("inf")
else:
if q == 0:
if b > l:
print(0)
else:
if 0 in a:
if b in a:
print(0)
else:
... | 116 | 93 | 15,564,800 | 25914081 | s, r, m, n = map(int, input().split())
bad = set(map(int, input().split()))
cnt = 0
if abs(s) > m:
print(0)
elif s == 0:
if 0 in bad:
print(0)
else:
print('inf')
elif r == 0 and s != 0:
if 0 in bad or m < 0:
if s in bad:
print(0)
else:
print(1)
... | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
127/B | 127 | B | Python 3 | TESTS | 40 | 46 | 307,200 | 212524838 | from collections import Counter
from heapq import *
n = int(input())
C = Counter(list(map(int, input().split())))
minHeap = []
for k, v in C.items():
if v < 2: continue
if v%2==0:
heappush(minHeap, (v, k))
else:
heappush(minHeap, (v-1, k))
ans = 0
while minHeap:
c, l = heappop(minHeap)
... | 93 | 46 | 0 | 151613716 | f= int(input())
y=input().split()
k=0
for i in range(0,f):
for j in range(i+1,f):
if (y[i]==y[j] and y[i]!=0 and y[j]!=0):
y[i]=0
y[j]=0
k=k+1
break
print(k//2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
682/B | 682 | B | Python 3 | TESTS | 66 | 187 | 7,475,200 | 101859467 | if __name__ == '__main__':
stack = []
amount = int(input())
array = input().split(" ")
array.sort()
for nr in array:
if int(nr) > len(stack):
stack.append(1)
print(len(stack)+1) | 127 | 93 | 13,209,600 | 226023931 | n = int(input())
arr = list(map(int, input().split()))
# Sort the array
arr.sort()
# Initialize the mex
mex = 1
# Check each element in the array
for a in arr:
if a >= mex:
mex += 1
print(mex) | Codeforces Round 358 (Div. 2) | CF | 2,016 | 1 | 256 | Alyona and Mex | Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array. | Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. | null | In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements. | [{"input": "5\n1 3 3 3 6", "output": "5"}, {"input": "2\n2 1", "output": "3"}] | 1,200 | ["sortings"] | 127 | [{"input": "5\r\n1 3 3 3 6\r\n", "output": "5\r\n"}, {"input": "2\r\n2 1\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n", "output": "2\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "2\r\n"}, {"input": "1\r\n2\r\n", "output": "2\r\n"}, {"input": "2\r\n1 1\r\n", "output": "2\r\n"}, {"input": "2\r\n1 3\r\n", "output"... | false | stdio | null | true |
868/C | 868 | C | Python 3 | TESTS | 61 | 530 | 6,963,200 | 34596255 | import math
def l(n,list):
for i in list:
if i>=n:
return True
return False
n,k=map(int,input().split())
a=[1]*k
c=[]
for i in range(n):
b=list(map(int,input().split()))
c.append(b.count(0))
for j in range(k):
a[j]=(a[j] and b[j])
if not(1 in a) and (l(math.ceil(k/2),c)) ... | 143 | 155 | 9,011,200 | 158133096 | 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")
#######################################... | Codeforces Round 438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) | CF | 2,017 | 2 | 256 | Qualification Rounds | Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.
k experienced teams are participating in the contest. Some of these teams already know some of the problems... | The first line contains two integers n, k (1 ≤ n ≤ 105, 1 ≤ k ≤ 4) — the number of problems and the number of experienced teams.
Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise. | Print "YES" (quotes for clarity), if it is possible to make an interesting problemset, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | null | In the first example you can't make any interesting problemset, because the first team knows all problems.
In the second example you can choose the first and the third problems. | [{"input": "5 3\n1 0 1\n1 1 0\n1 0 0\n1 0 0\n1 0 0", "output": "NO"}, {"input": "3 2\n1 0\n1 1\n0 1", "output": "YES"}] | 1,500 | ["bitmasks", "brute force", "constructive algorithms", "dp"] | 143 | [{"input": "5 3\r\n1 0 1\r\n1 1 0\r\n1 0 0\r\n1 0 0\r\n1 0 0\r\n", "output": "NO\r\n"}, {"input": "3 2\r\n1 0\r\n1 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 2\r\n1 0\r\n1 0\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 0\r\n1 1\r\n0 1\r\n0 1\r\n", "output": "YES\r\n"}, {"input": "10 3\r\n1 0 0\r\n0 1 1\r\n1 0 0\r\n0 1 0\r\... | false | stdio | null | true |
814/A | 814 | A | PyPy 3 | TESTS | 16 | 93 | 0 | 27632944 | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))[::-1]
cnt2 = 0
for i in range(n):
if a[i] == 0:
a[i] = b[cnt2]
cnt2 += 1
if a == sorted(a):
print("No")
else:
print("Yes") | 96 | 46 | 0 | 183853588 | n,k=map(int,input().split())
first=list(map(int,input().split()))
duplicate=[]
increasing=True
result=True
second=list(map(int,input().split()))
second_num=0
for i in range (len(second)-1):
if second[i]<second[i+1]:
temporary=second[i]
second[i]=second[i+1]
second[i+1]=temporary
for i in range(len(f... | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
814/A | 814 | A | Python 3 | TESTS | 16 | 93 | 307,200 | 99707439 | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))[::-1]
j = 0
for i in range(n):
if a[i]==0:
a[i]=b[j]
j+=1
if a==sorted(a):
print("No")
else:
print("Yes") | 96 | 46 | 0 | 186457386 | n,k = input().split()
L = [int(a) for a in input().split(" ",int(n)-1)]
l1 = [int(a) for a in input().split(" ",int(k)-1)]
a=0
l1.sort(reverse=True)
for i in range(int(n)):
if L[i]==0:
L[i]=l1[a]
a+=1
if a>len(l1):
break
l2=L[:]
l2.sort()
if l2==L:
print("NO")
else:
print("YES") | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
814/A | 814 | A | Python 3 | TESTS | 16 | 62 | 0 | 27659026 | n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
j = 1
for i in range(n):
if a[i] == 0:
a[i] = c[-j]
j += 1
ans = 'No'
for i in range(n - 1):
if a[i] > a[i + 1]:
ans = 'Yes'
print(ans) | 96 | 46 | 0 | 189449479 | n, k = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
for i in range(n):
if a[i] == 0:
a[i] = max(b)
del b[b.index(max(b))]
print(('YES', 'NO')[sorted(a) == a]) | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
660/A | 660 | A | PyPy 3 | TESTS | 12 | 109 | 2,457,600 | 106014524 | from math import gcd
n=int(input());arr=list(map(int,input().split()));ans=[]
cnt=0
for i in range(n-1):
if gcd(arr[i],arr[i+1])>1:
ans.append(arr[i])
ans.append(1213);cnt+=1
else:ans.append(arr[i])
ans.append(arr[-1])
print(cnt)
print(*ans) | 93 | 46 | 0 | 140663013 | n=int(input())
l=list(map(int,input().split()))
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
ls=[]
c=0
for i in range(n-1):
ls.append(l[i])
if gcd(l[i],l[i+1])!=1:
c+=1
ls.append(1)
ls.append(l[n-1])
print(c)
print(*ls) | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
997/A | 997 | A | PyPy 3 | TESTS | 7 | 155 | 3,276,800 | 58482763 | n,x,y = map(int,input().split())
a = input()
count = 0
for i in range(n-1):
if a[i] == '0' and a[i+1] == '1':
count+=1
elif a[i] == '0' and i == n-2:
count+=1
if count == 0:
print(0)
else:
print((count-1)*min(x,y)+y) | 115 | 77 | 2,560,000 | 205518974 | n, x, y = map(int, input().split(' '))
s = input()
cnt = 0
i = 0
# 1010
# 0110
# 0001
# 1111
# 0110
while i < len(s):
if s[i] == '0':
cnt += 1
while i < len(s) and s[i] == '0':
i += 1
i += 1
if cnt > 0:
if x < y:
print((cnt - 1) * x + y)
else:
print(cn... | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
660/A | 660 | A | Python 3 | TESTS | 14 | 62 | 6,963,200 | 123542744 | def mdcEuclidiano(x, y):
while(y):
x, y = y, x % y
return x
def achaBigMC(x,y):
t = True
num = x+1
while(t):
if(mdcEuclidiano(x, num) == 1 and mdcEuclidiano(num, y) == 1):
t = False
else:
num +=1
return num
tam = int(input())
k = 0
arraySaida = ""... | 93 | 46 | 0 | 155232013 | from math import gcd
tam = int(input())
seq = [int(n) for n in input().split()]
correta = [seq[0]]
i = 1
while i < len(seq):
mdc = gcd(seq[i], correta[-1])
if mdc == 1:
correta.append(seq[i])
i += 1
else:
correta.append(1)
correta = [str(n) for n in correta]
print(len(correta) - t... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
789/B | 789 | B | Python 3 | TESTS | 19 | 78 | 15,974,400 | 25921383 | b1, q, l, m = map(int, input().split())
a = set(map(int, input().split()))
b1 = abs(b1)
q = abs(q)
ans = 0
k = 0
while b1 <= l:
if not (b1 in a):
ans += 1
k += 1
b1 *= q
if k > m + 3:
if ans == 0 or ans == 1:
print(ans)
else:
print("inf")
exit()
... | 116 | 93 | 15,667,200 | 25926860 | b, q, l, m = map(int, input().split())
A = set(map(int, input().split()))
ans = 0
for _ in range(100):
if abs(b) > l:
break
if b not in A:
ans += 1
b *= q
if ans > 40:
print("inf")
else:
print(ans) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
660/A | 660 | A | PyPy 3-64 | TESTS | 14 | 61 | 1,536,000 | 204355182 | import math
n = int(input())
arr = list(map(int, input().split()))
ans = [arr[0]]
for i in range(1, n):
tmp = ans[-1]
if math.gcd(tmp, arr[i]) == 1:
ans.append(arr[i])
else:
temp = tmp+1
while True:
if math.gcd(tmp, temp) == 1 and math.gcd(temp, arr[i]) == 1:
... | 93 | 46 | 0 | 161637033 | 'https://codeforces.com/contest/660/problem/A'
def computeGCD(x, y):
while(y):
x,y=y,x%y
return abs(x)
n=int(input())
ans=0
num1=[]
num=list(map(int,input().split()))
for i in range(1,n):
if(computeGCD(num[i-1],num[i])==1):
num1.append(num[i-1])
else:
num1.append(num[i-1])
num1.append(1)
ans+=1
num1.appe... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
660/A | 660 | A | PyPy 3-64 | TESTS | 14 | 77 | 4,812,800 | 152705274 | from math import gcd
n = int(input())
count = 0
a = list(map(int, input().split()))
i = 0
k = len(a)
while i < k-1:
if gcd(a[i], a[i+1]) == 1:
i += 1
else:
l = a[i]+1
while gcd(a[i], l) != 1 or gcd(a[i+1], l) != 1:
l += 1
count += 1
a.insert(i+1, l)
k = ... | 93 | 46 | 0 | 175063273 | import math
n=int(input())
a=list(map(int,input().split()))
Ans=0
for i in range(n-1):
if math.gcd(a[i],a[i+1])!=1:
Ans+=1
print(Ans)
for i in range(n-1):
print(a[i],end=' ')
if math.gcd(a[i],a[i+1])!=1:
print(1,end=' ')
print(a[n-1]) | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
828/B | 828 | B | Python 3 | TESTS | 91 | 124 | 102,400 | 47422321 | bl,wt='B W'.split()
def gd(f,l):
"""get delta"""
return 2*int(l>f)-1
def fe(v,zf,zl,xf,xl,iv):#iv is vertical
"""find edge"""
dz=gd(zf,zl)
dx=gd(xf,xl)
for c in range(zf,zl,dz):
for d in range(xf,xl,dx):
t=v[c][d] if iv else v[d][c]
if t==bl:
return c
def cir(v,t,b,l,r):
"""count of white cell... | 128 | 62 | 4,608,000 | 28825584 | n,m = input().split(" ")
n = int(n)
m = int(m)
c = 0
u_black, b_black, l_black, r_black = n,0,m,0
for i in range(0,n):
row = str(input())
for j in range(0,m):
if row[j] == "B":
u_black = min(u_black,i)
b_black = max(b_black,i)
l_black = min(l_black,j)
r_black = max(r_black,j)
c = c + 1
length = max... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 91 | 77 | 5,632,000 | 28435728 | n,m = map(int,input().split())
minr = m
maxr = -1
minc = n
maxc = -1
black = 0
for i in range(n):
line = input()
for j in range(m):
if line[j] == 'B':
black += 1
if i < minc:
minc = i
if i > maxc:
maxc = i
if j < minr:
... | 128 | 62 | 4,915,200 | 28862034 | import sys
import math
inp = input()
sqr = []
for line in sys.stdin:
s = list(line.rstrip())
sqr.append(s)
r = -1
l = math.inf
d = -1
u = math.inf
for i, line in enumerate(sqr):
for j, b in enumerate(line):
if b == 'B':
if i < u:
u = i
if i+1 > d:
... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 91 | 77 | 5,632,000 | 28444181 | n, m = map(int, input().split())
l = []
for i in range(n):
l.append(list(input()))
minX, minY, maxX, maxY = n, m, -1, -1
zero = True
for i in range(n):
for j in range(m):
if l[i][j] == 'B':
zero = False
if i > maxX: maxX = i
if i < minX: minX = i
if j > ... | 128 | 62 | 5,529,600 | 28464798 | n,m=map(int,input().split())
x1,y1,x2,y2,c=m,n,0,0,0
for i in range(n):
s=input()
for j in range(m):
if s[j]=='B':
if x1>j:x1=j
if x2<j:x2=j
if y1>i:y1=i
if y2<i:y2=i
c+=1
if c==0:
print(1)
else:
w=x2-x1+1
h=y2-y1+1
h=max(w,h)
... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 91 | 62 | 0 | 29514098 | n, m = map(int, input().split())
g = [input() for i in range(n)]
b, r1, r2, c1, c2 = 0, n, -1, m, -1
for i in range(n):
for j in range(m):
if g[i][j] == 'B':
b += 1
r1 = min(r1, i)
r2 = max(r2, i)
c1 = min(c1, j)
c2 = max(c2, j)
s = max(r2 - r1 + 1... | 128 | 62 | 5,529,600 | 28474588 | rows,cols = [int(i) for i in input().strip().split()]
b_present = False
l,r,u,d = cols,cols,rows,-1
b_cnt = 0
for i in range(rows):
col = input().strip()
if 'B' in col:
b_present = True
l = min(l,col.index('B'))
u = min(u,i)
r = min(r,col[::-1].index('B'))
d = max(d,i)
b_cnt += col.count('B')
if not b_pre... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
828/B | 828 | B | Python 3 | TESTS | 61 | 62 | 4,915,200 | 28628279 | def getRowsContainingB(matrix):
beginningRow = -1
endingRow = -2
for i in range(len(matrix)):
for c in matrix[i]:
if c == "B":
if beginningRow == -1:
beginningRow = endingRow = i
else:
endingRow = i
return (endingRow - beginningRow) + 1
def getColumnsContainingB(matrix):
beginningColumn = -... | 128 | 62 | 5,529,600 | 28492131 | sheet = []
nm = input().split(' ')
n= int(nm[0])
m = int(nm[1])
countB = 0
minr = minc = 101
maxr = maxc = -1
for i in range(n):
sheet.append(input())
for j in range(len(sheet[i])):
if sheet[i][j]=='B':
countB+=1
if i<minr:
minr = i
if i>maxr:
... | Codeforces Round 423 (Div. 2, rated, based on VK Cup Finals) | CF | 2,017 | 1 | 256 | Black Square | Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible ... | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. | Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. | null | In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third exampl... | [{"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5"}, {"input": "1 2\nBB", "output": "-1"}, {"input": "3 3\nWWW\nWWW\nWWW", "output": "1"}] | 1,300 | ["implementation"] | 128 | [{"input": "5 4\r\nWWWW\r\nWWWB\r\nWWWB\r\nWWBB\r\nWWWW\r\n", "output": "5\r\n"}, {"input": "1 2\r\nBB\r\n", "output": "-1\r\n"}, {"input": "3 3\r\nWWW\r\nWWW\r\nWWW\r\n", "output": "1\r\n"}, {"input": "100 1\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nW\r\nB\r\nW\r\nW\r\nW\r\nW\r... | false | stdio | null | true |
895/A | 895 | A | PyPy 3 | TESTS | 51 | 124 | 23,142,400 | 32676792 | n = int(input())
a = [int(z) for z in input().split()]
ans = 360
for i in range(n):
tmp = 0
j = i
while j < n and tmp < 180:
tmp += a[j]
j += 1
ans = min(ans, abs(360 - tmp - tmp))
print(ans) | 93 | 62 | 5,529,600 | 33005485 | def findAngel(ang, n):
summ = 0
i = -1
while (summ < 180):
i += 1
summ += ang[i]
#print(i, summ)
return summ
n = int(input())
a = [int(i) for i in input().split()]
i = 0
summ = 0
minSumm = 360
while ((abs(360-2*summ) != 0) and (i < n)):
summ = findAngel([a[i]] + a[i + 1:len... | Codeforces Round 448 (Div. 2) | CF | 2,017 | 1 | 256 | Pizza Separation | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all piece... | The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers ai (1 ≤ ai ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all ai is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | null | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Pety... | [{"input": "4\n90 90 90 90", "output": "0"}, {"input": "3\n100 100 160", "output": "40"}, {"input": "1\n360", "output": "360"}, {"input": "4\n170 30 150 10", "output": "0"}] | 1,200 | ["brute force", "implementation"] | 93 | [{"input": "4\r\n90 90 90 90\r\n", "output": "0\r\n"}, {"input": "3\r\n100 100 160\r\n", "output": "40\r\n"}, {"input": "1\r\n360\r\n", "output": "360\r\n"}, {"input": "4\r\n170 30 150 10\r\n", "output": "0\r\n"}, {"input": "5\r\n10 10 10 10 320\r\n", "output": "280\r\n"}, {"input": "8\r\n45 45 45 45 45 45 45 45\r\n", ... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 34 | 187 | 20,275,200 | 218747359 | # LUOGU_RID: 120798760
n = int(input())
a = list(map(int, input().split()))
mp = {}
mpp = {}
sum_val = 0
sum1 = 0
for i in range(n):
sum_val += a[i]
if a[i] in mpp:
mpp[a[i]] += 1
else:
mpp[a[i]] = 1
if sum_val % 2 == 1:
print("NO")
else:
exp = sum_val // 2
for i in range(n):
... | 115 | 140 | 20,787,200 | 219378803 | n = int(input())
l = list(map(int,input().split()))
dic = dict()
sum = 0
for i,j in enumerate(l):
sum += j
dic[sum] = i
if sum % 2 == 1:
print("NO")
exit()
for i,j in enumerate(l):
v = sum // 2 - j
if v in dic and dic[v] < i:
print("YES")
exit()
v = sum / 2 + j
if v in d... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 34 | 202 | 20,275,200 | 218747578 | # LUOGU_RID: 120799086
n = int(input())
a = list(map(int, input().split()))
mpl = {}
mpr = {}
sum_val = 0
ans = 0
for i in range(n):
sum_val += a[i]
if a[i] in mpr:
mpr[a[i]] += 1
else:
mpr[a[i]] = 1
if sum_val % 2 == 1:
print("NO")
else:
flag = 0
sum_val //= 2
for i in ran... | 115 | 140 | 21,196,800 | 172169944 | n = int(input())
a = map(int, input().split(' '))
a = list(a)
mp = {}
dis = -sum(a)
a = list(map(lambda x: x * 2, a))
for x in a:
if -x not in mp:
mp[-x] = 0
mp[-x] += 1
tag = False
if dis in mp:
tag = True
for x in a:
dis += x
if x not in mp:
mp[x] = 0
mp[x] += 1
mp[... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 34 | 249 | 21,504,000 | 125002880 | import math
import sys
def main(arr):
left={}
right={}
for e in arr:
if e not in right:
right[e]=0
right[e]+=1
prefix=[arr[0]]
for i in range(1,len(arr)):
prefix.append(arr[i]+prefix[-1])
s=prefix[-1]
for i in range(len(arr)):
if arr[i] not in left:
left[arr[i]]=0
l... | 115 | 155 | 19,353,600 | 214509456 | import sys
def ainput():
return sys.stdin.readline()
n=int(ainput())
ls=[0]+list(map(int,ainput().split()))
s=sum(ls)/2
if sum(ls)%2!=0:
print('No')
exit()
res=0
z={}
z[0]=1
for i in range(1,n+1):
res+=ls[i]
z[ls[i]]=1
if (res-s) in z:
print('Yes')
break
else:
z.clear()
z... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
808/D | 808 | D | Python 3 | TESTS | 34 | 233 | 11,980,800 | 32036203 | import math
def f():
n=int(input())
s1=0
s2=0
m1={}
m2={}
A=list(map(int,input().split()))
if n==1:
print("NO")
return
for i in A:
s2+=i
if i in m2:
m2[i]+=1
else:
m2[i]=1
for i in A:
if (s1-s2)%2==0:
d=(s1-s2)//2
if d<0 and -d in m2:
print("YES")
return
elif d in m1:
pri... | 115 | 171 | 7,987,200 | 160513950 | n = int(input())
arr = list(map(int, input().split()))
total = sum(arr)
if (total&1) == 1 :
print("NO")
exit(0)
def solve(arr) :
st = set()
s = 0
for i in arr :
st.add(i)
s += i
if (s >= total//2) :
if (s-total//2) in st :
print("YES")
... | Educational Codeforces Round 21 | ICPC | 2,017 | 2 | 256 | Array Division | Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element be... | The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a1, a2... an (1 ≤ ai ≤ 109) — the elements of the array. | Print YES if Vasya can divide the array after moving one element. Otherwise print NO. | null | In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left. | [{"input": "3\n1 3 2", "output": "YES"}, {"input": "5\n1 2 3 4 5", "output": "NO"}, {"input": "5\n2 2 3 4 5", "output": "YES"}] | 1,900 | ["binary search", "data structures", "implementation"] | 115 | [{"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "NO\r\n"}, {"input": "5\r\n2 2 3 4 5\r\n", "output": "YES\r\n"}, {"input": "5\r\n72 32 17 46 82\r\n", "output": "NO\r\n"}, {"input": "6\r\n26 10 70 11 69 57\r\n", "output": "NO\r\n"}, {"input": "7\r\n4 7 10 7 5 5 1\r\n", "outpu... | false | stdio | null | true |
660/A | 660 | A | PyPy 3 | TESTS | 37 | 155 | 1,228,800 | 78349294 | import io, os
import sys
from math import gcd
from atexit import register
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0
def nextStr():
global tokens, tokens_next
while tokens_next >= len... | 93 | 46 | 0 | 179333013 | def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
input()
valores = list(map(int, input().split(" ")))
adicionados = 0
resultado = []
for i in range(len(valores) - 1):
mdc = gcd(valores[i], valores[i + 1])
resultado.append(valores[i])
if mdc != 1:
resultado.append(1)
... | Educational Codeforces Round 11 | ICPC | 2,016 | 1 | 256 | Co-prime Array | You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integer... | The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a. | Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers aj — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Als... | null | null | [{"input": "3\n2 7 28", "output": "1\n2 7 9 28"}] | 1,200 | ["greedy", "implementation", "math", "number theory"] | 93 | [{"input": "3\r\n2 7 28\r\n", "output": "1\r\n2 7 1 28\r\n"}, {"input": "1\r\n1\r\n", "output": "0\r\n1\r\n"}, {"input": "1\r\n548\r\n", "output": "0\r\n548\r\n"}, {"input": "1\r\n963837006\r\n", "output": "0\r\n963837006\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "0\r\n1 1 1 1 1 1 1 1 1 1\r\n"}, {"inp... | false | stdio | import sys
import math
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path) as f:
n = int(f.readline())
a = list(map(int, f.readline().split()))
# Read submission output
with open(submission_path) a... | true |
603/A | 603 | A | PyPy 3 | TESTS | 9 | 78 | 20,889,600 | 35743305 | n = int(input())
s = input()
cnt = 1
last = s[0]
for i in range(1, len(s)):
if s[i] != last:
cnt += 1
last = s[i]
if s.count('111') or s.count('000') or s.count('00') > 1 or s.count('11') > 1:
print(cnt+2)
elif s.count('11') or s.count('00'):
print(cnt+1)
else:
print(cnt) | 116 | 61 | 102,400 | 204916976 | n,s=int(input()),input()
print(min(n,s.count('01')+s.count('10')+3)) | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
127/B | 127 | B | PyPy 3-64 | TESTS | 23 | 62 | 0 | 192241219 | n = int(input())
a = list(map(int , input().split()))
c2 = []
c4 = []
for i in a :
if(i in c2 or i in c4):
continue
else:
if(a.count(i) >= 2):
c2.append(i)
c4.append(a.count(i) // 2)
print(sum(c4) // 2) | 93 | 46 | 0 | 155514969 | n = int(input())
a = list(map(int,input().split()))
d = dict.fromkeys(a,0)
for i in a:
d[i]+=1
s = 0
for i in d:
d[i]//=2
s+=d[i]
print(s//2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
858/C | 858 | C | Python 3 | TESTS | 41 | 62 | 5,529,600 | 30433231 | s=input()
a=0
b=''
c=['a', 'e', 'i', 'o','u']
S=''
f=0
for i in range(len(s)):
if a==0 and s[i] not in c :
b=s[i]
f=0
if a==2 and f==1 and s[i] not in c:
S+=' '
a=0
b=''
f=0
if a < 3 and s[i] not in c and s[i]!=b:
a+=1
f=1
... | 108 | 46 | 0 | 226365615 | s = list(input())
same = True
block = 0
vowels = ["a", "e", "i", "o", "u"]
spaces = []
for a in range(len(s)):
if s[a] in vowels:
block = 0
same = True
else:
block += 1
if block > 1 and s[a] != s[a-1]:
same = False
if block >= 3 and not same:
spaces.append... | Технокубок 2018 - Отборочный Раунд 1 | CF | 2,017 | 1 | 256 | Did you mean... | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are thr... | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | null | null | [{"input": "hellno", "output": "hell no"}, {"input": "abacaba", "output": "abacaba"}, {"input": "asdfasdf", "output": "asd fasd f"}] | 1,500 | ["dp", "greedy", "implementation"] | 108 | [{"input": "hellno\r\n", "output": "hell no \r\n"}, {"input": "abacaba\r\n", "output": "abacaba \r\n"}, {"input": "asdfasdf\r\n", "output": "asd fasd f \r\n"}, {"input": "ooo\r\n", "output": "ooo \r\n"}, {"input": "moyaoborona\r\n", "output": "moyaoborona \r\n"}, {"input": "jxegxxx\r\n", "output": "jxegx xx \r\n"}, {"i... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 16 | 62 | 0 | 29679665 | n=int(input())
s=input()
i=0
b=[]
j=0
l=1
chsl=0
while i < len(s):
if s[i]==' ':
b.append(chsl)
l=1
j+=1
chsl=0
else :
chsl=chsl+int(s[i])*l
l=l*10
i+=1
b.append(chsl)
b.sort()
if int(b[n-1])==int(b[n]) :
print('NO')
else:
print('YES') | 88 | 46 | 0 | 29845502 | n = int(input())
ranks = [int(x) for x in input().split()]
ranks.sort()
if ranks[n-1] == ranks[n]:
print('NO')
else:
print('YES') | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
815/A | 815 | A | PyPy 3 | TESTS | 18 | 171 | 26,521,600 | 89630219 | n, m = list(map(int, input().split()))
a = []
all_equals = True
for i in range(n):
row = list(map(int, input().split()))
a.append(row)
if row.count(a[0][0]) != len(row):
all_equals = False
def remove_cols():
ans = 0
min_col = [0] * m
for i in range(m):
min_col[i] = 1000
... | 177 | 170 | 5,222,400 | 157587945 | n, m = map(int, input().split())
a = [list(map(int, input().split()))for i in range(n)]
row = 'row'
col = 'col'
if n > m:
row, col = col, row
n, m = m, n
a = list(map(list, zip(*a)))
z = []
for i in range(n):
x = min(a[i])
for j in range(m):
a[i][j] -= x
z += [(row, i + 1)] * x
for i in range(1, n):
if a[i] !=... | Codeforces Round 419 (Div. 1) | CF | 2,017 | 2 | 512 | Karen and Game | On the way to school, Karen became fixated on the puzzle game on her phone!
The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0.
One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column.
To ... | The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively.
The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500). | If there is an error and it is actually not possible to beat the level, output a single integer -1.
Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level.
The next k lines should each contain one of the following, describing the moves in the order they must b... | null | In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level:
In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required... | [{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}] | 1,700 | ["brute force", "greedy", "implementation"] | 177 | [{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
grid = [list(map(int, f.readline().split())) for _ in range(n)]
possible = True
g1_1 = grid[0][0] if n... | true |
814/A | 814 | A | Python 3 | TESTS | 14 | 46 | 0 | 27634786 | n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
vis=[0 for i in range(250)]
cnt=0
num=0
for i in range(n):
if a[i]==0:
cnt+=1
for i in range(m):
if vis[b[i]]==0:
vis[b[i]]=1
num+=1
if num<cnt:
print('No')
elif num==1:
flag=True
i... | 96 | 46 | 0 | 191280778 | n, k = map(int, input().split())
a, b = list(map(int, input().split())), list(map(int, input().split()))
a[a.index(0)] = b[0]
print('Yes' if k > 1 or a != sorted(a) else 'No') | Codeforces Round 418 (Div. 2) | CF | 2,017 | 1 | 256 | An abandoned sentiment from past | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k... | Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. | null | In the first sample:
- Sequence a is 11, 0, 0, 14.
- Two of the elements are lost, and the candidates in b are 5 and 4.
- There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting seque... | [{"input": "4 2\n11 0 0 14\n5 4", "output": "Yes"}, {"input": "6 1\n2 3 0 8 9 10\n5", "output": "No"}, {"input": "4 1\n8 94 0 4\n89", "output": "Yes"}, {"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes"}] | 900 | ["constructive algorithms", "greedy", "implementation", "sortings"] | 96 | [{"input": "4 2\r\n11 0 0 14\r\n5 4\r\n", "output": "Yes\r\n"}, {"input": "6 1\r\n2 3 0 8 9 10\r\n5\r\n", "output": "No\r\n"}, {"input": "4 1\r\n8 94 0 4\r\n89\r\n", "output": "Yes\r\n"}, {"input": "7 7\r\n0 0 0 0 0 0 0\r\n1 2 3 4 5 6 7\r\n", "output": "Yes\r\n"}, {"input": "40 1\r\n23 26 27 28 31 35 38 40 43 50 52 53 ... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 61 | 0 | 29677284 | n=int(input())
#k=[]
k=input().split()
i=0
k.sort()
if int(k[n])>int(k[n-1]):
print('YES')
else:
print('NO') | 88 | 46 | 0 | 157877192 | import sys
input = sys.stdin.readline
n = int(input())
w = sorted(map(int, input().split()))
if w[n] == w[n-1]:
print("NO")
else:
print("YES") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 77 | 0 | 30044263 | n = int(input(''))
a = input('')
b = sorted(a.split())
if int(b[n-1]) < int(b[n]):
print('YES')
else:
print('NO') | 88 | 46 | 0 | 189799761 | # LUOGU_RID: 100288399
n, a = int(input()), []
t = input().split()
for x in t: a.append(int(x))
a.sort()
if a[n] > a[n - 1]: print("YES")
else: print("NO") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 62 | 0 | 29868692 | n=int(input())
str=input()
arr= str.split()
arr.sort()
if arr[n-1]==arr[n]:
print("NO")
else:
print("YES") | 88 | 46 | 0 | 213243425 | # LUOGU_RID: 114908305
n=int(input())
alist=list(map(int,input().split()))
alist.sort()
if alist[n]>alist[n-1]:
print("YES")
else:
print("NO") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 62 | 5,632,000 | 34226787 | a=int(input())
b=input()
b=b.split(' ')
b.sort()
c=len(b)//2
if b[c]==b[c-1]:
print('NO')
else:
print('YES') | 88 | 46 | 0 | 215073561 | n = int(input())
r = input()
ratings =[]
int_ratings =[]
counter = 0
for x in r:
if x == " ":
ratings.append(r[0:r.index(x)])
r = r.replace(r[0:r.index(x)+1], "", 1)
ratings.append(r)
for x in ratings:
int_ratings.append(int(x))
int_ratings.sort()
for x in int_ratings[0:n]:
if int_r... | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 62 | 0 | 29660553 | n = int(input())
a = []
s = input()
t = s.split()
for k in t:
if k != " ":
a.append(k)
a = sorted(a)
if a[n-1] == a[n]:
print("NO")
else:
print("YES") | 88 | 61 | 0 | 29648246 | n = int(input())
a = input().strip().split(' ')
for i in range(len(a)):
a[i] = int(a[i])
a.sort()
if a[n-1] >= a[n]:
print("NO")
else:
print("YES") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 62 | 0 | 29660327 | n = int(input())
a = input().split()
team_a = []
team_b = []
arr = sorted(a)
#print(arr)
for i in range(0, len(a)//2):team_b.append(arr[i])
for i in range(len(a)//2, len(a)):team_a.append(arr[i])
if(team_a[0] > team_b[-1]):
print("YES")
else:
print("NO") | 88 | 61 | 0 | 29648679 | n = int(input())
arr = sorted(map(int, input().split()))
arr1 = arr[:n]
arr2 = arr[n:]
if arr1[-1] >= arr2[0]:
print("NO")
else:
print("YES") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 77 | 0 | 30044378 | n = int(input(''))
a = input('').split()
for b in a:
b = int(b)
a.sort()
if a[n-1] < a[n]:
print('YES')
else:
print('NO') | 88 | 61 | 0 | 29652842 | import sys
def main():
n = int(sys.stdin.readline())
liste = list(map(int, sys.stdin.readline().split()))
liste.sort()
if liste[n-1] < liste[n]:
print("YES")
else:
print("NO")
main() | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 46 | 0 | 29663806 | n = int(input())
a = [i for i in input().split()]
a.sort()
st = 'YES'
if a[n-1] == a[n]:
st='NO'
print(st) | 88 | 61 | 0 | 29937775 | a = []
n = int(input())
a = input().split()
for i in range(n*2):
a[i] = int(a[i])
a.sort()
##print(a[n-1], a[n])
if(a[n-1] == a[n]):
print("NO")
else:
print("YES") | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
845/A | 845 | A | Python 3 | TESTS | 6 | 77 | 0 | 29925938 | n = int(input())
ratings = input().split(" ")
ratings.sort()
if ratings[n - 1] == ratings[n]:
print("NO")
else:
print("YES") | 88 | 61 | 4,300,800 | 133323495 | n = int(input())
p = sorted(list(map(int,input().split())))
print(('NO','YES')[p[n]>p[n-1]]) | Educational Codeforces Round 27 | ICPC | 2,017 | 1 | 256 | Chess Tourney | Berland annual chess tournament is coming!
Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizers sh... | The first line contains one integer n (1 ≤ n ≤ 100).
The second line contains 2·n integers a1, a2, ... a2n (1 ≤ ai ≤ 1000). | If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | null | null | [{"input": "2\n1 3 2 4", "output": "YES"}, {"input": "1\n3 3", "output": "NO"}] | 1,100 | ["implementation", "sortings"] | 88 | [{"input": "2\r\n1 3 2 4\r\n", "output": "YES\r\n"}, {"input": "1\r\n3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 2 2 3 3 3 3\r\n", "output": "NO\r\n"}, {"input": "5\r\n1 1 1 1 1 2 2 2 2 2\r\n", "output": "YES\r\n"}, {"input": "10\r\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1... | false | stdio | null | true |
671/A | 671 | A | Python 3 | TESTS | 40 | 888 | 5,222,400 | 17866913 | from math import *
ax, ay, bx, by, cx, cy = [int(t) for t in input().split()]
n = int(input())
dist = 0
maxv = [[-99999999, -99999999], [-99999999, -99999999]]
index = [[0,0], [0,0]]
def update(d, idx, p):
global maxv, index
if d > maxv[p][0]:
maxv[p][1] = maxv[p][0]
index[p][1] = index[p][0]
... | 148 | 826 | 13,107,200 | 151388689 | import math
class PoV:
def __init__(self,x,y):
self.x = x
self.y = y
def __sub__(self,o): return PoV(self.x-o.x,self.y-o.y)
def __abs__(self): return math.sqrt(self.x*self.x+self.y*self.y)
def minDet(a,b):
n = len(a)-1
pre = [0]*(n+1)
suf = [0]*(n+2)
pre[0] = float('inf... | Codeforces Round 352 (Div. 1) | CF | 2,016 | 2 | 256 | Recycling Bottles | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c... | First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.
Then follow n lines, each of them contains t... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checke... | null | Consider the first sample.
Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$.
Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$.
Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt... | [{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}] | 1,800 | ["dp", "geometry", "greedy", "implementation"] | 148 | [{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95... | false | stdio | import sys
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
with open(output_path) as f:
correct = f.read().strip()
with open(submission_path) as f:
submission = f.read().strip()
try:
correct_val = float(correct)
subm... | true |
997/A | 997 | A | Python 3 | TESTS | 15 | 155 | 3,891,200 | 45398240 | # 00101101001
n, x, y = map(int, input().split())
line = input()
temp = line.split('1')
cnt = 0
#print(temp)
for i in temp:
if len(i) > 0:
cnt += 1
print(min(y*cnt, y+x*(cnt-1))) | 115 | 77 | 2,764,800 | 205185457 | n,x,y = map(int,input().split())
s = input()
s += '1'
count = 0
cnt = 0
for i in range(n + 1):
if s[i] == '1':
if count:
cnt += 1
count = 0
else:
count += 1
if cnt == 0:
print(0)
else:
print(min((cnt - 1) * x + y,cnt * y)) | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
789/B | 789 | B | Python 3 | PRETESTS | 13 | 93 | 12,902,400 | 25903791 | from sys import stdin, stdout
b, q, l, m = map(int, stdin.readline().rstrip().split())
badInts = set([int(a) for a in stdin.readline().rstrip().split()])
totalInts = 0
if q==0:
if 0 not in badInts:
totalInts = -1
elif b in badInts:
totalInts = 0
else:
totalInts = 1
elif b==0:
... | 116 | 93 | 15,667,200 | 25931548 | B1, Q, L, M = map(int, input().split())
As = set(map(int, input().split()))
Bs = []
tmp = B1
cnt = 0
while abs(tmp) <= L and cnt < 100:
if tmp not in As:
Bs.append(tmp)
tmp *= Q
cnt += 1
if 32 < len(Bs):
print('inf')
else:
print(len(Bs)) | Codeforces Round 407 (Div. 2) | CF | 2,017 | 1 | 256 | Masha and geometric depression | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ..., where for each i > 1 the respective term satisfies the condition bi = ... | The first line of input contains four integers b1, q, l, m (-109 ≤ b1, q ≤ 109, 1 ≤ l ≤ 109, 1 ≤ m ≤ 105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integer... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | null | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
... | [{"input": "3 2 30 4\n6 14 25 48", "output": "3"}, {"input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0"}, {"input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf"}] | 1,700 | ["brute force", "implementation", "math"] | 116 | [{"input": "3 2 30 4\r\n6 14 25 48\r\n", "output": "3"}, {"input": "123 1 2143435 4\r\n123 11 -5453 141245\r\n", "output": "0"}, {"input": "123 1 2143435 4\r\n54343 -13 6 124\r\n", "output": "inf"}, {"input": "3 2 25 2\r\n379195692 -69874783\r\n", "output": "4"}, {"input": "3 2 30 3\r\n-691070108 -934106649 -220744807\... | false | stdio | null | true |
997/A | 997 | A | Python 3 | TESTS | 15 | 93 | 1,024,000 | 230901965 | n, x, y = map(int, input().split())
s = input()
zero = 0
for i, c in enumerate(s):
if c == '0' and (i == 0 or s[i-1] == '1'):
zero += 1
print(min(y*zero, x*(zero-1)+y)) | 115 | 77 | 2,969,600 | 168498916 | def rev():
ret=0
i=0
while i<n and s[i]=='1':i+=1
while i<n:
if s[i]=='1':
while i<n and s[i]=='1':i+=1
if i<n:ret+=x
else:i+=1
return ret+y
def change():
ret1,ret2=0,0
cnt=0
for i in s:
if i=='1':cnt+=1
ret1=(cnt*y)+(n*y)
i=0
... | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
997/A | 997 | A | PyPy 3-64 | TESTS | 15 | 139 | 39,731,200 | 157202162 | import sys
def II(): return int(sys.stdin.readline())
def LI(): return [int(num) for num in sys.stdin.readline().split()]
def SI(): return sys.stdin.readline().rstrip()
n, x, y = LI()
old_s = SI()
s = [old_s[0]]
prev = old_s[0]
for si in old_s:
if si != prev:
prev = si
s.append(si)
s = "".join(... | 115 | 77 | 20,889,600 | 201858445 | import sys
input = lambda: sys.stdin.readline().rstrip()
n,x,y = map(int, input().split())
S = input()
A = [S[0]]
for c in S[1:]:
if c==A[-1]:
continue
else:
A.append(c)
cnt = A.count('0')
if cnt==0:
print(0)
else:
print(y+min((cnt-1)*x, (cnt-1)*y)) | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
997/A | 997 | A | Python 3 | TESTS | 10 | 343 | 1,024,000 | 188358820 | def flip(s, startIndex):
flag = False
i1 = i2 = 0
for i in range(startIndex, len(s)):
if s[i] == "1":
flag = True
i1 = i
break
if flag:
i2 = i1
for i in range(i1, len(s)):
if s[i] == "0":
i2 = i - 1
b... | 115 | 78 | 921,600 | 205314625 | n,x,y=map(int,input().split(' '))
w=str(input())
cnt=int(w[0]=='0')
for i in range(1,n):
if w[i]=='0' and w[i-1]=='1': cnt+=1
if cnt==0:
print(0)
else:
res=y+min(x,y)*(cnt-1)
print(res) | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
997/A | 997 | A | Python 3 | TESTS | 15 | 233 | 1,126,400 | 47706443 | l = [()]
n = input().split(' ')
s = input()
x = int(n[1])
y = int(n[2])
com = ""
nn = 0
for i in s:
if len(com) ==0 or com[-1] != i:
com+=i
if(i == '0'):
nn+=1
print(min(nn*y, (nn-1)*x+y)) | 115 | 92 | 4,300,800 | 132037205 | def main():
n,x,y = map(int,input().split())
s = input()
curr = ''
zero = 0
for i in s:
if i != curr:
if curr == '0':
zero += 1
curr = i
if curr == '0':
zero += 1
min_val = float('inf')
for i in range(zero,0,-1):
min_val ... | Codeforces Round 493 (Div. 1) | CF | 2,018 | 1 | 256 | Convert to Ones | You've got a string $$$a_1, a_2, \dots, a_n$$$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $$$a_i, a_{i + 1}, \ldots, a_j$$$ ($$$1\leq i\leq j\leq n$$$) a substring of string $$$a$$$.
You can apply the following operations any number of times:
- Choose some substring of string $$$a$$... | The first line of input contains integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 300\,000, 0 \leq x, y \leq 10^9$$$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $$$a$$$ of len... | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $$$0$$$, if you do not need to perform any operations. | null | In the first sample, at first you need to reverse substring $$$[1 \dots 2]$$$, and then you need to invert substring $$$[2 \dots 5]$$$.
Then the string was changed as follows:
«01000» $$$\to$$$ «10000» $$$\to$$$ «11111».
The total cost of operations is $$$1 + 10 = 11$$$.
In the second sample, at first you need to i... | [{"input": "5 1 10\n01000", "output": "11"}, {"input": "5 10 1\n01000", "output": "2"}, {"input": "7 2 3\n1111111", "output": "0"}] | 1,500 | ["brute force", "greedy", "implementation", "math"] | 115 | [{"input": "5 1 10\r\n01000\r\n", "output": "11\r\n"}, {"input": "5 10 1\r\n01000\r\n", "output": "2\r\n"}, {"input": "7 2 3\r\n1111111\r\n", "output": "0\r\n"}, {"input": "1 60754033 959739508\r\n0\r\n", "output": "959739508\r\n"}, {"input": "1 431963980 493041212\r\n1\r\n", "output": "0\r\n"}, {"input": "1 314253869 ... | false | stdio | null | true |
979/B | 979 | B | Python 3 | TESTS | 94 | 62 | 716,800 | 194127133 | from sys import stdin ,stdout
input=stdin.readline
from collections import Counter , defaultdict
def print(*args, end='\n', sep=' ') -> None:
stdout.write(sep.join(map(str, args)) + end)
n= int(input()) ; a=input().strip() ; lenth=len(a) ; ku=sh=ka=min(n,lenth) ; c1=Counter(a) ; c2=Counter(input().strip()) ; c3... | 184 | 93 | 7,782,400 | 125617453 | from collections import Counter
def f(x):
return max(list(Counter(x).values()))
n=int(input())
z=input()
l=len(z)
a=f(z)
b=f(input())
c=f(input())
def v(x):
if x==l:
return x-1
else:
return x+1
if n==1:
a, b, c=v(a), v(b), v(c)
if a>b and a>c:
print("Kuro")
elif b>a a... | Codeforces Round 482 (Div. 2) | CF | 2,018 | 1 | 256 | Treasure Hunt | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed th... | Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw". | null | In the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon int... | [{"input": "3\nKuroo\nShiro\nKatie", "output": "Kuro"}, {"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces", "output": "Shiro"}, {"input": "1\nabcabc\ncbabac\nababca", "output": "Katie"}, {"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE", "output": "Draw"}] | 1,800 | ["greedy"] | 184 | [{"input": "3\r\nKuroo\r\nShiro\r\nKatie\r\n", "output": "Kuro\r\n"}, {"input": "7\r\ntreasurehunt\r\nthreefriends\r\nhiCodeforces\r\n", "output": "Shiro\r\n"}, {"input": "1\r\nabcabc\r\ncbabac\r\nababca\r\n", "output": "Katie\r\n"}, {"input": "15\r\nfoPaErcvJ\r\nmZaxowpbt\r\nmkuOlaHRE\r\n", "output": "Draw\r\n"}, {"in... | false | stdio | null | true |
603/A | 603 | A | Python 3 | TESTS | 7 | 77 | 4,812,800 | 26640717 | n = int(input())
s = input().strip()
ret = 1
nb2 = 0
for i in range(1,n):
if s[i-1] != s[i]:
ret += 1
else:
nb2 += 1
if nb2 >= 2:
ret += 2
elif n >= 2:
if s[0] == s[1] or s[-1] == s[-2]:
ret += 1
print(ret) | 116 | 61 | 102,400 | 228864100 | # brownfox2k6
n = int(input())
s = input()
alt = 1
for i in range(1, n):
alt += s[i] != s[i-1]
# at most we can get +2
ans = min(n, alt + 2)
print(ans) | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
603/A | 603 | A | Python 3 | TESTS | 7 | 109 | 6,758,400 | 14930988 | input()
a = input()
s = []
for c in a:
if not s or s[-1][0] != c:
s.append([c, 1])
else:
s[-1][1] += 1
s2 = sorted(s, key=lambda x: x[1])
delta = 0
if s2[-1][1] >= 3 or len(s2) > 1 and s2[-2][1] >= 2:
delta = 2
elif s[0][1] >= 2 or s[-1][1] >= 2:
delta = 1
print(len(s) + delta) | 116 | 62 | 0 | 170713558 | n,s,c=int(input()),input(),3
for i in range(n-1):c+=s[i]!=s[i+1]
print(min(n,c)) | Codeforces Round 334 (Div. 1) | CF | 2,015 | 2 | 256 | Alternative Thinking | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not... | The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000).
The following line contains a binary string of length n representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | null | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | [{"input": "8\n10000011", "output": "5"}, {"input": "2\n01", "output": "2"}] | 1,600 | ["dp", "greedy", "math"] | 116 | [{"input": "8\r\n10000011\r\n", "output": "5\r\n"}, {"input": "2\r\n01\r\n", "output": "2\r\n"}, {"input": "5\r\n10101\r\n", "output": "5\r\n"}, {"input": "75\r\n010101010101010101010101010101010101010101010101010101010101010101010101010\r\n", "output": "75\r\n"}, {"input": "11\r\n00000000000\r\n", "output": "3\r\n"}, ... | false | stdio | null | true |
127/B | 127 | B | PyPy 3-64 | TESTS | 49 | 62 | 0 | 180987651 | import sys
from itertools import combinations
def qinput():
return sys.stdin.readline().strip()
def qprint(string):
sys.stdout.write(str(string))
def solve(n, a):
counts = {}
frames = 0
for stick in a:
if stick in counts:
counts[stick] += 1
else:
counts[sti... | 93 | 46 | 0 | 166756707 | n = int(input())
a = list(map(int, input().split()))
a.sort()
prev = None
counter = 0
pairs = 0
for stick in a:
counter += 1
if stick != prev:
counter = 1
elif counter == 2:
pairs += 1
counter = 0
prev = stick
print(pairs // 2) | Codeforces Beta Round 93 (Div. 2 Only) | CF | 2,011 | 1 | 256 | Canvas Frames | Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whose lengths equal a1, a2, ... an. Nicholas does not want to break the... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of sticks. The second line contains n space-separated integers. The i-th integer equals the length of the i-th stick ai (1 ≤ ai ≤ 100). | Print the single number — the maximum number of frames Nicholas can make for his future canvases. | null | null | [{"input": "5\n2 4 3 2 3", "output": "1"}, {"input": "13\n2 2 4 4 4 4 6 6 6 7 7 9 9", "output": "3"}, {"input": "4\n3 3 3 5", "output": "0"}] | 1,000 | ["implementation"] | 93 | [{"input": "5\r\n2 4 3 2 3\r\n", "output": "1"}, {"input": "13\r\n2 2 4 4 4 4 6 6 6 7 7 9 9\r\n", "output": "3"}, {"input": "4\r\n3 3 3 5\r\n", "output": "0"}, {"input": "2\r\n3 5\r\n", "output": "0"}, {"input": "9\r\n1 2 3 4 5 6 7 8 9\r\n", "output": "0"}, {"input": "14\r\n2 4 2 6 2 3 4 1 4 5 4 3 4 1\r\n", "output": "... | false | stdio | null | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.