// This file is a "Hello, world!" in D language by DMD for wandbox.
import std.stdio;
import std.string;
import std.range;
import std.algorithm;
import std.conv;
void main()
{
    readln;
    size_t aa = 0;
    auto k = readln.strip.split(' ').map!(to!int).array;
    for (ptrdiff_t i = 0; i < k.length; i++)
    {
        bool f = false;
        for (ptrdiff_t j = k.length - 1; j >= i + 1; j--)
        {
            if (k[j] < k[j - 1])
            {
                f = true;aa++;
                swap(k[j], k[j - 1]);
            }
        }
        if (!f)break;
    }
    writeln(k.map!(to!string).join(" "));
    writeln(aa);
}
