#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v;
vector<long long int> vec;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  scanf("%d", &(n));
  int x;
  for (int i = 1; i <= 2 * n; i++) {
    scanf("%d", &(x));
    v.push_back(make_pair(x, i));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    vec.push_back(v[i].second);
  }
  long long int sum = vec[0] + vec[1] - 2;
  for (int i = 2; i < vec.size(); i += 2) {
    sum += abs(vec[i] - vec[i - 2]);
  }
  for (int i = 3; i < vec.size(); i += 2) {
    sum += abs(vec[i] - vec[i - 2]);
  }
  cout << sum << endl;
  return 0;
}
