def bubbleSort(a):
    sw = 0
    for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
    return a, sw

n = int(input())
a = list(map(int, input().split()))

a, sw = bubbleSort(a)

print(*a)
print(sw)
 def bubbleSort(a):
    sw = 0
    for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
    return a, sw bubbleSort sw = 0 sw 0 for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
     _ range(len(a) - 1) range len(a) - 1 len(a) len a 1 for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
     j range(len(a) - 1, 0, -1) range len(a) - 1 len(a) len a 1 0 -1 if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
     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 sw += 1 sw 1 return a, sw return a, sw a sw a a 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 a, sw = bubbleSort(a) a bubbleSort(a) bubbleSort a sw print(*a) print *a a print(sw) print sw sw = bubbleSort(a) bubbleSort(a) sw def bubbleSort(a):
    sw = 0
    for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
    return a, sw def bubbleSort(a):
    sw = 0
    for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
    return a, sw bubbleSort a, sw = bubbleSort(a) bubbleSort(a) a n = int(input()) int(input()) n a = list(map(int, input().split())) list(map(int, input().split())) a
def bubbleSort(a):
    sw = 0
    for _ in range(len(a) - 1):
        for j in range(len(a) - 1, 0, -1):
            if (a[j] < a[j - 1]):
                a[j], a[j - 1] = a[j - 1], a[j]
                sw += 1
    return a, sw

n = int(input())
a = list(map(int, input().split()))

a, sw = bubbleSort(a)

print(*a)
print(sw)

