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