#include<stdio.h>

int n, s[500000], n1[250000], n2[250000];

int main() {
    int i, j, k, mid, temp;
    int flag = 1;
    int count = 0;
    
    scanf("%d", &n);
    mid = n / 2;
    for (i = 0; i < mid; i++)
        scanf("%d", &n1[i]);
    for (i = mid; i < n; i++)
        scanf("%d", &n2[i]);
    
    while(flag){
        flag = 0;
        for(j = mid ; j >= 0; --j){
            if(n1[j] < n1[j - 1]){
                temp = n1[j];
                n1[j] = n1[j - 1];
                n1[j - 1] = temp;
                flag = 1;
                count++;
            }
        }
    }
    
    while(flag){
        flag = 0;
        for(j = n; j > mid; --j){
            if(n2[j] < n2[j - 1]){
                temp = n2[j];
                n2[j] = n2[j - 1];
                n2[j - 1] = temp;
                flag = 1;
                count++;
            }
        }
    }
    
    for (i = 0; i < n; i++){
        j = 0;
        k = 0;
        if(n1[j] <= n2[k]){
            s[i] = n1[j];
            j++;
        }else{
            s[i] = n2[k];
            k++;
        }
    }
    
    for (i = 0; i < n; i++){
        printf("%d", s[i]);
    }
    printf("%d\n", count);
    
}