n = int(raw_input())
a = map(int, raw_input().split())

flag = 1
count = 0
while flag:
    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
            count += 1
            flag = 1
            #print a

for i in range(n):
    if i == n -1:
        print a[i]
    else:
        print a[i],

print count n = int(raw_input()) n int(raw_input()) int raw_input() raw_input a = map(int, raw_input().split()) a map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split flag = 1 flag 1 count = 0 count 0 while flag:
    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
            count += 1
            flag = 1
            #print a flag 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
            count += 1
            flag = 1
            #print a 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
            count += 1
            flag = 1
            #print a 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 count += 1 count 1 flag = 1 flag 1 for i in range(n):
    if i == n -1:
        print a[i]
    else:
        print a[i], i range(n) range n if i == n -1:
        print a[i]
    else:
        print a[i], i == n -1 i n -1 n 1 print a[i] a i print a[i] a i print flag = 0 0 flag a = map(int, raw_input().split()) map(int, raw_input().split()) a flag = 1 1 flag count = 0 0 count flag = 1 1 flag n = int(raw_input()) int(raw_input()) n tmp = a[j] a[j] tmp count += 1 1 count
n = int(raw_input())
a = map(int, raw_input().split())

flag = 1
count = 0
while flag:
    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
            count += 1
            flag = 1
            #print a

for i in range(n):
    if i == n -1:
        print a[i]
    else:
        print a[i],

print count