def BubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
    print(' '.join(map(str,A)))
    print(count)
            
N = int(input())
A = input()
A = list(map(int,A.split()))
BubbleSort(A,N) def BubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
    print(' '.join(map(str,A)))
    print(count)
             BubbleSort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
     flag flag = 0 flag 0 for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
     i range(N-1,0,-1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
     A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 tmp = A[i] tmp A[i] A i A[i] = A[i- 1] A[i] A i A[i- 1] A i- 1 i 1 A[i-1] = tmp A[i-1] A i-1 i 1 tmp flag = 1 flag 1 count = count +1 count count +1 count 1 print(' '.join(map(str,A))) print ' '.join(map(str,A)) ' '.join ' ' join map(str,A) map str A print(count) print count A A N N N = int(input()) N int(input()) int input() input A = input() A input() input A = list(map(int,A.split())) A list(map(int,A.split())) list map(int,A.split()) map int A.split() A.split A split BubbleSort(A,N) BubbleSort A N def BubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
    print(' '.join(map(str,A)))
    print(count)
             def BubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
    print(' '.join(map(str,A)))
    print(count)
             BubbleSort A = list(map(int,A.split())) list(map(int,A.split())) A A = input() input() A N = int(input()) int(input()) N
def BubbleSort(A,N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                tmp = A[i]
                A[i] = A[i- 1]
                A[i-1] = tmp
                flag = 1
                count = count +1
    print(' '.join(map(str,A)))
    print(count)
            
N = int(input())
A = input()
A = list(map(int,A.split()))
BubbleSort(A,N)
