input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *
sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()
def main():
N = int(eval(input()))
h = list(map(... | import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *
sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()
def f(arr):
m = min(arr)
for i in range(len(arr)... | p03147 |
N = int(eval(input()))
H = list(map(int, input().split()))
count = 0
H.append(0)
for lv in range(1, 101):
flag = False
for h in H:
if flag and h < lv:
count += 1
flag = False
elif not flag and h >= lv:
flag = True
print(count)
| N=int(eval(input()))
*H,=list(map(int, input().split()))
H = [0] + H
ans = 0
for i in range(1,N+1):
w = H[i] - H[i-1]
if w > 0: ans += w
print(ans) | p03147 |
N = int(eval(input()))
H = list(map(int,input().split()))
ans = 0
for i in range(N-1):
if(H[i] > H[i+1]):
ans += H[i] - H[i+1]
print((ans + H[-1])) | def ans():
N = int(eval(input()))
H = list(map(int,input().split()))
res = 0
for i in range(N-1):
if(H[i] > H[i+1]):
res += H[i] - H[i+1]
print((res + H[-1]))
ans() | p03147 |
N = int(eval(input()))
h = list(map(int, input().split()))
board = [[0] * (N + 1) for _ in range(max(h))]
for i in range(N):
for j in range(h[i]):
board[j][i + 1] = 1
print((sum(row[i] == 0 and row[i + 1] == 1 for row in board for i in range(N))))
| eval(input())
ans, tmp = 0, 0
for h in map(int, input().split()):
ans += max(0, h - tmp)
tmp = h
print(ans)
| p03147 |
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)... | import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)... | p03147 |
N=int(eval(input()))
A=list(map(int,input().split()))
maxh=max(A)
ans=0
for i in range(1,maxh+1):
# i 以上の高さのブロック数をカウントする
block=0
cur=False
if A[0]>=i:
block+=1
cur=True
for j in range(1,len(A)):
if A[j]>=i:
if not cur:
block+=1
cur=True
else:
cur=... | N=int(eval(input()))
A=list(map(int,input().split()))
cur=0
ans=0
for i in range(N):
if A[i]>cur:
ans+=A[i]-cur
cur=A[i]
print(ans) | p03147 |
'''
数列hを棒グラフと見て
0と0で挟まれた山の個数を数える→すべて-1して山を削っていく
出力例2なら
[3 1 2 3 1]をmax(h)回,-1ずつ減らしていく
[2, 0, 1, 2, 0]
[1, 0, 0, 1, 0]
[0, 0, 0, 0, 0]
0になると花に水をやってはいけないから
count0でその花が何番目にあるか,を取得
数列count0で前項との差が1より大きければ山がある=水をかけれる
'''
n=int(eval(input()))
h=list(map(int, input().split()))
sum=0
for i in range(max(h)):
... | n,*h=list(map(int,open(0).read().split()))
a=h[0]
for i in range(1,n):
if h[i-1]<h[i]:
a+=h[i]-h[i-1]
print(a) | p03147 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
# 方針
# 前から順に-1していく... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
def LI(): return list(map(int,input().split()))
def I(): return int(eval(input()))
def LS(): return input().split()
def S(): return eval(input())
def main():
n=I(... | p03147 |
N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
for i in range(max(h)):
h.append(0)
count = 0
for k in range(N):
if h[k] != 0 and h[k + 1] == 0:
count += 1
ans += count
h = list([(x - 1, 0)[x == 0] for x in h])
print(ans) | N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
count = 0
h.append(0)
f = set(h)
for i in range(max(h)):
if i in f:
count = 0
for k in range(N):
if h[k] != 0 and h[k + 1] == 0:
count += 1
ans += count
h = list([(x - 1, 0)[x == 0] fo... | p03147 |
n=0
Answer=0
N=int(eval(input()))
h=list(map(int,input().split()))
h.insert(0,0)
for i in range(N):
if h[n]<=h[n+1]:
m=h[n+1]-h[n]
Answer=Answer+m
else :
pass
n=n+1
print(Answer) | N=int(eval(input()))
h=list(map(int,input().split()))
Answer=h[0]
for i in range(N-1):
if h[i]<=h[i+1]:
m=h[i+1]-h[i]
Answer=Answer+m
print(Answer) | p03147 |
n = int(eval(input()))
H = [int(i) for i in input().split()]
count = 0
for _ in range(100):
flag = 1
for i in range(n):
if H[i] > 0:
H[i] -= 1
if flag:
count += 1
flag = 0
else:
flag = 1
print(count) | n = int(eval(input()))
A = [0] + [int(i) for i in input().split()]
cnt = 0
for i in range(n):
if A[i + 1] > A[i]:
cnt += A[i + 1] - A[i]
print(cnt) | p03147 |
N = int(eval(input()))
h = list(map(int,input().split()))
if h == [0]*N:
print((0))
exit()
for i in range(1,10001):
f = False
for j in range(N):
if h[j] > 0:
h[j] -= 1
f = True
elif h[j] <= 0 and f:
break
if h == [0]*N:
ans = ... | N = int(eval(input()))
H = list(map(int,input().split()))
cnt = 0
for _ in range(10**4):
if any(H) is False:
break
cnt += 1
f = False
for i in range(len(H)):
if H[i] > 0:
H[i] -= 1
f = True
elif f and H[i] == 0:
break
print(cnt) | p03147 |
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li = [0] + li
zantei = 0
point = 0
for i in range(len(li)):
if li[i-1] <= li[i]:
point += li[i]-li[i-1]
print(point) | n = int(eval(input()))
h = list(map(int,input().split()))
point = 0
now = 0
for i in h:
if now <= i:
now,point = i,point+(i-now)
else:
now = i
print(point) | p03147 |
def calc(a,n):
array = [[a[j]>i for j in range(n)] for i in range(max(a))]
mat = [[a for a,b in zip(row,row[1:]+[False]) if a and a!=b]for row in array]
return sum([len(row)for row in mat])
n = int(eval(input()))
a = [int(e) for e in input().split()]
print((calc(a,n))) | n = int(eval(input()))
a = [int(e) for e in input().split()]
tmp_mat = [[a[j]>i for j in range(n)] for i in range(max(a))]
mat = [[a for a,b in zip(row,row[1:]+[False]) if a and a!=b]for row in tmp_mat]
print((sum([len(row)for row in mat]))) | p03147 |
N = int(eval(input()))
H = list(map(int,input().split()))
flowers = [0] * N
start = 0
end = 0
con = 0
while flowers != H:
for i in range(0,N):
if H[i] > flowers[i]:
start = i
for j in range(i,N):
if H[j] == flowers[j]:
end = j
break
else:
end = N
break
... | N = int(eval(input()))
L = list(map(int,input().split()))
s = L[0]
ans = s
for i in range(0,N):
if s <= L[i]:
ans += L[i] - s
s = L[i]
print(ans) | p03147 |
n=int(eval(input()))
h=[int(x) for x in input().split()]
height=[]
result=0
tmp=0
for i in range(max(h)):
buf=[]
for j in range(n):
if h[j] > i:
buf.append(1)
else:
buf.append(0)
height.append(buf)
for val in height:
while(tmp < len(val)):
... | n=int(eval(input()))
h=[int(x) for x in input().split()]
buf=[0 for i in range(n)]
ans=0
flag=False
for i in range(max(h)):
for j in range(n):
if h[j] >= i+1:
flag=True
if flag and h[j] <= i:
ans+=1
flag=False
if flag:
ans+=1
... | p03147 |
def main():
import sys
input = sys.stdin.readline
a = int(input().rstrip('\n'))
s = str(input().rstrip('\n'))
if a >= 3200:
print(s)
else:
print("red")
if __name__ == '__main__':
main()
| def slove():
import sys
input = sys.stdin.readline
a = int(input().rstrip('\n'))
s = str(input().rstrip('\n'))
print((s if a >= 3200 else "red"))
if __name__ == '__main__':
slove()
| p02933 |
import decimal
X = int(eval(input()))
i = 0
K = 100
while K < X:
i = i + 1
K_ = decimal.Decimal(str(K*1.01))
K = int(K_.quantize(decimal.Decimal('0'), rounding=decimal.ROUND_FLOOR))
print(i) | X = int(eval(input()))
i = 0
K = 100
while K < X:
i = i + 1
K = int(K*1.01)
print(i) | p02694 |
import sys
input = sys.stdin.readline
from collections import *
X = int(eval(input()))
now = 100
ans = 0
while now<X:
now = int(1.01*now)
ans += 1
print(ans) | X = int(eval(input()))
now = 100
ans = 0
while now<X:
now += now//100
ans += 1
print(ans) | p02694 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import floor
from decimal import Decimal
def main():
x = int(eval(input()))
n = Decimal(100)
r = 0
while n < x:
n = Decimal(floor((n * Decimal(101) / Decimal(100))))
r += 1
print(r)
if __name_... | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import floor
from decimal import Decimal
def main():
x = int(eval(input()))
n = Decimal(100)
r = 0
while n < x:
n = Decimal(floor((n * 101 / 100)))
r += 1
print(r)
if __name__ == '__main__':
... | p02694 |
from math import floor
def main():
X=int(eval(input()))
tmp=100
for year in range(1,4000):
tmp += tmp//100
if tmp >= X:
print(year)
exit()
main()
| def main():
X=int(eval(input()))
tmp=100
for year in range(1,4000):
tmp += tmp//100
if tmp >= X:
print(year)
exit()
main()
| p02694 |
from sys import exit
def main():
X = int(eval(input()))
deposit = 100
i = 0
while True:
deposit = int(deposit * 1.01)
i += 1
if deposit >= X:
print(i)
exit()
if __name__ == '__main__':
main() | # from sys import exit
def main():
x = int(eval(input()))
d = 100
ans = 0
while d < x:
d = int(d*1.01)
ans += 1
print(ans)
if __name__ == '__main__':
main() | p02694 |
import math
x = int(eval(input()))
a = 100
for i in range(1,4000):
a = math.floor(a * 1.01)
if a >= x:
print(i)
break
| x = int(eval(input()))
a = 100
ans = 0
while (a < x):
a += a//100
ans+=1
print(ans) | p02694 |
x=int(eval(input()))
n=100
cnt=0
while n<x:
cnt+=1
n*=101
n//=100
print(cnt) | x=int(eval(input()))
n=100
cnt=0
while n<x:
cnt+=1
n+=n//100
print(cnt)
| p02694 |
from math import floor,ceil
X = int(eval(input()))
p = 100
c = 0
while p < X:
p=floor(p*1.01)
c += 1
print(c) | from math import floor,ceil
X = int(eval(input()))
cash = 100
count = 0
while cash < X:
cash=floor(cash*1.01)
count += 1
print(count) | p02694 |
X = int(eval(input()))
a = 100
i = 0
while a < X:
a += a // 100
i += 1
print(i) | X = int(eval(input()))
# 割り算をして切り下げるときは a // b が良い!
a = 100
i = 0
while a < X:
a += a // 100
i += 1
print(i) | p02694 |
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
x = int(eval(input()))
yokin = 100
for i in range(1, 100000000000):
yokin *= 101
yokin = yokin //100
if (yokin >= x):
print(i)
break
| #k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))
x = int(eval(input()))
yokin = 100
for i in range(1, 100000000000):
yokin += yokin // 100
if (yokin >= x):
print(i)
break
| p02694 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, produc... | # -*- coding: utf-8 -*-
INF = 2**62-1
def read_int():
return int(eval(input()))
def slv(X):
T = 100
for i in range(INF):
T += T // 100
T = int(T)
if X <= T:
return i + 1
def main():
X = read_int()
print((slv(X)))
if __name__ == '__mai... | p02694 |
import math
from decimal import Decimal
X = int(eval(input()))
now = 100
year = 0
while True:
if now >= X:
break
#now = int(now * Decimal("1.01"))
now = int(now * round(Decimal(1.01), 2))
year += 1
print(year)
| import math
from decimal import Decimal
X = int(eval(input()))
now = 100
year = 0
while True:
if now >= X:
break
#now = int(now * Decimal("1.01"))
#now = int(now * round(Decimal(1.01), 2))
now += now // 100
year += 1
print(year)
| p02694 |
n = 0
m = 100
X = int(eval(input()))
while m < X:
m += (m // 100)
n += 1
print(n)
| X = int(eval(input()))
n = 0
x = 100
while x < X:
x += x // 100
n += 1
print(n) | p02694 |
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
... | x = int(eval(input()))
a = 100
count = 0
while a < x:
a = int(a*101//100)
count += 1
print(count) | p02694 |
x = int(eval(input()))
depo = 100
#rate = depo*0.01
count = 0
while depo < x:
rate = depo*0.01
depo += rate
depo = int(depo)
count += 1
print(count)
|
x = int(eval(input()))
depo = 100
count = 0
while depo < x:
depo += int(depo*0.01)
count += 1
print(count)
| p02694 |
x = int(eval(input()))
dum = 100
count = 0
while(1):
if dum >= x:
break
dum = dum*1.01
dum = dum//1
count += 1
#print(dum)
print(count) | import math
x = int(eval(input()))
a = 100
cnt = 0
while(1):
cnt += 1
a += a//100
if a >= x:
break
print(cnt)
| p02694 |
from math import floor
x = int(eval(input()))
ans = 0
y = 100
while y < x:
y = floor(y*1.01)
ans += 1
print(ans) | def resolve():
X = int(eval(input()))
tmp = 100
ans = 0
while tmp<X:
tmp += tmp//100
ans += 1
print(ans)
resolve() | p02694 |
X = int(eval(input()))
save = 100
count = 0
while save < X:
save += int(save * 0.01)
count += 1
print(count) | X = int(eval(input()))
m = 100
count = 0
while m < X:
m *= 1.01
m = int(m)
count += 1
print(count) | p02694 |
X = int(eval(input()))
count = 0
money = int(100)
while True:
money = int(money * 1.01)
count += 1
if money >= X:
print(count)
break
| X = int(eval(input()))
count = 0
money = 100
while True:
money = int(money * 1.01)
count += 1
if money >= X:
print(count)
break
| p02694 |
X = int(eval(input()))
p = 100
i = 0
while p < X:
i += 1
p += int(p*0.01)
print(i) | x = int(eval(input()))
i = 0
z = 100
while z < x:
i += 1
z = int(z * 1.01)
print(i) | p02694 |
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.... | #import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.... | p02694 |
import math
x = int(eval(input()))
y=math.floor(100)
d=int(y)
year=0
while y<x:
y*=1.01
d=int(y)
y=d
year+=1
#print(y,year)
print(year) | x = int(eval(input()))
y=100
year=0
while y<x:
y=int(y*1.01)
year+=1
print(year) | p02694 |
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from math import floor
x = int(readline())
v = 100
for i in range(x):
v = floor(v * 1.01)
if v >= x:
print((i + 1))
exit()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from math import floor
x = int(read())
v = 100
for i in range(x):
v = floor(v * 1.01)
if v >= x:
print((i + 1))
exit()
| p02694 |
import math
x = int(eval(input()))
m = 100
cnt = 0
while 1:
cnt += 1
m = m + math.floor(m * 0.01)
if m >= x:
break
print(cnt) | import math
x = int(eval(input()))
m = 100
cnt = 0
while 1:
cnt += 1
m = math.floor(m * 1.01)
if m >= x:
break
print(cnt) | p02694 |
x = int(eval(input()))
import sys
sys.setrecursionlimit(4000)
def f(n):
if n == 1:
return 101
else:
return int(f(n-1)*1.01)
n = 1
while f(n) < x:
n += 1
else:
print(n) | x = int(eval(input()))
import sys
sys.setrecursionlimit(4000)
import math
p = math.log(1.01, 10)
q = int(math.log(x/100, 10)/p)
def f(n):
if n == 1:
return 101
else:
return int(f(n-1)*1.01)
n = q
while f(n) < x:
n += 1
else:
print(n) | p02694 |
def main():
x = int(eval(input()))
m = 100
for i in range(10**5):
if m >= x:
print(i)
return
m += m//100
if __name__ == "__main__":
main() | def main():
x = int(eval(input()))
money = 100
for i in range(10**5):
if money >= x:
print(i)
return
money += money//100
if __name__ == "__main__":
main()
| p02694 |
import math
x = int(eval(input()))
a = 100
ans = 1
while True:
a = int(math.floor(a*1.01))
if a >= x:
print(ans)
exit()
else:
ans += 1 | import math
x = int(eval(input()))
money = 100
ans = 0
while True:
if money >= x:
print(ans)
exit()
else:
money = int(math.floor(money * 1.01))
ans += 1 | p02694 |
x = int(eval(input()))
money = 100
ans = 0
while money < x:
ans += 1
money *= 101
money //= 100
print(ans) | x = int(eval(input()))
money, cnt = 100, 0
while money < x:
money += money // 100
cnt += 1
print(cnt) | p02694 |
k = int(eval(input()))
now = 100
cnt = 0
while (now < k):
now *= 1.01
now = int(now)
cnt += 1
print(cnt) | x = int(eval(input()))
money = 100
ans = 0
while(money < x):
ans += 1
money *= 1.01
money = int(money)
print(ans)
| p02694 |
x = int(eval(input()))
total = 100
year = 0
while x > total:
year += 1
total += total//100
print(year)
| import math
x = int(eval(input()))
initial = 100
count = 0
while initial < x:
initial += initial//100
count += 1
print(count) | p02694 |
a = [100]
for i in range(4000):
a.append(a[-1] + a[-1] // 100)
x = int(eval(input()))
for i in range(4000):
if a[i] >= x:
print(i)
exit() | X = int(eval(input()))
x1 = 100
r = 0.01
t = 0
if 101 <= X <=10**18:
while x1 < X:
R = int(x1 * r)
x1 = R + x1
t = t + 1
print(t)
| p02694 |
x = int(eval(input()))
money = 100
year = 0
while money < x:
money += int(money / 100)
year += 1
print(year)
| x = int(eval(input()))
money = 100
year = 0
while money < x:
money += money // 100
year += 1
print(year)
| p02694 |
from math import floor
from fractions import Fraction
from decimal import Decimal
def com_interest(n: int) -> int:
saving = Decimal(100)
interest_per = 0.01
years = 0
while True:
years += 1
b = Decimal('1.01')
saving = int(saving) * b
if saving >= n:
... | from decimal import Decimal
def com_interest(n: int) -> int:
saving = Decimal('100')
interest_per = 0.01
years = 0
while True:
years += 1
saving = int(saving * Decimal('1.01'))
if saving >= n:
break
return years
print((com_interest(int(eval(in... | p02694 |
from decimal import Decimal
x=int(eval(input()))
n=Decimal("100")
ans=0
while True:
ans+=1
n*=Decimal("1.01")
n//=1
if n>=x:
print(ans)
break | x=int(eval(input()))
n=100
ans=0
while True:
ans+=1
n+=n//100
if n>=x:
print(ans)
break | p02694 |
X = int(eval(input()))
y = 100
flag = 1
con = 0
while flag:
y *= 1.01
y = int(y)
con += 1
if y >= X:
flag = 0
print(con)
| X = int(eval(input()))
money = 100
ans = 0
while money < X:
ans += 1
money = int(money*1.01)
print(ans) | p02694 |
x = int(eval(input()))
year = 0
m = 100
for i in range(100000):
m = int(m*1.01)
year += 1
if m >= x:
print(year)
exit() | x = int(eval(input()))
year = 0
m = 100
for i in range(100000):
m = m*101//100
year += 1
if m >= x:
print(year)
exit() | p02694 |
while 1:
N,T,L,B = list(map(int,input().split()))
if N == 0: break
lose = [int(input()) for i in range(L)]
back = [int(input()) for i in range(B)]
dp = [[0.0]*(N+1) for i in range(T+2)]
dp[0][0] = 1.0
ans = 0.0
p = 1.0/6.0
for t in range(T):
for i in range(N):
... | while 1:
N,T,L,B = list(map(int,input().split()))
if N == 0: break
lose = set([int(input()) for i in range(L)])
back = set([int(input()) for i in range(B)])
dp = [[0.]*(N+1) for i in range(T+1)]
dp[0][0] = 1.
p = 1./6.
for t in range(T):
for i in range(N):
t... | p00856 |
while 1:
N, T, L, B = list(map(int,input().split(" ")))
if N == T == L == B == 0: break
check = 0
dp = [[0 for _ in range(N+1)] for _ in range(T+1)]
Lose = set([int(input()) for _ in range(L)])
Back = set([int(input()) for _ in range(B)])
dp[0][0] = 1
for i in range(T):
for j in range(N):
rank = ... | while 1:
N, T, L, B = list(map(int,input().split(" ")))
if N == T == L == B == 0: break
dp = [[0 for _ in range(N+1)] for _ in range(T+1)]
Lose = set([int(input()) for _ in range(L)])
Back = set([int(input()) for _ in range(B)])
dp[0][0] = 1
for i in range(T):
for j in range(N):
rank = i-1 if j in ... | p00856 |
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(eval(input()))
rs = lambda : input().strip(... | import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(eval(input()))
rs = lambda : input().strip(... | p03684 |
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(eval(input()))
rs = lambda : input().strip(... | import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
#import time
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(eval(input()))
rs = lambda : input().strip(... | p03684 |
from collections import deque
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
... | from collections import deque
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
... | p03684 |
N=int(eval(input()))
city=[0]*N
for i in range(N):
x,y=list(map(int,input().split()))
city[i]=(i,x,y)
city.sort(key=lambda x:x[1])
data=[(city[i][0],city[i+1][0],city[i+1][1]-city[i][1]) for i in range(N-1)]
city.sort(key=lambda x:x[2])
data+=[(city[i][0],city[i+1][0],city[i+1][2]-city[i][2]) for i in r... | import sys
input=sys.stdin.readline
N=int(eval(input()))
P=[tuple(map(int,input().split())) for i in range(N)]
X=[(i,P[i][0]) for i in range(N)]
Y=[(i,P[i][1]) for i in range(N)]
X.sort(key=lambda x:x[1])
Y.sort(key=lambda x:x[1])
Z=[(X[i][0],X[i+1][0],X[i+1][1]-X[i][1]) for i in range(N-1)]+[(Y[i][0],Y[i+1][0]... | p03684 |
import heapq
class UnionFind():
def __init__(self, size):
self.table = [-1 for _ in range(size)]
self.count = 0
def find(self, x):
while self.table[x] >= 0:
x = self.table[x]
return x
def union(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
if self.table[s1] > se... | import heapq
import sys
sys.setrecursionlimit(10 ** 7)
class UnionFind():
def __init__(self, size):
self.table = [-1 for _ in range(size)]
self.count = 0
# def find(self, x):
# while self.table[x] >= 0:
# x = self.table[x]
# return x
def find(self, x):
if self.table[x] < 0:
return x
... | p03684 |
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(eval(input()))
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LIN... | # coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(eval(input()))
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LIN... | p03684 |
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(eval(input()))
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(L... | # coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
def II(): return int(eval(input()))
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(L... | p03684 |
import heapq
def prim_heap():
used = [True] * n #True:不使用
edgelist = []
for e in edge[0]:
heapq.heappush(edgelist,e)
used[0] = False
res = 0
while len(edgelist) != 0:
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = m... | import heapq
def prim_heap():
used = [True] * n #True:不使用
edgelist = []
for e in edge[0]:
heapq.heappush(edgelist,e)
used[0] = False
res = 0
while len(edgelist) != 0:
minedge = heapq.heappop(edgelist)
if not used[minedge[1]]:
continue
v = m... | p03684 |
#!/usr/bin/env python3
import heapq
def main():
n = int(eval(input()))
nodes = []
for i in range(n):
xi, yi = list(map(int, input().split()))
nodes.append((i, xi, yi))
adj = [[] for i in range(n)]
nodes.sort(key=(lambda x: x[1]))
for j in range(n):
i = no... | #!/usr/bin/env python3
import heapq
def main():
n = int(eval(input()))
nodes = []
for i in range(n):
xi, yi = list(map(int, input().split()))
nodes.append((i, xi, yi))
adj = [[] for i in range(n)]
nodesx = sorted(nodes, key=(lambda x: x[1]))
for j in range(n - 1):... | p03684 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
class UnionFind(object):
"""
query: O(Ack^-1(n,n)) (amortize)
"""
def __init__(self,n):
"""
param n: number of no... | import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
class UnionFind(object):
"""
query: O(Ack^-1(n,n)) (amortize)
"""
def __init__(self,n):
"""
param n: number of node... | p03684 |
import sys
import heapq
input = sys.stdin.readline
class Node:
def __init__(self, id):
self.id = id
self.check = False
self.link = []
self.cost = []
def __lt__(self, other):
return self.id < other.id
def main():
N = int(eval(input()))
... | import sys
input = sys.stdin.readline
def same_tree(node_a, node_b):
if node_a.root() == node_b.root():
return True
def unite(node_a, node_b):
root_a = node_a.root()
root_b = node_b.root()
if root_a == root_b:
return
if root_b.depth > root_a.depth:
root_a, root... | p03684 |
#!/usr/bin/env pypy3
import array
import collections
import heapq
import itertools
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
Town = collections.namedtuple("Town", "idx x y")
INF = 2 ** 31 - 1
NO_VERTEX = -1
# Prim法で頂点0からの最小全域木を求める
def compute_mst_prim(max_v, adj_list):... | #!/usr/bin/env pypy3
import array
import collections
import heapq
import itertools
AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
Town = collections.namedtuple("Town", "idx x y")
INF = 2 ** 31 - 1
NO_VERTEX = -1
# Prim法で頂点0からの最小全域木を求める
def compute_mst_prim(max_v, adj_list):... | p03684 |
N=int(eval(input()))
import sys
input=sys.stdin.readline
X=[[-10**10,0]]
Y=[[-10**10,0]]
for i in range(N):
x,y=list(map(int,input().split()))
X.append([x,i+1])
Y.append([y,i+1])
X.append([10**10,N+1])
Y.append([10**10,N+1])
X.sort()
Y.sort()
#print(X,Y)
L=[[]for i in range(N+1)]
for i ... | N=int(eval(input()))
import sys
input=sys.stdin.readline
X=[(-10**10,0)]
Y=[(-10**10,0)]
for i in range(N):
x,y=list(map(int,input().split()))
X.append((x,i+1))
Y.append((y,i+1))
X.append((10**10,N+1))
Y.append((10**10,N+1))
X.sort()
Y.sort()
#print(X,Y)
L=[[]for i in range(N+1)]
for i ... | p03684 |
import heapq
def prime_method():
start = graph[0]
not_went = [True] * n # n個の点に行ったかという話
edges = []
for e in start:
heapq.heappush(edges,e)
not_went[0] = False
cost = 0
while len(edges) != 0:
minedge = heapq.heappop(edges)
if not not_went[minedge[1]]:
... |
import heapq
def prime_method():
not_went = [True] * n # n個の点に行ったかという話
edges = []
start = graph[0]
for e in start:
heapq.heappush(edges,e)
not_went[0] = False
cost = 0
while len(edges) != 0:
minedge = heapq.heappop(edges)
if not not_went[minedge[1]]:
... | p03684 |
class UnionFindNode:
def __init__(self, group_id, parent=None, value=None):
self.group_id_ = group_id
self.parent_ = parent
self.value = value
self.rank_ = 1
self.member_num_ = 1
def is_root(self):
return not self.parent_
def root(self):
... | class UnionFindNode:
def __init__(self, group_id, parent=None, value=None):
self.group_id_ = group_id
self.parent_ = parent
self.value = value
self.rank_ = 1
self.member_num_ = 1
def is_root(self):
return not self.parent_
def root(self):
... | p03684 |
from itertools import accumulate
MOD = 10 ** 9 + 7
table_len = 2 * 10 ** 5 + 10
fac = [1, 1]
for i in range(2, table_len):
fac.append(fac[-1] * i % MOD)
finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len-1, -1, -1):
finv[i-1] = finv[i] * i % MOD
N = int... | from itertools import accumulate
MOD = 10 ** 9 + 7
table_len = 2 * 10 ** 5 + 10
fac = [1, 1]
for i in range(2, table_len):
fac.append(fac[-1] * i % MOD)
finv = [0] * table_len
finv[-1] = pow(fac[-1], MOD - 2, MOD)
for i in range(table_len-1, -1, -1):
finv[i-1] = finv[i] * i % MOD
N = int... | p02728 |
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:56:10 2020
"""
import sys
#import numpy as np
sys.setrecursionlimit(10 ** 9)
#def input():
# return sys.stdin.readline()[:-1]
mod = 10**9+7
N = int(eval(input()))
#X, Y = map(int,input().split())
ab = [list(map(int,input().split())) for i in rang... | # -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 22:56:10 2020
"""
import sys
#import numpy as np
sys.setrecursionlimit(10 ** 9)
#def input():
# return sys.stdin.readline()[:-1]
mod = 10**9+7
N = int(eval(input()))
#X, Y = map(int,input().split())
#ab = [list(map(int,input().split())) for i in ran... | p02728 |
class Factorial():
def __init__(self, n, mod):
self.mod = mod
self.factorial = [0 for _ in range(n + 1)]
self.inv = [0 for _ in range(n + 1)]
self.factorial[0] = 1
self.inv[0] = 1
for i in range(n):
self.factorial[i + 1] = self.factorial[i] * (i + ... | class Tree():
def __init__(self, n, edge):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - 1].append(e[1] - 1)
self.tree[e[1] - 1].append(e[0] - 1)
def setroot(self, root):
self.root = root
self.parent = [No... | p02728 |
n = int(eval(input())); arr = [list(map(int,input().split())) for _ in range(n-1)]
graph = [[] for _ in range(n)]
for a,b in arr:
graph[a-1].append(b-1); graph[b-1].append(a-1)
mod = 10**9+7
fac = [1]*(n+1)
inv = [1]*(n+1)
ifac = [1]*(n+1)
for i in range(2,n+1):
fac[i] = fac[i-1] * i % mod
inv... | n = int(eval(input())); arr = [list(map(int,input().split())) for _ in range(n-1)]
graph = [[] for _ in range(n)]
for a,b in arr:
graph[a-1].append(b-1); graph[b-1].append(a-1)
mod = 10**9+7
fac = [1]*(n+1)
inv = [1]*(n+1)
ifac = [1]*(n+1)
for i in range(2,n+1):
fac[i] = fac[i-1] * i % mod
inv... | p02728 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
mod = 10**9+7
fact = [1] * (N+1)
fact_inv = [1] * (N+1)
inv = lambda x : pow(x, mod-2, mod)
fo... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(lambda x : int(x)-1, input().split())
G[a].append(b)
G[b].append(a)
mod = 10**9+7
fact = [1] * N
fact_inv = [1] * N
inv = lambda x : pow(x, mod-2, mo... | p02728 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(lambda x : int(x)-1, input().split())
G[a].append(b)
G[b].append(a)
mod = 10**9+7
fact = [1] * N
fact_inv = [1] * N
inv = lambda x : pow(x, mod-2, mo... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
a, b = map(lambda x : int(x)-1, input().split())
G[a].append(b)
G[b].append(a)
mod = 10**9+7
fact = [1] * N
fact_inv = [1] * N
for i in range(1, N):
fact[i... | p02728 |
#ABC160F
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.buffer.readline()[:-1]
MOD = 10**9+7
n = int(eval(input()))
con = [[] for _ in range(n)]
for _ in range(n-1):
a, b = list(map(int, input().split()))
con[a-1].append(b-1)
con[b-1].append(a-1)
stair = [1] #階乗MOD
stairr =... | #ABC160F
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.buffer.readline()[:-1]
MOD = 10**9+7
n = int(eval(input()))
con = [[] for _ in range(n)]
for _ in range(n-1):
a, b = list(map(int, input().split()))
con[a-1].append(b-1)
con[b-1].append(a-1)
stair = [1] #階乗MOD
stairr =... | p02728 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
g[a].append(b)
g[b].append(a)
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テー... | import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
g[a].append(b)
g[b].append(a)
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1]... | p02728 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | p02728 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from... | p02728 |
import sys
sys.setrecursionlimit(10**7)
MOD = 10**9+7
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1; b -= 1
g[a].append(b)
g[b].append(a)
lim = 10**6
fact = [1, 1] + [0] * (lim-1)
fact_inv = [1, 1] + [0] * (lim-1)
inv = [0, 1] +... | import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().rstrip()
MOD = 10**9+7
n = int(input())
g = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
a -= 1; b -= 1
g[a].append(b)
g[b].append(a)
lim = 10**5*2
fact = [1, 1] + [0] * (lim-1)
... | p02728 |
import sys
sys.setrecursionlimit(10**7)
def modinv(a,m=10**9+7):
if a==0: return 1
b=m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx %... | import sys
sys.setrecursionlimit(10**7)
def modinv(a,m=10**9+7):
if a==0: return 1
b=m
(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
q = a // b
(a, b) = (b, a % b)
(x, lastx) = (lastx - q * x, x)
(y, lasty) = (lasty - q * y, y)
return lastx %... | p02728 |
import sys
from copy import deepcopy
from functools import lru_cache
sys.setrecursionlimit(10**6)
def main():
# input and preparation
F = 2*10**5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
... | import sys
from copy import deepcopy
from functools import lru_cache
sys.setrecursionlimit(10**6)
def main():
#node i is list of [child,size,comb] connected i
#return [size,comb]
@lru_cache(maxsize=1000000)
def deep(i,parent):
if len(node[i])==1 and parent!=-1:
return (1,... | p02728 |
import sys
F = 2*10**5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
for i in range(F-2,1,-1):
inv[i] = (inv[i+1]*(i+1))%mod
n=int(eval(input()))
neighbers=[[] for i in range(n)]
for i in range(n-1):
a,b=list(map(int,... | n=int(input())
F = n+5
mod = 10**9+7
fact = [1]*F
inv = [1]*F
for i in range(2,F):
fact[i]=(fact[i-1]*i)%mod
inv[F-1]=pow(fact[F-1],mod-2,mod)
for i in range(F-2,1,-1):
inv[i] = (inv[i+1]*(i+1))%mod
#invnum[0] cant be used
invnum=[fact[i-1]*inv[i] for i in range(n)]
graph=[[] for i in range(n)]
... | p02728 |
import sys
input = sys.stdin.readline
from collections import deque
class Factorial:
def __init__(self, n, mod):
self.f = [1]
self.mod = mod
for j in range(1, n + 1):
self.f.append(self.f[-1] * j % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for j ... | import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
class Factorial:
def __init__(self, n, mod):
self.f = [1]
self.mod = mod
for j in range(1, n + 1):
self.f.append(self.f[-1] * j % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for j in range(n, ... | p02728 |
import sys
input = sys.stdin.readline
class Factorial:
def __init__(self, n, mod):
self.f = [1]
self.mod = mod
for j in range(1, n + 1):
self.f.append(self.f[-1] * j % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for j in range(n, 0, -1):
... | import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
class Factorial:
def __init__(self, n, mod):
self.f = [1]
self.mod = mod
for j in range(1, n + 1):
self.f.append(self.f[-1] * j % mod)
self.i = [pow(self.f[-1], mod - 2, mod)]
for j in range(n, ... | p02728 |
def main():
from collections import deque
N = int(eval(input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
mod = 10**9+7
fact = [1]*(N+1)
fact_inv = [1]*(N+1)
for i in range(1,N+1):
fact[i] = (fact[i-1]*i)%mod
fact_inv[i] = pow(fact[i], mod-2, mod)
g = [deque([]) fo... | from collections import deque
N = int(eval(input()))
ab = [list(map(int,input().split())) for _ in range(N-1)]
mod = 10**9+7
fact = [1]*(N+1)
fact_inv = [1]*(N+1)
for i in range(1,N+1):
fact[i] = (fact[i-1]*i)%mod
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(N,0,-1):
fact_inv[i-1] = fact_in... | p02728 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def solve():
MOD = 10**9 + 7
N = int(eval(input()))
adjL = [[] for _ in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
adjL[a].append(b)
adjL[b].append... | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
def solve():
MOD = 10**9 + 7
N = int(eval(input()))
adjL = [[] for _ in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
adjL[a].append(b)
adjL[b].append... | p02728 |
import sys
sys.setrecursionlimit(10**7)
MOD = 1000000007
def modpow(a, b):
if b == 0:
return 1
if b % 2 == 0:
d = modpow(a, b / 2)
return (d ** 2) % MOD
d = modpow(a, b - 1)
return (a * d) % MOD
M = 2*10**5 + 10
fact = [1] * M
ifact = [1] * M
for i in range(2, M)... | MOD = 1000000007
M = 2*10**5 + 10
fact = [1] * M
ifact = [1] * M
for i in range(2, M):
fact[i] = fact[i - 1] * i % MOD
ifact[M - 1] = pow(fact[M - 1], MOD - 2, MOD)
for i in range(2, M - 1)[::-1]:
ifact[i] = ifact[i + 1] * (i + 1) % MOD
def comb(n, k):
if n < 0 or k > n:
return 0
... | p02728 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import resource
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_re... | # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import resource
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_re... | p02728 |
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
import resource
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_re... | # -*- coding: utf-8 -*-
from collections import defaultdict
class ReRooting:
def __init__(self, f, g, merge, ie):
self.tree = defaultdict(list)
self.f = f
self.g = g
self.merge = merge
self.ie = ie
self.dp = defaultdict(dict)
def add_edge(self, u... | p02728 |
# -*- coding: utf-8 -*-
from collections import defaultdict
class ReRooting:
def __init__(self, f, g, merge, ie):
self.tree = defaultdict(list)
self.f = f
self.g = g
self.merge = merge
self.ie = ie
self.dp = defaultdict(dict)
def add_edge(self, u... | # -*- coding: utf-8 -*-
from collections import defaultdict
class ReRooting:
def __init__(self, f, g, merge, ie):
self.tree = defaultdict(list)
self.f = f
self.g = g
self.merge = merge
self.ie = ie
self.dp = defaultdict(dict)
def add_edge(self, u... | p02728 |
import sys
input = sys.stdin.buffer.readline
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2... | import sys
input = sys.stdin.buffer.readline
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2... | p02728 |
import sys
input = sys.stdin.buffer.readline
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2... | import sys
input = sys.stdin.buffer.readline
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2... | p02728 |
class ReRooting:
def __init__(self, size, root, identDp=0, identCum=0):
"""
identDp: 木DP用 lift(a, identDp) = a
identCum: 累積用 merge(a, identCum) = a
"""
self.size = size
self.edges = [[] for _ in range(self.size + 1)]
self.root = root
self.iden... | class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fa... | p02728 |
class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fa... | class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fa... | p02728 |
#%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | #%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | p02728 |
#%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | #%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | p02728 |
#%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | #%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | p02728 |
#%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
de... | #%%
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from collections import deque
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保... | p02728 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.