def main():
    n = int(input())
    array = [int(x) for x in input().split()]

    cnt = 0
    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
    print(" ".join(map(str, array)))
    print(cnt)


main() def main():
    n = int(input())
    array = [int(x) for x in input().split()]

    cnt = 0
    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
    print(" ".join(map(str, array)))
    print(cnt) main 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 array = [int(x) for x in input().split()] array [int(x) for x in input().split()] cnt = 0 cnt 0 while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
     True flag = False flag False for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
         i range(1, n)[::-1] (1, n) range 1 n ::-1 -1 if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
         array[i-1] > array[i] array[i-1] array i-1 i 1 array[i] array i tmp = array[i] tmp array[i] array i array[i] = array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i-1] = tmp array[i-1] array i-1 i 1 tmp flag = True flag True cnt += 1 cnt 1 if not flag:
            break
     not flag flag break print(" ".join(map(str, array))) print " ".join(map(str, array)) " ".join " " join map(str, array) map str array print(cnt) print cnt main() main def main():
    n = int(input())
    array = [int(x) for x in input().split()]

    cnt = 0
    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
    print(" ".join(map(str, array)))
    print(cnt) def main():
    n = int(input())
    array = [int(x) for x in input().split()]

    cnt = 0
    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
    print(" ".join(map(str, array)))
    print(cnt) main
def main():
    n = int(input())
    array = [int(x) for x in input().split()]

    cnt = 0
    while True:
        flag = False
        for i in range(1, n)[::-1]:
            if array[i-1] > array[i]:
                tmp = array[i]
                array[i] = array[i-1]
                array[i-1] = tmp
                flag = True
                cnt += 1
        if not flag:
            break
    print(" ".join(map(str, array)))
    print(cnt)


main()
