N = int(input())
A = list(map(int,input().split()))

def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw)

sw = BubbleSort(A, N)
print(" ".join(map(str, A)))
print(sw) N = int(input()) N int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw) BubbleSort flag = 0 flag 0 sw = 0 sw 0 i = 0 i 0 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
  flag == 0 flag 0 flag = 1 flag 1 for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
   j range(N-1, i, -1) range N-1 N 1 i -1 if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
   A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = 0 flag 0 sw += 1 sw 1 i += 1 i 1 return str(sw) str(sw) str sw A A N N sw = BubbleSort(A, N) sw BubbleSort(A, N) BubbleSort A N print(" ".join(map(str, A))) print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(sw) print sw A = list(map(int,input().split())) list(map(int,input().split())) A N = int(input()) int(input()) N sw = BubbleSort(A, N) BubbleSort(A, N) sw def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw) def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw) BubbleSort
N = int(input())
A = list(map(int,input().split()))

def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw)

sw = BubbleSort(A, N)
print(" ".join(map(str, A)))
print(sw)