N = int(input())
A = list(map(int, input().split(" ")))

def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1])

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

A_sorted, c = BubbleSort(A, N)

print_list(A_sorted)
print(c) 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 " " def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1]) print_list for a in A[:-1]:
        print ("%d "%a, end="")
     a A[:-1] A :-1 -1 print ("%d "%a, end="") print "%d "%a "%d " a end="" end "" print(A[-1]) print A[-1] A -1 A A def BubbleSort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
    return A, count BubbleSort count = 0 count 0 flag = True flag True while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
     flag flag = False flag False for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
     j range(N-1, 0, -1) range N-1 N 1 0 -1 if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 v = A[j] v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v count += 1 count 1 flag = True flag True return A, count return A, count A count A A N N A_sorted, c = BubbleSort(A, N) A_sorted BubbleSort(A, N) BubbleSort A N c print_list(A_sorted) print_list A_sorted print(c) print c def BubbleSort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
    return A, count def BubbleSort(A, N):
    count = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
                
    return A, count BubbleSort N = int(input()) int(input()) N A_sorted, c = BubbleSort(A, N) BubbleSort(A, N) A_sorted A = list(map(int, input().split(" "))) list(map(int, input().split(" "))) A def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1]) def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1]) print_list c = BubbleSort(A, N) BubbleSort(A, N) c
N = int(input())
A = list(map(int, input().split(" ")))

def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1])

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

A_sorted, c = BubbleSort(A, N)

print_list(A_sorted)
print(c)