#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<V<T>>;
template <typename T>
using Mi = map<long long, T>;
template <typename T>
using MMi = map<long long, Mi<T>>;
const double PI = 3.141592653589793238463;
void cinArr(vector<long long> &arr) {
  for (int i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
}
void cinArr(V<int> &arr) {
  for (int i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
}
int xx[4] = {1, -1, 0, 0};
int yy[4] = {0, 0, 1, -1};
class Node {
 private:
  long long value;

 public:
  long long l;
  long long r;
  long long mod = 0;
  Node *lChildren;
  Node *rChildren;
  long long getValue() { return value + mod; }
  long long getValue(long long ind) {
    if (l == r) {
      return getValue();
    }
    long long mid = (l + r) / 2;
    if (ind <= mid) {
      return lChildren->getValue(ind);
    } else {
      return rChildren->getValue(ind);
    }
  }
  long long ansNode(long long a, long long b) { return min(a, b); }
  Node(long long l, long long r, vector<long long> &arr) {
    this->l = l;
    this->r = r;
    if (l == r) {
      value = arr[l];
    } else {
      long long mid = (l + r) / 2;
      lChildren = new Node(l, mid, arr);
      rChildren = new Node(mid + 1, r, arr);
      value = ansNode(lChildren->getValue(), rChildren->getValue());
    }
  }
  void update(long long l, long long r, long long add) {
    if (l == this->l && r == this->r) {
      mod += add;
      return;
    }
    long long mid = (this->l + this->r) / 2;
    if (l <= mid) {
      lChildren->update(l, min(mid, r), add);
    }
    if (r > mid) {
      rChildren->update(max(mid + 1, l), r, add);
    }
    value = ansNode(lChildren->getValue(), rChildren->getValue());
  }
};
long long nod(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  }
  return nod(b, a % b);
}
pair<long long, long long> zero = {0, 0};
bool f(pair<string, long long> &a, pair<string, long long> &b) {
  return a.second > b.second || (a.second == b.second && a.first < b.first);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(15);
  long long n;
  cin >> n;
  vector<vector<long long>> arr(n);
  for (int i = 0; i < n * 2; i++) {
    long long val;
    cin >> val;
    arr[val - 1].push_back(i);
  }
  long long pos1 = 0;
  long long pos2 = 0;
  long long ans = 0;
  for (long long need = 0; need < n; need++) {
    long long a, b;
    a = arr[need][0];
    b = arr[need][1];
    if (abs(pos1 - a) + abs(pos2 - b) < abs(pos1 - b) + abs(pos2 - a)) {
      ans += abs(pos1 - a) + abs(pos2 - b);
      pos1 = a;
      pos2 = b;
    } else {
      ans += abs(pos1 - b) + abs(pos2 - a);
      pos1 = b;
      pos2 = a;
    }
  }
  cout << ans;
  return 0;
}
