#include <iostream>
using namespace std;
int main()
{
    int n;  cin >> n;
    int arr[2*n] , copy[2*n];

    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        cin >> arr[i];
        copy[i] = i;
    }

    for ( int i = 0 ; i < 2*n ; i ++ )
    {
        for ( int j = 0 ; j < 2*n ; j ++ )
        {
            if ( arr[i] > arr[j] && i < j )
            {
                swap ( arr[i] , arr[j] );
                swap ( copy[i] , copy[j] );
            }
        }
    }

    int metr = 0;
    int b = 0;
    while ( b < 2*n )
    {
        metr += abs ( copy[b+1] - copy[b] );
        b += 2;
    }

    cout << metr;

    return 0;
}