# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
# Result:
import sys

nums_len = int(sys.stdin.readline())
nums_str = sys.stdin.readline().split(' ')
nums = map(int, nums_str)

swap_count = 0
flag = True
while flag:
    flag = False
    for i in reversed(range(1, nums_len)):
        if nums[i] < nums[i - 1]:
            v = nums[i]
            nums[i] = nums[i - 1]
            nums[i - 1] = v
            swap_count += 1
            flag = True

print ' '.join(map(str, nums))
print swap_count import sys sys nums_len = int(sys.stdin.readline()) nums_len int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline nums_str = sys.stdin.readline().split(' ') nums_str sys.stdin.readline().split(' ') sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split ' ' nums = map(int, nums_str) nums map(int, nums_str) map int nums_str swap_count = 0 swap_count 0 flag = True flag True while flag:
    flag = False
    for i in reversed(range(1, nums_len)):
        if nums[i] < nums[i - 1]:
            v = nums[i]
            nums[i] = nums[i - 1]
            nums[i - 1] = v
            swap_count += 1
            flag = True flag flag = False flag False for i in reversed(range(1, nums_len)):
        if nums[i] < nums[i - 1]:
            v = nums[i]
            nums[i] = nums[i - 1]
            nums[i - 1] = v
            swap_count += 1
            flag = True i reversed(range(1, nums_len)) reversed range(1, nums_len) range 1 nums_len if nums[i] < nums[i - 1]:
            v = nums[i]
            nums[i] = nums[i - 1]
            nums[i - 1] = v
            swap_count += 1
            flag = True nums[i] < nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 v = nums[i] v nums[i] nums i nums[i] = nums[i - 1] nums[i] nums i nums[i - 1] nums i - 1 i 1 nums[i - 1] = v nums[i - 1] nums i - 1 i 1 v swap_count += 1 swap_count 1 flag = True flag True print ' '.join(map(str, nums)) ' '.join ' ' join map(str, nums) map str nums print flag = False False flag flag = True True flag v = nums[i] nums[i] v nums_str = sys.stdin.readline().split(' ') sys.stdin.readline().split(' ') nums_str nums = map(int, nums_str) map(int, nums_str) nums flag = True True flag swap_count = 0 0 swap_count swap_count += 1 1 swap_count nums_len = int(sys.stdin.readline()) int(sys.stdin.readline()) nums_len
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
# Result:
import sys

nums_len = int(sys.stdin.readline())
nums_str = sys.stdin.readline().split(' ')
nums = map(int, nums_str)

swap_count = 0
flag = True
while flag:
    flag = False
    for i in reversed(range(1, nums_len)):
        if nums[i] < nums[i - 1]:
            v = nums[i]
            nums[i] = nums[i - 1]
            nums[i - 1] = v
            swap_count += 1
            flag = True

print ' '.join(map(str, nums))
print swap_count