#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  int x;
  for (int i = 1; i <= (2 * n); i++) {
    cin >> x;
    v.push_back(pair<int, int>(x, i));
  }
  sort(v.begin(), v.end());
  long long j = 0, pa = 0, push_back = 0, s = 1, d = 1, ans = 0, sml = 0;
  for (int i = 0; i < n; i++) {
    pa = v[j++].second;
    push_back = v[j++].second;
    sml = min((abs(s - pa) + abs(d - push_back)),
              (abs(s - push_back) + abs(d - pa)));
    if (sml == (abs(s - pa) + abs(d - push_back))) {
      ans += abs(s - pa) + abs(d - push_back);
      s = pa;
      d = push_back;
    } else {
      ans += abs(s - push_back) + abs(d - pa);
      d = pa;
      s = push_back;
    }
  }
  cout << ans << endl;
  return 0;
}
