num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
count = 0 

def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count

count = bubble_sort(num_list, count)

num_list =  map(str, num_list)
print " ".join(num_list)
print count num = raw_input() num raw_input() raw_input num_list = raw_input().split() num_list raw_input().split() ().split () raw_input split num_list = map(int, num_list) num_list map(int, num_list) map int num_list count = 0 count 0 def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count bubble_sort flag = True flag True i = 0 i 0 while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
     flag flag = False flag False for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
         j range(len(num_list)-1, i, -1) range len(num_list)-1 len(num_list) len num_list 1 i -1 if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
         num_list[j-1] > num_list[j] num_list[j-1] num_list j-1 j 1 num_list[j] num_list j temp = num_list[j] temp num_list[j] num_list j num_list[j] = num_list[j-1] num_list[j] num_list j num_list[j-1] num_list j-1 j 1 num_list[j-1] = temp num_list[j-1] num_list j-1 j 1 temp count += 1 count 1 flag = True flag True i += 1 i 1 return count count num_list num_list count count count = bubble_sort(num_list, count) count bubble_sort(num_list, count) bubble_sort num_list count num_list =  map(str, num_list) num_list map(str, num_list) map str num_list print " ".join(num_list) " ".join " " join num_list print num_list = raw_input().split() raw_input().split() num_list num = raw_input() raw_input() num num_list = map(int, num_list) map(int, num_list) num_list num_list =  map(str, num_list) map(str, num_list) num_list def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count bubble_sort count = bubble_sort(num_list, count) bubble_sort(num_list, count) count count = 0 0 count
num = raw_input()
num_list = raw_input().split()
num_list = map(int, num_list)
count = 0 

def bubble_sort(num_list, count):
    flag = True
    i = 0 
    while flag:
        flag = False
        for j in range(len(num_list)-1, i, -1):
            if num_list[j-1] > num_list[j]:
                temp = num_list[j]
                num_list[j] = num_list[j-1]
                num_list[j-1] = temp
                count += 1
                flag = True
        i += 1
    return count

count = bubble_sort(num_list, count)

num_list =  map(str, num_list)
print " ".join(num_list)
print count