q = int(input())

sort1 = list(map(int, input().split()))

def bubblesort(ary):
    cnt = 0
    for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
    return (ary, cnt)

ary, cnt = bubblesort(sort1)
print(" ".join(map(str, ary)))
print(cnt) q = int(input()) q int(input()) int input() input sort1 = list(map(int, input().split())) sort1 list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def bubblesort(ary):
    cnt = 0
    for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
    return (ary, cnt) bubblesort cnt = 0 cnt 0 for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
     i range(q) range q for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
     j range(q-1, i, -1) range q-1 q 1 i -1 if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
     ary[j] < ary[j-1] ary[j] ary j ary[j-1] ary j-1 j 1 ary[j-1], ary[j] = ary[j], ary[j-1] ary[j-1] ary j-1 j 1 ary[j] ary j ary[j] ary j ary[j-1] ary j-1 j 1 cnt += 1 cnt 1 return (ary, cnt) (ary, cnt) ary cnt ary ary ary, cnt = bubblesort(sort1) ary bubblesort(sort1) bubblesort sort1 cnt print(" ".join(map(str, ary))) print " ".join(map(str, ary)) " ".join " " join map(str, ary) map str ary print(cnt) print cnt sort1 = list(map(int, input().split())) list(map(int, input().split())) sort1 def bubblesort(ary):
    cnt = 0
    for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
    return (ary, cnt) def bubblesort(ary):
    cnt = 0
    for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
    return (ary, cnt) bubblesort cnt = bubblesort(sort1) bubblesort(sort1) cnt ary, cnt = bubblesort(sort1) bubblesort(sort1) ary q = int(input()) int(input()) q
q = int(input())

sort1 = list(map(int, input().split()))

def bubblesort(ary):
    cnt = 0
    for i in range(q):
        for j in range(q-1, i, -1):
            if ary[j] < ary[j-1]:
                ary[j-1], ary[j] = ary[j], ary[j-1]
                cnt += 1
    return (ary, cnt)

ary, cnt = bubblesort(sort1)
print(" ".join(map(str, ary)))
print(cnt)