import sys input = sys.stdin.readline from collections import * class CHT: def __init__(self): self.deq = deque() def check(self, f1, f2, f3): return (f2[0] - f1[0]) * (f3[1] - f2[1]) >= (f2[1] - f1[1]) * (f3[0] - f2[0]) def f(self, f1, x): return f1[0]*x + f1[1] # add f_i(x) = a*x + b def add_line(self, a, b): f1 = (a, b) while len(self.deq) >= 2 and self.check(self.deq[-2], self.deq[-1], f1): self.deq.pop() self.deq.append(f1) # min f_i(x) def get(self, x): while len(self.deq) >= 2 and self.f(self.deq[0], x) >= self.f(self.deq[1], x): self.deq.popleft() return self.f(self.deq[0], x) def dfs(l, r): # [l, r) global ans if r-l==1: ans[l] = min(ans[l], 1+A[l]) return m = (l+r)//2 # [l, m) if l