#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
vector<int> adj[maxn];
int main() {
  int n;
  cin >> n;
  int a[2 * n];
  for (int i = 0; i < 2 * n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 2 * n; i++) {
    adj[a[i]].push_back(i);
  }
  long long s1 = adj[1][0], s2 = adj[1][1];
  for (int i = 2; i <= n; i++) {
    s1 += abs(adj[i][0] - adj[i - 1][0]);
    s2 += abs(adj[i][1] - adj[i - 1][1]);
  }
  cout << s1 + s2 << endl;
  return 0;
}
