
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    flag = True
    while flag:
        flag = False
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
                ans += 1
    print(*a)
    print(ans)


if __name__ == '__main__':
    main() def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

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

    flag = True
    while flag:
        flag = False
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
                ans += 1
    print(*a)
    print(ans) def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    flag = True
    while flag:
        flag = False
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
                ans += 1
    print(*a)
    print(ans) main

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0

    flag = True
    while flag:
        flag = False
        for i in range(1, n):
            if a[i] < a[i-1]:
                a[i], a[i-1] = a[i-1], a[i]
                flag = True
                ans += 1
    print(*a)
    print(ans)


if __name__ == '__main__':
    main()
