count = int(input());
data = [int(n) for n in input().split(" ")];

def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o);

def show(data):
    print(" ".join(str(n) for n in data));

bubble_sort(data); count = int(input()) count 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 data = [int(n) for n in input().split(" ")] data [int(n) for n in input().split(" ")] def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o); bubble_sort count = len(data) count len(data) len data o = 0 o 0 for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
     i range(count) range count for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
     j range(count - 1, i, -1) range count - 1 count 1 i -1 if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
     data[j] < data[j - 1] data[j] data j data[j - 1] data j - 1 j 1 o += 1 o 1 temp = data[j] temp data[j] data j data[j] = data[j - 1] data[j] data j data[j - 1] data j - 1 j 1 data[j - 1] = temp data[j - 1] data j - 1 j 1 temp show(data) show data print(o) print o data data def show(data):
    print(" ".join(str(n) for n in data)); show print(" ".join(str(n) for n in data)) print " ".join(str(n) for n in data) " ".join " " join str(n) str n data data bubble_sort(data) bubble_sort data def show(data):
    print(" ".join(str(n) for n in data)); def show(data):
    print(" ".join(str(n) for n in data)); show data = [int(n) for n in input().split(" ")] [int(n) for n in input().split(" ")] data def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o); def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o); bubble_sort count = int(input()) int(input()) count
count = int(input());
data = [int(n) for n in input().split(" ")];

def bubble_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        for j in range(count - 1, i, -1):
            if data[j] < data[j - 1]:
                o += 1;
                temp = data[j];
                data[j] = data[j - 1];
                data[j - 1] = temp;
    show(data);
    print(o);

def show(data):
    print(" ".join(str(n) for n in data));

bubble_sort(data);
