def bubblesort(A):
    tot = 0
    flag = 1
    N = len(A)
    
    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
                tot += 1
    return A,tot

while True:
    try:
        N = int(raw_input())
    except EOFError:
        break
    A = map(int,raw_input().split())
    
    A,tot = bubblesort(A)
    print ' '.join(map(str,A))
    print tot def bubblesort(A):
    tot = 0
    flag = 1
    N = len(A)
    
    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
                tot += 1
    return A,tot bubblesort tot = 0 tot 0 flag = 1 flag 1 N = len(A) N len(A) len A 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
                tot += 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
                tot += 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
                tot += 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 tot += 1 tot 1 return A,tot return A,tot A tot A A while True:
    try:
        N = int(raw_input())
    except EOFError:
        break
    A = map(int,raw_input().split())
    
    A,tot = bubblesort(A)
    print ' '.join(map(str,A))
    print tot True try:
        N = int(raw_input())
    except EOFError:
        break
     except EOFError:
        break
     break N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = map(int,raw_input().split()) A map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split A,tot = bubblesort(A) A bubblesort(A) bubblesort A tot print ' '.join(map(str,A)) ' '.join ' ' join map(str,A) map str A print def bubblesort(A):
    tot = 0
    flag = 1
    N = len(A)
    
    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
                tot += 1
    return A,tot def bubblesort(A):
    tot = 0
    flag = 1
    N = len(A)
    
    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
                tot += 1
    return A,tot bubblesort N = int(raw_input()) int(raw_input()) N A,tot = bubblesort(A) bubblesort(A) A tot = bubblesort(A) bubblesort(A) tot A = map(int,raw_input().split()) map(int,raw_input().split()) A
def bubblesort(A):
    tot = 0
    flag = 1
    N = len(A)
    
    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
                tot += 1
    return A,tot

while True:
    try:
        N = int(raw_input())
    except EOFError:
        break
    A = map(int,raw_input().split())
    
    A,tot = bubblesort(A)
    print ' '.join(map(str,A))
    print tot