def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c

N = int(input())
A = list(map(int, input().split(' ')))
A, c = Bubble(A, N)
ans = ' '.join(map(str, A)) + '\n' + str(c)
print(ans) def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c Bubble f = 1 f 1 c = 0 c 0 while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
     f f = 0 f 0 j = N - 1 j N - 1 N 1 while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
     j > 0 j 0 if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
             A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 c += 1 c 1 a = A[j] a A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = a A[j - 1] A j - 1 j 1 a f = 1 f 1 j -= 1 j 1 return A, c return A, c A c A A N N 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 ' ' A, c = Bubble(A, N) A Bubble(A, N) Bubble A N c ans = ' '.join(map(str, A)) + '\n' + str(c) ans ' '.join(map(str, A)) + '\n' + str(c) ' '.join(map(str, A)) + '\n' ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A '\n' str(c) str c print(ans) print ans A = list(map(int, input().split(' '))) list(map(int, input().split(' '))) A N = int(input()) int(input()) N c = Bubble(A, N) Bubble(A, N) c ans = ' '.join(map(str, A)) + '\n' + str(c) ' '.join(map(str, A)) + '\n' + str(c) ans def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c Bubble A, c = Bubble(A, N) Bubble(A, N) A
def Bubble(A, N):
    f = 1
    c = 0
    while f:
        f = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                c += 1
                a = A[j]
                A[j] = A[j - 1]
                A[j - 1] = a
                f = 1
            j -= 1
    return A, c

N = int(input())
A = list(map(int, input().split(' ')))
A, c = Bubble(A, N)
ans = ' '.join(map(str, A)) + '\n' + str(c)
print(ans)
