n = input() a = map(int, raw_input().split()) total = sum(a) h = 1 ans = float('inf') while h * h <= total: c = h - 1 low = 0 high = 0 for i in xrange(1000): y = max(0, (i - c) + h if i <= c else -(i - c) + h) if 0 <= i and i < n: if a[i] < y: low += y - a[i] elif a[i] > y: high += a[i] - y else: low += y ans = min(ans, max(low, high)) h += 1 print ans