#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;
    }

    int min = arr[0];
    for ( int i = 0 ; i < n - 1 ; i ++ )
    {
        min = arr[i];
        for ( int j = 0 ; j < 2*n ; j ++ )
        {
            if ( min > arr[j] )
            {
                swap ( min , arr[j] );

                arr[i] = min;
                copy[i] = j;
            }
        }
    }

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

    cout << metr;


    return 0;
}