#include<stdio.h>

int main(){

????int n, k, A[100];
????int count = 0;
??
????scanf("%d", &n);
????for ( i = 0; i < n; i++ ){
????  scanf("%d", &A[ i ] );
????}
??????
  for ( i = n-1; i >= 0; i-- ){
    if(A[i] < A[i-1]){
      k = A[i];
      A[i] = A[i-1];
      A[i-1] = k;
      count++;
    }
  } 
  for ( i = 0; i < n; i++){
    printf("%d", A[i]);
  }

  printf("\n");
  printf("%d", count);

  return 0;
}