import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static int ans=0;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
}

private static void swap(int[] a,int s,int t){
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
}

private static void BubbleSort(int[] a){
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
}

private static void getValue(int[] a){
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
}
} import java.io.*; io.* java import java.util.StringTokenizer; StringTokenizer java.util class Main{

static final PrintWriter out=new PrintWriter(System.out);
static int ans=0;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
}

private static void swap(int[] a,int s,int t){
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
}

private static void BubbleSort(int[] a){
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
}

private static void getValue(int[] a){
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
}
} Main static final PrintWriter out=new PrintWriter(System.out); out new PrintWriter(System.out) static int ans=0; ans 0 public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
} main {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line=""; line "" while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
} (line=br.readLine())!=null&&!line.isEmpty() (line=br.readLine())!=null (line=br.readLine()) line br.readLine() br.readLine br null !line.isEmpty() line.isEmpty() line.isEmpty line {
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
} int n=Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line int[] a=new int[n]; a new int[n] n StringTokenizer st=new StringTokenizer(br.readLine()); st new StringTokenizer(br.readLine()) for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken()); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=Integer.parseInt(st.nextToken()); a[i]=Integer.parseInt(st.nextToken()) a[i] a i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st BubbleSort(a) BubbleSort a getValue(a) getValue a out.println(ans) out.println out ans out.flush() out.flush out String[] args args private static void swap(int[] a,int s,int t){
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
} swap {
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
} int tmp=a[s]; tmp a[s] a s a[s]=a[t] a[s] a s a[t] a t a[t]=tmp a[t] a t tmp ans++ ans int[] a a int s s int t t private static void BubbleSort(int[] a){
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
} BubbleSort {
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
} for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
} int i=0; int i=0; i 0 i<a.length-1 i a.length-1 a.length a a.length 1 i++ i++ i {
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
} {
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
} for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
} int j=a.length-1; int j=a.length-1; j a.length-1 a.length a a.length 1 j>i j i j-- j-- j {
if(a[j]<a[j-1]) swap(a,j,j-1);
} {
if(a[j]<a[j-1]) swap(a,j,j-1);
} if(a[j]<a[j-1]) swap(a,j,j-1); a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 swap(a,j,j-1) swap a j j-1 j 1 int[] a a private static void getValue(int[] a){
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
} getValue {
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
} for(int i=0;i<a.length-1;i++) out.print(a[i]+" "); int i=0; int i=0; i 0 i<a.length-1 i a.length-1 a.length a a.length 1 i++ i++ i out.print(a[i]+" "); out.print(a[i]+" ") out.print out a[i]+" " a[i] a i " " out.println(a[a.length-1]) out.println out a[a.length-1] a a.length-1 a.length a a.length 1 int[] a a
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static int ans=0;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
int n=Integer.parseInt(line);
int[] a=new int[n];
StringTokenizer st=new StringTokenizer(br.readLine());
for(int i=0;i<n;i++) a[i]=Integer.parseInt(st.nextToken());
BubbleSort(a);
getValue(a);
out.println(ans);
out.flush();
}
}

private static void swap(int[] a,int s,int t){
int tmp=a[s]; a[s]=a[t]; a[t]=tmp; ans++;
}

private static void BubbleSort(int[] a){
for(int i=0;i<a.length-1;i++){
for(int j=a.length-1;j>i;j--){
if(a[j]<a[j-1]) swap(a,j,j-1);
}
}
}

private static void getValue(int[] a){
for(int i=0;i<a.length-1;i++) out.print(a[i]+" ");
out.println(a[a.length-1]);
}
}