def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array


def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count)


if __name__ == '__main__':
    main() def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array input_data num = raw_input() num raw_input() raw_input array = [] array [] array = num.strip().split(" ") array num.strip().split(" ") num.strip().split num.strip() num.strip num strip split " " array = map(int, array) array map(int, array) map int array return array array def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count) main n = raw_input() n raw_input() raw_input count = 0 count 0 array = input_data() array input_data() input_data flag = True flag True i = 0 i 0 while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
     flag flag = False flag False for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
         j reversed(xrange(i + 1, int(n))) reversed xrange(i + 1, int(n)) xrange i + 1 i 1 int(n) int n if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
         array[j] < array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 v = array[j] v array[j] array j array[j] = array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 array[j - 1] = v array[j - 1] array j - 1 j 1 v flag = True flag True count += 1 count 1 i += 1 i 1 array = map(str, array) array map(str, array) map str array print " ".join(array) " ".join " " join array print str(count) str count if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count) def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count) main def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array input_data
def input_data():
    num = raw_input()
    array = []
    array = num.strip().split(" ")
    array = map(int, array)
    return array


def main():
    n = raw_input()
    count = 0
    array = input_data()
    flag = True
    i = 0
    while flag:
        flag = False
        for j in reversed(xrange(i + 1, int(n))):
            if array[j] < array[j - 1]:
                v = array[j]
                array[j] = array[j - 1]
                array[j - 1] = v
                flag = True
                count += 1
        i += 1
    array = map(str, array)
    print " ".join(array)
    print str(count)


if __name__ == '__main__':
    main()