# coding: UTF-8
def pprint(numlist):
  print(" ".join(map(str,numlist)))
N = int(input())
A = list(map(int,input().split()))
count = 0
flag = True
while flag:
  flag = False
  j = N - 1
  while j >= 1:
    if A[j-1] > A[j]:
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
    j -= 1
pprint(A)
print(count) def pprint(numlist):
  print(" ".join(map(str,numlist))) pprint print(" ".join(map(str,numlist))) print " ".join(map(str,numlist)) " ".join " " join map(str,numlist) map str numlist numlist numlist 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 count = 0 count 0 flag = True flag True while flag:
  flag = False
  j = N - 1
  while j >= 1:
    if A[j-1] > A[j]:
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
    j -= 1 flag flag = False flag False j = N - 1 j N - 1 N 1 while j >= 1:
    if A[j-1] > A[j]:
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
    j -= 1 j >= 1 j 1 if A[j-1] > A[j]:
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
     A[j-1] > A[j] A[j-1] A j-1 j 1 A[j] A j v = A[j] v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v flag = True flag True count += 1 count 1 j -= 1 j 1 pprint(A) pprint A print(count) print count def pprint(numlist):
  print(" ".join(map(str,numlist))) def pprint(numlist):
  print(" ".join(map(str,numlist))) pprint count = 0 0 count j -= 1 1 j flag = True True flag flag = True True flag N = int(input()) int(input()) N A = list(map(int,input().split())) list(map(int,input().split())) A flag = False False flag v = A[j] A[j] v j = N - 1 N - 1 j count += 1 1 count
# coding: UTF-8
def pprint(numlist):
  print(" ".join(map(str,numlist)))
N = int(input())
A = list(map(int,input().split()))
count = 0
flag = True
while flag:
  flag = False
  j = N - 1
  while j >= 1:
    if A[j-1] > A[j]:
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
    j -= 1
pprint(A)
print(count)
