# encoding: utf-8

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

def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count

main() def bubble_sort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
    return A, count bubble_sort flag = 1 flag 1 count = 0 count 0 while flag:
        flag = 0
        for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
     flag flag = 0 flag 0 for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
     j xrange(N-1, 0, -1) xrange N-1 N 1 0 -1 if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
     A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = 1 flag 1 count += 1 count 1 return A, count return A, count A count A A N N def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count main N = input() N input() input A = map(int, raw_input().split()) A map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split A, count = bubble_sort(A, N) A bubble_sort(A, N) bubble_sort A N count print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print main() main def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count main def bubble_sort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
    return A, count def bubble_sort(A, N):
    flag = 1
    count = 0
    while flag:
        flag = 0
        for j in xrange(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1
                count += 1
    return A, count bubble_sort
# encoding: utf-8

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

def main():
    N = input()
    A = map(int, raw_input().split())
    A, count = bubble_sort(A, N)
    print " ".join(map(str,A))
    print count

main()