import sys

def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a

def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip()

num = int(sys.stdin.readline().strip())

array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))

flag = True
swap_num = 0

while flag:
    flag = False
    for i in reversed(range(1, len(array))):
        if array[i] < array[i - 1]:
            swap(array, i, i-1)
            flag = True
            swap_num += 1
            
print list_to_string(array)
print str(swap_num) import sys sys def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a swap tmp = a[j] tmp a[j] a j a[j] = a[i] a[j] a j a[i] a i a[i] = tmp a[i] a i tmp return a a a a i i j j def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip() list_to_string s = "" s "" for n in a:
        s += str(n) + " "
     n a s += str(n) + " " s str(n) + " " str(n) str n " " return s.strip() s.strip() s.strip s strip a a num = int(sys.stdin.readline().strip()) num int(sys.stdin.readline().strip()) int sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip array = map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) array map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) map lambda x: int(x) int(x) int x x sys.stdin.readline().strip().split(" ") sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split " " flag = True flag True swap_num = 0 swap_num 0 while flag:
    flag = False
    for i in reversed(range(1, len(array))):
        if array[i] < array[i - 1]:
            swap(array, i, i-1)
            flag = True
            swap_num += 1
             flag flag = False flag False for i in reversed(range(1, len(array))):
        if array[i] < array[i - 1]:
            swap(array, i, i-1)
            flag = True
            swap_num += 1
             i reversed(range(1, len(array))) reversed range(1, len(array)) range 1 len(array) len array if array[i] < array[i - 1]:
            swap(array, i, i-1)
            flag = True
            swap_num += 1
             array[i] < array[i - 1] array[i] array i array[i - 1] array i - 1 i 1 swap(array, i, i-1) swap array i i-1 i 1 flag = True flag True swap_num += 1 swap_num 1 print list_to_string(array) list_to_string array print str(swap_num) str swap_num num = int(sys.stdin.readline().strip()) int(sys.stdin.readline().strip()) num flag = True True flag swap_num = 0 0 swap_num def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip() def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip() list_to_string swap_num += 1 1 swap_num flag = False False flag array = map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) map(lambda x: int(x), sys.stdin.readline().strip().split(" ")) array flag = True True flag def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a swap
import sys

def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp
    return a

def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip()

num = int(sys.stdin.readline().strip())

array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))

flag = True
swap_num = 0

while flag:
    flag = False
    for i in reversed(range(1, len(array))):
        if array[i] < array[i - 1]:
            swap(array, i, i-1)
            flag = True
            swap_num += 1
            
print list_to_string(array)
print str(swap_num)