#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) {
  if (a <= b) {
    return a;
  } else {
    return b;
  }
}
int main() {
  long long int n;
  cin >> n;
  vector<vector<long long int>> v(n + 1);
  for (long long int i = 0; i < (2 * n); i++) {
    long long int x;
    cin >> x;
    v[x].push_back(i);
  }
  long long int sum = 0, a1, a2;
  a1 = v[1][0];
  a2 = v[1][1];
  sum += (a1 + a2);
  for (long long int i = 2; i <= n; i++) {
    sum += min(abs(v[i][0] - a1) + abs(v[i][1] - a2),
               abs(v[i][0] - a2) + abs(v[i][1] - a1));
    a1 = v[i][0];
    a2 = v[i][1];
  }
  cout << sum << endl;
}
