def bubblesort(N, A):
    """Do BubbleSort"""
    m = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
    b = list(map(str, A))
    print(" ".join(b))
    print(m)

A = []
N = int(input())
s = input()
A = list(map(int, s.split()))
bubblesort(N, A) def bubblesort(N, A):
    """Do BubbleSort"""
    m = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
    b = list(map(str, A))
    print(" ".join(b))
    print(m) bubblesort """Do BubbleSort""" m = 0 m 0 flag = True flag True while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
     flag flag = False flag False for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
     i range(N-1, 0, -1) range N-1 N 1 0 -1 if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
     A[i-1] > A[i] A[i-1] A i-1 i 1 A[i] A i tmp = A[i-1] tmp A[i-1] A i-1 i 1 A[i-1] = A[i] A[i-1] A i-1 i 1 A[i] A i m += 1 m 1 A[i] = tmp A[i] A i tmp flag = True flag True b = list(map(str, A)) b list(map(str, A)) list map(str, A) map str A print(" ".join(b)) print " ".join(b) " ".join " " join b print(m) print m N N A A A = [] A [] N = int(input()) N int(input()) int input() input s = input() s input() input A = list(map(int, s.split())) A list(map(int, s.split())) list map(int, s.split()) map int s.split() s.split s split bubblesort(N, A) bubblesort N A N = int(input()) int(input()) N def bubblesort(N, A):
    """Do BubbleSort"""
    m = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
    b = list(map(str, A))
    print(" ".join(b))
    print(m) def bubblesort(N, A):
    """Do BubbleSort"""
    m = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
    b = list(map(str, A))
    print(" ".join(b))
    print(m) bubblesort A = list(map(int, s.split())) list(map(int, s.split())) A A = [] [] A s = input() input() s
def bubblesort(N, A):
    """Do BubbleSort"""
    m = 0
    flag = True
    while(flag):
        flag = False
        for i in range(N-1, 0, -1):
            if (A[i-1] > A[i]):
                tmp = A[i-1]
                A[i-1] = A[i]
                m += 1
                A[i] = tmp
                flag = True
    b = list(map(str, A))
    print(" ".join(b))
    print(m)

A = []
N = int(input())
s = input()
A = list(map(int, s.split()))
bubblesort(N, A)