#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??????????????????
??????????????????????????????????????¨?????????????????????Bubble??????
?°´??¢???????????£???????????????????????????????´????????????????????????????
??????????????????????¬???????????????¢?????´???????????§??°????????????????????????????????????

1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
2   flag = 1 // ????????£??\????´?????????¨??????
3   while flag
4     flag = 0
5     for j ??? N-1 ?????? 1 ?????§
6       if A[j] < A[j-1]
7         A[j] ??¨ A[j-1] ?????????
8         flag = 1

"""
import math

def bSort(A, N):
    cnt = 0
    f = True
    s = N-1
    e = 0
    while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
    return cnt

# ?????????
N = int(input().strip())
A = list(map(int,input().strip().split()))
cnt = bSort(A,N)
print(" ".join(map(str,A)))
print(cnt) """
??????????????????
??????????????????????????????????????¨?????????????????????Bubble??????
?°´??¢???????????£???????????????????????????????´????????????????????????????
??????????????????????¬???????????????¢?????´???????????§??°????????????????????????????????????

1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
2   flag = 1 // ????????£??\????´?????????¨??????
3   while flag
4     flag = 0
5     for j ??? N-1 ?????? 1 ?????§
6       if A[j] < A[j-1]
7         A[j] ??¨ A[j-1] ?????????
8         flag = 1

""" import math math def bSort(A, N):
    cnt = 0
    f = True
    s = N-1
    e = 0
    while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
    return cnt

# ????????? bSort cnt = 0 cnt 0 f = True f True s = N-1 s N-1 N 1 e = 0 e 0 while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
     f == True f True f = False f False for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
         j range(s, e, -1) range s e -1 x = A[j] x A[j] A j y = A[j-1] y A[j-1] A j-1 j 1 if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
         x < y x y A[j] = y A[j] A j y A[j-1] = x A[j-1] A j-1 j 1 x f = True f True cnt += 1 cnt 1 e += 1 e 1 if e > s:
            break
     e > s e s break return cnt cnt A A N N N = int(input().strip()) N int(input().strip()) int input().strip() ().strip () input strip A = list(map(int,input().strip().split())) A list(map(int,input().strip().split())) list map(int,input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split cnt = bSort(A,N) cnt bSort(A,N) bSort A N print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(cnt) print cnt def bSort(A, N):
    cnt = 0
    f = True
    s = N-1
    e = 0
    while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
    return cnt

# ????????? def bSort(A, N):
    cnt = 0
    f = True
    s = N-1
    e = 0
    while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
    return cnt

# ????????? bSort N = int(input().strip()) int(input().strip()) N A = list(map(int,input().strip().split())) list(map(int,input().strip().split())) A cnt = bSort(A,N) bSort(A,N) cnt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??????????????????
??????????????????????????????????????¨?????????????????????Bubble??????
?°´??¢???????????£???????????????????????????????´????????????????????????????
??????????????????????¬???????????????¢?????´???????????§??°????????????????????????????????????

1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
2   flag = 1 // ????????£??\????´?????????¨??????
3   while flag
4     flag = 0
5     for j ??? N-1 ?????? 1 ?????§
6       if A[j] < A[j-1]
7         A[j] ??¨ A[j-1] ?????????
8         flag = 1

"""
import math

def bSort(A, N):
    cnt = 0
    f = True
    s = N-1
    e = 0
    while f == True:
        f = False
#        print("start={0} end={1}\n".format(s, e))
        for j in range(s, e, -1):
            x = A[j]
            y = A[j-1]
#            print("A[{0}]={1} A[{2}]={3}".format(j, x, j-1, y))
#            print(A)
            if x < y:
#                print("swap {0} {1}".format(x, y))
                A[j] = y
                A[j-1] = x
                f = True
                cnt += 1
        e += 1
        if e > s:
            break
    return cnt

# ?????????
N = int(input().strip())
A = list(map(int,input().strip().split()))
cnt = bSort(A,N)
print(" ".join(map(str,A)))
print(cnt)