def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count

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

print(bubbles(numbers)) def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count bubbles count = 0 count 0 for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
     i range(len(N)) range len(N) len N for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
     j range(len(N)-1, i, -1) range len(N)-1 len(N) len N 1 i -1 if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
     N[j] < N[j-1] N[j] N j N[j-1] N j-1 j 1 N[j], N[j-1] = N[j-1], N[j] N[j] N j N[j-1] N j-1 j 1 N[j-1] N j-1 j 1 N[j] N j count += 1 count 1 c = 1 c 1 for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
     i N print(i, end='') print i end='' end '' if c < len(N):
            print(' ', end='')
            c += 1
     c < len(N) c len(N) len N print(' ', end='') print ' ' end='' end '' c += 1 c 1 print('') print '' return count count N N n = int(input()) n int(input()) int input() input numbers = list(map(int, input().split())) numbers list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split print(bubbles(numbers)) print bubbles(numbers) bubbles numbers numbers = list(map(int, input().split())) list(map(int, input().split())) numbers def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count bubbles n = int(input()) int(input()) n
def bubbles(N):
    count = 0
    for i in range(len(N)):
        for j in range(len(N)-1, i, -1):
            if N[j] < N[j-1]:
                N[j], N[j-1] = N[j-1], N[j]
                count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    return count

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

print(bubbles(numbers))