#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 0; i < 2 * n; i++) {
    int x;
    cin >> x;
    v.push_back({x, i});
  }
  sort(v.begin(), v.end());
  long long ans = v[0].second + v[1].second;
  for (int i = 2; i < 2 * n; i += 2) {
    ans += abs(v[i].second - v[i - 2].second) +
           abs(v[i - 1].second - v[i + 1].second);
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
