using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void provera(int[] a, ref int p, ref int t)
        {
            if (t == a.Length - 1)
            {
                zamena(a, a.Length - 2, t);
            }
            else 
            {
                int max = int.MinValue;
                for (int i = t; i < a.Length; i++)
                {
                    if (a[i] >= max)
                    {
                        max = a[i];
                        p = i;
                    }
                }
                if (p == t)
                {
                    t++;
                    provera(a, ref p, ref t);
                }
                else
                {
                    zamena(a, p, t);
                }
            }
            
        }
        static void zamena(int[] a, int p, int t)
        {
            Console.WriteLine(t);
            int k = a[p];
            a[p] = a[t];
            a[t] = k;
        }
        static void Main(string[] args)
        {
            int max = int.MinValue, p = 0, t = 0;
            int n = Convert.ToInt32(Console.ReadLine());
            int[] a = new int[n];
            string[] g = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt32(g[i]);
                if (a[i] >= max)
                {
                    max = a[i];
                    p = i;
                }
            }
            if (p == t)
            {
                provera(a,ref p, ref t);
            }
            else
            {
                zamena(a, p, t);
            }
            for (int i = 0; i < n; i++)
            {
                Console.Write(a[i] + " ");
            }
            Console.ReadLine();
        }
    }
}