N = int(input())
a = [int(i) for i in input().split()]
frag = 1
i = 0
count = 0
while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            count += 1
        frag = 1
        
    i += 1

print(" ".join(map(str, a)))
print(count) N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] frag = 1 frag 1 i = 0 i 0 count = 0 count 0 while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            count += 1
        frag = 1
        
    i += 1 frag frag = 0 frag 0 for j in range(N-1,i,-1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            count += 1
        frag = 1
        
     j range(N-1,i,-1) range N-1 N 1 i -1 if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            count += 1
         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 frag = 1 frag 1 i += 1 i 1 print(" ".join(map(str, a))) print " ".join(map(str, a)) " ".join " " join map(str, a) map str a print(count) print count i = 0 0 i count += 1 1 count i += 1 1 i count = 0 0 count frag = 0 0 frag frag = 1 1 frag frag = 1 1 frag N = int(input()) int(input()) N a = [int(i) for i in input().split()] [int(i) for i in input().split()] a
N = int(input())
a = [int(i) for i in input().split()]
frag = 1
i = 0
count = 0
while frag:
    frag = 0
    for j in range(N-1,i,-1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            count += 1
        frag = 1
        
    i += 1

print(" ".join(map(str, a)))
print(count)