n = int(input())
a = [int(i) for i in input().split()]

num = 0

is_swapped = True
i = 0
while is_swapped:
    is_swapped = False
    for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 1
    i += 1

print(' '.join([str(i) for i in a]))
print(num) 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()] num = 0 num 0 is_swapped = True is_swapped True i = 0 i 0 while is_swapped:
    is_swapped = False
    for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 1
    i += 1 is_swapped is_swapped = False is_swapped False for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 1
     j range(n-1, i, -1) range n-1 n 1 i -1 if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 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 is_swapped = True is_swapped True num += 1 num 1 i += 1 i 1 str(i) for i in a for i in a i a for i in a str(i) str i print(' '.join([str(i) for i in a])) print ' '.join([str(i) for i in a]) ' '.join ' ' join [str(i) for i in a] print(num) print num is_swapped = False False is_swapped i += 1 1 i a = [int(i) for i in input().split()] [int(i) for i in input().split()] a num = 0 0 num tmp = a[j] a[j] tmp is_swapped = True True is_swapped i = 0 0 i num += 1 1 num n = int(input()) int(input()) n is_swapped = True True is_swapped
n = int(input())
a = [int(i) for i in input().split()]

num = 0

is_swapped = True
i = 0
while is_swapped:
    is_swapped = False
    for j in range(n-1, i, -1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            is_swapped = True
            num += 1
    i += 1

print(' '.join([str(i) for i in a]))
print(num)
