#include <bits/stdc++.h>
using namespace std;
int def(int a, int b) { return a > b ? a - b : b - a; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int ar[n], ar2[n], a;
  memset(ar, -1, sizeof(ar));
  for (int i = 0; i < n * 2; i++) {
    cin >> a;
    if (ar[a - 1] == -1)
      ar[a - 1] = i;
    else
      ar2[a - 1] = i;
  }
  long long res = ar[0];
  for (int i = 1; i < n; i++) {
    res += def(ar[i], ar[i - 1]);
  }
  res += ar2[0];
  for (int i = 1; i < n; i++) {
    res += def(ar2[i], ar2[i - 1]);
  }
  cout << res;
  return 0;
}
