#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const long long int INF = 2e18 + 10;
const int Mod = 1e9 + 7;
const int MAXN = 1000010;
const int N = 1e5 + 10;
const int M = 210;
const int M1 = 1e9 + 7;
const int M2 = 1e9 + 9;
const int base = 131;
int a[2 * N];
long long int c[N][2];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> a[i];
    if (c[a[i]][0] != 0) {
      c[a[i]][1] = i;
    } else {
      c[a[i]][0] = i;
    }
  }
  long long int x = c[1][0] - 1, y = c[1][1] - 1;
  for (int i = 2; i <= n; i++) {
    long long int p = abs(c[i][0] - c[i - 1][0]) + x;
    long long int q = abs(c[i][1] - c[i - 1][1]) + y;
    long long int a = abs(c[i][1] - c[i - 1][0]) + x;
    long long int b = abs(c[i][0] - c[i - 1][1]) + y;
    if ((p + q) < (a + b)) {
      x = p;
      y = q;
    } else {
      x = a;
      y = b;
    }
  }
  cout << (x + y) << endl;
  return 0;
}
