#include <bits/stdc++.h>
using namespace std;
int A[200050];
int B[200050];
int C[200050];
int flag[200050];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= 2 * n; i++) {
    cin >> A[i];
    if (!flag[A[i]]) {
      flag[A[i]] = 1;
      B[A[i]] = i;
    } else
      C[A[i]] = i;
  }
  int now = 0, plaA = 1, plaB = 1;
  long long ans = 0;
  while (now < n) {
    ++now;
    if (abs(B[now] - plaA) + abs(C[now] - plaB) <
        abs(B[now] - plaB) + abs(C[now] - plaA)) {
      ans += abs(B[now] - plaA) + abs(C[now] - plaB);
      plaA = B[now];
      plaB = C[now];
    } else {
      ans += abs(B[now] - plaB) + abs(C[now] - plaA);
      plaA = C[now];
      plaB = B[now];
    }
  }
  cout << ans << endl;
}
