import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques,heapqueue template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve():int= var n = scan() y = newseqwith(n,scan()) ymin=y.min() ymax = y.max()-y.min() dp = newseqwith(n,newseqwith(ymax+1,int.high.div(4))) smallerVal = newseqwith(2,newseqwith(ymax+1,int.high.div(4))) for i in 0..0: smallerVal[0][tail]=min(smallerVal[0][tail-1],dp[0][tail]) else: smallerVal[0][tail]=dp[0][tail] for i in 1..0: smallerVal[now][tail]=min(smallerVal[now][tail-1],dp[i][tail]) else: smallerVal[now][tail]=dp[i][tail] return smallerVal[(n-1).mod(2)][^1] echo solve()