N = int(input().rstrip())

A = list(map(int, input().rstrip().split()))



flag = True

c = 0

while flag:

    flag = False

    for j in reversed(list(range(1, N))):

        if  A[j - 1] > A[j]:

            A[j - 1],    A[j] = A[j], A[j - 1]

            c += 1

            flag = True

    

print((' '.join(map(str, A))))

print(c)
def bubble_sort(A, N):

    sw = 0

    flag = True

    while flag:

        flag = False

        for j in reversed(list(range(1, N))):

            if  A[j - 1] > A[j]:

                A[j - 1],   A[j] = A[j], A[j - 1]

                sw += 1

                flag = True

    return sw



def main():

    N = int(input().rstrip())

    A = list(map(int, input().rstrip().split()))

     

    sw = bubble_sort(A, N)                            



    print((' '.join(map(str, A))))

    print(sw)



if __name__ == '__main__':

    main()
N = int(input().rstrip())
A = list(map(int, input().rstrip().split()))
flag = True
c = 0
while flag:
    flag = False
    for j in reversed(list(range(1, N))):
        if A[j - 1] > A[j]:
            A[j - 1], A[j] = A[j], A[j - 1]
            c += 1
            flag = True
print((" ".join(map(str, A))))
print(c)

def bubble_sort(A, N):
    sw = 0
    flag = True
    while flag:
        flag = False
        for j in reversed(list(range(1, N))):
            if A[j - 1] > A[j]:
                A[j - 1], A[j] = A[j], A[j - 1]
                sw += 1
                flag = True
    return sw


def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    sw = bubble_sort(A, N)
    print((" ".join(map(str, A))))
    print(sw)


if __name__ == "__main__":
    main()

-N = int(input().rstrip()) -A = list(map(int, input().rstrip().split())) -flag = True -c = 0 -while flag: -    flag = False -    for j in reversed(list(range(1, N))): -        if A[j - 1] > A[j]: -            A[j - 1], A[j] = A[j], A[j - 1] -            c += 1 -            flag = True -print((" ".join(map(str, A)))) -print(c) +def bubble_sort(A, N): +    sw = 0 +    flag = True +    while flag: +        flag = False +        for j in reversed(list(range(1, N))): +            if A[j - 1] > A[j]: +                A[j - 1], A[j] = A[j], A[j - 1] +                sw += 1 +                flag = True +    return sw + + +def main(): +    N = int(input().rstrip()) +    A = list(map(int, input().rstrip().split())) +    sw = bubble_sort(A, N) +    print((" ".join(map(str, A)))) +    print(sw) + + +if __name__ == "__main__": +    main()