N = int(raw_input())
A = map(int, raw_input().split())

counter = 0
while True:
  ischanged = False
  for i in xrange(1, N):
    if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
  if ischanged == False:
    break
print " ".join(map(str, A))
print counter N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = map(int, raw_input().split()) A map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split counter = 0 counter 0 while True:
  ischanged = False
  for i in xrange(1, N):
    if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
  if ischanged == False:
    break True ischanged = False ischanged False for i in xrange(1, N):
    if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
   i xrange(1, N) xrange 1 N if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
   A[N-i] < A[N-i-1] A[N-i] A N-i N i A[N-i-1] A N-i-1 N-i N i 1 tmp = A[N-i] tmp A[N-i] A N-i N i A[N-i] = A[N-i-1] A[N-i] A N-i N i A[N-i-1] A N-i-1 N-i N i 1 A[N-i-1] = tmp A[N-i-1] A N-i-1 N-i N i 1 tmp counter += 1 counter 1 ischanged = True ischanged True if ischanged == False:
    break ischanged == False ischanged False break print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print counter += 1 1 counter tmp = A[N-i] A[N-i] tmp ischanged = True True ischanged ischanged = False False ischanged A = map(int, raw_input().split()) map(int, raw_input().split()) A N = int(raw_input()) int(raw_input()) N counter = 0 0 counter
N = int(raw_input())
A = map(int, raw_input().split())

counter = 0
while True:
  ischanged = False
  for i in xrange(1, N):
    if A[N-i] < A[N-i-1]:
      tmp = A[N-i]
      A[N-i] = A[N-i-1]
      A[N-i-1] = tmp
      counter += 1
      ischanged = True
  if ischanged == False:
    break
print " ".join(map(str, A))
print counter