#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
#??????????????????
#?????????????´?????¢????????????£????????????????????????????????¨???????¢?????????¨
#?????°??¢??°???????¨???????????¢????????????????

def bubble_sort(target_list):
    list_length = len(target_list)
    
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
    return change_count

def main():
    n_list = int(input())
    target_list = [int(n) for n in input().split()]
    cc = bubble_sort(target_list)
    print(*target_list)
    print(cc)
if __name__ == "__main__":
    main() def bubble_sort(target_list):
    list_length = len(target_list)
    
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
    return change_count bubble_sort list_length = len(target_list) list_length len(target_list) len target_list flag = True flag True change_count = 0 change_count 0 top_index = 1 top_index 1 while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
     flag flag = False flag False for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
         i range(top_index, list_length)[::-1] (top_index, list_length) range top_index list_length ::-1 -1 if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
         target_list[i] < target_list[i - 1] target_list[i] target_list i target_list[i - 1] target_list i - 1 i 1 tmp = target_list[i] tmp target_list[i] target_list i target_list[i] = target_list[i - 1] target_list[i] target_list i target_list[i - 1] target_list i - 1 i 1 target_list[i - 1] = tmp target_list[i - 1] target_list i - 1 i 1 tmp change_count += 1 change_count 1 flag = True flag True top_index += 1 top_index 1 return change_count change_count target_list target_list def main():
    n_list = int(input())
    target_list = [int(n) for n in input().split()]
    cc = bubble_sort(target_list)
    print(*target_list)
    print(cc) main n_list = int(input()) n_list int(input()) int input() input int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n target_list = [int(n) for n in input().split()] target_list [int(n) for n in input().split()] cc = bubble_sort(target_list) cc bubble_sort(target_list) bubble_sort target_list print(*target_list) print *target_list target_list print(cc) print cc if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n_list = int(input())
    target_list = [int(n) for n in input().split()]
    cc = bubble_sort(target_list)
    print(*target_list)
    print(cc) def main():
    n_list = int(input())
    target_list = [int(n) for n in input().split()]
    cc = bubble_sort(target_list)
    print(*target_list)
    print(cc) main def bubble_sort(target_list):
    list_length = len(target_list)
    
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
    return change_count def bubble_sort(target_list):
    list_length = len(target_list)
    
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
    return change_count bubble_sort
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A&lang=jp
#??????????????????
#?????????????´?????¢????????????£????????????????????????????????¨???????¢?????????¨
#?????°??¢??°???????¨???????????¢????????????????

def bubble_sort(target_list):
    list_length = len(target_list)
    
    flag = True
    change_count = 0
    top_index = 1
    while flag:
        flag = False
        for i in range(top_index, list_length)[::-1]:
            if target_list[i] < target_list[i - 1]:
                tmp = target_list[i]
                target_list[i] = target_list[i - 1]
                target_list[i - 1] = tmp
                change_count += 1
                flag = True
        top_index += 1
        
    return change_count

def main():
    n_list = int(input())
    target_list = [int(n) for n in input().split()]
    cc = bubble_sort(target_list)
    print(*target_list)
    print(cc)
if __name__ == "__main__":
    main()