def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count)


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count) 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 flag = True flag True count = 0 count 0 while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
     flag flag = False flag False for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
     i range(N-1,0,-1) range N-1 N 1 0 -1 if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
     A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 count += 1 count 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 print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(count) print count if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() __name__ == "__main__" __name__ "__main__" import os os import sys sys if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() len(sys.argv) > 1 len(sys.argv) len sys.argv sys argv 1 if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
     sys.argv[1] == "-d" sys.argv[1] sys.argv sys argv 1 "-d" fd = os.open("input.txt", os.O_RDONLY) fd os.open("input.txt", os.O_RDONLY) os.open os open "input.txt" os.O_RDONLY os O_RDONLY os.dup2(fd, sys.stdin.fileno()) os.dup2 os dup2 fd sys.stdin.fileno() sys.stdin.fileno sys.stdin sys stdin fileno main() main main() main fd = os.open("input.txt", os.O_RDONLY) os.open("input.txt", os.O_RDONLY) fd def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count) def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count) main
def main():
    N = int(input())
    A = list(map(int,input().split()))
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(N-1,0,-1):
            if A[i] < A[i-1]:
                count += 1
                A[i], A[i-1] = A[i-1], A[i]
                flag = True
    print(" ".join(map(str,A)))
    print(count)


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()