import sys

ERROR_INPUT = 'input is invalid'


def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0


def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums]


def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count


main() import sys sys ERROR_INPUT = 'input is invalid' ERROR_INPUT 'input is invalid' def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0 main n = get_length() n get_length() get_length arr = get_array(length=n) arr get_array(length=n) get_array length=n length n sourtLi, count = bubbleSort(li=arr, length=n) sourtLi bubbleSort(li=arr, length=n) bubbleSort li=arr li arr length=n length n count print(*sourtLi) print *sourtLi sourtLi print(count) print count return 0 0 def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n get_length n = int(input()) n int(input()) int input() input if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n n < 0 or n > 100 n < 0 n 0 n > 100 n 100 print(ERROR_INPUT) print ERROR_INPUT sys.exit(1) sys.exit sys exit 1 return n n def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums] get_array nums = input().split(' ') nums input().split(' ') ().split () input split ' ' str2int(string=n) for n in nums for n in nums n nums for n in nums str2int(string=n) str2int string=n string n return [str2int(string=n) for n in nums] [str2int(string=n) for n in nums] length length def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n str2int n = int(string) n int(string) int string if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n n < 0 or n > 100 n < 0 n 0 n > 100 n 100 print(ERROR_INPUT) print ERROR_INPUT sys.exit(1) sys.exit sys exit 1 return n n string string def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count bubbleSort count = 0 count 0 for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

     n range(length) range length for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

     n range(1, length - n) range 1 length - n length n if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

     li[n] < li[n - 1] li[n] li n li[n - 1] li n - 1 n 1 li[n], li[n - 1] = li[n - 1], li[n] li[n] li n li[n - 1] li n - 1 n 1 li[n - 1] li n - 1 n 1 li[n] li n count += 1 count 1 return li, count return li, count li count li li length length main() main def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n get_length ERROR_INPUT = 'input is invalid' 'input is invalid' ERROR_INPUT def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums] def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums] get_array def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n str2int def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count bubbleSort def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0 def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0 main
import sys

ERROR_INPUT = 'input is invalid'


def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = bubbleSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0


def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums]


def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def bubbleSort(li, length):
    count = 0
    for n in range(length):
        for n in range(1, length - n):
            if li[n] < li[n - 1]:
                li[n], li[n - 1] = li[n - 1], li[n]
                count += 1

    return li, count


main()