bit=[0 for i in xrange(200)]
n=int(raw_input().strip())
class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val


def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s
def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i


def sort2(lst):
    lens=len(lst)
    sm=0
    for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
    return sm
lst=map(int,raw_input().strip().split())
vals=[]
lens=len(lst)
for i in xrange(lens):
    vals.append(dig(lst[i],i+1))
vals.sort()
ans=0
for i in vals:
    #print i.val,i.id
    ans+=sum(i.id)
    add(i.id,1)
ans=sort2(lst)
lst.sort()
print " ".join(str(pp) for pp in lst)
print ans

 0 for i in xrange(200) for i in xrange(200) i xrange(200) xrange 200 for i in xrange(200) 0 bit=[0 for i in xrange(200)] bit [0 for i in xrange(200)] n=int(raw_input().strip()) n int(raw_input().strip()) int raw_input().strip() ().strip () raw_input strip class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val dig def __init__(self,val,id):
        self.val=val
        self.id=id
     __init__ self.val=val self.val self val val self.id=id self.id self id id self self val val id id def __gt__(self,other):
        return self.val<other.val __gt__ return self.val<other.val self.val<other.val self.val self val other.val other val self self other other def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s sum s=0 s 0 i=int(i) i int(i) int i while i>0:
        s+=bit[i]
        i-=i&(-i)
     i>0 i 0 s+=bit[i] s bit[i] bit i i-=i&(-i) i i&(-i) i -i i return s s i i def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i add i=int(i) i int(i) int i while i<=n:
        bit[i]+=x
        i+=i&-i i<=n i n bit[i]+=x bit[i] bit i x i+=i&-i i i&-i i -i i i i x x def sort2(lst):
    lens=len(lst)
    sm=0
    for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
    return sm sort2 lens=len(lst) lens len(lst) len lst sm=0 sm 0 for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
     i xrange(lens) xrange lens for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
     j xrange(i+1,lens) xrange i+1 i 1 lens if lst[i]>lst[j]:
                sm+=1
     lst[i]>lst[j] lst[i] lst i lst[j] lst j sm+=1 sm 1 return sm sm lst lst lst=map(int,raw_input().strip().split()) lst map(int,raw_input().strip().split()) map int raw_input().strip().split() ().strip().split ().strip() ().strip () raw_input strip split vals=[] vals [] lens=len(lst) lens len(lst) len lst for i in xrange(lens):
    vals.append(dig(lst[i],i+1)) i xrange(lens) xrange lens vals.append(dig(lst[i],i+1)) vals.append vals append dig(lst[i],i+1) dig lst[i] lst i i+1 i 1 vals.sort() vals.sort vals sort ans=0 ans 0 for i in vals:
    #print i.val,i.id
    ans+=sum(i.id)
    add(i.id,1) i vals ans+=sum(i.id) ans sum(i.id) sum i.id i id add(i.id,1) add i.id i id 1 ans=sort2(lst) ans sort2(lst) sort2 lst lst.sort() lst.sort lst sort print " ".join(str(pp) for pp in lst) " ".join " " join str(pp) str pp print def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s sum lst=map(int,raw_input().strip().split()) map(int,raw_input().strip().split()) lst n=int(raw_input().strip()) int(raw_input().strip()) n def sort2(lst):
    lens=len(lst)
    sm=0
    for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
    return sm def sort2(lst):
    lens=len(lst)
    sm=0
    for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
    return sm sort2 bit=[0 for i in xrange(200)] [0 for i in xrange(200)] bit vals=[] [] vals ans=0 0 ans lens=len(lst) len(lst) lens ans+=sum(i.id) sum(i.id) ans ans=sort2(lst) sort2(lst) ans class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val dig def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i add
bit=[0 for i in xrange(200)]
n=int(raw_input().strip())
class dig:
    def __init__(self,val,id):
        self.val=val
        self.id=id
    def __gt__(self,other):
        return self.val<other.val


def sum(i):
    s=0
    i=int(i)
    while i>0:
        s+=bit[i]
        i-=i&(-i)
    return s
def add(i,x):
    i=int(i)
    while i<=n:
        bit[i]+=x
        i+=i&-i


def sort2(lst):
    lens=len(lst)
    sm=0
    for i in xrange(lens):
        for j in xrange(i+1,lens):
            if lst[i]>lst[j]:
                sm+=1
    return sm
lst=map(int,raw_input().strip().split())
vals=[]
lens=len(lst)
for i in xrange(lens):
    vals.append(dig(lst[i],i+1))
vals.sort()
ans=0
for i in vals:
    #print i.val,i.id
    ans+=sum(i.id)
    add(i.id,1)
ans=sort2(lst)
lst.sort()
print " ".join(str(pp) for pp in lst)
print ans


