#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

#define ELEMENT_CNT_MIN (1)
#define ELEMENT_CNT_MAX (200000)
#define ELEMENT_VALUE_MIN (0)
#define ELEMENT_VALUE_MAX (1000000000)
#define STR_SIZE    (11)
#define SUCCESS     (0)
#define FAILURE     (-1)
#define FALSE       (0)
#define TRUE        (1)


typedef enum
{
    LINE_FEED,
    BLANK,
    DELIMITER_ERROR
}DELIMITER_INFO;

DELIMITER_INFO get_int_sequence(int *p_arr, int size, int min ,int max);
DELIMITER_INFO get_int(int *num, int min, int max);
DELIMITER_INFO get_str(char *p_str, int max);
int judge_constraint(int test_num, int min, int max);


int main(void)
{
    int num;
    int arr[ELEMENT_CNT_MAX];
    int i;
    int j;
    int min;
    int cnt = 0;

    
    if(get_int(&num, ELEMENT_CNT_MIN, ELEMENT_CNT_MAX) != LINE_FEED)
    {
        return FAILURE;
    }
    
    if(get_int_sequence(&arr[0], num, ELEMENT_VALUE_MIN, ELEMENT_VALUE_MAX) != LINE_FEED)
    {
        return FAILURE;
    }
     
    
    for(i = 0; i < num; i++)
    {
        min = i;
        for(j = i + 1; j < num; j++)
        {
            if(arr[min] > arr[j])
            {
                min = j;
            }
        }
        int tmp;
        tmp = arr[min];
        arr[min] = arr[i];
        arr[i] = arr[min];
        cnt += min - i;
    }
    
    printf("%d\n", cnt);
       
    return SUCCESS;
}

DELIMITER_INFO get_int_sequence(int *p_arr, int size, int min ,int max)
{
    int i;
     
    for(i = 0; i < size - 1; i++)
    {
        if(get_int(&p_arr[i], min, max) != BLANK)
        {
            return DELIMITER_ERROR;
        }
    }
    if(get_int(&p_arr[i], min, max) != LINE_FEED)
    {
        return DELIMITER_ERROR;
    }
    
    return LINE_FEED;
}

DELIMITER_INFO get_int(int *num, int min, int max)
{
    char str[STR_SIZE];
    DELIMITER_INFO delimiter;
    int i;

    delimiter = get_str(str, max);

    for(i = 0; i < STR_SIZE; i++)
    {
        if(str[i] == '\0')
        {
            break;
        }
        if(!isdigit(str[i]))
        {
            return DELIMITER_ERROR;
        }
    }

    *num = atoi(str);

    if(judge_constraint(*num, min, max) == -1)
    {
        return DELIMITER_ERROR;
    }

    return delimiter;
}

DELIMITER_INFO get_str(char *p_str, int max)
{
    int cnt = 0;
    int ch;
    
    while((ch = getchar()) != EOF)
    {
        if(cnt > 0)
        {
            if(ch == ' ' || ch == '\n')
            {
                p_str[cnt] = '\0';
                if(ch == ' ')
                {
                    return BLANK;
                }
                else
                {
                    return LINE_FEED;
                }
            }
        }
        
        if(judge_constraint(cnt, 0, max) == SUCCESS)
        {
            p_str[cnt] = ch;
            cnt++;
        }
        else
        {
            return DELIMITER_ERROR;
        }
    }
    
    return DELIMITER_ERROR;
}

int judge_constraint(int test_num, int min, int max)
{
    if((test_num < min) || (test_num > max))
    {
        return FAILURE;
    }
    
    return SUCCESS;
}
