class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def build(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] def sum(self, i): # [0, i) の要素の総和を返す s = 0 while i>0: s += self.tree[i] i -= i & -i return s # 0 index を 1 index に変更 転倒数を求めるなら1を足していく def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i # 総和がx以上になる位置のindex をbinary search def bsearch(self,x): le = 0 ri = 1<<(self.size.bit_length()-1) while ri > 0: if le+ri <= self.size and self.tree[le+ri]>= 1 return le+1 from heapq import heappop, heappush n = int(input()) A = list(map(int,input().split())) M = 10**5 use = [0]*(M+1) use[0] = 1 ans = 0 h = [[-M,0]] bit = BIT(M+2) bit.add(0,1) bit.add(M+1,1) for a in A: if use[a]: continue ans += 1 num = bit.sum(a) ind = bit.bsearch(num)-1 now = a-ind l = [] while h and -h[0][0] >= now: size,lind = heappop(h) size *= -1 use[lind+now] = 1 bit.add(lind+now,1) l.append([-now+1,lind]) l.append([-size+now,lind+now]) for nex in l: heappush(h,nex) print(ans)