#include <bits/stdc++.h>
using namespace std;
long long n, pos1 = 1, pos2 = 1, ans = 0;
vector<long long> v[100010];
int main() {
  cin >> n;
  for (long long i = 1; i <= 2 * n; i++) {
    long long a;
    cin >> a;
    v[a].push_back(i);
  }
  for (long long i = 1; i <= n; i++) {
    ans += min(abs(pos1 - v[i][0]) + abs(pos2 - v[i][1]),
               abs(pos2 - v[i][0]) + abs(pos1 - v[i][1]));
    pos1 = v[i][0];
    pos2 = v[i][1];
  }
  cout << ans;
  return 0;
}
