#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr[n + 1];
  int a;
  for (int i = 0; i < 2 * n; i++) {
    cin >> a;
    arr[a].push_back(i);
  }
  long long ans = 0;
  int start[2] = {0, 0};
  for (int i = 1; i <= n; i++) {
    int temp = INT_MAX;
    int jj = 0, kk = 0;
    for (int k = 0; k < 2; k++) {
      int diff =
          abs(arr[i][0] - start[k]) + abs(arr[i][1] - start[(k + 1) % 2]);
      if (diff < temp) {
        kk = k;
        temp = diff;
      }
    }
    ans += (long long)temp;
    start[kk] = arr[i][0];
    start[(kk + 1) % 2] = arr[i][1];
  }
  cout << ans << "\n";
  return 0;
}
