#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, temp;
  cin >> n;
  vector<vector<long long> > v(n + 1);
  for (long long i = 0; i < 2 * n; i++) {
    cin >> temp;
    v[temp].push_back(i);
  }
  long long fsum = v[1][0];
  for (long long i = 2; i <= n; i++) {
    fsum += abs(v[i][0] - v[i - 1][0]);
  }
  long long ssum = v[1][1];
  for (long long i = 2; i <= n; i++) {
    ssum += abs(v[i][1] - v[i - 1][1]);
  }
  long long ans = fsum + ssum;
  cout << ans;
}
