n = int(eval(input()))

li = list(map(int, input().split()))

cnt = 0



flag = True



while flag:

	flag = False

	for i in range(n-1,0,-1):

		if li[i] < li[i-1]:

			li[i], li[i-1] = li[i-1], li[i]

			flag = True

			cnt +=1



print((*li))

print(cnt)
N = int(eval(input()))

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



def bubblesort(A, N):

    flag = True

    i = 0

    cnt = 0

    while flag:

        flag = False

        for j in range(N-1, i, -1):

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

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

                flag = True

                cnt += 1

        i += 1     

    print((*A))

    print(cnt)



bubblesort(A,N)
n = int(eval(input()))
li = list(map(int, input().split()))
cnt = 0
flag = True
while flag:
    flag = False
    for i in range(n - 1, 0, -1):
        if li[i] < li[i - 1]:
            li[i], li[i - 1] = li[i - 1], li[i]
            flag = True
            cnt += 1
print((*li))
print(cnt)

N = int(eval(input()))
A = list(map(int, input().split()))


def bubblesort(A, N):
    flag = True
    i = 0
    cnt = 0
    while flag:
        flag = False
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                flag = True
                cnt += 1
        i += 1
    print((*A))
    print(cnt)


bubblesort(A, N)

-n = int(eval(input())) -li = list(map(int, input().split())) -cnt = 0 -flag = True -while flag: -    flag = False -    for i in range(n - 1, 0, -1): -        if li[i] < li[i - 1]: -            li[i], li[i - 1] = li[i - 1], li[i] -            flag = True -            cnt += 1 -print((*li)) -print(cnt) +N = int(eval(input())) +A = list(map(int, input().split())) + + +def bubblesort(A, N): +    flag = True +    i = 0 +    cnt = 0 +    while flag: +        flag = False +        for j in range(N - 1, i, -1): +            if A[j] < A[j - 1]: +                A[j], A[j - 1] = A[j - 1], A[j] +                flag = True +                cnt += 1 +        i += 1 +    print((*A)) +    print(cnt) + + +bubblesort(A, N)