def bubbleSort(A,N,cnt=0):
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
    return A , cnt

N = int(input())
A = list(map(int,input().split()))
X , cnt = bubbleSort(A,N)
print(*X)
print(cnt) def bubbleSort(A,N,cnt=0):
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
    return A , cnt bubbleSort flag = 1 flag 1 while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
     flag flag = 0 flag 0 for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
     i range(N-1,0,-1) range N-1 N 1 0 -1 if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
     A[i-1] > A[i] A[i-1] A i-1 i 1 A[i] A i A[i-1] , A[i] = A[i] , A[i-1] A[i-1] A i-1 i 1 A[i] A i A[i] A i A[i-1] A i-1 i 1 cnt += 1 cnt 1 flag = 1 flag 1 return A , cnt return A , cnt A cnt A A N N cnt=0 cnt 0 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 X , cnt = bubbleSort(A,N) X bubbleSort(A,N) bubbleSort A N cnt print(*X) print *X X print(cnt) print cnt N = int(input()) int(input()) N cnt = bubbleSort(A,N) bubbleSort(A,N) cnt X , cnt = bubbleSort(A,N) bubbleSort(A,N) X A = list(map(int,input().split())) list(map(int,input().split())) A def bubbleSort(A,N,cnt=0):
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
    return A , cnt def bubbleSort(A,N,cnt=0):
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
    return A , cnt bubbleSort
def bubbleSort(A,N,cnt=0):
    flag = 1
    while flag:
        flag = 0
        for i in range(N-1,0,-1):
            if A[i-1] > A[i]:
                A[i-1] , A[i] = A[i] , A[i-1]
                cnt += 1
                flag = 1
    return A , cnt

N = int(input())
A = list(map(int,input().split()))
X , cnt = bubbleSort(A,N)
print(*X)
print(cnt)