#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x;
  cin >> n;
  std::vector<pair<int, int> > v(2 * n);
  for (int i = 0; i < 2 * n; ++i) {
    cin >> x;
    v[i] = {x, i};
  }
  sort(v.begin(), v.end());
  std::map<int, int> f, m;
  long long p1 = 0, p2 = 0, ans = 0;
  for (int i = 0; i < 2 * n; ++i) {
    if (m[v[i].first] == 0) {
      ans += (abs(p1 - v[i].second));
      m[v[i].first] = 1;
      p1 = v[i].second;
    } else {
      ans += (abs(p2 - v[i].second));
      m[v[i].first] = 2;
      p2 = v[i].second;
    }
  }
  cout << ans;
}
