N = int(input()) l = list(map(int, input().split())) zero_l = [0 for i in range(120)] l = l + zero_l sum = 0 for l_i in l: sum += int(l_i) top = 0 while sum >= top * top: top += 1 top -= 1 copy_top = top - 1 pyramid = [] for i in range(1, top + 1): pyramid.append(i) for i in range(len(pyramid) - 1): pyramid.append(copy_top) copy_top -= 1 pyramid = pyramid + [0] ans = 0 for i in range(len(l) - len(pyramid)): ck_here = i ck_ans = 0 for j in range(len(pyramid)): ck_ans += min(l[ck_here], pyramid[j]) ck_here += 1 if ck_ans > ans: ans = ck_ans print(sum - ans)