
def BubbleSort(A, N):
    cnt = 0 # swap???????????£????????°????¨???????????????°
    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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
    return cnt


N = int(input())
A = [int(a) for a in input().split()]

cnt = BubbleSort(A, N)

print(*A)
print(cnt) def BubbleSort(A, N):
    cnt = 0 # swap???????????£????????°????¨???????????????°
    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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
    return cnt BubbleSort cnt = 0 cnt 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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
     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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
     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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
     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 cnt += 1 cnt 1 flag = 1 flag 1 return cnt cnt A A N N N = int(input()) N int(input()) int input() input int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a A = [int(a) for a in input().split()] A [int(a) for a in input().split()] cnt = BubbleSort(A, N) cnt BubbleSort(A, N) BubbleSort A N print(*A) print *A A print(cnt) print cnt cnt = BubbleSort(A, N) BubbleSort(A, N) cnt N = int(input()) int(input()) N A = [int(a) for a in input().split()] [int(a) for a in input().split()] A def BubbleSort(A, N):
    cnt = 0 # swap???????????£????????°????¨???????????????°
    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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
    return cnt def BubbleSort(A, N):
    cnt = 0 # swap???????????£????????°????¨???????????????°
    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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
    return cnt BubbleSort

def BubbleSort(A, N):
    cnt = 0 # swap???????????£????????°????¨???????????????°
    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]
                cnt += 1
                flag = 1

    # swap???????????£????????°?????????
    return cnt


N = int(input())
A = [int(a) for a in input().split()]

cnt = BubbleSort(A, N)

print(*A)
print(cnt)