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