n = int(input())

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

def swap(a, b):
    t = a
    a = b
    b = t
    return [a, b]

def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count

l, count = bubble_sort(A)
print(' '.join(str(x) for x in l))
print(count) 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 swap(a, b):
    t = a
    a = b
    b = t
    return [a, b] swap t = a t a a = b a b b = t b t return [a, b] [a, b] a b a a b b def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count bubble_sort count = 0 count 0 for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
     i range(0, len(l)) range 0 len(l) len l for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
     j reversed(range(i+1, len(l))) reversed range(i+1, len(l)) range i+1 i 1 len(l) len l if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
     l[j] < l[j-1] l[j] l j l[j-1] l j-1 j 1 count += 1 count 1 l[j], l[j-1] = swap(l[j], l[j-1]) l[j] l j swap(l[j], l[j-1]) swap l[j] l j l[j-1] l j-1 j 1 l[j-1] l j-1 j 1 return l, count return l, count l count l l l, count = bubble_sort(A) l bubble_sort(A) bubble_sort A count print(' '.join(str(x) for x in l)) print ' '.join(str(x) for x in l) ' '.join ' ' join str(x) str x print(count) print count count = bubble_sort(A) bubble_sort(A) count n = int(input()) int(input()) n def swap(a, b):
    t = a
    a = b
    b = t
    return [a, b] def swap(a, b):
    t = a
    a = b
    b = t
    return [a, b] swap l, count = bubble_sort(A) bubble_sort(A) l def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count bubble_sort A = list(map(int, input().split())) list(map(int, input().split())) A
n = int(input())

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

def swap(a, b):
    t = a
    a = b
    b = t
    return [a, b]

def bubble_sort(l):
    count = 0
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            if l[j] < l[j-1]:
                count += 1
                l[j], l[j-1] = swap(l[j], l[j-1])
    return l, count

l, count = bubble_sort(A)
print(' '.join(str(x) for x in l))
print(count)