#include <bits/stdc++.h>
using namespace std;
const int N = 200007;
long long Arr[N];
long long ind[N][2];
long long ans[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= 2 * n; i++) cin >> Arr[i];
  for (int i = 1; i <= 2 * n; i++) {
    if (ind[Arr[i]][0])
      ind[Arr[i]][1] = i;
    else
      ind[Arr[i]][0] = i;
  }
  ind[0][1] = 1;
  ind[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    ans[i] =
        ans[i - 1] +
        min(abs(ind[i][0] - ind[i - 1][0]) + abs(ind[i][1] - ind[i - 1][1]),
            abs(ind[i][0] - ind[i - 1][1]) + abs(ind[i][1] - ind[i - 1][0]));
  }
  cout << ans[n];
  return 0;
}
