#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 = 0; i < n; i++){??
    for ( j = n-1; j >= 0; j-- ){
      if(A[j] < A[j-1]){
        k = A[j];
        A[j] = A[j-1];
        A[j-1] = k;
        count++;
      }
    }
  } 
  for ( i = 0; i < n; i++){
    printf("%d", A[i]);
  }

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

  return 0;
}