#include <bits/stdc++.h>
using namespace std;
int n, a[200005];
vector<int> v[200005];
int main() {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= 2 * n; i++) {
    scanf("%d", &a[i]);
    v[a[i]].push_back(i);
  }
  for (i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
  long long ans = 0;
  int pos1 = 1, pos2 = 1;
  for (i = 1; i <= n; i++) {
    ans += abs(v[i][0] - pos1);
    ans += abs(v[i][1] - pos2);
    pos1 = v[i][0];
    pos2 = v[i][1];
  }
  cout << ans << endl;
  return 0;
}
