N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))

def bubble_sort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = 1
    return A, count


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

def bubble_sort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                count += 1
                flag = 1
    return A, count


A, count = bubble_sort(A, N)
string = list(map(str, A))
print(' '.join(string))
print(count)

