n=gets.to_i-1
a=gets.split
b=*a
r=0..n
r.map{|i|n.downto(i+1){|j|a[k=j-1][1]>a[j][1]&&(a[k,2]=a[j],a[k])}}
r.map{|i|m=i
(m..n).map{|j|b[m][1]>b[j][1]&&m=j}
b[i],b[m]=b[m],b[i]}
puts a*" ",:Stable,b*" ",a==b ?s: "Not stable"