def bubble(A, N):
    c = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
    return A, c

if __name__ == "__main__":
    N = int(input())
    A = [int(i) for i in input().split()]

    A, c = bubble(A, N)
    print (*A)
    print (c) def bubble(A, N):
    c = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
    return A, c bubble c = 0 c 0 flag = True flag True while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
     flag flag = False flag False for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
     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]
                c += 1
                flag = True
     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 c += 1 c 1 flag = True flag True return A, c return A, c A c A A N N if __name__ == "__main__":
    N = int(input())
    A = [int(i) for i in input().split()]

    A, c = bubble(A, N)
    print (*A)
    print (c) __name__ == "__main__" __name__ "__main__" N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] A, c = bubble(A, N) A bubble(A, N) bubble A N c print (*A) print *A A print (c) print c def bubble(A, N):
    c = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
    return A, c def bubble(A, N):
    c = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
    return A, c bubble c = bubble(A, N) bubble(A, N) c A = [int(i) for i in input().split()] [int(i) for i in input().split()] A N = int(input()) int(input()) N A, c = bubble(A, N) bubble(A, N) A
def bubble(A, N):
    c = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                c += 1
                flag = True
    return A, c

if __name__ == "__main__":
    N = int(input())
    A = [int(i) for i in input().split()]

    A, c = bubble(A, N)
    print (*A)
    print (c)