#!/usr/bin/env python
# -*- coding: utf-8 -*-


def print_array(a):
    print(" ".join(map(str, a)))


def bubblesort(a, n):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
    return (a, swap)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    (b, swap) = bubblesort(a, n)
    print_array(b)
    print(swap)

if __name__ == "__main__":
    main() def print_array(a):
    print(" ".join(map(str, a))) print_array print(" ".join(map(str, a))) print " ".join(map(str, a)) " ".join " " join map(str, a) map str a a a def bubblesort(a, n):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
    return (a, swap) bubblesort swap = 0 swap 0 flag = True flag True while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
     flag flag = False flag False for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
     j range(n - 1, 0, -1) range n - 1 n 1 0 -1 if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
     a[j] < a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 (a[j], a[j - 1]) = (a[j - 1], a[j]) (a[j], a[j - 1]) a[j] a j a[j - 1] a j - 1 j 1 (a[j - 1], a[j]) a[j - 1] a j - 1 j 1 a[j] a j swap += 1 swap 1 flag = True flag True return (a, swap) (a, swap) a swap a a n n def main():
    n = int(input())
    a = list(map(int, input().split()))
    (b, swap) = bubblesort(a, n)
    print_array(b)
    print(swap) main 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 (b, swap) = bubblesort(a, n) (b, swap) b swap bubblesort(a, n) bubblesort a n print_array(b) print_array b print(swap) print swap if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def print_array(a):
    print(" ".join(map(str, a))) def print_array(a):
    print(" ".join(map(str, a))) print_array def main():
    n = int(input())
    a = list(map(int, input().split()))
    (b, swap) = bubblesort(a, n)
    print_array(b)
    print(swap) def main():
    n = int(input())
    a = list(map(int, input().split()))
    (b, swap) = bubblesort(a, n)
    print_array(b)
    print(swap) main def bubblesort(a, n):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
    return (a, swap) def bubblesort(a, n):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
    return (a, swap) bubblesort
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def print_array(a):
    print(" ".join(map(str, a)))


def bubblesort(a, n):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(n - 1, 0, -1):
            if a[j] < a[j - 1]:
                (a[j], a[j - 1]) = (a[j - 1], a[j])
                swap += 1
                flag = True
    return (a, swap)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    (b, swap) = bubblesort(a, n)
    print_array(b)
    print(swap)

if __name__ == "__main__":
    main()