def bubble_sort(target):
    global cnt
    flag = True
    while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
    return target

N = int(input())
A = [int(s) for s in input().split()]
cnt = 0
print(' '.join(str(s) for s in bubble_sort(A)))
print(cnt) def bubble_sort(target):
    global cnt
    flag = True
    while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
    return target bubble_sort global cnt flag = True flag True while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
     flag flag = False flag False for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
     i range(len(target)-1, 0, -1) range len(target)-1 len(target) len target 1 0 -1 if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
     target[i] < target[i-1] target[i] target i target[i-1] target i-1 i 1 target[i-1], target[i] = target[i], target[i-1] target[i-1] target i-1 i 1 target[i] target i target[i] target i target[i-1] target i-1 i 1 flag = True flag True cnt += 1 cnt 1 return target target target target N = int(input()) N int(input()) int input() input int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s A = [int(s) for s in input().split()] A [int(s) for s in input().split()] cnt = 0 cnt 0 print(' '.join(str(s) for s in bubble_sort(A))) print ' '.join(str(s) for s in bubble_sort(A)) ' '.join ' ' join str(s) str s print(cnt) print cnt N = int(input()) int(input()) N cnt = 0 0 cnt A = [int(s) for s in input().split()] [int(s) for s in input().split()] A def bubble_sort(target):
    global cnt
    flag = True
    while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
    return target def bubble_sort(target):
    global cnt
    flag = True
    while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
    return target bubble_sort
def bubble_sort(target):
    global cnt
    flag = True
    while flag:
        flag = False
        for i in range(len(target)-1, 0, -1):
            if target[i] < target[i-1]:
                target[i-1], target[i] = target[i], target[i-1]
                flag = True
                cnt += 1
    return target

N = int(input())
A = [int(s) for s in input().split()]
cnt = 0
print(' '.join(str(s) for s in bubble_sort(A)))
print(cnt)