def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn)

if __name__ == "__main__":
      N = int(input())
      A = input()
      A = A.split()
      bubbleSort(A, N) def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn) bubbleSort ctn = 0 ctn 0 for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
       i range(0,N) range 0 N for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
       j range(0,N-i-1) range 0 N-i-1 N-i N i 1 if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
       int(A[j]) > int(A[j+1]) int(A[j]) int A[j] A j int(A[j+1]) int A[j+1] A j+1 j 1 t = A[j] t A[j] A j A[j] = A[j+1] A[j] A j A[j+1] A j+1 j 1 A[j+1] = t A[j+1] A j+1 j 1 t ctn = ctn + 1 ctn ctn + 1 ctn 1 for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
       i range(0,N) range 0 N if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
       i < N-1 i N-1 N 1 print(A[i],end=' ') print A[i] A i end=' ' end ' ' print(A[i]) print A[i] A i print(ctn) print ctn A A N N if __name__ == "__main__":
      N = int(input())
      A = input()
      A = A.split()
      bubbleSort(A, N) __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input A = input() A input() input A = A.split() A A.split() A.split A split bubbleSort(A, N) bubbleSort A N def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn) def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn) bubbleSort N = int(input()) int(input()) N A = input() input() A A = A.split() A.split() A
def bubbleSort(A, N):
      ctn = 0
      for i in range(0,N):
            for j in range(0,N-i-1):
                  if int(A[j]) > int(A[j+1]):
                        t = A[j]
                        A[j] = A[j+1]
                        A[j+1] = t
                        ctn = ctn + 1
      for i in range(0,N):
            if i < N-1:
                  print(A[i],end=' ')
            else:
                  print(A[i])
      print(ctn)

if __name__ == "__main__":
      N = int(input())
      A = input()
      A = A.split()
      bubbleSort(A, N)