#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long n;
  cin >> n;
  vector<long long> loc[100000 + 2];
  for (long long i = 0; i < 2 * n; i++) {
    long long t;
    cin >> t;
    loc[t].push_back(i);
  }
  long long dist = 0;
  long long s_i = 0;
  long long d_i = 0;
  for (int i = 1; i <= n; i++) {
    dist += (s_i > loc[i][0]) ? (s_i - loc[i][0]) : (loc[i][0] - s_i);
    dist += (d_i > loc[i][1]) ? (d_i - loc[i][1]) : (loc[i][1] - d_i);
    s_i = loc[i][0];
    d_i = loc[i][1];
  }
  cout << dist << "\n";
  return 0;
}
