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

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

cnt = 0
flag = 1
while flag > 0:
    flag = 0
    for j in range(n-1,0,-1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            flag = 1
            cnt += 1
print(' '.join(map(str,a)))
print(cnt)

