# -*- coding: utf-8 -*-


def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt)


def to_int(v):
    return int(v)


def to_seq(v):
    return [int(c) for c in v.split()]


if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    bubble_sort(seq, l) def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt) bubble_sort cnt = 0 cnt 0 for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

     max_size range(l, 0, -1) range l 0 -1 for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

     left range(1, max_size) range 1 max_size if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

     seq[left-1] > seq[left] seq[left-1] seq left-1 left 1 seq[left] seq left seq[left-1], seq[left] = seq[left], seq[left-1] seq[left-1] seq left-1 left 1 seq[left] seq left seq[left] seq left seq[left-1] seq left-1 left 1 cnt += 1 cnt 1 str(i) for i in seq for i in seq i seq for i in seq str(i) str i print(' '.join([str(i) for i in seq])) print ' '.join([str(i) for i in seq]) ' '.join ' ' join [str(i) for i in seq] print(cnt) print cnt seq seq l l def to_int(v):
    return int(v) to_int return int(v) int(v) int v v v def to_seq(v):
    return [int(c) for c in v.split()] to_seq int(c) for c in v.split() for c in v.split() c v.split() v.split v split for c in v.split() int(c) int c return [int(c) for c in v.split()] [int(c) for c in v.split()] v v if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    bubble_sort(seq, l) __name__ == '__main__' __name__ '__main__' l = to_int(input()) l to_int(input()) to_int input() input seq = to_seq(input()) seq to_seq(input()) to_seq input() input bubble_sort(seq, l) bubble_sort seq l def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt) def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt) bubble_sort def to_seq(v):
    return [int(c) for c in v.split()] def to_seq(v):
    return [int(c) for c in v.split()] to_seq l = to_int(input()) to_int(input()) l seq = to_seq(input()) to_seq(input()) seq def to_int(v):
    return int(v) def to_int(v):
    return int(v) to_int
# -*- coding: utf-8 -*-


def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt)


def to_int(v):
    return int(v)


def to_seq(v):
    return [int(c) for c in v.split()]


if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    bubble_sort(seq, l)