def bubbleSort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count

def show(a, n):
    for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i],

n = input()
a = map(int, raw_input().split())
c = bubbleSort(a, n)
show(a, n)
print "%d" % c def bubbleSort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count bubbleSort flag = True flag True count = 0 count 0 while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
     flag flag = False flag False for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
     j range(1, n)[::-1] (1, n) range 1 n ::-1 -1 if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
     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 count += 1 count 1 flag = True flag True return count count a a n n def show(a, n):
    for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i], show for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i], i range(n) range n if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i], i == n-1 i n-1 n 1 print "%d" % a[i] "%d" a[i] a i print "%d" % a[i] "%d" a[i] a i a a n n 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 c = bubbleSort(a, n) c bubbleSort(a, n) bubbleSort a n show(a, n) show a n print "%d" % c "%d" c a = map(int, raw_input().split()) map(int, raw_input().split()) a def show(a, n):
    for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i], def show(a, n):
    for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i], show n = input() input() n c = bubbleSort(a, n) bubbleSort(a, n) c def bubbleSort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count def bubbleSort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count bubbleSort
def bubbleSort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(1, n)[::-1]:
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                count += 1
                flag = True
    return count

def show(a, n):
    for i in range(n):
        if i == n-1:
            print "%d" % a[i]
        else:
            print "%d" % a[i],

n = input()
a = map(int, raw_input().split())
c = bubbleSort(a, n)
show(a, n)
print "%d" % c