import algorithm, deques, heapqueue, math, sets, sequtils, strutils, sugar, tables proc input*(): string = return stdin.readLine proc chmax*[T: SomeNumber](num0: var T, num1: T) = num0 = max(num0, num1) proc chmin*[T: SomeNumber](num0: var T, num1: T) = num0 = min(num0, num1) proc bit_length(n: Natural): Natural = const BIT_SIZE = 60 if n == 0: return 0 let s = toBin(n, BIT_SIZE) return BIT_SIZE - s.find('1') type LazySegmentTree*[T] = ref object LV: Natural N0: Positive ide_ele, lazy_ide_ele: T data, lazy_data: seq[T] segfunc: proc (a, b: T): T proc initLazySegmentTree*[T](size: Positive, ide_ele, lazy_ide_ele: T, f: proc (a, b: T): T): LazySegmentTree[T] = var LV = bit_length(size - 1) N0 = 1 shl LV data = newSeqWith(2*N0, ide_ele) lazy_data = newSeqWith(2*N0, lazy_ide_ele) return LazySegmentTree[T](LV: LV, N0: N0, ide_ele: ide_ele, lazy_ide_ele: lazy_ide_ele, data: data, lazy_data: lazy_data, segfunc: f) proc toLazySegmentTree*[T](init_value: openArray[T], ide_ele, lazy_ide_ele: T, f: proc (a, b: T): T): LazySegmentTree[T] = var LV = bit_length(init_value.len - 1) N0 = 1 shl LV data = newSeqWith(2*N0, ide_ele) lazy_data = newSeqWith(2*N0, lazy_ide_ele) for i, x in init_value: data[i + N0 - 1] = x for i in countdown(N0 - 2, 0): data[i] = f(data[2*i + 1], data[2*i + 2]) return LazySegmentTree[T](LV: LV, N0: N0, ide_ele: ide_ele, lazy_ide_ele: lazy_ide_ele, data: data, lazy_data: lazy_data, segfunc: f) iterator gindex*[T](self: var LazySegmentTree[T], left, right: Natural): Natural = var L = (left + self.N0) shr 1 R = (right + self.N0) shr 1 lc = if (left and 1) == 1: 0 else: bit_length(L and -L) rc = if (right and 1) == 1: 0 else: bit_length(R and -R) for i in 0.. max(a, b)) let M = input().parseInt ans = newSeq[int](M) var li, ri, di: int for i in 0..