#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, t, c = 0, d;
  cin >> n;
  long long int a[n + 1], b[n + 1];
  memset(a, -1, sizeof(a));
  memset(b, -1, sizeof(b));
  a[0] = 1;
  b[0] = 1;
  for (i = 1; i <= 2 * n; i++) {
    cin >> t;
    if (a[t] == -1) {
      a[t] = i;
    } else {
      b[t] = i;
    }
  }
  for (i = 0; i < n; i++) {
    c = c + min((abs(a[i] - a[i + 1]) + abs(b[i] - b[i + 1])),
                (abs(a[i] - b[i + 1]) + abs(b[i] - a[i + 1])));
  }
  cout << c << endl;
  return 0;
}
