#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000005;
const double PI = 4 * atan(1);
long long n, m;
long long x;
map<long long, vector<long long> > maa;
bool vis[N];
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    cin >> x;
    maa[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    sort(maa[i].begin(), maa[i].end());
  }
  long long ans = maa[1][0] + maa[1][1];
  for (int i = 1; i <= n - 1; i++) {
    ans += abs(maa[i + 1][0] - maa[i][0]);
    ans += abs(maa[i + 1][1] - maa[i][1]);
  }
  cout << ans;
  return 0;
}
