#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, k, l = 0, m = 0, n, p, t, a, q, b;
  cin >> n;
  vector<pair<long long int, long long int> > v;
  for (i = 0; i < 2 * n; i++) {
    cin >> a;
    v.push_back(make_pair(a, i));
  }
  sort(v.begin(), v.end());
  a = 0;
  b = 0;
  for (i = 0; i < v.size(); i += 2) {
    l += abs(v[i].second - a);
    a = v[i].second;
  }
  for (i = 1; i < v.size(); i += 2) {
    m += abs(v[i].second - b);
    b = v[i].second;
  }
  cout << l + m;
}
