#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
int n;
long long now1 = 0, now2 = 0, res = 0;
vector<long long> v[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    int x;
    cin >> x;
    v[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    res = res + abs(v[i][0] - now1);
    now1 = v[i][0];
  }
  for (int i = 1; i <= n; i++) {
    res = res + abs(v[i][1] - now2);
    now2 = v[i][1];
  }
  cout << res << '\n';
}
