#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > V(n + 1);
  fill(begin(V), end(V), make_pair(-1, -1));
  V[0] = make_pair(0, 0);
  for (int i = 0, a; i < 2 * n; i++) {
    cin >> a;
    if (V[a].first == -1)
      V[a].first = i;
    else
      V[a].second = i;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans += min(
        abs(V[i - 1].first - V[i].first) + abs(V[i - 1].second - V[i].second),
        abs(V[i - 1].first - V[i].second) + abs(V[i - 1].second - V[i].first));
  cout << ans << endl;
  return 0;
}
