def buble_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
    return seq, cnt


n = int(input())
a = list(map(int, input().split()))
sorted_a, num_swap = buble_sort(a)
print(' '.join(map(str, sorted_a)))
print(num_swap) def buble_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
    return seq, cnt buble_sort l = len(seq) l len(seq) len seq cnt = 0 cnt 0 for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
     i range(l) range l for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
     j range(i+1, l)[::-1] (i+1, l) range i+1 i 1 l ::-1 -1 if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
     seq[j] < seq[j-1] seq[j] seq j seq[j-1] seq j-1 j 1 seq[j], seq[j-1] = seq[j-1], seq[j] seq[j] seq j seq[j-1] seq j-1 j 1 seq[j-1] seq j-1 j 1 seq[j] seq j cnt += 1 cnt 1 return seq, cnt return seq, cnt seq cnt seq seq 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 sorted_a, num_swap = buble_sort(a) sorted_a buble_sort(a) buble_sort a num_swap print(' '.join(map(str, sorted_a))) print ' '.join(map(str, sorted_a)) ' '.join ' ' join map(str, sorted_a) map str sorted_a print(num_swap) print num_swap a = list(map(int, input().split())) list(map(int, input().split())) a sorted_a, num_swap = buble_sort(a) buble_sort(a) sorted_a n = int(input()) int(input()) n num_swap = buble_sort(a) buble_sort(a) num_swap def buble_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
    return seq, cnt def buble_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
    return seq, cnt buble_sort
def buble_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        for j in range(i+1, l)[::-1]:
            if seq[j] < seq[j-1]:
                seq[j], seq[j-1] = seq[j-1], seq[j]
                cnt += 1
    return seq, cnt


n = int(input())
a = list(map(int, input().split()))
sorted_a, num_swap = buble_sort(a)
print(' '.join(map(str, sorted_a)))
print(num_swap)