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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
327/C | 327 | C | PyPy 3-64 | TESTS | 4 | 92 | 2,150,400 | 174870955 | n=input(); ans= 0;d=int(input()); c = len(n)
for x in range(c) :
if n[x] == '0' or n[x] == '5' :
ans+=2**x; a = x+c
for i in range(1,d) :
ans+=2**a
a+=c
print(ans) | 33 | 280 | 1,740,800 | 176646198 | # 327C - TsunamiNoLetGo
s=input()
k=int(input())
p=10**9+7
n=len(s)
amodp = (pow(2,k*n,p)-1)%p
b1modp = pow ( (pow(2,n,p) -1 + p)%p , p-2 , p )
MOD = (amodp*b1modp) % p
ans=0
for i in range(len(s)):
if(s[i]=='5' or s[i]=='0'):
ans+=pow(2,i,10**9+7)
Ans=0
Ans+= ans*( MOD )
Ans%=p
print(Ans) | Codeforces Round 191 (Div. 2) | CF | 2,013 | 1 | 256 | Magic Five | There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways... | In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k. | Print a single integer — the required number of ways modulo 1000000007 (109 + 7). | null | In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d... | [{"input": "1256\n1", "output": "4"}, {"input": "13990\n2", "output": "528"}, {"input": "555\n2", "output": "63"}] | 1,700 | ["combinatorics", "math"] | 33 | [{"input": "1256\r\n1\r\n", "output": "4\r\n"}, {"input": "13990\r\n2\r\n", "output": "528\r\n"}, {"input": "555\r\n2\r\n", "output": "63\r\n"}, {"input": "14\r\n178\r\n", "output": "0\r\n"}, {"input": "277557766562106078327886194146355351781887756238383139670139581436190170050799912854698535037185625049275351767138797... | false | stdio | null | true |
327/C | 327 | C | PyPy 3-64 | TESTS | 4 | 310 | 14,028,800 | 231272220 | import math
import random
import sys
import decimal
def solve():
a = str(sys.stdin.readline().strip())
k = int(sys.stdin.readline())
res = 0
mod = 10 ** 9 + 7
for i in range(len(a)):
if int(a[i]) % 5 == 0:
x = i
ll = k - 1
# e = 2 ** (x - 1) * (2 + 2 ... | 33 | 310 | 4,812,800 | 223275637 | M=10**9+7
s=[int(e) for e in input()]
q=len(s)
k=int(input())
b=sum(pow(2,i,M) for i in range(q) if s[i]==0 or s[i]==5)%M
Q=pow(2,q,M)
print((b*(pow(Q,k,M)-1)*pow(Q-1,-1,M))%M) | Codeforces Round 191 (Div. 2) | CF | 2,013 | 1 | 256 | Magic Five | There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways... | In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k. | Print a single integer — the required number of ways modulo 1000000007 (109 + 7). | null | In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d... | [{"input": "1256\n1", "output": "4"}, {"input": "13990\n2", "output": "528"}, {"input": "555\n2", "output": "63"}] | 1,700 | ["combinatorics", "math"] | 33 | [{"input": "1256\r\n1\r\n", "output": "4\r\n"}, {"input": "13990\r\n2\r\n", "output": "528\r\n"}, {"input": "555\r\n2\r\n", "output": "63\r\n"}, {"input": "14\r\n178\r\n", "output": "0\r\n"}, {"input": "277557766562106078327886194146355351781887756238383139670139581436190170050799912854698535037185625049275351767138797... | false | stdio | null | true |
792/F | 792 | F | Python 3 | TESTS | 4 | 498 | 12,083,200 | 88761570 | #site : https://codeforces.com/contest/792/problem/F
#Spells characterized by 2 values : x[i] and y[i]
#Doesn't have to use spell for int(x) amounts of seconds
#x = damage , y = mana cost , z = seconds
#deals x * z damage spends y * z mana
#If no mana is left , canUseSpell = False
#Can fight monsters : t[j] and h[j] .... | 36 | 873 | 15,564,800 | 37535361 | #!/usr/bin/env python3
# solution after hint
# (instead of best hit/mana spell store convex hull of spells)
# O(n^2) instead of O(n log n)
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
spell_chull = [(0, 0)] # lower hull _/
def is_... | Educational Codeforces Round 18 | ICPC | 2,017 | 2 | 256 | Mages and Monsters | Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ... | The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight.
i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106).
Using them you can restore queries this way: let j be the index... | For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise. | null | In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with... | [{"input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO"}] | 3,100 | ["data structures", "geometry"] | 36 | [{"input": "3 100\r\n1 4 9\r\n2 19 49\r\n2 19 49\r\n", "output": "YES\r\nNO\r\n"}, {"input": "10 442006988299\r\n2 10 47\r\n1 9 83\r\n1 15 24\r\n2 19 47\r\n2 75 99\r\n2 85 23\r\n2 8 33\r\n2 9 82\r\n1 86 49\r\n2 71 49\r\n", "output": "NO\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "2 424978864039\r\n2 7 3... | false | stdio | null | true |
327/C | 327 | C | Python 3 | TESTS | 4 | 124 | 0 | 175006786 | import sys
n = input()
ans = 0; r = 2**len(n); c = len(n)
d = int(sys.stdin.readline())
for x in range(c) :
if int(n[x])%5 == 0 : ans += ((1-(r**(d))) // (1-r) * 2**x) % 1000000007
print(ans ) | 33 | 342 | 3,481,600 | 209220368 | MOD = 1000000007
def power(x, n):
result = 1
while n > 0:
if n % 2 == 1:
result = (result * x) % MOD
x = (x * x) % MOD
n //= 2
return result
S = input().strip()
k = int(input())
len_s = len(S)
ans = 0
tmp = 0
for i in range(len_s - 1, -1, -1):
if S[i] == '0' or S[... | Codeforces Round 191 (Div. 2) | CF | 2,013 | 1 | 256 | Magic Five | There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.
Now Iahub wants to count the number of ways... | In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k. | Print a single integer — the required number of ways modulo 1000000007 (109 + 7). | null | In the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.
In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.
In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to d... | [{"input": "1256\n1", "output": "4"}, {"input": "13990\n2", "output": "528"}, {"input": "555\n2", "output": "63"}] | 1,700 | ["combinatorics", "math"] | 33 | [{"input": "1256\r\n1\r\n", "output": "4\r\n"}, {"input": "13990\r\n2\r\n", "output": "528\r\n"}, {"input": "555\r\n2\r\n", "output": "63\r\n"}, {"input": "14\r\n178\r\n", "output": "0\r\n"}, {"input": "277557766562106078327886194146355351781887756238383139670139581436190170050799912854698535037185625049275351767138797... | false | stdio | null | true |
792/F | 792 | F | Python 3 | TESTS | 33 | 701 | 15,872,000 | 37261618 | #!/usr/bin/env python3
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
(xb, yb) = (0, 1)
for i, qi in enumerate(qis):
(k, a, b) = qi
x = (a + j) % mod + 1
y = (b + j) % mod + 1
if k == 1:
if x * yb > y * xb:
(xb, yb) = (x, y)
... | 36 | 873 | 15,564,800 | 37535361 | #!/usr/bin/env python3
# solution after hint
# (instead of best hit/mana spell store convex hull of spells)
# O(n^2) instead of O(n log n)
[q, m] = map(int, input().strip().split())
qis = [tuple(map(int, input().strip().split())) for _ in range(q)]
mod = 10**6
j = 0
spell_chull = [(0, 0)] # lower hull _/
def is_... | Educational Codeforces Round 18 | ICPC | 2,017 | 2 | 256 | Mages and Monsters | Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells.
Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ... | The first line contains two integer numbers q and m (2 ≤ q ≤ 105, 1 ≤ m ≤ 1012) — the number of queries and the amount of mana at the beginning of every fight.
i-th of each next q lines contains three numbers ki, ai and bi (1 ≤ ki ≤ 2, 1 ≤ ai, bi ≤ 106).
Using them you can restore queries this way: let j be the index... | For every query of second type print YES if Vova is able to win the fight with corresponding monster and NO otherwise. | null | In first example Vova's character at first learns the spell with 5 damage and 10 mana cost per second. Next query is a fight with monster which can kill character in 20 seconds and has 50 health points. Vova kills it in 10 seconds (spending 100 mana). Next monster has 52 health, so Vova can't deal that much damage with... | [{"input": "3 100\n1 4 9\n2 19 49\n2 19 49", "output": "YES\nNO"}] | 3,100 | ["data structures", "geometry"] | 36 | [{"input": "3 100\r\n1 4 9\r\n2 19 49\r\n2 19 49\r\n", "output": "YES\r\nNO\r\n"}, {"input": "10 442006988299\r\n2 10 47\r\n1 9 83\r\n1 15 24\r\n2 19 47\r\n2 75 99\r\n2 85 23\r\n2 8 33\r\n2 9 82\r\n1 86 49\r\n2 71 49\r\n", "output": "NO\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\nYES\r\n"}, {"input": "2 424978864039\r\n2 7 3... | false | stdio | null | true |
272/D | 272 | D | PyPy 3 | TESTS | 2 | 154 | 0 | 117479770 | n=int(input())
a=sorted([[i,1] for i in list(map(int,input().split()))]+[[i,2] for i in list(map(int,input().split()))])
m=int(input())
d=f=0
e=1
for i in range(1,2*n):
if a[i][0]!=a[i-1][0]:
b=1
for j in range(f-d+1,i-d+1):
b*=j
if j-f+d-1<=i-f:
b/=j-f+d
... | 51 | 654 | 15,769,600 | 106221161 | from sys import stdin,stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int,stdin.readline().split()))
for _ in range(1):#nmbr()):
n=nmbr()
a=lst()
b=lst()
M=nmbr()
tot={}
ans=1
mp={}
for v,v1 in zip(a,b):
tot[v]=tot.get(v,0)+1
tot[v1]=tot.get(v1,0)+1
... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.
The last line contains integer m (2 ≤ m ≤ 109 + 7). | In the single line print the remainder after dividing the answer to the problem by number m. | null | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [{"input": "1\n1\n2\n7", "output": "1"}, {"input": "2\n1 2\n2 3\n11", "output": "2"}] | 1,600 | ["combinatorics", "math", "sortings"] | 51 | [{"input": "1\r\n1\r\n2\r\n7\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n1 2\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n1009\r\n", "output": "16\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n1 2 3 5 3\r\n12\r\n", "output": "0\r\n"}, {"input... | false | stdio | null | true |
272/D | 272 | D | PyPy 3 | TESTS | 4 | 216 | 0 | 117491376 | n=int(input())
y=list(map(int,input().split()))
z=list(map(int,input().split()))
a=sorted([[y[i],i] for i in range(n)]+[[z[i],i] for i in range(n)])
f=0
for i in range(1,2*n):
if a[i]==a[i-1]:
f+=1
m=int(input())
c=1
b=[]
for i in range(1,2*n+1):
c*=i
c%=m
b.append(c)
e=1/(2**f)
d=0
for i in ran... | 51 | 778 | 47,718,400 | 124594862 | n = int(input()) #tamaño de las sucesiones
a_n = input().split() #sucesion a_n
b_n = input().split() #sucesion b_n
k = int(input()) #numero para obtener un resultado de la forma km + r con 0 <= r < k
def solution(n, a_n, b_n, k):
c_n = {} #sucesion c_n que representa la union de a_n con b_n
... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.
The last line contains integer m (2 ≤ m ≤ 109 + 7). | In the single line print the remainder after dividing the answer to the problem by number m. | null | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [{"input": "1\n1\n2\n7", "output": "1"}, {"input": "2\n1 2\n2 3\n11", "output": "2"}] | 1,600 | ["combinatorics", "math", "sortings"] | 51 | [{"input": "1\r\n1\r\n2\r\n7\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n1 2\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n1009\r\n", "output": "16\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n1 2 3 5 3\r\n12\r\n", "output": "0\r\n"}, {"input... | false | stdio | null | true |
272/D | 272 | D | PyPy 3 | TESTS | 2 | 186 | 0 | 117869009 | n=int(input())
y=list(map(int,input().split()))
z=list(map(int,input().split()))
a=sorted([[y[i],i] for i in range(n)]+[[z[i],i] for i in range(n)])
f=0
for i in range(1,2*n):
if a[i]==a[i-1]:
f+=1
m=int(input())
d=0
e=1
for i in range(1,2*n):
if a[i][0]!=a[i-1][0]:
for j in range(1,i-d+1):
... | 51 | 872 | 23,244,800 | 94951314 | from math import sqrt,ceil,gcd
from collections import defaultdict
def modInverse(b,m):
g = gcd(b, m)
if (g != 1):
# print("Inverse doesn't exist")
return -1
else:
# If b and m are relatively prime,
# then modulo inverse is b^(m-2) mode m
return pow(b, m - 2, m)
d... | Codeforces Round 167 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Two Sequences | Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in th... | The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). The third line contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 109). The numbers in the lines are separated by spaces.
The last line contains integer m (2 ≤ m ≤ 109 + 7). | In the single line print the remainder after dividing the answer to the problem by number m. | null | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | [{"input": "1\n1\n2\n7", "output": "1"}, {"input": "2\n1 2\n2 3\n11", "output": "2"}] | 1,600 | ["combinatorics", "math", "sortings"] | 51 | [{"input": "1\r\n1\r\n2\r\n7\r\n", "output": "1\r\n"}, {"input": "2\r\n1 2\r\n2 3\r\n11\r\n", "output": "2\r\n"}, {"input": "2\r\n1 2\r\n1 2\r\n4\r\n", "output": "1\r\n"}, {"input": "4\r\n1 2 3 4\r\n4 3 2 1\r\n1009\r\n", "output": "16\r\n"}, {"input": "5\r\n1 2 3 3 5\r\n1 2 3 5 3\r\n12\r\n", "output": "0\r\n"}, {"input... | false | stdio | null | true |
620/D | 620 | D | PyPy 3 | TESTS | 2 | 93 | 0 | 29683053 | def SortByFirst(input):
return input[0]
def Find_2_Nearest(input,left,right,value):
if right == left:
return [input[right - 1],input[right],input[right + 1]]
if right - left == 1:
if input[left][0] == value:
return [input[left],input[left]]
elif input[right][0] == value:
... | 24 | 2,995 | 152,166,400 | 92182162 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
sum_a, sum_b = sum(a), sum(b)
delta = sum_b - sum_a
ans = abs(delta)
ans_swap = []
for i in range(n):
for j in range(m):
if abs((sum_a - a[i] + b[j]) - (sum_b + a[i] - b... | Educational Codeforces Round 6 | ICPC | 2,016 | 3 | 256 | Professor GukiZ and Two Arrays | Professor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb. So he wants to minimize the value v = |sa - sb|.
In one operation professor can swap some element from the array a and some element f... | The first line contains integer n (1 ≤ n ≤ 2000) — the number of elements in the array a.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109) — the elements of the array a.
The third line contains integer m (1 ≤ m ≤ 2000) — the number of elements in the array b.
The fourth line contains m integers bj ( - 109 ... | In the first line print the minimal value v = |sa - sb| that can be got with no more than two swaps.
The second line should contain the number of swaps k (0 ≤ k ≤ 2).
Each of the next k lines should contain two integers xp, yp (1 ≤ xp ≤ n, 1 ≤ yp ≤ m) — the index of the element in the array a and the index of the ele... | null | null | [{"input": "5\n5 4 3 2 1\n4\n1 1 1 1", "output": "1\n2\n1 1\n4 2"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "0\n0"}, {"input": "5\n1 2 3 4 5\n4\n1 2 3 4", "output": "1\n1\n3 1"}] | 2,200 | ["binary search", "two pointers"] | 24 | [{"input": "5\r\n5 4 3 2 1\r\n4\r\n1 1 1 1\r\n", "output": "1\r\n2\r\n1 1\r\n4 2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "0\r\n0\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n4\r\n1 2 3 4\r\n", "output": "1\r\n1\r\n3 1\r\n"}, {"input": "1\r\n-42\r\n1\r\n-86\r\n", "output": "44\r\n0\r\n"}, {"input": "1\r\n-21\... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input
with open(input_path) as f:
n = int(f.readline().strip())
a = list(map(int, f.readline().strip().split()))
m = int(f.readline().strip())
b = list(map(int, f.readline().strip().split()))
# Read r... | true |
340/E | 340 | E | PyPy 3 | TESTS | 2 | 748 | 61,849,600 | 85542541 | #lahub and Permutations
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
res = 1
while p > 0:
if p % 2 == 0:
n = n ** 2 % mod
p //= 2
else:
res = res * n % mod
... | 18 | 154 | 3,379,200 | 232103838 | M=10**9+7
R=10**4
Fact=[1]*(R+1)
for i in range(2,R+1):
Fact[i]=(i*Fact[i-1])%M
Facthyp=[1]*(R+1)
Facthyp[R]=pow(Fact[R],M-2,M)
for i in range(R-1,-1,-1):
Facthyp[i]=((i+1)*Facthyp[i+1])%M
def C(n,k):
if n<k or n<0 or k<0:
return 0
return (Fact[n]*Facthyp[n-k]*Facthyp[k])%M
n=int(input())
a=[int... | Codeforces Round 198 (Div. 2) | CF | 2,013 | 1 | 256 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | null | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [{"input": "5\n-1 -1 4 3 -1", "output": "2"}] | 2,000 | ["combinatorics", "math"] | 18 | [{"input": "5\r\n-1 -1 4 3 -1\r\n", "output": "2\r\n"}, {"input": "8\r\n2 4 5 3 -1 8 -1 6\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 -1 7 1 6\r\n", "output": "4\r\n"}, {"input": "6\r\n-1 -1 -1 -1 -1 -1\r\n", "output": "265\r\n"}, {"input": "2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "10\r\n4 10 -1 1 6 8 9 2 ... | false | stdio | null | true |
340/E | 340 | E | Python 3 | TESTS | 2 | 186 | 307,200 | 102144502 | M =pow(10,9) + 7
def iahub_and_permutations(n,p):
k = len([i for i in p if i == -1])
f = factorial(k)
s =[f[k]]
for i in range(1,k+1):
s_i =(c(k,i,f) * f[k-i]) % M
s.append(s_i)
r = 1
result = 0
for t in s:
result = (result + (r * t)) % M
r *= -1
return... | 18 | 186 | 2,252,800 | 141588352 | '''Author- Akshit Monga'''
from sys import stdin, stdout
input = stdin.readline
mod=1000000007
N = MAXN = 2005
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)
def InverseofNumber(p):
naturalNumInverse[0] = naturalNumInverse[1] = 1
for i in range(2, N + 1, 1)... | Codeforces Round 198 (Div. 2) | CF | 2,013 | 1 | 256 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | null | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [{"input": "5\n-1 -1 4 3 -1", "output": "2"}] | 2,000 | ["combinatorics", "math"] | 18 | [{"input": "5\r\n-1 -1 4 3 -1\r\n", "output": "2\r\n"}, {"input": "8\r\n2 4 5 3 -1 8 -1 6\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 -1 7 1 6\r\n", "output": "4\r\n"}, {"input": "6\r\n-1 -1 -1 -1 -1 -1\r\n", "output": "265\r\n"}, {"input": "2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "10\r\n4 10 -1 1 6 8 9 2 ... | false | stdio | null | true |
340/E | 340 | E | Python 3 | TESTS | 2 | 62 | 0 | 141893249 | n = int(input())
p = list(map(int,input().split()))
k= p.count(-1)
dp = [0]*(10001)
dp[1]=0
dp[2]=1
dp[3]=2
for i in range(4,n+1):
dp[i]=(dp[i-1]*(i-1)+dp[i-2]*(i-1))%1000000007
print(dp[k])
# Fri Jan 07 2022 09:35:54 GMT+0000 (Coordinated Universal Time) | 18 | 216 | 4,812,800 | 153656474 | import sys
def fact(be, en):
res, res2 = [1] * (en + 1), [1] * (en + 1)
for i in range(be, en + 1):
res[i] = mult(res[i - 1], i)
res2[i] = inv(res[i])
return res, res2
def ncr(n, r):
if n < r:
return 0
return mult(mult(facs[n], invs[n - r]), invs[r])
mod = 10 ** 9 + 7
a... | Codeforces Round 198 (Div. 2) | CF | 2,013 | 1 | 256 | Iahub and Permutations | Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his research work.
The girl finds an important permutation for the resea... | The first line contains integer n (2 ≤ n ≤ 2000). On the second line, there are n integers, representing Iahub's important permutation after Iahubina replaces some values with -1.
It's guaranteed that there are no fixed points in the given permutation. Also, the given sequence contains at least two numbers -1 and each... | Output a single integer, the number of ways Iahub could recover his permutation, modulo 1000000007 (109 + 7). | null | For the first test example there are two permutations with no fixed points are [2, 5, 4, 3, 1] and [5, 1, 4, 3, 2]. Any other permutation would have at least one fixed point. | [{"input": "5\n-1 -1 4 3 -1", "output": "2"}] | 2,000 | ["combinatorics", "math"] | 18 | [{"input": "5\r\n-1 -1 4 3 -1\r\n", "output": "2\r\n"}, {"input": "8\r\n2 4 5 3 -1 8 -1 6\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 -1 7 1 6\r\n", "output": "4\r\n"}, {"input": "6\r\n-1 -1 -1 -1 -1 -1\r\n", "output": "265\r\n"}, {"input": "2\r\n-1 -1\r\n", "output": "1\r\n"}, {"input": "10\r\n4 10 -1 1 6 8 9 2 ... | false | stdio | null | true |
690/D1 | 690 | D1 | PyPy 3 | TESTS | 5 | 124 | 20,172,800 | 86081750 | h,w = list(map(int,input().split()))
arr = []
for i in range(h):
arr.append(list(input()))
c = 1
if ("B" in arr[h-1]):
for i in range(arr[h-1].index("B"),w - arr[h-1][::-1].index("B")):
s = 0
for g in range(h):
if arr[g][i] != ".":
s+=1
if s == 0:
... | 119 | 46 | 0 | 140331902 | n, m = map(int, input().split())
a = [input() for i in range(n)]
ans = 0
i = 0
while i < m:
if a[n-1][i] == "B":
ans += 1
while i < m and a[n-1][i] == "B":
i += 1
i += 1
print(ans) | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 0.5 | 256 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise. | The number of wall segments in the input configuration. | null | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | [{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\... | 1,200 | [] | 119 | [{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n... | false | stdio | null | true |
690/F1 | 690 | F1 | Python 3 | TESTS | 5 | 31 | 102,400 | 223515608 | def solve():
n=int(input())
adj=[[] for i in range(n+1)]
for _ in range(n-1):
a,b=[int(x) for x in input().split()]
adj[a].append(b)
adj[b].append(a)
"""for i in range(1,n):
print(i,adj[i],end=" ")"""
ans=0
for i in range(1,n):
val=len(adj[i])
val=... | 19 | 61 | 204,800 | 146886555 | o = {}
n = int(input())
for _ in range(n-1):
one, two = map(int, input().split())
if o.get(one):
o[one] += 1
else:
o[one] = 1
if o.get(two):
o[two] += 1
else:
o[two] = 1
# print(o)
trees = 0
for key, value in o.items():
trees += int(((value-1)/2)*(1+(value... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Tree of Life (easy) | Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.
On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (... | The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n).... | Print one integer – the number of lifelines in the tree. | null | In the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5. | [{"input": "4\n1 2\n1 3\n1 4", "output": "3"}, {"input": "5\n1 2\n2 3\n3 4\n3 5", "output": "4"}] | 1,300 | [] | 19 | [{"input": "4\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "3"}, {"input": "5\r\n1 2\r\n2 3\r\n3 4\r\n3 5\r\n", "output": "4"}, {"input": "2\r\n1 2\r\n", "output": "0"}, {"input": "3\r\n2 1\r\n3 2\r\n", "output": "1"}, {"input": "10\r\n5 1\r\n1 2\r\n9 3\r\n10 5\r\n6 3\r\n8 5\r\n2 7\r\n2 3\r\n9 4\r\n", "output": "11"}] | false | stdio | null | true |
690/D1 | 690 | D1 | PyPy 3 | TESTS | 5 | 93 | 0 | 119584876 | n,m=map(int,input().split())
k1=[]
for i in range(n):
k=list(map(str,input()))
k1.append(k)
k2=[0]*m
l=m
r=0
for i in range(n):
for j in range(m):
if k1[i][j]=="B":
k2[j]+=1
if j<l:
l=j
if j>r:
r=j
print(k2[l:r+1].count(0)+1) | 119 | 46 | 0 | 144044966 | r,c=list(map(int,input().split()))
for i in range(r):
walls=input()
count=0
for i in range(c):
if i==0 and walls[i]=='.':
continue
elif i==0 and walls[i]=='B':
count+=1
elif walls[i]=='B' and walls[i-1]=='.':
count+=1
else:
continue
print(count) | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 0.5 | 256 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise. | The number of wall segments in the input configuration. | null | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | [{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\... | 1,200 | [] | 119 | [{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n... | false | stdio | null | true |
689/D | 689 | D | Python 3 | TESTS | 2 | 31 | 102,400 | 192806177 | import sys
from types import GeneratorType
from collections import defaultdict
import math
inf = float("inf")
class FastIO:
def __init__(self):
return
@staticmethod
def _read():
return sys.stdin.readline().strip()
def read_int(self):
return int(self._read())
def read_flo... | 94 | 982 | 456,908,800 | 159169002 | dx=[[0]*(1<<20) for _ in range(20)]
dy=[[0]*(1<<20) for _ in range(20)]
lg=[0]*(1<<20)
def mx(l,r):
p=lg[r-l+1]
return max(dx[p][l],dx[p][r-(1<<p)+1])
def mn(l,r):
p=lg[r-l+1]
return min(dy[p][l],dy[p][r-(1<<p)+1])
if __name__ == '__main__':
n=int(input())
dx[0][1:n]=[int(x) for x in input()... | Codeforces Round 361 (Div. 2) | CF | 2,016 | 2 | 512 | Friends and Subsequences | Mike and !Mike are old childhood rivals, they are opposite in everything they do, except programming. Today they have a problem they cannot solve on their own, but together (with you) — who knows?
Every one of them has an integer sequences a and b of length n. Being given a query of the form of pair of integers (l, r)... | The first line contains only integer n (1 ≤ n ≤ 200 000).
The second line contains n integer numbers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the sequence a.
The third line contains n integer numbers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109) — the sequence b. | Print the only integer number — the number of occasions the robot will count, thus for how many pairs $$\max_{i=l}^{r}a_i = \min_{i=l}^{r}b_i$$ is satisfied. | null | The occasions in the first sample case are:
1.l = 4,r = 4 since max{2} = min{2}.
2.l = 4,r = 5 since max{2, 1} = min{2, 3}.
There are no occasions in the second sample case since Mike will answer 3 to any query pair, but !Mike will always answer 1. | [{"input": "6\n1 2 3 2 1 4\n6 7 1 2 3 2", "output": "2"}, {"input": "3\n3 3 3\n1 1 1", "output": "0"}] | 2,100 | ["binary search", "data structures"] | 94 | [{"input": "6\r\n1 2 3 2 1 4\r\n6 7 1 2 3 2\r\n", "output": "2\r\n"}, {"input": "3\r\n3 3 3\r\n1 1 1\r\n", "output": "0\r\n"}, {"input": "17\r\n714413739 -959271262 714413739 -745891378 926207665 -404845105 -404845105 -959271262 -189641729 -670860364 714413739 -189641729 192457837 -745891378 -670860364 536388097 -95927... | false | stdio | null | true |
796/D | 796 | D | Python 3 | TESTS | 4 | 1,575 | 60,416,000 | 194891184 | from collections import deque, defaultdict
def answer(police_locations, hashmap, d, city):
result, visited, queue = set(), set(), deque()
for police in police_locations:
queue.append((police, d))
while queue:
curr, distance = queue.popleft()
if distance == 0:
continue
... | 135 | 1,184 | 107,827,200 | 127039977 | import io, os, sys
from collections import deque
pypyin = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cpyin = sys.stdin.readline
input = pypyin if 'PyPy' in sys.version else cpyin
def strput():
return input().decode() if 'PyPy' in sys.version else input()
# code starts here
def main():
n, k, d = [i... | Codeforces Round 408 (Div. 2) | CF | 2,017 | 2 | 256 | Police Stations | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | The first line contains three integers n, k, and d (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — each denoting the city each police station ... | In the first line, print one integer s that denotes the maximum number of roads that can be shut down.
In the second line, print s distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | null | In the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | [{"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "1\n5"}, {"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "output": "2\n4 5"}] | 2,100 | ["constructive algorithms", "dfs and similar", "dp", "graphs", "shortest paths", "trees"] | 135 | [{"input": "6 2 4\r\n1 6\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n", "output": "1\r\n3 "}, {"input": "6 3 2\r\n1 5 6\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n5 6\r\n", "output": "2\r\n4 5 "}, {"input": "10 1 5\r\n5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "0\r\n"}, {"input": "11 1 5\r\n6\r\n1 ... | false | stdio | null | true |
796/D | 796 | D | PyPy 3-64 | TESTS | 4 | 1,591 | 119,808,000 | 154001304 | from sys import stdin,stdout
from collections import deque
n,k,d = map(int,stdin.readline().split()) #value of d does not matter here
stations = map(lambda x: int(x) - 1, stdin.readline().split()) #offset by 1 due to zero indexing
adjList = [[] for _ in range(n)]
for i in range(n-1):
a,b = map(int,stdin.readline()... | 135 | 1,325 | 54,374,400 | 83862601 | import math
import sys
input = sys.stdin.readline
inf = int(1e9)
n, m, d = map(int, input().split())
l = [0] * (n - 1)
r = [0] * (n - 1)
g = [[] for _ in range(n)]
station = [int(_) - 1 for _ in input().split()]
for i in range(n - 1):
l[i], r[i] = map(lambda i : int(i) - 1 , input().split())
g[l[i]].append(i)
... | Codeforces Round 408 (Div. 2) | CF | 2,017 | 2 | 256 | Police Stations | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | The first line contains three integers n, k, and d (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — each denoting the city each police station ... | In the first line, print one integer s that denotes the maximum number of roads that can be shut down.
In the second line, print s distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | null | In the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | [{"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "1\n5"}, {"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "output": "2\n4 5"}] | 2,100 | ["constructive algorithms", "dfs and similar", "dp", "graphs", "shortest paths", "trees"] | 135 | [{"input": "6 2 4\r\n1 6\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n", "output": "1\r\n3 "}, {"input": "6 3 2\r\n1 5 6\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n5 6\r\n", "output": "2\r\n4 5 "}, {"input": "10 1 5\r\n5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "0\r\n"}, {"input": "11 1 5\r\n6\r\n1 ... | false | stdio | null | true |
537/D | 538 | D | Python 3 | PRETESTS | 0 | 46 | 4,710,400 | 10891729 | import sys
n = int(input())
s = [input() for i in range(n)]
a = [[1] * (2 * n) for i in range(2 * n)]
for i in range(n):
for j in range(n):
if s[i][j] != 'o':
continue
for x in range(n):
for y in range(n):
if s[x][y] == '.':
a[n + x - i][n... | 41 | 1,138 | 1,024,000 | 62668650 | import math
from sys import stdin
from math import ceil
import sys
if __name__ == '__main__':
n = int(input())
table = list()
# newT = list()
for i in range(n):
table.append(input())
# for i in range(2 * n):
# newT.append(1)
# table = [input() for i in range(n)]
newT = [[1] *... | VK Cup 2015 - Wild Card Round 2 | IOI | 2,015 | 2 | 256 | Weird Chess | Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous.
Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of piece... | The first line contains a single integer n (1 ≤ n ≤ 50).
The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values:
- o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some ... | If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2n - 1) × (2n - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the in... | null | In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight. | [{"input": "5\noxxxx\nx...x\nx...x\nx...x\nxxxxo", "output": "YES\n....x....\n....x....\n....x....\n....x....\nxxxxoxxxx\n....x....\n....x....\n....x....\n....x...."}, {"input": "6\n.x.x..\nx.x.x.\n.xo..x\nx..ox.\n.x.x.x\n..x.x.", "output": "YES\n...........\n...........\n...........\n....x.x....\n...x...x...\n.....o..... | 1,800 | ["brute force", "constructive algorithms", "implementation"] | 41 | [{"input": "5\r\noxxxx\r\nx...x\r\nx...x\r\nx...x\r\nxxxxo\r\n", "output": "YES\r\nxxxxxxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nx...xxxxx\r\nxxxxoxxxx\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxx...x\r\nxxxxxxxxx\r\n"}, {"input": "6\r\n.x.x..\r\nx.x.x.\r\n.xo..x\r\nx..ox.\r\n.x.x.x\r\n..x.x.\r\n", "output": "YES\r\nxxxxxxxxxxx\r\nxxxx... | false | stdio | import sys
def read_grid(path, n):
with open(path, 'r') as f:
lines = [line.strip() for line in f.readlines()]
return [list(line) for line in lines]
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r')... | true |
690/D1 | 690 | D1 | PyPy 3-64 | TESTS | 2 | 61 | 0 | 179829691 | n, m = list(map(int, input().split()))
grid = []
for _ in range(n):
grid.append([i for i in input()])
def hole(row, col):
if row > 0 and col > 0 and grid[row - 1][col - 1] == "B":
grid[row - 1][col - 1] = "."
hole(row - 1, col - 1)
if row > 0 and grid[row - 1][col] == 'B':
grid[row - 1][col] = "... | 119 | 46 | 0 | 159638169 | a , b = map(int , input().split())
for i in range(a):
l = list(map(str , input().split()))
if i == a-1:
l = str(l)
l = l.replace('.' , ' '); l = l.replace('[' , ' '); l = l.replace(']' , ' '); l = l.replace("'" , ' ');
fragments = list(map(str , l.split()))
print(len(fragments)... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 0.5 | 256 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise. | The number of wall segments in the input configuration. | null | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | [{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\... | 1,200 | [] | 119 | [{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n... | false | stdio | null | true |
690/D1 | 690 | D1 | Python 3 | TESTS | 3 | 31 | 0 | 189108883 | row, column = [*map(int, input().split())]
str = ''
Sum = 0
for i in range(row):
str = input()
if i == row - 1:
for j in range(column - 1):
if j == 0 and str[j] == "B":
Sum += 1
elif str[j] == "." and str[j + 1] == "B":
Sum += 1
print(Sum) | 119 | 46 | 0 | 180058226 | m,n=map(int,input().split())
for rows in range(m):
row = input()
row="."+row
print(row.count(".B")) | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 0.5 | 256 | The Wall (easy) | "The zombies are lurking outside. Waiting. Moaning. And when they come..."
"When they come?"
"I hope the Wall is high enough."
Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segment... | The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:
- each of the R lines contains a string of length C,
- the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise. | The number of wall segments in the input configuration. | null | In the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second. | [{"input": "3 7\n.......\n.......\n.BB.B..", "output": "2"}, {"input": "4 5\n..B..\n..B..\nB.B.B\nBBB.B", "output": "2"}, {"input": "4 6\n..B...\nB.B.BB\nBBB.BB\nBBBBBB", "output": "1"}, {"input": "1 1\nB", "output": "1"}, {"input": "10 7\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n.......\n...B...\... | 1,200 | [] | 119 | [{"input": "3 7\r\n.......\r\n.......\r\n.BB.B..\r\n", "output": "2\r\n"}, {"input": "4 5\r\n..B..\r\n..B..\r\nB.B.B\r\nBBB.B\r\n", "output": "2\r\n"}, {"input": "4 6\r\n..B...\r\nB.B.BB\r\nBBB.BB\r\nBBBBBB\r\n", "output": "1\r\n"}, {"input": "1 1\r\nB\r\n", "output": "1\r\n"}, {"input": "10 7\r\n.......\r\n.......\r\n... | false | stdio | null | true |
690/C3 | 690 | C3 | Python 3 | TESTS | 3 | 374 | 5,632,000 | 35531302 | class Brain:
def __init__(self, valor, parent):
self.value = valor
self.childs = []
self.parent = parent
def addChild(self, child):
self.childs.append(child)
def getChilds(self):
return self.childs
class Zombie:
def __init__(self):
self.firstBrain = Bra... | 18 | 951 | 178,073,600 | 165319619 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wr... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Brain Network (hard) | Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of ... | The first line of the input contains one number n – the number of brains in the final nervous system (2 ≤ n ≤ 200000). In the second line a history of zombie's nervous system evolution is given. For convenience, we number all the brains by 1, 2, ..., n in the same order as they appear in the nervous system (the zombie ... | Output n - 1 space-separated numbers – the brain latencies after the brain number k is added, for k = 2, 3, ..., n. | null | null | [{"input": "6\n1\n2\n2\n1\n5", "output": "1 2 2 3 4"}] | 2,200 | ["trees"] | 18 | [{"input": "2\r\n1\r\n", "output": "1 "}, {"input": "3\r\n1\r\n2\r\n", "output": "1 2 "}, {"input": "10\r\n1\r\n1\r\n1\r\n1\r\n3\r\n3\r\n7\r\n5\r\n5\r\n", "output": "1 2 2 2 3 3 4 5 5 "}, {"input": "120\r\n1\r\n1\r\n2\r\n2\r\n3\r\n3\r\n4\r\n4\r\n5\r\n5\r\n6\r\n6\r\n7\r\n7\r\n8\r\n8\r\n9\r\n9\r\n10\r\n10\r\n11\r\n11\r\n... | false | stdio | null | true |
796/D | 796 | D | PyPy 3 | TESTS | 5 | 1,091 | 110,592,000 | 189014057 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def bfs(p):
q, k = list(p), 0
color = [0] * (n + 1)
for i in p:
color[i] = i
e = []
for k in range(n):
i = q[k]
ci = color[i]
for j in G[i]:
if not color[j]:
q... | 135 | 1,372 | 73,932,800 | 126162316 | import math
import sys
input = sys.stdin.readline
inf = int(1e9)
n, m, d = map(int, input().split())
l = [0] * (n - 1)
r = [0] * (n - 1)
g = [[] for _ in range(n)]
station = [int(_) - 1 for _ in input().split()]
for i in range(n - 1):
l[i], r[i] = map(lambda i : int(i) - 1 , input().split())
g[l[i]].append(i)
... | Codeforces Round 408 (Div. 2) | CF | 2,017 | 2 | 256 | Police Stations | Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own.
Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos... | The first line contains three integers n, k, and d (2 ≤ n ≤ 3·105, 1 ≤ k ≤ 3·105, 0 ≤ d ≤ n - 1) — the number of cities, the number of police stations, and the distance limitation in kilometers, respectively.
The second line contains k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — each denoting the city each police station ... | In the first line, print one integer s that denotes the maximum number of roads that can be shut down.
In the second line, print s distinct integers, the indices of such roads, in any order.
If there are multiple answers, print any of them. | null | In the first sample, if you shut down road 5, all cities can still reach a police station within k = 4 kilometers.
In the second sample, although this is the only largest valid set of roads that can be shut down, you can print either 4 5 or 5 4 in the second line. | [{"input": "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6", "output": "1\n5"}, {"input": "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6", "output": "2\n4 5"}] | 2,100 | ["constructive algorithms", "dfs and similar", "dp", "graphs", "shortest paths", "trees"] | 135 | [{"input": "6 2 4\r\n1 6\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n", "output": "1\r\n3 "}, {"input": "6 3 2\r\n1 5 6\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n5 6\r\n", "output": "2\r\n4 5 "}, {"input": "10 1 5\r\n5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n5 6\r\n6 7\r\n7 8\r\n8 9\r\n9 10\r\n", "output": "0\r\n"}, {"input": "11 1 5\r\n6\r\n1 ... | false | stdio | null | true |
690/C3 | 690 | C3 | Python 3 | TESTS | 3 | 1,060 | 5,017,600 | 25767481 | n = int(input())
dep = [0] * n
anc = [[0] * 18 for _ in range(n)]
def dist(x, y):
s = dep[x] + dep[y]
if dep[x] > dep[y]:
x, y = y, x
diff = dep[y] - dep[x]
i = 0
while diff > 0:
if diff % 2 == 1:
y = anc[y][i]
diff /= 2
i += 1
if x == y:
ret... | 18 | 951 | 178,073,600 | 165319619 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.wr... | Helvetic Coding Contest 2016 online mirror (teams, unrated) | ICPC | 2,016 | 2 | 256 | Brain Network (hard) | Breaking news from zombie neurology! It turns out that – contrary to previous beliefs – every zombie is born with a single brain, and only later it evolves into a complicated brain structure. In fact, whenever a zombie consumes a brain, a new brain appears in its nervous system and gets immediately connected to one of ... | The first line of the input contains one number n – the number of brains in the final nervous system (2 ≤ n ≤ 200000). In the second line a history of zombie's nervous system evolution is given. For convenience, we number all the brains by 1, 2, ..., n in the same order as they appear in the nervous system (the zombie ... | Output n - 1 space-separated numbers – the brain latencies after the brain number k is added, for k = 2, 3, ..., n. | null | null | [{"input": "6\n1\n2\n2\n1\n5", "output": "1 2 2 3 4"}] | 2,200 | ["trees"] | 18 | [{"input": "2\r\n1\r\n", "output": "1 "}, {"input": "3\r\n1\r\n2\r\n", "output": "1 2 "}, {"input": "10\r\n1\r\n1\r\n1\r\n1\r\n3\r\n3\r\n7\r\n5\r\n5\r\n", "output": "1 2 2 2 3 3 4 5 5 "}, {"input": "120\r\n1\r\n1\r\n2\r\n2\r\n3\r\n3\r\n4\r\n4\r\n5\r\n5\r\n6\r\n6\r\n7\r\n7\r\n8\r\n8\r\n9\r\n9\r\n10\r\n10\r\n11\r\n11\r\n... | false | stdio | null | true |
261/A | 261 | A | Python 3 | TESTS | 3 | 92 | 102,400 | 160215420 | import dis
def solve(_,q,n,a):
q.sort(key=lambda a:-a)
discount = 0
for d in q:
if n>=d:
discount = d
break
a.sort(key=lambda a:-a)
discount2 = discount3 = discount
discount+=2
boxNum = n//d
sum=0
i=0
while n>i:
if discount2 == 0:
... | 45 | 310 | 7,680,000 | 111177282 | I=lambda:map(int,input().split())
m,q,n,a,r,k=int(input()),min(I()),int(input())-1,sorted(I()),0,0
while n>-1:
r+=a[n]
k+=1
if k==q:n-=3;k=0
else:n-=1
print(r) | Codeforces Round 160 (Div. 1) | CF | 2,013 | 2 | 256 | Maxim and Discounts | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).
The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices... | In a single line print a single integer — the answer to the problem. | null | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}] | 1,400 | ["greedy", "sortings"] | 45 | [{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46... | false | stdio | null | true |
261/A | 261 | A | Python 3 | TESTS | 3 | 122 | 0 | 30185746 | m = int(input())
q = [int(i) for i in input().split()]
n = int(input())
a = [int(i) for i in input().split()]
c = min(q)
a.sort()
price = 0
for i in range(n-c, 0, -2*c):
for j in range(c):
price += a[i+j]
for j in range(n%c):
price += a[j]
print(price) | 45 | 342 | 9,523,200 | 186268165 | m = int(input())
q = list(map(int,input().split()))
n = int(input())
a = list(map(int,input().split()))
q = sorted(q)
a = sorted(a,reverse = True)
count = 0
i = 0
cost = 0
while i<n:
if count==q[0]:
i+=2
count = 0
else:
count+=1
cost+=a[i]
i+=1
print(cost) | Codeforces Round 160 (Div. 1) | CF | 2,013 | 2 | 256 | Maxim and Discounts | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).
The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices... | In a single line print a single integer — the answer to the problem. | null | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}] | 1,400 | ["greedy", "sortings"] | 45 | [{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46... | false | stdio | null | true |
546/B | 546 | B | Python 3 | TESTS | 3 | 31 | 0 | 228056871 | n = int(input())
a = list(map(int,(input().split())))
c = []
counter = 0
for i in a:
if i not in c:
c.append(i)
else:
while i in c:
i -= 1
counter += 1
print(counter) | 49 | 62 | 307,200 | 11214027 | n = int(input())
a = list(map(int,input().split()))
a.sort()
c = 0
for i in range(1,n):
if a[i] > a[i-1]:
continue
c += a[i-1] + 1 - a[i]
a[i]= a[i-1] + 1
print(c) | Codeforces Round 304 (Div. 2) | CF | 2,015 | 3 | 256 | Soldier and Badges | Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.
For every pair of soldiers one of them should get a badge with strictly higher factor than the second... | First line of input consists of one integer n (1 ≤ n ≤ 3000).
Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge. | Output single integer — minimum amount of coins the colonel has to pay. | null | In first sample test we can increase factor of first badge by 1.
In second sample test we can increase factors of the second and the third badge by 1. | [{"input": "4\n1 3 1 4", "output": "1"}, {"input": "5\n1 2 3 2 5", "output": "2"}] | 1,200 | ["brute force", "greedy", "implementation", "sortings"] | 49 | [{"input": "4\r\n1 3 1 4\r\n", "output": "1"}, {"input": "5\r\n1 2 3 2 5\r\n", "output": "2"}, {"input": "5\r\n1 5 3 2 4\r\n", "output": "0"}, {"input": "10\r\n1 1 2 3 4 5 6 7 8 9\r\n", "output": "9"}, {"input": "11\r\n9 2 10 3 1 5 7 1 4 8 6\r\n", "output": "10"}, {"input": "4\r\n4 3 2 2\r\n", "output": "3"}, {"input":... | false | stdio | null | true |
543/D | 543 | D | Python 3 | TESTS | 3 | 93 | 8,704,000 | 124454470 | import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,it... | 42 | 514 | 72,294,400 | 199415564 | import sys
from typing import Callable, Generic, List, TypeVar
T = TypeVar("T")
class Rerooting(Generic[T]):
__slots__ = ("adjList", "_n", "_decrement")
def __init__(self, n: int, decrement: int = 0):
self.adjList = [[] for _ in range(n)]
self._n = n
self._decrement = decrement
... | Codeforces Round 302 (Div. 1) | CF | 2,015 | 2 | 256 | Road Improvement | The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that... | The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i. | Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i. | null | null | [{"input": "3\n1 1", "output": "4 3 3"}, {"input": "5\n1 2 3 4", "output": "5 8 9 8 5"}] | 2,300 | ["dp", "trees"] | 42 | [{"input": "3\r\n1 1\r\n", "output": "4 3 3"}, {"input": "5\r\n1 2 3 4\r\n", "output": "5 8 9 8 5"}, {"input": "31\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870... | false | stdio | null | true |
543/D | 543 | D | PyPy 3-64 | TESTS | 2 | 61 | 614,400 | 178102723 | def rerooting():
dp=[[E]*len(edge[v]) for v in range(n)]
# dfs1
memo=[E]*n
for v in order[::-1]:
res=E
for i in range(len(edge[v])):
if edge[v][i]==par[v]:
continue
dp[v][i]=memo[edge[v][i]]
res=merge(res,f(dp[v][i],edge[v][i]))
memo[v]=g(res,v)
# dfs2
memo2=[E]... | 42 | 1,310 | 135,577,600 | 214714289 | n = int(input())
p = list(map(int, input().split()))
mod = 10 ** 9 + 7
g = [[] for _ in range(n)]
for i in range(n - 1):
g[p[i] - 1].append(i + 1)
g[i + 1].append(p[i] - 1)
count = [[0, 1] for _ in range(n)]
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
... | Codeforces Round 302 (Div. 1) | CF | 2,015 | 2 | 256 | Road Improvement | The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that... | The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cities in the country. Next line contains n - 1 positive integers p2, p3, p4, ..., pn (1 ≤ pi ≤ i - 1) — the description of the roads in the country. Number pi means that the country has a road connecting city pi and city i. | Print n integers a1, a2, ..., an, where ai is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (109 + 7), if the capital of the country is at city number i. | null | null | [{"input": "3\n1 1", "output": "4 3 3"}, {"input": "5\n1 2 3 4", "output": "5 8 9 8 5"}] | 2,300 | ["dp", "trees"] | 42 | [{"input": "3\r\n1 1\r\n", "output": "4 3 3"}, {"input": "5\r\n1 2 3 4\r\n", "output": "5 8 9 8 5"}, {"input": "31\r\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870... | false | stdio | null | true |
545/B | 545 | B | Python 3 | TESTS | 1 | 31 | 0 | 205606150 | a = input()
b = input()
x = str(int(a) ^ int(b))
if x.count("1") %2 != 0 :
print("IMPOSSIBLE")
else :
res = ""
flag1 = True
for idx , value in enumerate(x) :
if value == "0":
res += str(a)[idx]
else:
if flag1 :
res += "1"
fl... | 54 | 93 | 307,200 | 221864627 | str_1, str_2 = input(), input()
new_string = ""
listOf_indices = 0
a = True
for i in range(len(str_1)):
if str_1[i] != str_2[i]:
if a:
new_string += str_1[i]
else:
new_string += str_2[i]
a = not a
listOf_indices += 1
else:
new_string += str_1[i]
if... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 1 | 256 | Equidistant String | Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance:
We will define the distance between two strings s and t of the same length consisting of digits zero and one as the num... | The first line contains string s of length n.
The second line contains string t of length n.
The length of string n is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one. | Print a string of length n, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes).
If there are multiple possible answers, print any of them. | null | In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101. | [{"input": "0001\n1011", "output": "0011"}, {"input": "000\n111", "output": "impossible"}] | 1,100 | ["greedy"] | 54 | [{"input": "0001\r\n1011\r\n", "output": "0011\r\n"}, {"input": "000\r\n111\r\n", "output": "impossible\r\n"}, {"input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\r\n0101111111000100010100001100010101000000011000000000011011000001100100001110111011111000001110... | 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:
s = f.readline().strip()
t = f.readline().strip()
n = len(s)
assert len(t) == n
with open(submission_path, 'r') as f:
submission... | true |
545/E | 545 | E | PyPy 3 | TESTS | 3 | 108 | 0 | 207066967 | import heapq
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def dijkstra(s):
inf = pow(10, 15) + 1
dist = [inf] * (n + 1)
dist[s] = 0
visit = [0] * (n + 1)
p = []
heapq.heappush(p, (dist[s], s))
while p:
d, u = heapq.heappop(p)
if dist[u] < d... | 62 | 2,635 | 76,288,000 | 184261586 | import heapq
n, m = map(int, input().split())
g = [[] for _ in range(n + 1)]
for i in range(1, m + 1):
u, v, w = map(int, input().split())
g[u].append((i, v, w))
g[v].append((i, u, w))
src = int(input())
pq = [(0, 0, src, -1)]
mk = [0] * (n + 1)
t = []
s = 0
while pq:
d, w, u, e = heapq.heappop(pq)
... | Codeforces Round 303 (Div. 2) | CF | 2,015 | 3 | 256 | Paths and Trees | Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows.
Let's assume that we are given a c... | The first line contains two numbers, n and m (1 ≤ n ≤ 3·105, 0 ≤ m ≤ 3·105) — the number of vertices and edges of the graph, respectively.
Next m lines contain three integers each, representing an edge — ui, vi, wi — the numbers of vertices connected by an edge and the weight of the edge (ui ≠ vi, 1 ≤ wi ≤ 109). It is... | In the first line print the minimum total weight of the edges of the tree.
In the next line print the indices of the edges that are included in the tree, separated by spaces. The edges are numbered starting from 1 in the order they follow in the input. You may print the numbers of the edges in any order.
If there are... | null | In the first sample there are two possible shortest path trees:
- with edges 1 – 3 and 2 – 3 (the total weight is 3);
- with edges 1 – 2 and 2 – 3 (the total weight is 2);
And, for example, a tree with edges 1 – 2 and 1 – 3 won't be a shortest path tree for vertex 3, because the distance from vertex 3 to vertex 2 in ... | [{"input": "3 3\n1 2 1\n2 3 1\n1 3 2\n3", "output": "2\n1 2"}, {"input": "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4", "output": "4\n2 3 4"}] | 2,000 | ["graphs", "greedy", "shortest paths"] | 62 | [{"input": "3 3\r\n1 2 1\r\n2 3 1\r\n1 3 2\r\n3\r\n", "output": "2\r\n1 2 \r\n"}, {"input": "4 4\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 1 2\r\n4\r\n", "output": "4\r\n2 3 4 \r\n"}, {"input": "4 5\r\n1 2 1\r\n1 3 1\r\n2 4 1\r\n3 4 1\r\n2 3 10\r\n1\r\n", "output": "3\r\n1 2 3 \r\n"}, {"input": "6 8\r\n1 2 30\r\n1 3 20\r\n2 3 50... | false | stdio | import sys
import heapq
def main():
input_path = sys.argv[1]
output_path = sys.argv[2]
submission_path = sys.argv[3]
# Read input
with open(input_path, 'r') as f:
n, m = map(int, f.readline().split())
edges = []
adj = [[] for _ in range(n+1)]
for idx in range(m):
... | true |
261/A | 261 | A | PyPy 3 | TESTS | 3 | 248 | 0 | 57768489 | import sys
def procesar(canastas, precios, total=[]):
if len(canastas) == 0:
return sum(total)
max_can = canastas[-1]
if max_can > len(precios):
return procesar(canastas[1:], precios, total)
for _ in range(max_can):
total.append(precios.pop())
if len(precios) <= 2:
... | 45 | 342 | 9,728,000 | 110169407 | m = int(input())
q = list(map(int, input().split()))
c = min(q)
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n):
if i % (c+2) < c:
res += a[n-1-i]
print(res) | Codeforces Round 160 (Div. 1) | CF | 2,013 | 2 | 256 | Maxim and Discounts | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).
The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices... | In a single line print a single integer — the answer to the problem. | null | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}] | 1,400 | ["greedy", "sortings"] | 45 | [{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46... | false | stdio | null | true |
261/A | 261 | A | Python 3 | TESTS | 2 | 216 | 0 | 82184623 | n=int(input())
a=list(map(int,input().split()))
m=int(input())
b=list(map(int,input().split()))
k=max(a)
s=0
for i in range(m):
if(i<k):
d=max(b)
s+=d
b.remove(d)
print(s) | 45 | 374 | 19,968,000 | 167172311 | import sys
input = sys.stdin.readline
m = int(input())
q = sorted(map(int, input().split()))
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
x = q[0]
c = 0
i = 0
while i < n:
if x + 2 < n:
c += sum(a[i:i+x])
i += x + 2
else:
c += sum(a[i:i+x])
break
print(c... | Codeforces Round 160 (Div. 1) | CF | 2,013 | 2 | 256 | Maxim and Discounts | Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a special basket, where he puts exactly qi items he buys. Under the term... | The first line contains integer m (1 ≤ m ≤ 105) — the number of discount types. The second line contains m integers: q1, q2, ..., qm (1 ≤ qi ≤ 105).
The third line contains integer n (1 ≤ n ≤ 105) — the number of items Maxim needs. The fourth line contains n integers: a1, a2, ..., an (1 ≤ ai ≤ 104) — the items' prices... | In a single line print a single integer — the answer to the problem. | null | In the first sample Maxim needs to buy two items that cost 100 and get a discount for two free items that cost 50. In that case, Maxim is going to pay 200.
In the second sample the best strategy for Maxim is to buy 3 items and get 2 items for free using the discount. In that case, Maxim is going to pay 150. | [{"input": "1\n2\n4\n50 50 100 100", "output": "200"}, {"input": "2\n2 3\n5\n50 50 50 50 50", "output": "150"}, {"input": "1\n1\n7\n1 1 1 1 1 1 1", "output": "3"}] | 1,400 | ["greedy", "sortings"] | 45 | [{"input": "1\r\n2\r\n4\r\n50 50 100 100\r\n", "output": "200\r\n"}, {"input": "2\r\n2 3\r\n5\r\n50 50 50 50 50\r\n", "output": "150\r\n"}, {"input": "1\r\n1\r\n7\r\n1 1 1 1 1 1 1\r\n", "output": "3\r\n"}, {"input": "18\r\n16 16 20 12 13 10 14 15 4 5 6 8 4 11 12 11 16 7\r\n15\r\n371 2453 905 1366 6471 4331 4106 2570 46... | false | stdio | null | true |
1298/E | 978 | F | Python 3 | TESTS | 5 | 31 | 0 | 197963178 | n,k=map(int,input().split())
a=list(map(int,input().split()))
f={}
pos={}
for i in range(n):
f[i]=0
for j in range(k):
x,y=map(int,input().split())
x-=1;y-=1
if a[x]<a[y]:
f[y]+=1
else:
f[x]+=1
s=[-1]+sorted(a)
#print(f)
for i in range(n):
res=a[i]
l=0
r=n
while r-l... | 41 | 343 | 34,508,800 | 168026382 | from collections import *
from heapq import *
from bisect import *
from itertools import *
from functools import *
from math import *
from string import *
import operator
import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
ratings = list(map(int, input().split()))
ans = [0... | Kotlin Heroes: Practice 3 | ICPC | 2,020 | 3 | 256 | Mentors | In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$.
A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $... | The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel.
The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ... | Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input. | null | In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b... | [{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}] | null | ["*special", "data structures", "implementation"] | 41 | [{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222... | false | stdio | null | true |
802/M | 802 | M | Python 3 | TESTS | 5 | 31 | 0 | 216622872 | n, a = map(int, input().split())
s = input()
if n == 8:
print(5)
if n == 10:
print(7)
if n == 5:
print(10)
if n == 6:
print(36)
if n == 1:
print(100) | 14 | 46 | 0 | 136757702 | #!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-24 23:46:53
LastEditTime: 2021-11-24 23:48:39
Description: April Fools' Problem (easy)
FilePath: CF802M.py
'''
def func():
n, k = map(int, input().strip().split())
lst = sorted(map(int, input().strip().split()))
print(sum(lst[:k]))
if ... | Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) | ICPC | 2,017 | 2 | 256 | April Fools' Problem (easy) | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). | Output one number. | null | null | [{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}] | 1,200 | ["greedy", "sortings"] | 14 | [{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1... | false | stdio | null | true |
802/M | 802 | M | Python 3 | TESTS | 1 | 62 | 0 | 111716721 | num,sample= input().split()
num = int(num)
sample = int(sample)
l = list(map(int,input().split()))
sum_sol = 0
while sample>0:
sum_sol = sum_sol+min(l)
for i in range(0,len(l)-1):
if(l[i]==min(l)):
l.pop(i)
break
sample = sample-1
pass
print(sum_sol) | 14 | 46 | 0 | 144049405 | n,k = list(map(int,input().split()))
arr= list(map(int,input().split()))
arr.sort()
summ=0
for i in range(k):
summ+=arr[i]
print(summ) | Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) | ICPC | 2,017 | 2 | 256 | April Fools' Problem (easy) | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). | Output one number. | null | null | [{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}] | 1,200 | ["greedy", "sortings"] | 14 | [{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1... | false | stdio | null | true |
258/D | 258 | D | Python 3 | TESTS | 5 | 218 | 307,200 | 64359073 | inp = input().split(' ')
val=[];
totNums = int(inp[0]); totOpt = int(inp[1]);
inp = input().split(' '); assert(len(inp) == totNums);
for it in inp: val.append(it)
dp = [[0.0 for _ in range(0,totNums)] for __ in range(0,totNums)]
for i in range(0,totNums):
for j in range(0,totNums):
if inp[i]>inp[j]: dp[i]... | 55 | 996 | 43,212,800 | 130036596 | import bisect
import copy
import decimal
import fractions
import functools
import heapq
import itertools
import math
import random
import sys
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _hea... | Codeforces Round 157 (Div. 1) | CF | 2,012 | 2 | 256 | Little Elephant and Broken Sorting | The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n.
This time the Little Elephant has permutation p1, p2, ..., pn. Its sort... | The first line contains two integers n and m (1 ≤ n, m ≤ 1000, n > 1) — the permutation size and the number of moves. The second line contains n distinct integers, not exceeding n — the initial permutation. Next m lines each contain two integers: the i-th line contains integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the... | In the only line print a single real number — the answer to the problem. The answer will be considered correct if its relative or absolute error does not exceed 10 - 6. | null | null | [{"input": "2 1\n1 2\n1 2", "output": "0.500000000"}, {"input": "4 3\n1 3 2 4\n1 2\n2 3\n1 4", "output": "3.000000000"}] | 2,600 | ["dp", "math", "probabilities"] | 55 | [{"input": "2 1\r\n1 2\r\n1 2\r\n", "output": "0.500000000\r\n"}, {"input": "4 3\r\n1 3 2 4\r\n1 2\r\n2 3\r\n1 4\r\n", "output": "3.000000000\r\n"}, {"input": "7 4\r\n7 6 4 2 1 5 3\r\n1 3\r\n2 1\r\n7 2\r\n3 5\r\n", "output": "11.250000000\r\n"}, {"input": "10 1\r\n1 2 3 4 5 6 7 8 9 10\r\n1 10\r\n", "output": "8.5000000... | 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_line = f.readline().strip()
correct = float(correct_line)
with open(submission_path) as f:
submitted_line = f.readline().strip()... | true |
803/E | 803 | E | PyPy 3 | TESTS | 2 | 124 | 0 | 118095842 | n,k=map(int,input().split())
s=input().strip()
dp=[[0]*(2*k) for i in range(n) ]
dp[0][1]=(s[0]=="?")|(s[0]=="W")
dp[0][0]=(s[0]=="?")|(s[0]=="D")
dp[0][-1]=(s[0]=="?")|(s[0]=="L")
for i in range(1,n-1):
for j in range(-k+1,k):
if s[i]=="?":
dp[i][j]|=dp[i-1][j]
if j!=-k+1:
... | 28 | 296 | 47,104,000 | 117989693 | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO,IOBase
def main():
n,k = map(int,input().split())
s = input().strip()
dp = [[0]*(2*k+5) for _ in range(n+1)]
# diff ; win/draw/lose
dp[0][0] = 1
prev = [[-1]*(2*k+5) for _ in range(n+1)]
for i i... | Educational Codeforces Round 20 | ICPC | 2,017 | 2 | 256 | Roma and Poker | Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser.
Last evening Roma started to play poker. He decided to spend no more than k virtual bourl... | The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000).
The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence. | If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO.
Otherwise print this sequence. If there are multiple answers, print any of them. | null | null | [{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}] | 2,000 | ["dp", "graphs"] | 28 | [{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\... | 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, k = map(int, f.readline().split())
s = f.readline().strip()
with open(submission_path, 'r') as f:
submission = f.read().strip()
... | true |
802/M | 802 | M | PyPy 3-64 | TESTS | 1 | 46 | 0 | 179116870 | a, k = input().split()
string = input()
a = min(list(string.split()))
print(int(a) * string.count(a) if string.count(a) < int(k) else int(k) * int(a)) | 14 | 46 | 0 | 165857669 | n,k=map(int,input().split())
l = [int(x) for x in input().split()]
l.sort()
print(sum(l[:k])) | Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) | ICPC | 2,017 | 2 | 256 | April Fools' Problem (easy) | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). | Output one number. | null | null | [{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}] | 1,200 | ["greedy", "sortings"] | 14 | [{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1... | false | stdio | null | true |
802/M | 802 | M | Python 3 | TESTS | 1 | 93 | 0 | 70822153 | a = input().split()
s = input().split()
s.sort()
d = 0
for i in range(int(a[1])):
d += int(s.pop(0))
print(d) | 14 | 46 | 0 | 166859784 | N,K=map(int,input().split())
A=list(map(int,input().split()))
print(sum(sorted(A)[:K])) | Helvetic Coding Contest 2017 online mirror (teams allowed, unrated) | ICPC | 2,017 | 2 | 256 | April Fools' Problem (easy) | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea... | The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104). | Output one number. | null | null | [{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}] | 1,200 | ["greedy", "sortings"] | 14 | [{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1... | false | stdio | null | true |
553/A | 553 | A | PyPy 3-64 | TESTS | 2 | 46 | 2,867,200 | 225728898 | def fact(n):
if(n<1):
return 1
return n * fact(n-1)
n = int(input())
prod = 1
sum = 0
for i in range(n):
k = int(input())
prod *= fact(sum+k-1)/fact(sum)/fact(k-1)
prod = prod % 1000000007
sum += k
print(int(prod)) | 27 | 46 | 0 | 11745129 | #! /usr/bin/env python3
k = int(input())
c = [int(input()) for _ in range(k)]
MOD = (10 ** 9 + 7)
def fact(x):
prod = 1
for i in range(1, x + 1):
prod *= i
return prod
def C(n, k):
prod = 1
for i in range(n - k + 1, n + 1):
prod *= i
return (prod // fact(k)) % MOD
prod = 1
c_... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
553/A | 553 | A | Python 3 | TESTS | 2 | 46 | 4,608,000 | 26643589 | k = int(input())
a = []
for _ in range(k):
a.append(int(input()))
n = sum(a)
N = 1000000007
def getCombi(a,n):
b = min(a,n-a)
ret = 1
for i in range(1,b+1):
ret = (ret*(n+1-i))//i
ret %= N
return ret
ret = 1
for i in range(k-1,0,-1):
ai = a[i] - 1
ni = sum(a[:i])
ret *= getCombi(ai,ni+ai)
re... | 27 | 46 | 0 | 136732218 | k = int(input())
colnum = []
for t in range(k):
a = int(input())
colnum.append(a)
def fact(m,n):
sumnum =1
for i in range(m,n+1):
sumnum*=i
return sumnum
m = colnum[0]+1
answ = 1
for i in range(1,k):
n = m+colnum[i]-2
answ *= fact(m,n)//fact(1,colnum[i]-1)
answ = answ%(10**9+7)
... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
447/B | 447 | B | Python 3 | TESTS | 2 | 93 | 307,200 | 84514730 | s = input()
n = len(s)
k = int(input())
lst = list(map(int, input().split()))
maxx = max(lst)
alphabets = 'abcdefghijklmnopqrstuvw'
ans = 0
index = 0
for i in range(n):
index = alphabets.find(s[i])
ans += lst[index]*(i+1)
for i in range(1, k+1):
ans += (n + i)*maxx
print(ans) | 24 | 46 | 0 | 143239480 | alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
string = input()
k = int(input())
w = list(map(int, input().split()))
dictWeight = {}
maxWeight = max(w)
for i in range(len(w)):
dictWeight[alpha[i]] = w[i]
ans = 0
for i in range(1, 1 + len(string)... | Codeforces Round #FF (Div. 2) | CF | 2,014 | 1 | 256 | DZY Loves Strings | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where
$$f(s) = \sum_{i=1}^{|s|} (w_{s_i} \cdot i).$$
Now DZY has a str... | The first line contains a single string s (1 ≤ |s| ≤ 103).
The second line contains a single integer k (0 ≤ k ≤ 103).
The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | null | In the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | [{"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41"}] | 1,000 | ["greedy", "implementation"] | 24 | [{"input": "abc\r\n3\r\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\r\n", "output": "41\r\n"}, {"input": "mmzhr\r\n3\r\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453\r\n", "output": "29978\r\n"}, {"input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\r... | false | stdio | null | true |
140/D | 140 | D | Python 3 | TESTS | 3 | 218 | 0 | 62210897 | n=int(input())
a=str(input()).split()
a=map(int,a)
a=sorted(a)
i=0
s=10
while s+a[i]<360:
s+=a[i]
i+=1
k=i
a[i]=a[i]-360+s
s=0
while s+a[i]<360:
s+=a[i]
i+=1
k+=1
print(k,' ',s) | 32 | 124 | 0 | 11634370 | N = int(input())
nums = list(map(int, input().split()))
nums.sort()
fulltime = 720
start = 10
penalty = 0
probs = 0
for t in nums:
if t+start <= fulltime:
start += t
probs += 1
if start > 360:
penalty += (start - 360)
print(probs, penalty) | Codeforces Round 100 | CF | 2,012 | 2 | 256 | New Year Contest | As Gerald sets the table, Alexander sends the greeting cards, and Sergey and his twins create an army of clone snowmen, Gennady writes a New Year contest.
The New Year contest begins at 18:00 (6.00 P.M.) on December 31 and ends at 6:00 (6.00 A.M.) on January 1. There are n problems for the contest. The penalty time fo... | The first line contains an integer n (1 ≤ n ≤ 100) — the number of the problems. The next line contains n space-separated integers ai (1 ≤ ai ≤ 720) — each number shows how much time in minutes Gennady will spend writing a solution to the problem. | Print two integers — the number of problems Gennady will solve and the total penalty time considering that he chooses the optimal strategy. | null | In the sample, one of Gennady's possible optimal strategies is as follows. At 18:10 (6:10 PM) he begins to write the first problem and solves it in 30 minutes (18:40 or 6.40 P.M.). At 18:40 (6.40 P.M.) he begins to write the second problem. There are 320 minutes left before the New Year, so Gennady does not have the ti... | [{"input": "3\n30 330 720", "output": "2 10"}] | 1,800 | ["greedy", "sortings"] | 32 | [{"input": "3\r\n30 330 720\r\n", "output": "2 10\r\n"}, {"input": "1\r\n720\r\n", "output": "0 0\r\n"}, {"input": "5\r\n100 200 300 400 500\r\n", "output": "3 250\r\n"}, {"input": "7\r\n120 110 100 110 120 120 50\r\n", "output": "6 420\r\n"}, {"input": "3\r\n350 340 360\r\n", "output": "2 340\r\n"}, {"input": "8\r\n15... | false | stdio | null | true |
140/B | 140 | B | Python 3 | TESTS | 5 | 218 | 0 | 40548211 | def f(k):
t = [0] * (n + 1)
for i, j in enumerate(map(int, input().split())): t[j] = i
t[k] = n
return t
n = int(input())
p = [f(i + 1) for i in range(n)]
s = f(0)
r = [1] * n
r[0] = 2
j = 1
for i in range(n):
if s[j] > s[i + 1]:
j = i + 1
for k in range(n):
if p[k][r[k]]... | 17 | 154 | 1,536,000 | 206064960 | def f():
t = [0] * n
for i, j in enumerate(input().split()): t[int(j) - 1] = i
return t
n = int(input())
p = [f() for i in range(n)]
s = f()
for x, t in enumerate(p):
i = j = x < 1
for y in range(n):
if x != y and s[y] < s[i]: i = y
if t[i] < t[j]: j = i
print(j + 1) | Codeforces Round 100 | CF | 2,012 | 2 | 256 | New Year Cards | As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ... | The first line contains an integer n (2 ≤ n ≤ 300) — the number of Alexander's friends, equal to the number of cards. Next n lines contain his friends' preference lists. Each list consists of n different integers from 1 to n. The last line contains Alexander's preference list in the same format. | Print n space-separated numbers: the i-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the i-th friend. If there are several solutions, print any of them. | null | In the sample, the algorithm of actions Alexander and his friends perform is as follows:
1. Alexander receives card 1 from the first friend.
2. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3.
3. Alexande... | [{"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "output": "2 1 1 4"}] | 1,800 | ["brute force", "greedy", "implementation"] | 17 | [{"input": "4\r\n1 2 3 4\r\n4 1 3 2\r\n4 3 1 2\r\n3 4 2 1\r\n3 1 2 4\r\n", "output": "2 1 1 3\r\n"}, {"input": "2\r\n1 2\r\n2 1\r\n2 1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n1 2 3\r\n2 3 1\r\n1 3 2\r\n3 2 1\r\n", "output": "2 3 1\r\n"}, {"input": "5\r\n1 4 2 3 5\r\n5 1 3 4 2\r\n3 2 4 1 5\r\n1 4 5 3 2\r\n5 2 3 4 1\... | false | stdio | null | true |
140/B | 140 | B | Python 3 | TESTS | 5 | 216 | 0 | 40552808 | def f():
t = [0] * n
for i, j in enumerate(input().split()): t[int(j) - 1] = i
return t
n = int(input())
p = [f() for i in range(n)]
s = f()
for k, t in enumerate(p):
t[k] = 1e9
i = j = k < 1
for k in range(n):
if s[k] < s[i]: i = k
if t[i] < t[j]: j = i
print(j + 1) | 17 | 186 | 716,800 | 198693301 | def f():
w = [0] * n
for i, j in enumerate(input().split()): w[int(j) - 1] = i
return w
n = int(input()) # read the inputs
p = [f() for i in range(n)]
s = f()
for x, w in enumerate(p):
i = j = x < 1
for y in range(n):
if x != y and s[y] < s[i]: i = y
if w[i] ... | Codeforces Round 100 | CF | 2,012 | 2 | 256 | New Year Cards | As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ... | The first line contains an integer n (2 ≤ n ≤ 300) — the number of Alexander's friends, equal to the number of cards. Next n lines contain his friends' preference lists. Each list consists of n different integers from 1 to n. The last line contains Alexander's preference list in the same format. | Print n space-separated numbers: the i-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the i-th friend. If there are several solutions, print any of them. | null | In the sample, the algorithm of actions Alexander and his friends perform is as follows:
1. Alexander receives card 1 from the first friend.
2. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3.
3. Alexande... | [{"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "output": "2 1 1 4"}] | 1,800 | ["brute force", "greedy", "implementation"] | 17 | [{"input": "4\r\n1 2 3 4\r\n4 1 3 2\r\n4 3 1 2\r\n3 4 2 1\r\n3 1 2 4\r\n", "output": "2 1 1 3\r\n"}, {"input": "2\r\n1 2\r\n2 1\r\n2 1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n1 2 3\r\n2 3 1\r\n1 3 2\r\n3 2 1\r\n", "output": "2 3 1\r\n"}, {"input": "5\r\n1 4 2 3 5\r\n5 1 3 4 2\r\n3 2 4 1 5\r\n1 4 5 3 2\r\n5 2 3 4 1\... | false | stdio | null | true |
14/D | 14 | D | PyPy 3 | TESTS | 0 | 122 | 0 | 218454418 | # Function to perform depth-first search and find the farthest node
def dfs(node, _from, graph, length, dist, furthest):
if length > dist:
dist = length
furthest = node
for u in range(len(graph[node])):
if not graph[node][u]:
continue
if u == _from:
contin... | 45 | 218 | 0 | 177565815 | def dfs(node, depth):
max_depth = 0
farthest_node = node
visit[node] = True
for neighbor in AdjList[node]:
if node == erase_1 and neighbor == erase_2:
continue
if node == erase_2 and neighbor == erase_1:
continue
if not visit[neighbor]:
temp1, ... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Two Paths | As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.
The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path ... | The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n). | Output the maximum possible profit. | null | null | [{"input": "4\n1 2\n2 3\n3 4", "output": "1"}, {"input": "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7", "output": "0"}, {"input": "6\n1 2\n2 3\n2 4\n5 4\n6 4", "output": "4"}] | 1,900 | ["dfs and similar", "dp", "graphs", "shortest paths", "trees", "two pointers"] | 45 | [{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n2 4\r\n5 4\r\n6 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n1 2\r\n", "output": "0\r\n"}, {"inp... | false | stdio | null | true |
553/A | 553 | A | Python 3 | TESTS | 2 | 93 | 307,200 | 90393062 | mod = 10 ** 9 + 7
def C(n, r):
if r > n - r:
r = n - r
val = 1
for i in range(r):
val *= n - i
val //= i + 1
val %= mod
return val
n = int(input())
a = []
for _ in range(n):
a.append(int(input()))
z = [0 for _ in range(n)]
z[0] = 1
cum = a[0]
for i in range(1, n):... | 27 | 46 | 0 | 143888945 | k=int(input()) #number of colors
c=[]
for i in range(0,k):
c.append(int(input())) #Ci
m=1000000007
import math
total=0
sum=1
for i in range(0,k):
total=total+c[i]
sum=sum*math.comb(total-1,c[i]-1) % m
print(sum) | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
14/D | 14 | D | PyPy 3-64 | TESTS | 0 | 92 | 0 | 219652718 | import sys
from collections import defaultdict
def add_edge(u, v):
graph[u].append(v)
graph[v].append(u)
def dfs(v, parent):
length1 = length2 = 0
for u in graph[v]:
if u == parent:
continue
length = dfs(u, v) + 1
if length >= length1:
length1, length2 =... | 45 | 248 | 307,200 | 11198347 | __author__ = 'Darren'
def solve():
def get_diameter(u):
depth, v = dfs(u, set())
return dfs(v, set())[0]
def dfs(u, visited):
visited.add(u)
max_depth, deepest_node = -1, u
for v in adj_list[u]:
if v not in visited:
depth, w = dfs(v, visite... | Codeforces Beta Round 14 (Div. 2) | ICPC | 2,010 | 2 | 64 | Two Paths | As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads.
The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path ... | The first line contains an integer n (2 ≤ n ≤ 200), where n is the amount of cities in the country. The following n - 1 lines contain the information about the roads. Each line contains a pair of numbers of the cities, connected by the road ai, bi (1 ≤ ai, bi ≤ n). | Output the maximum possible profit. | null | null | [{"input": "4\n1 2\n2 3\n3 4", "output": "1"}, {"input": "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7", "output": "0"}, {"input": "6\n1 2\n2 3\n2 4\n5 4\n6 4", "output": "4"}] | 1,900 | ["dfs and similar", "dp", "graphs", "shortest paths", "trees", "two pointers"] | 45 | [{"input": "4\r\n1 2\r\n2 3\r\n3 4\r\n", "output": "1\r\n"}, {"input": "7\r\n1 2\r\n1 3\r\n1 4\r\n1 5\r\n1 6\r\n1 7\r\n", "output": "0\r\n"}, {"input": "6\r\n1 2\r\n2 3\r\n2 4\r\n5 4\r\n6 4\r\n", "output": "4\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n3 1\r\n1 2\r\n", "output": "0\r\n"}, {"inp... | false | stdio | null | true |
553/C | 553 | C | Python 3 | TESTS | 2 | 124 | 409,600 | 98159553 | def dfsO(node, color):
# print(f"visiting node {node} with color {color}")
if colors[node] == -1:
colors[node] = color
else:
if colors[node] != color:
# print(f"Failed at vertex {node} visiting with color {color} having color {colors[node]}")
bipartite[0] = False
... | 67 | 264 | 25,497,600 | 197709814 | import sys
input = sys.stdin.buffer.readline
def find_root(root_dict, x):
L = []
while x != root_dict[x]:
L.append(x)
x = root_dict[x]
for y in L:
root_dict[y] = x
return x
p = 10**9+7
def process(n, G):
g = [[] for i in range(n+1)]
root_dict = [i for i in range(n+1)]
... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Love Triangles | There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (the... | The first line of input will contain two integers n, m (3 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000).
The next m lines will contain the description of the known relationships. The i-th line will contain three integers ai, bi, ci. If ci is 1, then ai and bi are in love, otherwise, they hate each other (1 ≤ ai, bi ≤ n, ai ≠ bi, $$... | Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1 000 000 007. | null | In the first sample, the four ways are to:
- Make everyone love each other
- Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this).
In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. | [{"input": "3 0", "output": "4"}, {"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0", "output": "1"}, {"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1", "output": "0"}] | 2,200 | ["dfs and similar", "dsu", "graphs"] | 67 | [{"input": "3 0\r\n", "output": "4\r\n"}, {"input": "4 4\r\n1 2 1\r\n2 3 1\r\n3 4 0\r\n4 1 0\r\n", "output": "1\r\n"}, {"input": "4 4\r\n1 2 1\r\n2 3 1\r\n3 4 0\r\n4 1 1\r\n", "output": "0\r\n"}, {"input": "100000 0\r\n", "output": "303861760\r\n"}, {"input": "100 3\r\n1 2 0\r\n2 3 0\r\n3 1 0\r\n", "output": "0\r\n"}, ... | false | stdio | null | true |
553/A | 553 | A | PyPy 3-64 | TESTS | 2 | 46 | 0 | 174196309 | def frac(v1,v2,v3):
loops = max(v1-v2,v3)
result = 1
for i in range(loops):
if(v1 != v2):
result = result*v1
v1 = v1 - 1
while(result % v3 == 0 and v3 > 1):
result /= v3
v3 = v3 - 1
if(v3 <= 1):
result = result % 1000000007... | 27 | 46 | 0 | 184122918 | from math import comb
mod=10**9+7
k =int(input())
res=1
tot=int(input())
for i in range(1,k,1):
c=int(input())
res=res*comb(tot+c-1,c-1)%mod
tot+=c
print(res) | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
553/A | 553 | A | Python 3 | TESTS | 2 | 46 | 0 | 11770332 | import math
k = int(input())
c = []
for i in range(k):
c.append(int(input()))
mod = 1000000007
def cnk(n,k):
return int(math.factorial(n)/(math.factorial(k)*math.factorial(n-k)))
res = 1
total = c[0]
for i in range(1,k):
k1 = c[i]
c1 = cnk(total + k1 - 1, k1-1)
res *= c1
res = res % mod
t... | 27 | 46 | 0 | 184154849 | from math import comb
dec=10**9 + 7
k =int(input())
color_counts = [0] * k
for i in range(0, k):
color_counts[i] = int(input())
result = 1
curr = color_counts[0]
for i in range(1,k):
result = result * comb(curr + color_counts[i] - 1 , color_counts[i] - 1) % dec
curr = curr + color_counts[i]
print(resu... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
553/A | 553 | A | Python 3 | TESTS | 2 | 31 | 0 | 12121453 | def g(): return int(input())
def ncr(n,r):
if 2*r > n:
r = n-r
a = 1
for i in range(r):
a = a * (n-i) // (i+1) % 1000000007
return a
k = g()
ans = 1
n2 = g()
for i in range(k-1):
n1 = n2
n2 += g()
ans = ans * ncr(n2-1,n1) % 1000000007
print(ans) | 27 | 61 | 0 | 11744542 | if __name__ == '__main__':
data = [int(input()) for i in range(int(input()))]
total = 1
prev = data[0]
for i, x in enumerate(data[1:]):
prev += 1
f = 1
c = 1
for j in range(x - 1):
total *= prev
prev += 1
f *= c
c += 1
... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
553/A | 553 | A | Python 3 | TESTS | 2 | 93 | 0 | 64642014 | import math
def nCr(n, r):
return (math.factorial(n) / (math.factorial(r)
* math.factorial(n - r)))
mod = 1000000007
n = int(input())
data = []
for i in range(n):
data.append(int(input()))
ans = 1
total = data[0]
for i in range(1,n):
total += data[i]
ans *= int(nCr(total-1,data[i]-1))... | 27 | 61 | 0 | 11745531 | import sys
def choose(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
R = 1000000007
def main():
k = int(sys.stdin.readline())
data ... | Codeforces Round 309 (Div. 1) | CF | 2,015 | 2 | 256 | Kyoya and Colored Balls | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | The first line of input will have one integer k (1 ≤ k ≤ 1000) the number of colors.
Then, k lines will follow. The i-th line will contain ci, the number of balls of the i-th color (1 ≤ ci ≤ 1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1 000 000 007. | null | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | [{"input": "3\n2\n2\n1", "output": "3"}, {"input": "4\n1\n2\n3\n4", "output": "1680"}] | 1,500 | ["combinatorics", "dp", "math"] | 27 | [{"input": "3\r\n2\r\n2\r\n1\r\n", "output": "3\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n4\r\n", "output": "1680\r\n"}, {"input": "10\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n100\r\n", "output": "12520708\r\n"}, {"input": "5\r\n10\r\n10\r\n10\r\n10\r\n10\r\n", "output": "425711769\r\n"}, {"input":... | false | stdio | null | true |
803/G | 803 | G | PyPy 3-64 | TESTS | 5 | 140 | 7,065,600 | 150414693 | import sys, random
input = sys.stdin.readline
M = 10**9+8
class Node:
def __init__(self, value, size, num, start = 0):
self.value = value
self.size = size
self.num = num
self.min = num if num else getmin(start, start+size)
self.start = start
self.prior = random.random... | 32 | 2,823 | 117,350,400 | 230770543 | import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class SegmentTree():
def __init__(self, init, unitX, f):
self.f = f # (X, X) -> X
self.unitX = unitX
self.f = f
if type(init) == int:
self.n = init
self.n = 1 << ... | Educational Codeforces Round 20 | ICPC | 2,017 | 4 | 512 | Periodic RMQ Problem | You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
- 1 l r x — for each index i such that l ≤ i ≤ r set ai = x.
- 2 l r — find the minimum among such ai that l ≤ i ≤ r.
We decided that this problem is too easy. So the array a is given in a compressed ... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104).
The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).
The third line contains one integer q (1 ≤ q ≤ 105).
Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s... | For each query of type 2 print the answer to this query — the minimum on the corresponding segment. | null | null | [{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}] | 2,300 | ["data structures"] | 32 | [{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1... | false | stdio | null | true |
149/C | 149 | C | PyPy 3-64 | TESTS | 2 | 46 | 0 | 175203093 | import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
d = sorted([(j, i+1) for i, j in enumerate(w)])
e = sorted([(d[i+1][0] - d[i][0], d[i][1], d[i+1][1]) for i in range(0, n//2+1, 2)])
s = sum(i[0] for i in e)
x = d[-1][0]
if s > x:
for i in range(len(e)-1, -1, -1):
a... | 47 | 436 | 22,016,000 | 196388111 | n = int(input())
a = list(map(int,input().split()))
s = sum(a)
mx = max(a)
a = [[a[i], i+1] for i in range(n)]
a.sort()
o = []
t = []
os = 0
ts = 0
a = a[::-1]
while len(a) >= 2:
x,i = a.pop()
y,j = a.pop()
if os <= ts:
o.append(j)
t.append(i)
os+= y
ts += x
else:
o.append(i)
t.append(j... | Codeforces Round 106 (Div. 2) | CF | 2,012 | 1 | 256 | Division into Teams | Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).
The key in football is to divide into teams fairly before the ... | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individu... | null | Let's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, th... | [{"input": "3\n1 2 1", "output": "2\n1 2\n1\n3"}, {"input": "5\n2 3 3 1 1", "output": "3\n4 1 3\n2\n5 2"}] | 1,500 | ["greedy", "math", "sortings"] | 47 | [{"input": "3\r\n1 2 1\r\n", "output": "2\r\n1 2 \r\n1\r\n3 \r\n"}, {"input": "5\r\n2 3 3 1 1\r\n", "output": "3\r\n4 1 3 \r\n2\r\n5 2 \r\n"}, {"input": "10\r\n2 2 2 2 2 2 2 1 2 2\r\n", "output": "5\r\n8 2 4 6 9 \r\n5\r\n1 3 5 7 10 \r\n"}, {"input": "10\r\n2 3 3 1 3 1 1 1 2 2\r\n", "output": "5\r\n4 7 1 10 3 \r\n5\r\n6... | false | stdio | import sys
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n = int(f.readline().strip())
a = list(map(int, f.readline().split()))
max_a = max(a)
with open(submission_path) as f:
lines = [line.strip() for line in f.readlines()]
if len... | true |
149/D | 149 | D | PyPy 3-64 | TESTS | 4 | 92 | 0 | 196396083 | s = input()
n = len(s)
num = [0]*(n)
que = []
d = dict()
cnt = 0
for i in range(n):
if s[i] == "(":
que.append(i)
else:
pre = que.pop()
num[pre] = cnt
num[i] = cnt
d[i] = pre
d[pre] = i
cnt +=1
mod = 10**9+7
def f(l,r):
if l == r-1:
ll = [[0]*3 for i in range(3)]
ll[0][1] = ... | 38 | 436 | 10,649,600 | 203663266 | from functools import lru_cache
import sys
input = lambda: sys.stdin.readline().strip()
def solve():
s = input()
n = len(s)
right_pos = [-1]*n
stk = []
mod = 10**9+7
for i, c in enumerate(s):
if c == '(':
stk.append(i)
else:
right_pos[stk.pop()] = i
dp... | Codeforces Round 106 (Div. 2) | CF | 2,012 | 2 | 256 | Coloring Brackets | Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.
You are given string s. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a ... | The first line contains the single string s (2 ≤ |s| ≤ 700) which represents a correct bracket sequence. | Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109 + 7). | null | Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below.
The two ways of coloring shown below are incorrect. | [{"input": "(())", "output": "12"}, {"input": "(()())", "output": "40"}, {"input": "()", "output": "4"}] | 1,900 | ["dp"] | 38 | [{"input": "(())\r\n", "output": "12\r\n"}, {"input": "(()())\r\n", "output": "40\r\n"}, {"input": "()\r\n", "output": "4\r\n"}, {"input": "((()))\r\n", "output": "36\r\n"}, {"input": "()(())\r\n", "output": "42\r\n"}, {"input": "()()()\r\n", "output": "48\r\n"}, {"input": "(())(())\r\n", "output": "126\r\n"}, {"input"... | false | stdio | null | true |
803/G | 803 | G | PyPy 3 | TESTS | 5 | 109 | 20,480,000 | 127583486 | from collections import deque
import sys
input = sys.stdin.readline
def slide_min(n, k, a):
ans = []
s = deque()
for i in range(n):
ai = a[i]
while s:
if a[s[-1]] >= ai:
s.pop()
else:
break
s.append(i)
while s:
... | 32 | 2,823 | 117,350,400 | 230770543 | import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class SegmentTree():
def __init__(self, init, unitX, f):
self.f = f # (X, X) -> X
self.unitX = unitX
self.f = f
if type(init) == int:
self.n = init
self.n = 1 << ... | Educational Codeforces Round 20 | ICPC | 2,017 | 4 | 512 | Periodic RMQ Problem | You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
- 1 l r x — for each index i such that l ≤ i ≤ r set ai = x.
- 2 l r — find the minimum among such ai that l ≤ i ≤ r.
We decided that this problem is too easy. So the array a is given in a compressed ... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104).
The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).
The third line contains one integer q (1 ≤ q ≤ 105).
Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s... | For each query of type 2 print the answer to this query — the minimum on the corresponding segment. | null | null | [{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}] | 2,300 | ["data structures"] | 32 | [{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1... | false | stdio | null | true |
803/G | 803 | G | Python 3 | TESTS | 9 | 1,013 | 1,331,200 | 26920263 | from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split())) * k
m = int(stdin.readline())
n *= k
size = 1
while (size < n):
size *= 2
tree = [float('inf') for i in range(2 * size)]
updating = [0 for i in range (2 * size)]
for i in range(n):
tre... | 32 | 2,823 | 117,350,400 | 230770543 | import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class SegmentTree():
def __init__(self, init, unitX, f):
self.f = f # (X, X) -> X
self.unitX = unitX
self.f = f
if type(init) == int:
self.n = init
self.n = 1 << ... | Educational Codeforces Round 20 | ICPC | 2,017 | 4 | 512 | Periodic RMQ Problem | You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
- 1 l r x — for each index i such that l ≤ i ≤ r set ai = x.
- 2 l r — find the minimum among such ai that l ≤ i ≤ r.
We decided that this problem is too easy. So the array a is given in a compressed ... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104).
The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).
The third line contains one integer q (1 ≤ q ≤ 105).
Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s... | For each query of type 2 print the answer to this query — the minimum on the corresponding segment. | null | null | [{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}] | 2,300 | ["data structures"] | 32 | [{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1... | false | stdio | null | true |
267/A | 267 | A | Python 3 | TESTS | 1 | 30 | 0 | 178134468 | inputs = int(input())
numbersList = []
for i in range(inputs):
numbersList.append(input())
for i in range(inputs):
numbers = numbersList[i].split()
n1 = int(numbers[0])
n2 = int(numbers[1])
times = 0
while n1 != n2 and n1 != 0 and n2 != 0:
if n1 > n2:
new = n1//n2
... | 35 | 46 | 0 | 145791141 | def main():
for _ in range(int(input())):
a, b = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
counter = 0
while a > 0 and b > 0:
divisor = b // a
counter += divisor
b -= divisor * a
a, b = b, a
print(co... | Codeforces Testing Round 5 | CF | 2,013 | 1 | 256 | Subtractions | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109). | Print the sought number of operations for each pair on a single line. | null | null | [{"input": "2\n4 17\n7 987654321", "output": "8\n141093479"}] | 900 | ["math", "number theory"] | 35 | [{"input": "2\r\n4 17\r\n7 987654321\r\n", "output": "8\r\n141093479\r\n"}, {"input": "10\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n", "output": "141093479\r\n141093479\r\n141093479\r\n141093479\r\n141093479\r... | false | stdio | null | true |
267/A | 267 | A | Python 3 | TESTS | 1 | 31 | 0 | 204511373 | n = int(input())
def solve(a, b):
a, b = min(a, b), max(a, b)
if a == 0 or a == b:
return 0
d, r = divmod(b, a)
return d + solve(r, a)
for _ in range(n):
a, b = (int(i) for i in input().split())
res = solve(a, b)
print(res) | 35 | 46 | 0 | 146777585 | for _ in range(0, int(input())):
m, M = map(int, input().split())
t = 0
while m != 0 and M != 0:
m, M = sorted([m, M])
v = (M // m)
M = M - (v * m)
t += v
print(t) | Codeforces Testing Round 5 | CF | 2,013 | 1 | 256 | Subtractions | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some num... | The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109). | Print the sought number of operations for each pair on a single line. | null | null | [{"input": "2\n4 17\n7 987654321", "output": "8\n141093479"}] | 900 | ["math", "number theory"] | 35 | [{"input": "2\r\n4 17\r\n7 987654321\r\n", "output": "8\r\n141093479\r\n"}, {"input": "10\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n", "output": "141093479\r\n141093479\r\n141093479\r\n141093479\r\n141093479\r... | false | stdio | null | true |
803/G | 803 | G | PyPy 3-64 | TESTS | 5 | 46 | 614,400 | 180994282 | class segtree():
def __init__(self,init,func,ide):
self.n=len(init)
self.func=func
self.ide=ide
self.size=1<<(self.n-1).bit_length()
self.tree=[self.ide for i in range(2*self.size)]
for i in range(self.n):
self.tree[self.size+i]=init[i]
for i in range(self.size-1,0,-1):
self.tr... | 32 | 2,823 | 117,350,400 | 230770543 | import sys
import random
input = sys.stdin.readline
rd = random.randint(10 ** 9, 2 * 10 ** 9)
class SegmentTree():
def __init__(self, init, unitX, f):
self.f = f # (X, X) -> X
self.unitX = unitX
self.f = f
if type(init) == int:
self.n = init
self.n = 1 << ... | Educational Codeforces Round 20 | ICPC | 2,017 | 4 | 512 | Periodic RMQ Problem | You are given an array a consisting of positive integers and q queries to this array. There are two types of queries:
- 1 l r x — for each index i such that l ≤ i ≤ r set ai = x.
- 2 l r — find the minimum among such ai that l ≤ i ≤ r.
We decided that this problem is too easy. So the array a is given in a compressed ... | The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 104).
The second line contains n integers — elements of the array b (1 ≤ bi ≤ 109).
The third line contains one integer q (1 ≤ q ≤ 105).
Then q lines follow, each representing a query. Each query is given either as 1 l r x — set all elements in the s... | For each query of type 2 print the answer to this query — the minimum on the corresponding segment. | null | null | [{"input": "3 1\n1 2 3\n3\n2 1 3\n1 1 2 4\n2 1 3", "output": "1\n3"}, {"input": "3 2\n1 2 3\n5\n2 4 4\n1 4 4 5\n2 4 4\n1 1 6 1\n2 6 6", "output": "1\n5\n1"}] | 2,300 | ["data structures"] | 32 | [{"input": "3 1\r\n1 2 3\r\n3\r\n2 1 3\r\n1 1 2 4\r\n2 1 3\r\n", "output": "1\r\n3\r\n"}, {"input": "3 2\r\n1 2 3\r\n5\r\n2 4 4\r\n1 4 4 5\r\n2 4 4\r\n1 1 6 1\r\n2 6 6\r\n", "output": "1\r\n5\r\n1\r\n"}, {"input": "10 10\r\n10 8 10 9 2 2 4 6 10 1\r\n10\r\n1 17 87 5\r\n2 31 94\r\n1 5 56 8\r\n1 56 90 10\r\n1 25 93 6\r\n1... | false | stdio | null | true |
558/D | 558 | D | PyPy 3 | TESTS | 39 | 810 | 43,315,200 | 206006500 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
h, q = map(int, input().split())
u = []
l0, r0 = pow(2, h - 1), pow(2, h) - 1
for _ in range(q):
i, l, r, a = map(int, input().split())
for _ in range(h - i):
l, r = 2 * l, 2 * r + 1
if a:
u.append((l, r + 1))
... | 90 | 779 | 50,688,000 | 155784759 | import sys
input = sys.stdin.buffer.readline
def process(h, Q):
L1, R1 = 2**(h-1), 2**h-1
Q1 = []
n = 0
for i, L, R, ans in Q:
L2, R2 = 2**(h-i)*L, 2**(h-i)*R+2**(h-i)-1
if ans==0:
Q1.append([L2, 0, n])
Q1.append([R2, 1, n])
n+=1
else:
... | Codeforces Round 312 (Div. 2) | CF | 2,015 | 2 | 256 | Guess Your Way Out! II | Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the nodes of the tree such tha... | The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively.
The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, $$ans \in \{0, 1\}$$), representing a question as described in the statement with its ... | If the information provided by the game is contradictory output "Game cheated!" without the quotes.
Else if you can uniquely identify the exit to the maze output its index.
Otherwise output "Data not sufficient!" without the quotes. | null | Node u is an ancestor of node v if and only if
- u is the same node as v,
- u is the parent of node v,
- or u is an ancestor of the parent of node v.
In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7.
In the second... | [{"input": "3 1\n3 4 6 0", "output": "7"}, {"input": "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "output": "14"}, {"input": "4 2\n3 4 6 1\n4 12 15 1", "output": "Data not sufficient!"}, {"input": "4 2\n3 4 5 1\n2 3 3 1", "output": "Game cheated!"}] | 2,300 | ["data structures", "implementation", "sortings"] | 90 | [{"input": "3 1\r\n3 4 6 0\r\n", "output": "7"}, {"input": "4 3\r\n4 10 14 1\r\n3 6 6 0\r\n2 3 3 1\r\n", "output": "14"}, {"input": "4 2\r\n3 4 6 1\r\n4 12 15 1\r\n", "output": "Data not sufficient!"}, {"input": "4 2\r\n3 4 5 1\r\n2 3 3 1\r\n", "output": "Game cheated!"}, {"input": "1 0\r\n", "output": "1"}, {"input": ... | false | stdio | null | true |
677/A | 677 | A | Python 3 | TESTS | 3 | 31 | 0 | 225635104 | inp = list(input())
height = list(input())
i ,gk , pk = 0 , 0 ,0
new_height = []
new_inp = []
total_height = 0
while i < len(height):
k =height[i]
if k != ' ':
new_height.append(k)
i = i+1
while gk < len(inp):
k =inp[gk]
if k != ' ':
new_inp.append(k)
gk = gk+1
kkk = len... | 29 | 31 | 0 | 215784293 | n,h = map(int,input().split())
lst = input().split()
lst2 = [int(i) for i in lst]
w=0
for i in lst2:
if i<=h:
w+=1
else:
w+=2
print(w) | Codeforces Round 355 (Div. 2) | CF | 2,016 | 1 | 256 | Vanya and Fence | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the... | The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively.
The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person. | Print a single integer — the minimum possible valid width of the road. | null | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | [{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}] | 800 | ["implementation"] | 29 | [{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o... | false | stdio | null | true |
677/A | 677 | A | Python 3 | TESTS | 3 | 30 | 0 | 219456027 | s = input()
h = int(s[-1])
t = input()
dat = t.split()
ctr = 0
for ele in dat:
if int(ele) > h:
ctr += 2
else:
ctr += 1
print(ctr) | 29 | 31 | 0 | 216067687 | n,h=map(int,input().split())
a=list(map(int,input().split()))
count=0
for i in a:
if i>h:
count+=2
else:
count+=1
print(count) | Codeforces Round 355 (Div. 2) | CF | 2,016 | 1 | 256 | Vanya and Fence | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the... | The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively.
The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person. | Print a single integer — the minimum possible valid width of the road. | null | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | [{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}] | 800 | ["implementation"] | 29 | [{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o... | false | stdio | null | true |
558/D | 558 | D | Python 3 | TESTS | 5 | 607 | 16,076,800 | 12328408 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
def ReadIn():
height, n = [int(x) for x in input().split()]
queries = [tuple(int(x) for x in input().split())
for q in range(n)]
return height, queries
def MoveToLeaves(height, queries):
leaves = []
for level, left, right, yn in queries:... | 90 | 1,076 | 16,998,400 | 12062622 | h,q=map(int,input().split())
d=[(2**h,0),(2**(h-1),0)]
for _ in range(q):
i,l,r,a=map(int,input().split())
l,r=l*2**(h-i),(r+1)*2**(h-i)
d.extend([[(l,1),(r,-1)],[(0,1),(l,-1),(r,1)]][a])
s=0
l=0
d=sorted(d)
for (a,x),(b,_) in zip(d,d[1:]):
s+=x
if a!=b and s==0:q=a;l+=b-a
print(("Game cheated!",q,"Data not suffic... | Codeforces Round 312 (Div. 2) | CF | 2,015 | 2 | 256 | Guess Your Way Out! II | Amr bought a new video game "Guess Your Way Out! II". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node.
Let's index all the nodes of the tree such tha... | The first line contains two integers h, q (1 ≤ h ≤ 50, 0 ≤ q ≤ 105), the height of the tree and the number of questions respectively.
The next q lines will contain four integers each i, L, R, ans (1 ≤ i ≤ h, 2i - 1 ≤ L ≤ R ≤ 2i - 1, $$ans \in \{0, 1\}$$), representing a question as described in the statement with its ... | If the information provided by the game is contradictory output "Game cheated!" without the quotes.
Else if you can uniquely identify the exit to the maze output its index.
Otherwise output "Data not sufficient!" without the quotes. | null | Node u is an ancestor of node v if and only if
- u is the same node as v,
- u is the parent of node v,
- or u is an ancestor of the parent of node v.
In the first sample test there are 4 leaf nodes 4, 5, 6, 7. The first question says that the node isn't in the range [4, 6] so the exit is node number 7.
In the second... | [{"input": "3 1\n3 4 6 0", "output": "7"}, {"input": "4 3\n4 10 14 1\n3 6 6 0\n2 3 3 1", "output": "14"}, {"input": "4 2\n3 4 6 1\n4 12 15 1", "output": "Data not sufficient!"}, {"input": "4 2\n3 4 5 1\n2 3 3 1", "output": "Game cheated!"}] | 2,300 | ["data structures", "implementation", "sortings"] | 90 | [{"input": "3 1\r\n3 4 6 0\r\n", "output": "7"}, {"input": "4 3\r\n4 10 14 1\r\n3 6 6 0\r\n2 3 3 1\r\n", "output": "14"}, {"input": "4 2\r\n3 4 6 1\r\n4 12 15 1\r\n", "output": "Data not sufficient!"}, {"input": "4 2\r\n3 4 5 1\r\n2 3 3 1\r\n", "output": "Game cheated!"}, {"input": "1 0\r\n", "output": "1"}, {"input": ... | false | stdio | null | true |
846/F | 846 | F | PyPy 3-64 | TESTS | 4 | 187 | 22,016,000 | 210551799 | import math
import random
import time
from decimal import *
def binary_search(vector,valoarea):
left=0
right=len(vector)-1
while left<=right:
centru=(left+right)//2
# print(left,right,centru,vector[centru])
if vector[centru]<valoarea:
left=centru+1
else:
right=centru-1
# print(left... | 31 | 951 | 75,161,600 | 93377821 | import sys
from collections import defaultdict
n = int(sys.stdin.buffer.readline().decode('utf-8'))
a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
next_dic = defaultdict(list)
for i in range(n-1, -1, -1):
next_dic[a[i]].append(i)
fx = sum((n-v[-1])*2 for v in next_dic.values())
ans = 0
... | Educational Codeforces Round 28 | ICPC | 2,017 | 2 | 256 | Random Query | You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the ar... | The first line contains one integer number n (1 ≤ n ≤ 106). The second line contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 106) — elements of the array. | Print one number — the expected number of unique elements in chosen segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if $${ \operatorname* { m i n } } ( | x - y |, { \frac { | x - y | } { x } } ) \leq 1 0 ^ { - 4 }$$, where x is j... | null | null | [{"input": "2\n1 2", "output": "1.500000"}, {"input": "2\n2 2", "output": "1.000000"}] | 1,800 | ["data structures", "math", "probabilities", "two pointers"] | 31 | [{"input": "2\r\n1 2\r\n", "output": "1.500000\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1.000000\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "3.100000\r\n"}, {"input": "20\r\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21\r\n", "output": "7.010000\r\n"}, {"input": "1\r\n1000000\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
correct_output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read correct output
with open(correct_output_path, 'r') as f:
correct_line = f.readline().strip()
x = float(correct_line)
# Read submission output
with open... | true |
677/A | 677 | A | Python 3 | TESTS | 3 | 31 | 0 | 225634260 | x,y = input().split()
height = list(input())
i , pk = 0 , 0
new_height = []
total_height = 0
while i < len(height):
k =height[i]
if k != ' ':
new_height.append(k)
i = i+1
kkk = len(new_height)
while pk < kkk:
k = new_height[pk]
if k <= y:
total_height = total_height + 1
else:... | 29 | 31 | 0 | 216662568 | ip = input().split(" ")
heights = input().split(" ")
width = 0
n = ip[0]
fence = ip[1]
for i in range(len(heights)):
if int(heights[i]) > int(fence):
width += 2
else:
width += 1
print(int(width)) | Codeforces Round 355 (Div. 2) | CF | 2,016 | 1 | 256 | Vanya and Fence | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the... | The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively.
The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person. | Print a single integer — the minimum possible valid width of the road. | null | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | [{"input": "3 7\n4 5 14", "output": "4"}, {"input": "6 1\n1 1 1 1 1 1", "output": "6"}, {"input": "6 5\n7 6 8 9 10 5", "output": "11"}] | 800 | ["implementation"] | 29 | [{"input": "3 7\r\n4 5 14\r\n", "output": "4\r\n"}, {"input": "6 1\r\n1 1 1 1 1 1\r\n", "output": "6\r\n"}, {"input": "6 5\r\n7 6 8 9 10 5\r\n", "output": "11\r\n"}, {"input": "10 420\r\n214 614 297 675 82 740 174 23 255 15\r\n", "output": "13\r\n"}, {"input": "10 561\r\n657 23 1096 487 785 66 481 554 1000 821\r\n", "o... | false | stdio | null | true |
175/B | 175 | B | Python 3 | TESTS | 0 | 154 | 0 | 53661028 | n = int(input())
d = {}
for i in range(n):
s, v = input().split()
d[s] = max(d.get(s,0), int(v))
print(len(d))
for i in d:
c = 0
for j in d:
if (d[j] > d[i]):
c += 1
if (c * 2 > n): res = "noob"
elif (c * 5 > n): res = "random"
elif (c * 10 > n): res = "average"
... | 46 | 186 | 1,740,800 | 168027864 | import sys
input = sys.stdin.readline
def rank(q):
a = q/m * 100
if a < 50:
return 'noob'
elif a < 80:
return 'random'
elif a < 90:
return 'average'
elif a < 99:
return 'hardcore'
else:
return 'pro'
n = int(input())
d = dict()
for _ in range(n):
a,... | Codeforces Round 115 | CF | 2,012 | 2 | 256 | Plane of Tanks: Pro | Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results.
A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has... | The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results.
Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T... | Print on the first line the number m — the number of players, who participated in one round at least.
Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th... | null | In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes... | [{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}] | 1,400 | ["implementation"] | 78 | [{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input data
with open(input_path) as f:
n = int(f.readline())
players = {}
for _ in range(n):
name, points = f.readline().strip().split()
points = int(points)
if name not in players ... | true |
559/E | 559 | E | Python 3 | TESTS | 2 | 46 | 307,200 | 109825401 | no = int(input())
details = []
for _ in range(no):
v = input().split()
v[0] = int(v[0])
v[1] = int(v[1])
details.append(v)
details.sort()
ans = 0
for i in range(no):
if i==0 or i==(no-1):
ans+=details[i][1]
else:
if details[i-1][0]<details[i+1][0]:
ans+=details[i-1][1]
else:
ans+=details[i+1][1]
print... | 90 | 342 | 20,787,200 | 163409586 | import dataclasses
import sys
inf = float('inf')
# change stdout buffer size
buffer = open(1, 'w', 10**6)
# fast printing function
def print(*args, sep=' ', end='\n'):
buffer.write(sep.join(str(arg) for arg in args) + end)
# flush stdout
def flush():
buffer.flush()
def read_ints(index=None):
if ind... | Codeforces Round 313 (Div. 1) | CF | 2,015 | 4 | 256 | Gerald and Path | The main walking trail in Geraldion is absolutely straight, and it passes strictly from the north to the south, it is so long that no one has ever reached its ends in either of the two directions. The Geraldionians love to walk on this path at any time, so the mayor of the city asked the Herald to illuminate this path ... | The first line contains integer n (1 ≤ n ≤ 100) — the number of spotlights. Each of the n lines contains two space-separated integers, ai and li (0 ≤ ai ≤ 108, 1 ≤ li ≤ 108). Number ai shows how much further the i-th spotlight to the north, and number li shows the length of the segment it illuminates.
It is guaranteed... | Print a single integer — the maximum total length of the illuminated part of the path. | null | null | [{"input": "3\n1 1\n2 2\n3 3", "output": "5"}, {"input": "4\n1 2\n3 3\n4 3\n6 2", "output": "9"}] | 3,000 | ["dp", "sortings"] | 90 | [{"input": "3\r\n1 1\r\n2 2\r\n3 3\r\n", "output": "5\r\n"}, {"input": "4\r\n1 2\r\n3 3\r\n4 3\r\n6 2\r\n", "output": "9\r\n"}, {"input": "5\r\n3 3\r\n4 1\r\n2 2\r\n0 3\r\n9 5\r\n", "output": "13\r\n"}, {"input": "5\r\n3 3\r\n4 3\r\n6 4\r\n2 3\r\n1 5\r\n", "output": "14\r\n"}, {"input": "5\r\n1 2\r\n7 5\r\n9 4\r\n5 1\r... | false | stdio | null | true |
675/C | 675 | C | Python 3 | TESTS | 4 | 62 | 4,608,000 | 18105101 | n = int(input())
a = list(map(int,input().split()))
if a == [0]*n:
print(0)
exit(0)
dp1 = [0]*n
dp1[0] = a[0]
dp2 = {a[0]:0}
res = 0
last = 0
for i in range(1, n):
dp1[i] = dp1[i-1]+a[i]
if dp1[i] in dp2:
res += 1
for j in range(last, i):
dp2.pop(dp1[j])
last = i
... | 41 | 109 | 15,667,200 | 217255153 | n = int(input())
a = list(map(int, input().split()))
p = [0] * n
p[0] = a[0]
for i in range(1, n):
p[i] = a[i] + p[i - 1]
p.sort()
p.append(float('inf'))
ans = 0
i = 0
while i < n:
j = i
while p[j] == p[i]:
j += 1
ans = max(ans, j - i)
i = j
print(n - ans)# 1691240835.7281392 | Codeforces Round 353 (Div. 2) | CF | 2,016 | 1 | 256 | Money Transfers | There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative, meaning V... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0. | Print the minimum number of operations required to change balance in each bank to zero. | null | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the se... | [{"input": "3\n5 0 -5", "output": "1"}, {"input": "4\n-1 0 1 0", "output": "2"}, {"input": "4\n1 2 3 -6", "output": "3"}] | 2,100 | ["constructive algorithms", "data structures", "greedy", "sortings"] | 41 | [{"input": "3\r\n5 0 -5\r\n", "output": "1\r\n"}, {"input": "4\r\n-1 0 1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 3 -6\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "50\r\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 9... | false | stdio | null | true |
675/C | 675 | C | Python 3 | TESTS | 4 | 62 | 4,608,000 | 18104524 | n = int(input())
a = list(map(int,input().split()))
if a == [0]*n:
print(0)
exit(0)
f = 0
for i in range(n):
if a[i] != 0:
f = i
break
res = 0
tmp = 0
s = 0
for j in range(f, f+n):
i = j % n
s += a[i]
if s == 0:
res += tmp
tmp = 0
else:
tmp += 1
a = a[... | 41 | 124 | 11,264,000 | 19615409 | n = int(input())
a = list(map(int, input().split()))
search = dict()
sum = 0
for b in a:
sum += b
if not sum in search:
search[sum] = 1
else:
search[sum] += 1
print(n - max(search.values())) | Codeforces Round 353 (Div. 2) | CF | 2,016 | 1 | 256 | Money Transfers | There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative, meaning V... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0. | Print the minimum number of operations required to change balance in each bank to zero. | null | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the se... | [{"input": "3\n5 0 -5", "output": "1"}, {"input": "4\n-1 0 1 0", "output": "2"}, {"input": "4\n1 2 3 -6", "output": "3"}] | 2,100 | ["constructive algorithms", "data structures", "greedy", "sortings"] | 41 | [{"input": "3\r\n5 0 -5\r\n", "output": "1\r\n"}, {"input": "4\r\n-1 0 1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 3 -6\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "50\r\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 9... | false | stdio | null | true |
175/B | 175 | B | Python 3 | TESTS | 0 | 60 | 0 | 214357609 | n = int(input())
d = {}
for _ in range(n):
a,b = input().split()
if a in d:
d[a] = max(int(b),d[a])
else:
d[a] = int(int(b))
print(len(d))
for s in d:
k=0
for y in d:
if d[y]>d[s]: k+=1
if k*2>n:
print(s,"noob")
elif k*5>n:
print(s,"random")
elif k... | 46 | 218 | 307,200 | 98247277 | n = int(input())
dic = {}
length = 0
for i in range(n):
player,score = input().split()
score = int(score)
if player not in dic:
dic[player] = score
length += 1
else:
if dic[player]<score:
dic[player] = score
sortd_values = sorted(dic.values(),reverse=True)
print(lengt... | Codeforces Round 115 | CF | 2,012 | 2 | 256 | Plane of Tanks: Pro | Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results.
A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has... | The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results.
Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T... | Print on the first line the number m — the number of players, who participated in one round at least.
Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th... | null | In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes... | [{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}] | 1,400 | ["implementation"] | 78 | [{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas... | false | stdio | import sys
def main(input_path, output_path, submission_path):
# Read input data
with open(input_path) as f:
n = int(f.readline())
players = {}
for _ in range(n):
name, points = f.readline().strip().split()
points = int(points)
if name not in players ... | true |
594/A | 594 | A | Python 3 | TESTS | 3 | 31 | 0 | 172342090 | n = int(input())
arr = list(map(int,input().split()))[:n]
a = arr[1:n]
print(abs(arr[0]-a[(n-1)//2])) | 50 | 202 | 16,179,200 | 189262992 | # LUOGU_RID: 99814222
ans=0x3f3f3f3f
n=int(input())
a=list(map(int,input().split()))
b=n//2
a.sort()
for i in range(b):
ans=min(ans,a[b+i]-a[i])
print(ans) | Codeforces Round 330 (Div. 1) | CF | 2,015 | 2 | 256 | Warrior and Archer | In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model solution corresponds to what jury wanted it to be during the contest.
V... | The first line on the input contains a single integer n (2 ≤ n ≤ 200 000, n is even) — the number of positions available initially. The second line contains n distinct integers x1, x2, ..., xn (0 ≤ xi ≤ 109), giving the coordinates of the corresponding positions. | Print the distance between the warrior and the archer at the beginning of the fight, provided that both Vova and Lesha play optimally. | null | In the first sample one of the optimum behavior of the players looks like that:
1. Vova bans the position at coordinate 15;
2. Lesha bans the position at coordinate 3;
3. Vova bans the position at coordinate 31;
4. Lesha bans the position at coordinate 1.
After these actions only positions 0 and 7 will remain, and th... | [{"input": "6\n0 1 3 7 15 31", "output": "7"}, {"input": "2\n73 37", "output": "36"}] | 2,300 | ["games"] | 50 | [{"input": "6\r\n0 1 3 7 15 31\r\n", "output": "7\r\n"}, {"input": "2\r\n73 37\r\n", "output": "36\r\n"}, {"input": "2\r\n0 1000000000\r\n", "output": "1000000000\r\n"}, {"input": "8\r\n729541013 135019377 88372488 319157478 682081360 558614617 258129110 790518782\r\n", "output": "470242129\r\n"}, {"input": "2\r\n0 1\r... | false | stdio | null | true |
675/C | 675 | C | Python 3 | TESTS | 4 | 77 | 7,065,600 | 36379325 | import math as m
n=int(input())
a=list(map(int,input().split()))
ans1=0
ans2=0
curr=0
i=0
while i<n:
if curr!=0:
ans1+=1
curr+=a[i]
else:
curr+=a[i]
i+=1
curr=0
b=[]
b.append(a[0])
for i in reversed(a):
b.append(i)
i=0
curr=0
while i<n:
if curr!=0:
ans2+=1
curr+=b[i]
else:
curr+=b[i]
i+=1
print(min(a... | 41 | 140 | 12,800,000 | 18990549 | n = int(input())
a = map(int,input().split())
search =dict()
sum=0
for b in a:
sum+=b
if not sum in search:
search[sum] = 1
else:
search[sum] +=1
print(n-max(search.values())) | Codeforces Round 353 (Div. 2) | CF | 2,016 | 1 | 256 | Money Transfers | There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative, meaning V... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0. | Print the minimum number of operations required to change balance in each bank to zero. | null | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the se... | [{"input": "3\n5 0 -5", "output": "1"}, {"input": "4\n-1 0 1 0", "output": "2"}, {"input": "4\n1 2 3 -6", "output": "3"}] | 2,100 | ["constructive algorithms", "data structures", "greedy", "sortings"] | 41 | [{"input": "3\r\n5 0 -5\r\n", "output": "1\r\n"}, {"input": "4\r\n-1 0 1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 3 -6\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "50\r\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 9... | false | stdio | null | true |
675/C | 675 | C | PyPy 3 | TESTS | 4 | 124 | 0 | 82404119 | n = int(input())
a = list(map(int,input().split()))
a.append(a[0])
ct1,s = 0,0
for i in range(n):
s += a[i]
if(s != 0):
ct1 += 1
ct2,s = 0,0
for i in range(n,0,-1):
s += a[i]
if(s != 0):
ct2 += 1
print(min(ct1,ct2)) | 41 | 155 | 16,384,000 | 26412739 | n=int(input())
a=list(map(int,input().split()))
d,s={},0
for i in range(n):
s+=a[i]
if s not in d:d[s]=0
d[s]+=1
print(n-max(d.values())) | Codeforces Round 353 (Div. 2) | CF | 2,016 | 1 | 256 | Money Transfers | There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative, meaning V... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0. | Print the minimum number of operations required to change balance in each bank to zero. | null | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the se... | [{"input": "3\n5 0 -5", "output": "1"}, {"input": "4\n-1 0 1 0", "output": "2"}, {"input": "4\n1 2 3 -6", "output": "3"}] | 2,100 | ["constructive algorithms", "data structures", "greedy", "sortings"] | 41 | [{"input": "3\r\n5 0 -5\r\n", "output": "1\r\n"}, {"input": "4\r\n-1 0 1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 3 -6\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "50\r\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 9... | false | stdio | null | true |
245/A | 245 | A | Python 3 | TESTS | 3 | 60 | 0 | 169204946 | for _ in range(int(input())):
s,l,d=map(int,input().split())
if s==1:
a=(l,d)
else:
b=(l,d)
print("LIVE" if a[0]>=a[1] else "DEAD")
print("LIVE" if b[0]>=b[1] else "DEAD") | 13 | 78 | 102,400 | 4010030 | n=int(input())
live1, dead1, live2, dead2 = 0, 0, 0, 0
for i in range(n):
I=[int(j) for j in input().split()]
if I[0]==1:
live1+=I[1]
dead1+=I[2]
else:
live2+=I[1]
dead2+=I[2]
if live1>=(live1+dead1)/2: print('LIVE')
else: print('DEAD')
if live2>=(live2+dead2)/2: print('LIVE'... | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | System Administrator | Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =... | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server b in the similar format. | null | Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ... | [{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}] | 800 | ["implementation"] | 23 | [{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1... | false | stdio | null | true |
245/A | 245 | A | Python 3 | TESTS | 3 | 62 | 4,505,600 | 133423594 | n=input()
aWon=0
aLost=0
bWon=0
bLost=0
for i in range(0,int(n)):
p=input().split()
if int(p[0])==1:
if int(p[1])>=int(p[2]):
aWon+=1
else:
aLost+=1
elif int(p[0])==2:
if int(p[1])>=int(p[2]):
bWon+=1
else:
bLost+=1
if aWon>=aLost:
print("LIVE")
elif aWon<aLost:
print("... | 13 | 92 | 0 | 4504982 | while(1):
try:
n=int(input())
a,b,c=[0 for j in range(n)],[0 for j in range(n)],[0 for j in range(n)]
sum1,sum2=0,0
for i in range(0,n):
a[i],b[i],c[i]=map(int,input().split())
if a[i]==1:
sum1+=b[i]
else:
sum2+=b[i]... | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | System Administrator | Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =... | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server b in the similar format. | null | Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ... | [{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}] | 800 | ["implementation"] | 23 | [{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1... | false | stdio | null | true |
675/C | 675 | C | Python 3 | TESTS | 4 | 31 | 0 | 135875024 | # 1 2 3 -6
n=int(input())
l=[int(i) for i in input().split()]
s=0
ans=0
new=[]
new+=l
for i in range(len(l)):
if s!=0:
ans+=1
s+=l[i]
l=l[::-1]
p=0
ans2=0
for i in range(len(l)):
if p!=0:
ans2+=1
p+=l[i]
l=l[1:]+[l[0]]
p=0
ans3=0
for i in range(len(l)):
if p!=0:
ans3+=1
... | 41 | 155 | 16,588,800 | 19938344 | n = int(input())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(1, n):
s.append(s[i - 1] + a[i])
d = {}
for x in s:
if x not in d:
d[x] = 1
else:
d[x] += 1
print(n - max(d.values())) | Codeforces Round 353 (Div. 2) | CF | 2,016 | 1 | 256 | Money Transfers | There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.
Vasya has an account in each bank. Its balance may be negative, meaning V... | The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.
The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0. | Print the minimum number of operations required to change balance in each bank to zero. | null | In the first sample, Vasya may transfer 5 from the first bank to the third.
In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.
In the third sample, the following sequence provides the optimal answer:
1. transfer 1 from the first bank to the se... | [{"input": "3\n5 0 -5", "output": "1"}, {"input": "4\n-1 0 1 0", "output": "2"}, {"input": "4\n1 2 3 -6", "output": "3"}] | 2,100 | ["constructive algorithms", "data structures", "greedy", "sortings"] | 41 | [{"input": "3\r\n5 0 -5\r\n", "output": "1\r\n"}, {"input": "4\r\n-1 0 1 0\r\n", "output": "2\r\n"}, {"input": "4\r\n1 2 3 -6\r\n", "output": "3\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "50\r\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 9... | false | stdio | null | true |
245/A | 245 | A | Python 3 | TESTS | 3 | 92 | 307,200 | 4993073 | n = int(input())
r = [1,1]
for i in range(n):
t,x,y = map(int, input().split())
if x < y:
r[t-1] = 0
else:
r[t-1] = 1
for i in r:
if i == 0:
print('DEAD')
else:
print('LIVE') | 13 | 92 | 0 | 4648150 | n = int(input())
u, v = [0, 0], [0, 0]
for i in range(n):
t, x, y = map(int, input().split())
k = int(t == 1)
u[k] += x
v[k] += y
print('LDIEVAED'[u[1] < v[1] :: 2])
print('LDIEVAED'[u[0] < v[0] :: 2]) | CROC-MBTU 2012, Elimination Round (ACM-ICPC) | ICPC | 2,012 | 2 | 256 | System Administrator | Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program re... | The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti =... | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server b in the similar format. | null | Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this ... | [{"input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE"}, {"input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD"}] | 800 | ["implementation"] | 23 | [{"input": "2\r\n1 5 5\r\n2 6 4\r\n", "output": "LIVE\r\nLIVE\r\n"}, {"input": "3\r\n1 0 10\r\n2 0 10\r\n1 10 0\r\n", "output": "LIVE\r\nDEAD\r\n"}, {"input": "10\r\n1 3 7\r\n2 4 6\r\n1 2 8\r\n2 5 5\r\n2 10 0\r\n2 10 0\r\n1 8 2\r\n2 2 8\r\n2 10 0\r\n1 1 9\r\n", "output": "DEAD\r\nLIVE\r\n"}, {"input": "11\r\n1 8 2\r\n1... | false | stdio | null | true |
811/E | 811 | E | Python 3 | TESTS | 3 | 46 | 5,529,600 | 28023760 | import sys
data=sys.stdin.read().split("\n")
del data[len(data)-1]
n= int(data[0][0])
for ii in range(n+1, len(data)):
cnt=[]
suffix=0
left=int(data[ii].split(" ")[0])-1
right=int(data[ii].split(" ")[1])-1
array=[i.split(" ") for i in data[1:n+1]]
for line in range(0,n):
lines=array[l... | 120 | 1,653 | 111,513,600 | 221893861 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return u * n + v
def get_root(s):
v = []
while not s == root[s]:
v.append(s)
s = root[s]
for i in v:
root[i] = s
return s
def unite(s, t):
s, t = get_root(s), get_root(t)
i... | Codeforces Round 416 (Div. 2) | CF | 2,017 | 2 | 256 | Vladik and Entertaining Flags | In his spare time Vladik estimates beauty of the flags.
Every flag could be represented as the matrix n × m which consists of positive integers.
Let's define the beauty of the flag as number of components in its matrix. We call component a set of cells with same numbers and between any pair of cells from that set the... | First line contains three space-separated integers n, m, q (1 ≤ n ≤ 10, 1 ≤ m, q ≤ 105) — dimensions of flag matrix and number of segments respectively.
Each of next n lines contains m space-separated integers — description of flag matrix. All elements of flag matrix is positive integers not exceeding 106.
Each of ne... | For each segment print the result on the corresponding line. | null | Partitioning on components for every segment from first test case: | [{"input": "4 5 4\n1 1 1 1 1\n1 2 2 3 3\n1 1 1 2 5\n4 4 5 5 5\n1 5\n2 5\n1 2\n4 5", "output": "6\n7\n3\n4"}] | 2,600 | ["data structures", "dsu", "graphs"] | 120 | [{"input": "4 5 4\r\n1 1 1 1 1\r\n1 2 2 3 3\r\n1 1 1 2 5\r\n4 4 5 5 5\r\n1 5\r\n2 5\r\n1 2\r\n4 5\r\n", "output": "6\r\n7\r\n3\r\n4\r\n"}, {"input": "5 2 9\r\n6 1\r\n6 6\r\n6 6\r\n6 6\r\n5 6\r\n1 2\r\n1 1\r\n1 2\r\n1 2\r\n1 2\r\n1 1\r\n1 1\r\n1 2\r\n1 1\r\n", "output": "3\r\n2\r\n3\r\n3\r\n3\r\n2\r\n2\r\n3\r\n2\r\n"}, ... | false | stdio | null | true |
246/B | 246 | B | Python 3 | TESTS | 4 | 124 | 0 | 106645643 | n = int(input())
a,*arr = list(map(int,input().split()))
s = 0
for i in range(n-1):
s += -arr[i]
if (a+s)%2:
print(n-1)
else:
print(n) | 30 | 92 | 3,174,400 | 185712401 | n = int(input())
lst = list(map(int, input().split()))
if sum(lst)%n==0:
print(n)
else:
print(n-1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
846/F | 846 | F | PyPy 3-64 | TESTS | 4 | 202 | 21,504,000 | 210559118 | import math
import random
import time
from decimal import *
def binary_search(vector,valoarea):
left=0
right=len(vector)-1
while left<=right:
centru=(left+right)//2
# print(left,right,centru,vector[centru])
if vector[centru]<valoarea:
left=centru+1
else:
right=centru-1
# print(left... | 31 | 998 | 74,444,800 | 75166697 | n = int(input())
arr = [0]
arr = arr + list(map(int, input().split(' ')))
def getCounts(arr):
last = {}
ans = 0.0
prev = 0.0
res = 0.0
for i in range(1, len(arr)):
if arr[i] not in last:
ans = prev + i
else:
ans = prev + i - last[arr[i]]
prev = ans
... | Educational Codeforces Round 28 | ICPC | 2,017 | 2 | 256 | Random Query | You are given an array a consisting of n positive integers. You pick two integer numbers l and r from 1 to n, inclusive (numbers are picked randomly, equiprobably and independently). If l > r, then you swap values of l and r. You have to calculate the expected value of the number of unique elements in segment of the ar... | The first line contains one integer number n (1 ≤ n ≤ 106). The second line contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 106) — elements of the array. | Print one number — the expected number of unique elements in chosen segment.
Your answer will be considered correct if its absolute or relative error doesn't exceed 10 - 4 — formally, the answer is correct if $${ \operatorname* { m i n } } ( | x - y |, { \frac { | x - y | } { x } } ) \leq 1 0 ^ { - 4 }$$, where x is j... | null | null | [{"input": "2\n1 2", "output": "1.500000"}, {"input": "2\n2 2", "output": "1.000000"}] | 1,800 | ["data structures", "math", "probabilities", "two pointers"] | 31 | [{"input": "2\r\n1 2\r\n", "output": "1.500000\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1.000000\r\n"}, {"input": "10\r\n9 6 8 5 5 2 8 9 2 2\r\n", "output": "3.100000\r\n"}, {"input": "20\r\n49 33 9 8 50 21 12 44 23 39 24 10 17 4 17 40 24 19 27 21\r\n", "output": "7.010000\r\n"}, {"input": "1\r\n1000000\r\n", "outpu... | false | stdio | import sys
def main():
input_path = sys.argv[1]
correct_output_path = sys.argv[2]
submission_output_path = sys.argv[3]
# Read correct output
with open(correct_output_path, 'r') as f:
correct_line = f.readline().strip()
x = float(correct_line)
# Read submission output
with open... | true |
247/B | 250 | B | Python 3 | TESTS | 6 | 248 | 0 | 62996758 | # from dust i have come, dust i will be
def solve(ip):
ch = ip.split(':')
n = len(ch)
if ch[n - 1] == '' and n - 2 >= 0 and ch[n - 2] == '':
ch.pop(n - 1)
extra = 8 - len(ch)
ans = []
for i in range(len(ch)):
if ch[i] != '':
while len(ch[i]) < 4:
... | 40 | 92 | 0 | 156767698 | n = int(input())
res = ""
for i in range(n):
short = input()
blocks = short.split(':')
if '' in blocks:
countOfNull = 9 - len(blocks)
# short[short.index('::')+1]
short = short.replace("::", ":0000"*countOfNull + ":")
blocks = short.split(':')
short = ""
for block in bloc... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
246/B | 246 | B | Python 3 | TESTS | 5 | 154 | 0 | 39017955 | n = int(input())
arr = list(map(int,input().split()))
if (n&1 == 1) and sum(arr) == ((n*(n+1)) >> 1):
print(n)
else:
print(n-1) | 30 | 92 | 3,174,400 | 189678648 | n=int(input()) ; arr=list(map(int,input().split())) ; summ=sum(arr) ; avg=summ/n ; print(n if int(avg)==avg else n-1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 30 | 0 | 156838375 | def ipv6(inputs):
result = list()
data = list(map(str, inputs.split()))
size = int(data.pop(0))
for i in range(size):
current = data.pop(0).split(':')
result.append("")
difference = 8-len(current)
for value in current:
if value == '':
result[i]... | 40 | 92 | 0 | 156840243 | def ipv6(inputs):
result = list()
data = list(map(str, inputs.split()))
size = int(data.pop(0))
for _ in range(size):
current = data.pop(0).split(':')
result.append("")
current_length = len(current)
#difference = 8-current_length
while len(current) > 0:
... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
246/B | 246 | B | Python 3 | TESTS | 4 | 62 | 0 | 223411385 | n=int(input())
a=list(map(int,input().split()))
j=sum(a)//n
man=[]
mos=[]
m=0
for i in range(0,len(a)) :
if j-a[i]<0 :
man.append(abs(j-a[i]))
else :
mos.append(j-a[i])
m+=j-a[i]
o=0
man.sort()
for i in range(0,len(man)) :
if m-man[i]>=0 :
o+=1
m-=man[i]
else :
... | 30 | 92 | 3,379,200 | 144936948 | n=int(input())
ls=list(map(int,input().split()))
print(n if sum(ls)%n==0 else n-1) | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 62 | 0 | 144806838 | for _ in range(int(input())):
st = input()
arr = st.split(':')
for i in range(len(arr)):
while 0 != len(arr[i]) != 4:
arr[i] = "0" + arr[i]
while '' in arr:
ind = arr.index('')
arr[ind] = "0000"
for __ in range(8 - len(arr)):
arr.insert(ind, "0000"... | 40 | 92 | 0 | 166403517 | # coding=utf8
cnt = input()
for k in range(int(cnt)):
ip = input()
if ip == "":
print("0000:0000:0000:0000:0000:0000:0000:0000")
continue
ip = ip.split(":")
ret = ""
# 扩::
if ip[0] == "":
ip = ["0000"] * (8 - len(ip) + 2) + ip[2:]
elif ip[-1] == "":
ip = ip[:-... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
246/B | 246 | B | Python 3 | TESTS | 4 | 62 | 0 | 176971636 | input()
l = list(map(int, input().split()))
l.sort()
while True:
l = sorted(l)
if abs(l[-1] - l[0]) > 1:
l[0] += 1
l[-1] -= 1
else:
break
l1 = list(set(l))
q = 0
for i in l1:
c = l.count(i)
if c > q:
q = c
print(q) | 30 | 92 | 3,379,200 | 146607760 | # Author: Riddhish V. Lichade
# username: root_rvl
# codeforces 246B
from collections import Counter
from sys import stdin, stdout
from heapq import nlargest, nsmallest
def outnl(x): stdout.write(str(x) + '\n')
def outsl(x): stdout.write(str(x) + ' ')
def instr(): return stdin.readline().strip()
def inint(): return int... | Codeforces Round 151 (Div. 2) | CF | 2,012 | 2 | 256 | Increase and Decrease | Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array ai, aj (i ≠ j);
- h... | The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | null | null | [{"input": "2\n2 1", "output": "1"}, {"input": "3\n1 4 1", "output": "3"}] | 1,300 | ["greedy", "math"] | 30 | [{"input": "2\r\n2 1\r\n", "output": "1\r\n"}, {"input": "3\r\n1 4 1\r\n", "output": "3\r\n"}, {"input": "4\r\n2 -7 -2 -6\r\n", "output": "3\r\n"}, {"input": "4\r\n2 0 -2 -1\r\n", "output": "3\r\n"}, {"input": "6\r\n-1 1 0 0 -1 -1\r\n", "output": "5\r\n"}, {"input": "5\r\n0 0 0 0 0\r\n", "output": "5\r\n"}] | false | stdio | null | true |
925/A | 925 | A | PyPy 3-64 | TESTS | 7 | 452 | 13,824,000 | 182208608 | import sys
input = sys.stdin.readline
from bisect import bisect
def f(x, y, z, q):
global ew
if len(x) == 0:
return
a1 = bisect(x, y)
if a1 == 0:
if x[0] < z:
ew = min(ew, q+z-y)
else:
ew = min(ew, (x[0]-z)*2+z-y+q)
elif a1 == len(x):
ew = ... | 27 | 1,450 | 22,323,200 | 37718038 | # python3
import sys
from bisect import bisect
def readline(): return tuple(map(int, input().split()))
def readlines():
return (tuple(map(int, line.split())) for line in sys.stdin.readlines())
def bisect_bounds(arr, val):
idx = bisect(arr, val)
if idx: yield idx - 1
if idx < len(arr): yield idx
cl... | VK Cup 2018 - Round 3 | CF | 2,018 | 2 | 256 | Stairs and Elevators | In the year of $$$30XX$$$ participants of some world programming championship live in a single large hotel. The hotel has $$$n$$$ floors. Each floor has $$$m$$$ sections with a single corridor connecting all of them. The sections are enumerated from $$$1$$$ to $$$m$$$ along the corridor, and all sections with equal num... | The first line contains five integers $$$n, m, c_l, c_e, v$$$ ($$$2 \leq n, m \leq 10^8$$$, $$$0 \leq c_l, c_e \leq 10^5$$$, $$$1 \leq c_l + c_e \leq m - 1$$$, $$$1 \leq v \leq n - 1$$$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator,... | Print $$$q$$$ integers, one per line — the answers for the queries. | null | In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.
In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in th... | [{"input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3", "output": "7\n5\n4"}] | 1,600 | ["binary search"] | 27 | [{"input": "5 6 1 1 3\r\n2\r\n5\r\n3\r\n1 1 5 6\r\n1 3 5 4\r\n3 3 5 3\r\n", "output": "7\r\n5\r\n4\r\n"}, {"input": "2 2 0 1 1\r\n\r\n1\r\n1\r\n1 2 2 2\r\n", "output": "3\r\n"}, {"input": "4 4 1 0 1\r\n4\r\n\r\n5\r\n1 1 2 2\r\n1 3 2 2\r\n3 3 4 3\r\n3 2 2 2\r\n1 2 2 3\r\n", "output": "6\r\n4\r\n3\r\n5\r\n4\r\n"}, {"inpu... | false | stdio | null | true |
430/A | 430 | A | Python 3 | TESTS | 3 | 61 | 0 | 7699791 | #input
n,m=map(int,input().split())
xlist=[int(x) for x in input().split()]
#variables
#main
for i in range(n):
if xlist[i]%2==0:
xlist[i]='0'
else:
xlist[i]='1'
print(''.join([xlist[i]+' ' for i in range(n)])) | 12 | 46 | 0 | 9383025 | n, m = map(int, input().split())
p = sorted((x[1], x[0]) for x in enumerate(map(int, input().split())))
p = sorted((x[1], str(i % 2)) for i, x in enumerate(p))
print(' '.join(x[1] for x in p)) | Codeforces Round 245 (Div. 2) | CF | 2,014 | 1 | 256 | Points and Segments (easy) | Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following.
Iahub wants to draw n distinct points and m segme... | The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤... | If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue).
If there are multiple good drawings you can output any of them. | null | null | [{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}] | 1,600 | ["constructive algorithms", "sortings"] | 12 | [{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ... | false | stdio | import sys
def read_ints(file):
return list(map(int, file.read().split()))
def main(input_path, output_path, submission_path):
with open(input_path) as f:
n, m = map(int, f.readline().split())
points = list(map(int, f.readline().split()))
segments = [tuple(map(int, f.readline().split()... | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 92 | 0 | 227614298 | # LUOGU_RID: 128695624
for i in range(int(input())):
a=input().replace('::',':#:').split(':')
while len(a)<8:a.insert(a.index('#'),'0000')
for i in range(8):
if'#'==a[i]:a[i]='0000'
else:a[i]='0'*(4-len(a[i]))+a[i]
print(str(a)[2:-2].replace("', '",':')) | 40 | 92 | 0 | 166411665 | def _ip_ (ipv6):
l = 7 - (len (ipv6) - len (ipv6.replace (":", "", )))
ipv6 = ipv6.replace ("::", ":" * (l + 2))
list = ipv6.split (":", )
ip = ["", "", "", "", "", "", "", ""]
for i in range(0, 8):
t = list [i]
while len (t) != 4:
t = "0" + t
ip [i] = t
t = "... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
665/B | 665 | B | PyPy 3 | TESTS | 1 | 93 | 512,000 | 119286782 | import sys
sys.stderr = sys.stdout
import heapq
from collections import deque
def shop(n, m, k, P, A):
t = 0
for Ai in A:
d = deque(reversed(Ai), m+1)
o = {a:i for i, a in enumerate(Ai)}
l = [None] * m
j = 0
for i in range(k):
p = P[i]
if p in o... | 10 | 46 | 0 | 179558449 | f = lambda: map(int, input().split())
n, m, k = f()
a = list(f())
s = m * n
for i in range(n):
for b in f():
i = a.index(b)
s += i
a = [a.pop(i)] + a
print(s) | Educational Codeforces Round 12 | ICPC | 2,016 | 1 | 256 | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the ... | The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are... | Print the only integer t — the total time needed for Ayush to process all the orders. | null | Customer 1 wants the items 1 and 5.
pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
pos(1) = 3, so the new positi... | [{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}] | 1,400 | ["brute force"] | 10 | [{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99... | false | stdio | null | true |
355/B | 355 | B | PyPy 3 | TESTS | 3 | 92 | 0 | 109971543 | if __name__ == '__main__':
c1,c2,c3,c4 = map(int, input().split())
n,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = min(c1,c2,c3,c4)
l = []
if s == c4:
print(c4)
elif s == c3:
if 2*c3 > c4 and c4 <= min((c1*min(a)+c2),(c1*min(b)+c2),c1*sum(a),c2*(su... | 27 | 46 | 307,200 | 4775478 | c1,c2,c3,c4=map(int,input().split())
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[]
s0=0
for i in range(n):
s.append(min(a[i]*c1,c2))
s0+=s[i]
s1=[]
s10=0
for i in range(m):
s1.append(min(b[i]*c1,c2))
s10+=s1[i]
print(min((min(s0,c3)+min(s10,c3)),c4)) | Codeforces Round 206 (Div. 2) | CF | 2,013 | 1 | 256 | Vasya and Public Transport | Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m.
Public transport is not free. There are 4 types of tickets:
1. A ticket for one ride... | The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.
The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go... | Print a single number — the minimum sum of burles Vasya will have to spend on the tickets. | null | In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles.
In the second sample the profitable strategy is to buy one ticket of t... | [{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}] | 1,100 | ["greedy", "implementation"] | 27 | [{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ... | false | stdio | null | true |
665/B | 665 | B | PyPy 3 | TESTS | 1 | 93 | 102,400 | 119285806 | import sys
sys.stderr = sys.stdout
from collections import deque
def shop(n, m, k, P, A):
t = 0
for Ai in A:
d = deque(reversed(Ai), m+1)
s = set(Ai)
o = {}
j = 0
for i in range(k):
p = P[i]
if p in s:
t += (i+1)
... | 10 | 46 | 0 | 184897242 | n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
cnt=0
for i in range(n):
b=list(map(int,input().split()))
for j in range(len(b)):
c=a.index(b[j])+1
cnt+=c
a.insert(0,b[j])
del a[c]
print(cnt) | Educational Codeforces Round 12 | ICPC | 2,016 | 1 | 256 | Shopping | Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online.
The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order.
Due to the ... | The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market.
The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are... | Print the only integer t — the total time needed for Ayush to process all the orders. | null | Customer 1 wants the items 1 and 5.
pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5].
pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2].
Time taken for the first customer is 3 + 5 = 8.
Customer 2 wants the items 3 and 1.
pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2].
pos(1) = 3, so the new positi... | [{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}] | 1,400 | ["brute force"] | 10 | [{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99... | false | stdio | null | true |
358/C | 358 | C | Python 3 | PRETESTS | 2 | 46 | 307,200 | 4882199 | n=int(input())
cur=[]
while n>0:
cx=int(input())
if(cx!=0):
cur.append(-cx)
else:
fx=[i for i in cur]
fx.sort()
fx=fx[:3]
used=''
ux=0
for i in cur:
if i == fx[0]:
print('pushStack')
fx[0]=0
... | 26 | 311 | 28,569,600 | 135330920 | # Author Name: Ajay Meena
# Codeforce : https://codeforces.com/profile/majay1638
import sys
import math
import bisect
import heapq
from bisect import bisect_right
from sys import stdin, stdout
# -------------- INPUT FUNCTIONS ------------------
def get_ints_in_variables(): return map(
int, sys.stdin.readline().s... | Codeforces Round 208 (Div. 2) | CF | 2,013 | 2 | 256 | Dima and Containers | Dima has a birthday soon! It's a big day! Saryozha's present to Dima is that Seryozha won't be in the room and won't disturb Dima and Inna as they celebrate the birthday. Inna's present to Dima is a stack, a queue and a deck.
Inna wants her present to show Dima how great a programmer he is. For that, she is going to g... | The first line contains integer n (1 ≤ n ≤ 105) — the number of Inna's commands. Then n lines follow, describing Inna's commands. Each line consists an integer:
1. Integer a (1 ≤ a ≤ 105) means that Inna gives Dima a command to add number a into one of containers.
2. Integer 0 shows that Inna asks Dima to make at most... | Each command of the input must correspond to one line of the output — Dima's action.
For the command of the first type (adding) print one word that corresponds to Dima's choice:
- pushStack — add to the end of the stack;
- pushQueue — add to the end of the queue;
- pushFront — add to the beginning of the deck;
- push... | null | null | [{"input": "10\n0\n1\n0\n1\n2\n0\n1\n2\n3\n0", "output": "0\npushStack\n1 popStack\npushStack\npushQueue\n2 popStack popQueue\npushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}, {"input": "4\n1\n2\n3\n0", "output": "pushStack\npushQueue\npushFront\n3 popStack popQueue popFront"}] | 2,000 | ["constructive algorithms", "greedy", "implementation"] | 26 | [{"input": "10\r\n0\r\n1\r\n0\r\n1\r\n2\r\n0\r\n1\r\n2\r\n3\r\n0\r\n", "output": "0\r\npushStack\r\n1 popStack\r\npushStack\r\npushQueue\r\n2 popStack popQueue\r\npushStack\r\npushQueue\r\npushFront\r\n3 popStack popQueue popFront\r\n"}, {"input": "4\r\n1\r\n2\r\n3\r\n0\r\n", "output": "pushStack\r\npushQueue\r\npushFr... | false | stdio | import sys
from collections import deque
def main(input_path, output_path, submission_path):
with open(input_path) as f:
input_lines = f.read().splitlines()
n = int(input_lines[0])
input_commands = input_lines[1:n+1]
with open(submission_path) as f:
submission_lines = [line.strip()... | true |
247/B | 250 | B | Python 3 | TESTS | 1 | 92 | 0 | 22707021 | for i in range(int(input())):
ipv6 = input().split(':')
ipv6 = [((4 - len(i))*'0' + i) if i != '' else '' for i in ipv6]
if ipv6[-1] == '':
ipv6[-1] = '0000'
if ipv6[0] == '':
ipv6[0] = '0000'
if '' in ipv6:
string = '0000:'*(8 - len(ipv6) + 1)
ipv6[ipv6.index('')] = string[:-1]
print(':'.jo... | 40 | 92 | 0 | 175711939 | import sys
input = sys.stdin.readline
for _ in range(int(input())):
s = input()[:-1].split(':')
c = 0
for i in s:
if i != '':
c += 1
d = []
x = 0
for i in s:
if i != '':
d.append(i.rjust(4, '0'))
else:
if x == 0:
x = 1
... | CROC-MBTU 2012, Final Round | CF | 2,012 | 2 | 256 | Restoring IPv6 | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer n — the number of records to restore (1 ≤ n ≤ 100).
Each of the following n lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is described... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | null | null | [{"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0... | 1,500 | [] | 40 | [{"input": "6\r\na56f:d3:0:0124:01:f19a:1000:00\r\na56f:00d3:0000:0124:0001::\r\na56f::0124:0001:0000:1234:0ff0\r\na56f:0000::0000:0001:0000:1234:0ff0\r\n::\r\n0ea::4d:f4:6:0\r\n", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\r\na56f:00d3:0000:0124:0001:0000:0000:0000\r\na56f:0000:0000:0124:0001:0000:1234:0ff0\r\... | false | stdio | null | true |
82/B | 82 | B | PyPy 3 | TESTS | 32 | 624 | 5,836,800 | 64872281 | n=int(input())
st=[]
from collections import *
cnt=defaultdict(list)
for _ in range((n*(n-1))//2):
x=str(_)
l=set(int(j) for j in input().split()[1:])
for i in l:
cnt[i].append(x)
for i,j in cnt.items():
cnt[i]='#'.join(j)
finset=defaultdict(list)
for i,j in cnt.items():
finset[j].append(i)
... | 34 | 186 | 2,457,600 | 4454031 | n=int(input())
L=[]
for i in range((n*(n-1))//2):
A=input().split()
L.append(A[1:])
x=L[0][0]
Set=list(L[0])
Set.remove(x)
for i in range(1,(n*(n-1))//2):
if(x in L[i]):
for item in L[i]:
if(item in Set):
Set.remove(item)
break
x=Set[0]
Sets=[]
Sets.append(... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
82/B | 82 | B | PyPy 3-64 | TESTS | 32 | 778 | 36,556,800 | 167598152 | import itertools
import math
import time
from builtins import input, range
from math import gcd as gcd
import sys
import queue
import itertools
import collections
from heapq import heappop, heappush
import random
import os
from random import randint
import decimal
# from sys import stdin, stdout
# input, print = stdin... | 34 | 186 | 10,649,600 | 126790096 | #Med_Neji
#x,y=map( lambda x:int(x)//abs(int(x)) ,input().split())
#x,y=map(int,input().split())
#n=int(input())
#l=list(map(int,input().split()))
#s=input()
#x=0
n=int(input())
l = [(set(input().split()[1:])) for _ in range(n*(n-1)//2)]
if n==2:
l=list(l[0])
print(1,l[0])
print(len(l)-1,*l[1:])
q=set()
... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
82/B | 82 | B | Python 3 | TESTS | 32 | 1,466 | 2,457,600 | 136687666 | import math
#s = input()
#n = int(input())
#n= (map(int, input().split()))
my_list = list()
list_mn = list()
#n, m, k =(map(int, input().split()))
def recurse(my_set_):
for i in my_list:
set_ = my_set_& i
if(len(set_)):
set_ = i - set_
if(set_ in list_mn):
... | 34 | 248 | 7,577,600 | 196930821 | from copy import copy
from sys import stdin
n = int(stdin.readline())
if n == 2:
a, *arr = map(int, stdin.readline().strip().split())
first = arr[:len(arr) // 2]
second = arr[len(arr) // 2:]
print(len(first), *first)
print(len(second), *second)
exit()
neigh_by_element = dict()
for i in range(... | Yandex.Algorithm 2011: Qualification 2 | CF | 2,011 | 2 | 256 | Sets | Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.
One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible... | The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then fo... | Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. ... | null | null | [{"input": "4\n3 2 7 4\n3 1 7 3\n3 5 4 2\n3 1 3 5\n4 3 1 2 4\n2 5 7", "output": "1 7\n2 2 4\n2 1 3\n1 5"}, {"input": "4\n5 6 7 8 9 100\n4 7 8 9 1\n4 7 8 9 2\n3 1 6 100\n3 2 6 100\n2 1 2", "output": "3 7 8 9\n2 6 100\n1 1\n1 2"}, {"input": "3\n2 1 2\n2 1 3\n2 2 3", "output": "1 1\n1 2\n1 3"}] | 1,700 | ["constructive algorithms", "hashing", "implementation"] | 34 | [{"input": "4\r\n3 2 7 4\r\n3 1 7 3\r\n3 5 4 2\r\n3 1 3 5\r\n4 3 1 2 4\r\n2 5 7\r\n", "output": "1 7 \r\n2 2 4 \r\n2 1 3 \r\n1 5 \r\n"}, {"input": "4\r\n5 6 7 8 9 100\r\n4 7 8 9 1\r\n4 7 8 9 2\r\n3 1 6 100\r\n3 2 6 100\r\n2 1 2\r\n", "output": "3 7 8 9 \r\n2 6 100 \r\n1 1 \r\n1 2 \r\n"}, {"input": "3\r\n2 1 2\r\n2 1 3\... | false | stdio | import sys
def main():
input_path = sys.argv[1]
submission_path = sys.argv[3]
with open(input_path, 'r') as f:
lines = [l.strip() for l in f if l.strip()]
n = int(lines[0])
m = n * (n - 1) // 2
input_unions = set()
for line in lines[1:1+m]:
parts = list(map(int, line.s... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.