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

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

res = BubbleSort(N, A)
print(" ".join(map(str, res[0])))
print(res[1]) 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()] def BubbleSort(N, A):
    flag = 1
    cnt = 0
    while flag > 0:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
    return A, cnt BubbleSort flag = 1 flag 1 cnt = 0 cnt 0 while flag > 0:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
     flag > 0 flag 0 flag = 0 flag 0 for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
     j range(N-1, 0, -1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 tmp = A[j] tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = 1 flag 1 cnt += 1 cnt 1 return A, cnt return A, cnt A cnt N N A A res = BubbleSort(N, A) res BubbleSort(N, A) BubbleSort N A print(" ".join(map(str, res[0]))) print " ".join(map(str, res[0])) " ".join " " join map(str, res[0]) map str res[0] res 0 print(res[1]) print res[1] res 1 def BubbleSort(N, A):
    flag = 1
    cnt = 0
    while flag > 0:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
    return A, cnt def BubbleSort(N, A):
    flag = 1
    cnt = 0
    while flag > 0:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                tmp = A[j]
                A[j] = A[j-1]
                A[j-1] = tmp
                flag = 1
                cnt += 1
    return A, cnt BubbleSort A = [int(i) for i in input().split()] [int(i) for i in input().split()] A res = BubbleSort(N, A) BubbleSort(N, A) res N = int(input()) int(input()) N
N = int(input())
A = [int(i) for i in input().split()]

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

res = BubbleSort(N, A)
print(" ".join(map(str, res[0])))
print(res[1])