def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)
  return 0

if __name__ == '__main__':
  main() def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)
  return 0 main element_num = int(input()) element_num int(input()) int input() input int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s elements = [int(s) for s in input().split()] elements [int(s) for s in input().split()] swap_count = 0 swap_count 0 for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

   i range(1, element_num) range 1 element_num for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

   j reversed(range(i, element_num)) reversed range(i, element_num) range i element_num if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

   elements[j-1] > elements[j] elements[j-1] elements j-1 j 1 elements[j] elements j elements[j-1], elements[j] = elements[j], elements[j-1] elements[j-1] elements j-1 j 1 elements[j] elements j elements[j] elements j elements[j-1] elements j-1 j 1 swap_count += 1 swap_count 1 print(' '.join(list(map(str, elements)))) print ' '.join(list(map(str, elements))) ' '.join ' ' join list(map(str, elements)) list map(str, elements) map str elements print(swap_count) print swap_count return 0 0 if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)
  return 0 def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)
  return 0 main
def main():
  element_num = int(input())
  elements = [int(s) for s in input().split()]
  swap_count = 0

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if elements[j-1] > elements[j]:
        elements[j-1], elements[j] = elements[j], elements[j-1]
        swap_count += 1

  print(' '.join(list(map(str, elements))))
  print(swap_count)
  return 0

if __name__ == '__main__':
  main()