n = int(input())
sequence = [int(x) for x in input().split(' ')]

def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1])

def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count

sequence, count = bubleSort(n, sequence)
pretty_sequence(sequence)
print(count) n = int(input()) n int(input()) int input() input int(x) for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') int(x) int x sequence = [int(x) for x in input().split(' ')] sequence [int(x) for x in input().split(' ')] def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1]) pretty_sequence n = len(sequence) n len(sequence) len sequence for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
     i range(n-1) range n-1 n 1 print(format(sequence[i]) + ' ', end='') print format(sequence[i]) + ' ' format(sequence[i]) format sequence[i] sequence i ' ' end='' end '' print(sequence[n - 1]) print sequence[n - 1] sequence n - 1 n 1 sequence sequence def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count bubleSort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
     flag flag = 0 flag 0 for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
     i range(n-1, 0, -1) range n-1 n 1 0 -1 if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
     sequence[i] < sequence[i-1] sequence[i] sequence i sequence[i-1] sequence i-1 i 1 tmp_val = sequence[i] tmp_val sequence[i] sequence i sequence[i] = sequence[i-1] sequence[i] sequence i sequence[i-1] sequence i-1 i 1 sequence[i-1] = tmp_val sequence[i-1] sequence i-1 i 1 tmp_val count += 1 count 1 flag = 1 flag 1 return sequence, count return sequence, count sequence count n n sequence sequence sequence, count = bubleSort(n, sequence) sequence bubleSort(n, sequence) bubleSort n sequence count pretty_sequence(sequence) pretty_sequence sequence print(count) print count n = int(input()) int(input()) n sequence, count = bubleSort(n, sequence) bubleSort(n, sequence) sequence def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count bubleSort def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1]) def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1]) pretty_sequence sequence = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] sequence count = bubleSort(n, sequence) bubleSort(n, sequence) count
n = int(input())
sequence = [int(x) for x in input().split(' ')]

def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1])

def bubleSort(n, sequence):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if sequence[i] < sequence[i-1]:
                tmp_val = sequence[i]
                sequence[i] = sequence[i-1]
                sequence[i-1] = tmp_val
                count += 1
                flag = 1
    return sequence, count

sequence, count = bubleSort(n, sequence)
pretty_sequence(sequence)
print(count)