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

    return a, c

if __name__ == "__main__":
    n = int(input())
    a_l = [int(a) for a in input().split()]

    as_l, c  = bubbleSort(a_l, n)
    print(' '.join(map(str, as_l)))
    print(c) def bubbleSort(a, n):
    flag = True
    c = 0
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 1
                flag = True

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

     flag flag = False flag False for j in reversed(range(1, n)):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 1
                flag = True

     j reversed(range(1, n)) reversed range(1, n) range 1 n if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 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 a[j-1] a j-1 j 1 a[j-1] a j-1 j 1 a[j] a j c += 1 c 1 flag = True flag True return a, c return a, c a c a a n n if __name__ == "__main__":
    n = int(input())
    a_l = [int(a) for a in input().split()]

    as_l, c  = bubbleSort(a_l, n)
    print(' '.join(map(str, as_l)))
    print(c) __name__ == "__main__" __name__ "__main__" n = int(input()) n int(input()) int input() input int(a) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) int a a_l = [int(a) for a in input().split()] a_l [int(a) for a in input().split()] as_l, c  = bubbleSort(a_l, n) as_l bubbleSort(a_l, n) bubbleSort a_l n c print(' '.join(map(str, as_l))) print ' '.join(map(str, as_l)) ' '.join ' ' join map(str, as_l) map str as_l print(c) print c def bubbleSort(a, n):
    flag = True
    c = 0
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 1
                flag = True

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

    return a, c bubbleSort as_l, c  = bubbleSort(a_l, n) bubbleSort(a_l, n) as_l a_l = [int(a) for a in input().split()] [int(a) for a in input().split()] a_l n = int(input()) int(input()) n c  = bubbleSort(a_l, n) bubbleSort(a_l, n) c
def bubbleSort(a, n):
    flag = True
    c = 0
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 1
                flag = True

    return a, c

if __name__ == "__main__":
    n = int(input())
    a_l = [int(a) for a in input().split()]

    as_l, c  = bubbleSort(a_l, n)
    print(' '.join(map(str, as_l)))
    print(c)