# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
sample_input = list(range(3))
sample_input[0] = '''5
5 3 2 4 1'''
sample_input[1] = '''6
5 2 4 6 1 3'''
sample_input[2] = '''1
100'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main part
def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp

num_of_data = int(input())
list_of_data = list(map(int, input().split()))

swap_count = 0
flag = True
while flag:
    flag = False
    n = num_of_data - 1
    while n >= 1:
        if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
        n -= 1

result = ''
for number in list_of_data:
    result += str(number) + ' '
print(result.strip())
print(swap_count) sample_input = list(range(3)) sample_input list(range(3)) list range(3) range 3 sample_input[0] = '''5
5 3 2 4 1''' sample_input[0] sample_input 0 '''5
5 3 2 4 1''' sample_input[1] = '''6
5 2 4 6 1 3''' sample_input[1] sample_input 1 '''6
5 2 4 6 1 3''' sample_input[2] = '''1
100''' sample_input[2] sample_input 2 '''1
100''' give_sample_input = None give_sample_input None if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main part give_sample_input is not None give_sample_input None sample_input_list = sample_input[give_sample_input].split('\n') sample_input_list sample_input[give_sample_input].split('\n') [give_sample_input].split [give_sample_input] sample_input give_sample_input split '\n' def input():
        return sample_input_list.pop(0)
        
# main part input return sample_input_list.pop(0) sample_input_list.pop(0) sample_input_list.pop sample_input_list pop 0 def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp swap_list_item tmp = lst[i] tmp lst[i] lst i lst[i] = lst[j] lst[i] lst i lst[j] lst j lst[j] = tmp lst[j] lst j tmp lst lst i i j j num_of_data = int(input()) num_of_data int(input()) int input() input list_of_data = list(map(int, input().split())) list_of_data list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split swap_count = 0 swap_count 0 flag = True flag True while flag:
    flag = False
    n = num_of_data - 1
    while n >= 1:
        if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
        n -= 1 flag flag = False flag False n = num_of_data - 1 n num_of_data - 1 num_of_data 1 while n >= 1:
        if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
        n -= 1 n >= 1 n 1 if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
         list_of_data[n] < list_of_data[n-1] list_of_data[n] list_of_data n list_of_data[n-1] list_of_data n-1 n 1 swap_list_item(list_of_data, n, n-1) swap_list_item list_of_data n n-1 n 1 flag = True flag True swap_count += 1 swap_count 1 n -= 1 n 1 result = '' result '' for number in list_of_data:
    result += str(number) + ' ' number list_of_data result += str(number) + ' ' result str(number) + ' ' str(number) str number ' ' print(result.strip()) print result.strip() result.strip result strip print(swap_count) print swap_count sample_input = list(range(3)) list(range(3)) sample_input result += str(number) + ' ' str(number) + ' ' result give_sample_input = None None give_sample_input def input():
        return sample_input_list.pop(0)
        
# main part def input():
        return sample_input_list.pop(0)
        
# main part input sample_input_list = sample_input[give_sample_input].split('\n') sample_input[give_sample_input].split('\n') sample_input_list flag = True True flag n -= 1 1 n flag = True True flag flag = False False flag num_of_data = int(input()) int(input()) num_of_data def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp swap_list_item swap_count += 1 1 swap_count list_of_data = list(map(int, input().split())) list(map(int, input().split())) list_of_data n = num_of_data - 1 num_of_data - 1 n swap_count = 0 0 swap_count result = '' '' result
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
sample_input = list(range(3))
sample_input[0] = '''5
5 3 2 4 1'''
sample_input[1] = '''6
5 2 4 6 1 3'''
sample_input[2] = '''1
100'''
give_sample_input = None
if give_sample_input is not None:
    sample_input_list = sample_input[give_sample_input].split('\n')
    def input():
        return sample_input_list.pop(0)
        
# main part
def swap_list_item(lst, i, j):
    tmp = lst[i]
    lst[i] = lst[j]
    lst[j] = tmp

num_of_data = int(input())
list_of_data = list(map(int, input().split()))

swap_count = 0
flag = True
while flag:
    flag = False
    n = num_of_data - 1
    while n >= 1:
        if list_of_data[n] < list_of_data[n-1]:
            swap_list_item(list_of_data, n, n-1)
            flag = True
            swap_count += 1
        n -= 1

result = ''
for number in list_of_data:
    result += str(number) + ' '
print(result.strip())
print(swap_count)