def buble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
    return (a,count)

n = int(input())
a = list(map(int, input().split()))
a,c = buble_sort(a,n)
print(' '.join(map(str, a)))
print(c) def buble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
    return (a,count) buble_sort flag = True flag True count = 0 count 0 while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
     flag flag = False flag False for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
     j range(n-1,0,-1) range n-1 n 1 0 -1 if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
     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 count += 1 count 1 flag = True flag True return (a,count) (a,count) a count a a n n 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,c = buble_sort(a,n) a buble_sort(a,n) buble_sort a n c print(' '.join(map(str, a))) print ' '.join(map(str, a)) ' '.join ' ' join map(str, a) map str a print(c) print c def buble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
    return (a,count) def buble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
    return (a,count) buble_sort n = int(input()) int(input()) n a = list(map(int, input().split())) list(map(int, input().split())) a c = buble_sort(a,n) buble_sort(a,n) c a,c = buble_sort(a,n) buble_sort(a,n) a
def buble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                count += 1
                flag = True
    return (a,count)

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