def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = 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]
                flag = True
                count += 1
    
    print(*a)
    print(count)

if __name__ == '__main__':
    main() def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = 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]
                flag = True
                count += 1
    
    print(*a)
    print(count) main n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] count = 0 count 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]
                flag = True
                count += 1
    
     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]
                flag = True
                count += 1
    
     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]
                flag = True
                count += 1
    
     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 flag = True flag True count += 1 count 1 print(*a) print *a a print(count) print count if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = 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]
                flag = True
                count += 1
    
    print(*a)
    print(count) def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = 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]
                flag = True
                count += 1
    
    print(*a)
    print(count) main
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    
    count = 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]
                flag = True
                count += 1
    
    print(*a)
    print(count)

if __name__ == '__main__':
    main()
