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