import java.io.*;
import java.util.*;

public class sequence_bm_tl {
	FastScanner in;
	PrintWriter out;

	/*
	 * This is not optimized correct O(n^2) solution. I hope it will work > x10 TL,
	 * otherwise tests are weak
	 */

	long[] pref(long[] a) {
		long[] res = new long[a.length + 1];
		for (int i = 0; i < a.length; i++) {
			res[i + 1] = res[i] + a[i];
		}
		return res;
	}

	// k = number of elements <= a[i] - b[j]
	long getCost(long[] a, long[] b, long[] c, long[] prefA, long[] prefB,
			long[] prefC, int i, int j, int k) {
		if (k > 0 && a[i] - b[j] < c[k - 1]) {
			throw new AssertionError();
		}
		if (k != c.length && a[i] - b[j] >= c[k]) {
			throw new AssertionError();
		}
		long cntA = prefA[prefA.length - 1] - 2 * prefA[i]
				+ (2 * i + 1 - prefA.length) * 1L * a[i];
		long cntB = prefB[prefB.length - 1] - 2 * prefB[j]
				+ (2 * j + 1 - prefB.length) * 1L * b[j];
		long cntC = prefC[prefC.length - 1] - 2 * prefC[k]
				+ (2 * k + 1 - prefC.length) * 1L * (a[i] - b[j]);
		return cntA + cntB + cntC;
	}

	// [answer, A, B]
	long[] getAnswer(long[] a, long[] b, long[] c) {
		long[] prefA = pref(a), prefB = pref(b), prefC = pref(c);
		long[] res = new long[] { Long.MAX_VALUE, 0, 0 };
		int it2 = 0, it3 = 0, it32 = it3;
		for (int i = 0; i < a.length; i++) {
			while (it3 < c.length && a[i] - b[it2] >= c[it3]) {
				it3++;
			}
			long curCost = getCost(a, b, c, prefA, prefB, prefC, i, it2, it3);
			while (it2 != b.length - 1) {
				it32 = it3;
				while (it32 != 0 && a[i] - b[it2 + 1] < c[it32 - 1]) {
					it32--;
				}
				long nextCost = getCost(a, b, c, prefA, prefB, prefC, i,
						it2 + 1, it32);
				if (nextCost <= curCost) {
					it2++;
					it3 = it32;
					curCost = nextCost;
				} else {
					break;
				}
			}
			if (curCost < res[0]) {
				res[0] = curCost;
				res[1] = a[i];
				res[2] = b[it2];
			}
		}
		return res;
	}

	long smart(int[] a) {
		int n = a.length;
		long[] A = new long[(n + 2) / 3];
		long[] B = new long[(n + 1) / 3];
		long[] C = new long[n / 3];
		int it1 = 0, it2 = 0, it3 = 0;
		for (int i = 0; i < n; i++) {
			int mul = (i % 6) < 3 ? 1 : -1;
			if ((i % 3) == 0) {
				A[it1++] = a[i] * mul;
			} else {
				if ((i % 3) == 1) {
					B[it2++] = a[i] * mul;
				} else {
					C[it3++] = a[i] * mul * -1;
				}
			}
		}
		Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		long res = Long.MAX_VALUE, ansA = 0, ansB = 0;
		{
			long[] tmp = getAnswer(A, B, C);
			if (tmp[0] < res) {
				res = tmp[0];
				ansA = tmp[1];
				ansB = tmp[2];
			}
		}
		{
			long[] tmp = getAnswer(A, C, B);
			if (tmp[0] < res) {
				res = tmp[0];
				ansA = tmp[1];
				ansB = tmp[1] - tmp[2];
			}
		}
		{
			for (int tt = 0; tt < C.length; tt++) {
				C[tt] *= -1;
			}
			for (int l = 0, r = C.length - 1; l < r; l++, r--) {
				long tt = C[l];
				C[l] = C[r];
				C[r] = tt;
			}
			long[] tmp = getAnswer(B, C, A);
			if (tmp[0] < res) {
				res = tmp[0];
				ansA = tmp[1] - tmp[2];
				ansB = tmp[1];
			}
		}
		long[] result = new long[n];
		result[0] = ansA;
		result[1] = ansB;
		for (int i = 2; i < n; i++) {
			result[i] = result[i - 1] - result[i - 2];
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			ans += Math.abs(result[i] - a[i]);
		}
		if (ans != res) {
			throw new AssertionError();
		}
		out.println(ans);
/*		for (long x : result) {
			out.print(x + " ");
		}
		out.println();*/
		return ans;
	}

	void solve() {
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		smart(a);
	}

	void run() {
		try {
			in = new FastScanner(new File("sequence.in"));
			out = new PrintWriter(new File("sequence.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new sequence_bm_tl().run();
	}
}