#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v[n + 1];
  for (int i = 1; i <= 2 * n; i++) {
    int tmp;
    cin >> tmp;
    v[tmp].push_back(i);
  }
  long long need = 2;
  long long a, b, ac, bc;
  a = b = 0;
  ac = bc = 1;
  if (v[1][0] == 1) {
    b += v[1][1] - 1;
    bc = v[1][1];
  } else if (v[1][1] == 1) {
    b += v[1][0] - 1;
    bc = v[1][0];
  } else {
    a += v[1][0] - 1;
    ac = v[1][0];
    b += v[1][1] - 1;
    bc = v[1][1];
  }
  while (need <= n) {
    int x = v[need][0];
    int y = v[need][1];
    if (abs(x - ac) + abs(y - bc) < abs(x - bc) + abs(y - ac)) {
      a += abs(x - ac);
      ac = x;
      b += abs(y - bc);
      bc = y;
    } else {
      a += abs(y - ac);
      ac = y;
      b += abs(x - bc);
      bc = x;
    }
    need++;
  }
  cout << a + b << endl;
  return 0;
}
