INF = 1 << 60 N = int(input()) H = list(map(int, input().split())) st = [(INF, 0, 0)] for i, h in enumerate(H): v = 1 if i % 2 == 0 else -1 # 0=緑色 1=水色 while st[-1][0] <= h: st.pop() ph, pv, pt = st[-1] if pv == v: print(pt) continue t = pt + h * v print(t) st.append((h, v, t)) # # w = st[-1][2] # if st[-1][1] == 0: # w += h * v # elif st[-1][1] == 1: # if v == 0: # w -= h # # print(w) # st.append((h, v, w))