#https://yukicoder.me/problems/528 def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate #from itertools import product from bisect import bisect_left,bisect_right import heapq from math import floor, ceil #from operator import itemgetter inf = 10**17 #mod = 10**9 + 7 N = int(input()) M = [int(input()) for _ in range(N)] dp = [inf]*(1<