Sonya was unable to think of a story for this problem, so here comes the formal description.

You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.

Next line contains n integer a_{i} (1 ≤ a_{i} ≤ 10^9).


-----Output-----

Print the minimum number of operation required to make the array strictly increasing.


-----Examples-----
Input
7
2 1 5 11 5 9 11

Output
9

Input
5
5 4 3 2 1

Output
12



-----Note-----

In the first sample, the array is going to look as follows:

2 3 5 6 7 9 11

|2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9

And for the second sample:

1 2 3 4 5

|5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12

Source: codeforces | Difficulty: HARD
Tags: Dynamic programming

Sorting


Solutions:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a[i] -= i
sorted_a = sorted(a)
dp = [0.0] * n
dp2 = [0.0] * n
for i in range(n):
	mn_prev_state = 10000000000000.0
	for j in range(n):
		mn_prev_state = min(mn_prev_state, dp[j])
		dp2[j] = mn_prev_state + abs(a[i] - sorted_a[j])
	for j in range(n):
		dp[j] = dp2[j]
print(int(min(dp)))


from bisect import bisect_left as BL
n = int(input())
graph = [(-99 ** 9, 0, 0)]
for (i, a) in enumerate(map(int, input().split())):
	a -= i
	new = []
	turnj = BL(graph, (a, 99 ** 9)) - 1
	for j in range(turnj):
		(x, y, sl) = graph[j]
		new.append((x, y + (a - x), sl - 1))
	for j in range(turnj, len(graph)):
		(x, y, sl) = graph[j]
		if j == turnj:
			new.append((x, y + (a - x), sl - 1))
			new.append((a, y + (a - x) + (sl - 1) * (a - x), sl + 1))
		else:
			new.append((x, y + (x - a), sl + 1))
	graph = new
	while graph[-1][2] > 0:
		(x, y, sl) = graph.pop()
	if graph[-1][2] != 0:
		graph.append((x, y, 0))
print(graph[-1][1])


N = int(input())
s = list(map(int, input().split()))
for i in range(N):
	s[i] -= i
X = sorted(s)
dp = [0] * N
for i in s:
	mi = 7e+77
	for j in range(N):
		mi = min(mi, dp[j])
		dp[j] = mi + abs(i - X[j])
print(min(dp))


from heapq import *
n = int(input())
turn = [99 ** 9]
opty = 0
for (i, a) in enumerate(map(int, input().split())):
	a -= i
	optx = -turn[0]
	if optx <= a:
		heappush(turn, -a)
	else:
		heappush(turn, -a)
		heappop(turn)
		heappush(turn, -a)
		opty += optx - a
print(opty)


from heapq import *

class Maxheap:

	def __init__(_):
		_.h = []

	def add(_, v):
		heappush(_.h, -v)

	def top(_):
		return -_.h[0]

	def pop(_):
		return -heappop(_.h)

class Graph:

	def __init__(_):
		_.change = Maxheap()
		_.change.add(-10 ** 18)
		_.a = _.y = 0
		_.dx = 0

	def __repr__(_):
		return f'<{[x + _.dx for x in _.change]}; {_.a} {_.y}>'

	def shiftx(_, v):
		_.dx += v

	def shifty(_, v):
		_.y += v

	def addleft(_, v):
		if _.change.top() < v - _.dx:
			dx = v - _.dx - _.change.top()
			_.y += _.a * dx
		_.change.add(v - _.dx)

	def addright(_, v):
		if _.change.top() < v - _.dx:
			dx = v - _.dx - _.change.top()
			_.y += _.a * dx
			_.a += 1
			_.change.add(v - _.dx)
			return
		_.change.add(v - _.dx)
		_.a += 1
		_.y += _.change.top() - (v - _.dx)

	def cutright(_):
		dx = _.change.pop() - _.change.top()
		_.a -= 1
		_.y -= _.a * dx
n = int(input())
G = Graph()
for x in map(int, input().split()):
	G.shiftx(1)
	G.addleft(x)
	G.addright(x)
	while G.a > 0:
		G.cutright()
print(G.y)


import heapq
n = int(input())
d = list(map(int, input().split()))
pq = [-d[0]]
heapq.heapify(pq)
ans = 0
for i in range(1, n):
	temp = i - d[i]
	heapq.heappush(pq, temp)
	if heapq.nsmallest(1, pq)[0] < temp:
		ans += temp - heapq.nsmallest(1, pq)[0]
		heapq.heappushpop(pq, temp)
print(ans)


from bisect import insort

class Graph:

	def __init__(_):
		_.change = [-10 ** 27]
		_.a = _.y = 0
		_.dx = 0

	def __repr__(_):
		return f'<{[x + _.dx for x in _.change]}; {_.a} {_.y}>'

	def shiftx(_, v):
		_.dx += v

	def shifty(_, v):
		_.y += v

	def addleft(_, v):
		if _.change[-1] < v - _.dx:
			dx = v - _.dx - _.change[-1]
			_.y += _.a * dx
		insort(_.change, v - _.dx)

	def addright(_, v):
		if _.change[-1] < v - _.dx:
			dx = v - _.dx - _.change[-1]
			_.y += _.a * dx
			_.a += 1
			insort(_.change, v - _.dx)
			return
		insort(_.change, v - _.dx)
		_.a += 1
		_.y += _.change[-1] - (v - _.dx)

	def cutright(_):
		dx = _.change.pop() - _.change[-1]
		_.a -= 1
		_.y -= _.a * dx
n = int(input())
G = Graph()
for x in map(int, input().split()):
	G.shiftx(1)
	G.addleft(x)
	G.addright(x)
	while G.a > 0:
		G.cutright()
print(G.y)