3
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
 
void print(int* A, int N){
  int i;
  for(i = 0; i < N; i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}
 
int bubble_sort(int* A, int N){
  int i,j, cnt = 0;
  for(i = 0; i < N; i++)
    for(j = N-1; j >= i+1; j--)
      if(A[j] < A[j-1]){
    int tmp = A[j];
    A[j] = A[j-1];
    A[j-1] = tmp;
    cnt++;
      }
  print(A,N);
  return cnt;
}
 
int main(){
  int i,N,data[100];
  scanf("%d",&N);
  for(i = 0; i < N; i++) scanf("%d",&data[i]);
  printf("%d\n",bubble_sort(data,N));
  return 0;
}
