#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

c = 0
flag = True
while flag:
    flag = False
    for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True
print(' '.join((str(x) for x in A)))
print(c) 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 c = 0 c 0 flag = True flag True while flag:
    flag = False
    for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True flag flag = False flag False for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True i range(N - 1, 0, -1) range N - 1 N 1 0 -1 if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i], A[i - 1] = A[i - 1], A[i] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] A i - 1 i 1 A[i] A i c += 1 c 1 flag = True flag True str(x) for x in A for x in A x A for x in A str(x) str x print(' '.join((str(x) for x in A))) print ' '.join((str(x) for x in A)) ' '.join ' ' join (str(x) for x in A) print(c) print c c += 1 1 c A = list(map(int, input().split())) list(map(int, input().split())) A flag = True True flag N = int(input()) int(input()) N flag = True True flag c = 0 0 c flag = False False flag
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

c = 0
flag = True
while flag:
    flag = False
    for i in range(N - 1, 0, -1):
        if A[i] < A[i - 1]:
            A[i], A[i - 1] = A[i - 1], A[i]
            c += 1
            flag = True
print(' '.join((str(x) for x in A)))
print(c)