import sequtils proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': return result = 10 * result + k.ord - '0'.ord type BinaryIndexedTree*[CNT:static[int],T] = object data: array[CNT,T] # 引数以下の部分和 proc len*[CNT,T](bit:BinaryIndexedTree[CNT,T]): int = bit.data.len() proc update*[CNT,T](bit:var BinaryIndexedTree[CNT,T],i:int,val:T) = var i = i while i < bit.len(): bit.data[i] += val i = i or (i + 1) proc `[]`*[CNT,T](bit:BinaryIndexedTree[CNT,T],i:int): T = result = 0 var i = i while i >= 0: result += bit.data[i] i = (i and (i + 1)) - 1 proc `$`*[CNT,T](bit:BinaryIndexedTree[CNT,T]): string = result = "[" for i in 0.. 100 : " ...]" else: "]") let n = scan() var E = newSeqWith(n,newSeq[int]()) for i in 1..