
def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1]


def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num


def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp


if __name__ == "__main__":
    main() def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1] print_array for i in xrange(N - 1):
        print str(A[i]),

     i xrange(N - 1) xrange N - 1 N 1 print str(A[i]) str A[i] A i print A[N - 1] A N - 1 N 1 A A N N def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num bubbleSort swap_num = 0 swap_num 0 flag = 1 flag 1 while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

     flag == 1 flag 1 flag = 0 flag 0 for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

     j xrange(N - 1, 0, -1) xrange N - 1 N 1 0 -1 if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

     A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 swap_num += 1 swap_num 1 temp = A[j] temp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = temp A[j - 1] A j - 1 j 1 temp flag = 1 flag 1 return swap_num swap_num A A N N def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp main N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = [] A [] for num in raw_input().split():
        A.append(int(num))

     num raw_input().split() ().split () raw_input split A.append(int(num)) A.append A append int(num) int num temp = bubbleSort(A, N) temp bubbleSort(A, N) bubbleSort A N print_array(A, N) print_array A N print if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num bubbleSort def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1] def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1] print_array def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp main

def print_array(A, N):
    for i in xrange(N - 1):
        print str(A[i]),

    print A[N - 1]


def bubbleSort(A, N):
    swap_num = 0
    flag = 1
    while flag == 1:
        flag = 0
        for j in xrange(N - 1, 0, -1):
            if A[j] < A[j - 1]:
                swap_num += 1

                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                flag = 1

    return swap_num


def main():
    N = int(raw_input())
    A = []

    for num in raw_input().split():
        A.append(int(num))

    temp = bubbleSort(A, N)
    print_array(A, N)

    print temp


if __name__ == "__main__":
    main()