N = int(input())
A = [int(i) for i in input().split()]

# A = [5, 3, 2, 4, 1]

def bubbleSort(arr):
    arr_len = len(arr)
    flg = True
    cnt = 0
    while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
    print(' '.join([str(x) for x in arr]))
    print(cnt)

bubbleSort(A) N = int(input()) N int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] def bubbleSort(arr):
    arr_len = len(arr)
    flg = True
    cnt = 0
    while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
    print(' '.join([str(x) for x in arr]))
    print(cnt) bubbleSort arr_len = len(arr) arr_len len(arr) len arr flg = True flg True cnt = 0 cnt 0 while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
     flg flg = False flg False for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
     i range(arr_len -1, 0, -1) range arr_len -1 arr_len 1 0 -1 if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
     arr[i] < arr[i-1] arr[i] arr i arr[i-1] arr i-1 i 1 arr[i], arr[i-1] = arr[i-1], arr[i] arr[i] arr i arr[i-1] arr i-1 i 1 arr[i-1] arr i-1 i 1 arr[i] arr i flg = True flg True cnt = cnt + 1 cnt cnt + 1 cnt 1 str(x) for x in arr for x in arr x arr for x in arr str(x) str x print(' '.join([str(x) for x in arr])) print ' '.join([str(x) for x in arr]) ' '.join ' ' join [str(x) for x in arr] print(cnt) print cnt arr arr bubbleSort(A) bubbleSort A N = int(input()) int(input()) N def bubbleSort(arr):
    arr_len = len(arr)
    flg = True
    cnt = 0
    while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
    print(' '.join([str(x) for x in arr]))
    print(cnt) def bubbleSort(arr):
    arr_len = len(arr)
    flg = True
    cnt = 0
    while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
    print(' '.join([str(x) for x in arr]))
    print(cnt) bubbleSort A = [int(i) for i in input().split()] [int(i) for i in input().split()] A
N = int(input())
A = [int(i) for i in input().split()]

# A = [5, 3, 2, 4, 1]

def bubbleSort(arr):
    arr_len = len(arr)
    flg = True
    cnt = 0
    while flg:
        flg = False
        for i in range(arr_len -1, 0, -1):
            if arr[i] < arr[i-1]:
                arr[i], arr[i-1] = arr[i-1], arr[i]
                flg = True
                cnt = cnt + 1
                
    print(' '.join([str(x) for x in arr]))
    print(cnt)

bubbleSort(A)
