# -*- coding: utf-8 -*-
"""
Created on Sat Jun 17 09:42:24 2017

@author: syaga
"""

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    flag = 1
    num = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
    print(" ".join(map(str, A)))
    print(num) """
Created on Sat Jun 17 09:42:24 2017

@author: syaga
""" if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    flag = 1
    num = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
    print(" ".join(map(str, A)))
    print(num) __name__ == "__main__" __name__ "__main__" 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 flag = 1 flag 1 num = 0 num 0 while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
     flag flag = 0 flag 0 for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
     j range(N-1, 0, -1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 temp = A[j] temp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = temp A[j-1] A j-1 j 1 temp flag = 1 flag 1 num += 1 num 1 print(" ".join(map(str, A))) print " ".join(map(str, A)) " ".join " " join map(str, A) map str A print(num) print num N = int(input()) int(input()) N temp = A[j] A[j] temp num += 1 1 num flag = 0 0 flag A = list(map(int, input().split())) list(map(int, input().split())) A num = 0 0 num flag = 1 1 flag flag = 1 1 flag
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 17 09:42:24 2017

@author: syaga
"""

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    flag = 1
    num = 0
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                temp = A[j]
                A[j] = A[j-1]
                A[j-1] = temp
                flag = 1
                num += 1
    print(" ".join(map(str, A)))
    print(num)