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

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

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