#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, i, b, c, d, j, ds = 0, id1 = 0, id2 = 0;
  cin >> n;
  vector<pair<long long int, long long int> > v;
  for (i = 0; i < 2 * n; i++) {
    cin >> b;
    v.push_back(make_pair(b, i));
  }
  sort(v.begin(), v.end());
  c = 0;
  for (i = 0; i < 2 * n; i += 2) {
    id1 += abs(v[i].second - c);
    c = v[i].second;
  }
  c = 0;
  for (i = 1; i < 2 * n; i += 2) {
    id2 += abs(v[i].second - c);
    c = v[i].second;
  }
  cout << id1 + id2 << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
