using System;
using System.IO;
using System.Linq;

namespace Codeforces.R259
{
    public class Task_B
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private const int MAXB = 60;
        private int[] factor = new int[MAXB + 1];

        private void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int maxMask = 1 << prime.Length;

            for (int i = 1; i <= MAXB; i++)
            {
                int mask = 0;
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                    {
                        mask |= 1 << j;
                    }
                }
                factor[i] = mask;
            }

            var prev = new int[maxMask];
            var current = new int[maxMask];
            var back = new byte[100, maxMask];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < current.Length; j++)
                    current[j] = 100000;

                for (byte j = 1; j <= MAXB; j++)
                {
                    var goodMask = (~factor[j]) & (maxMask - 1);
                    var delta = Math.Abs(a[i] - j);
                    for (int old = goodMask; ; old = (old - 1) & goodMask)
                    {
                        var newMask = old | factor[j];
                        var newResult = prev[old] + delta;
                        if (newResult < current[newMask])
                        {
                            current[newMask] = newResult;
                            back[i, newMask] = j;
                        }

                        if (old == 0)
                            break;
                    }
                }

                Array.Copy(current, prev, current.Length);
            }

            var res = new int[n];
            var cmask = maxMask - 1;
            for (int i = n - 1; i >= 0; i--)
            {
                res[i] = back[i, cmask];
                cmask = cmask & ~factor[res[i]];
            }

            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                    Console.Write(" ");
                Console.Write(res[i]);
            }
        }
    }
}

using System;
using System.IO;
using System.Text;

namespace Little_Pony_and_Harmony_Chest
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static readonly int[] prime = new[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n + 1];

            for (int i = 1; i <= n; i++)
            {
                nn[i] = Next();
            }

            var mask = new int[61];
            for (int i = 0; i < prime.Length; i++)
            {
                int m = 1 << i;
                for (int j = prime[i]; j < mask.Length; j += prime[i])
                {
                    mask[j] |= m;
                }
            }
            int mm = 1 << prime.Length;
            var dp = new int[n + 1][];
            var bdp = new int[n + 1][];
            dp[0] = new int[mm];
            for (int j = 0; j < mm; j++)
            {
                dp[0][j] = 100*n;
            }
            dp[0][0] = 0;
            for (int i = 1; i <= n; i++)
            {
                dp[i] = new int[mm];
                for (int j = 0; j < mm; j++)
                {
                    dp[i][j] = int.MaxValue;
                }
                bdp[i] = new int[mm];

                for (int j = 1; j < mask.Length; j++)
                {
                    int submask = ~mask[j] & (mm - 1);

                    for (int s = submask;; s = (s - 1) & submask)
                    {
                        if (dp[i][s | mask[j]] > dp[i - 1][s] + Math.Abs(nn[i] - j))
                        {
                            dp[i][s | mask[j]] = dp[i - 1][s] + Math.Abs(nn[i] - j);
                            bdp[i][s | mask[j]] = j;
                        }

                        if (s == 0)
                            break;
                    }
                }
            }

            var ans = new int[n];

            int index = 0;
            for (int i = 1; i < mm; i++)
            {
                if (dp[n][i] < dp[n][index])
                    index = i;
            }

            for (int i = n - 1; i >= 0; i--)
            {
                ans[i] = bdp[i + 1][index];
                index ^= mask[bdp[i + 1][index]];
            }

            foreach (int an in ans)
            {
                writer.Write(an);
                writer.Write(' ');
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.IO;
using System.Linq;

namespace Codeforces.R259
{
    public class Task_B
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private const int MAXB = 60;
        private int[] factor = new int[MAXB + 1];

        private void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int maxMask = 1 << prime.Length;

            for (int i = 1; i <= MAXB; i++)
            {
                int mask = 0;
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                    {
                        mask |= 1 << j;
                    }
                }
                factor[i] = mask;
            }

            var prev = new int[maxMask];
            var current = new int[maxMask];
            var back = new int[100, maxMask];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < current.Length; j++)
                    current[j] = 100000;

                for (int j = 1; j <= MAXB; j++)
                {
                    var goodMask = (~factor[j]) & (maxMask - 1);
                    for (int old = goodMask; ; old = (old - 1) & goodMask)
                    {
                        var newMask = old | factor[j];
                        var newResult = prev[old] + Math.Abs(a[i] - j);
                        if (newResult < current[newMask])
                        {
                            current[newMask] = newResult;
                            back[i, newMask] = j;
                        }

                        if (old == 0)
                            break;
                    }
                }

                Array.Copy(current, prev, current.Length);
            }

            var res = new int[n];
            var cmask = maxMask - 1;
            for (int i = n - 1; i >= 0; i--)
            {
                res[i] = back[i, cmask];
                cmask = cmask & ~factor[res[i]];
            }

            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                    Console.Write(" ");
                Console.Write(res[i]);
            }
        }
    }
}

using System;
using System.IO;
using System.Linq;

namespace Codeforces.R259
{
    public class Task_B
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private const int MAXB = 60;
        private int[] factor = new int[MAXB + 1];

        private void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int maxMask = 1 << prime.Length;

            for (int i = 1; i <= MAXB; i++)
            {
                int mask = 0;
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                    {
                        mask |= 1 << j;
                    }
                }
                factor[i] = mask;
            }

            var prev = new int[maxMask];
            var current = new int[maxMask];
            var back = new short[100, maxMask];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < current.Length; j++)
                    current[j] = 100000;

                for (short j = 1; j <= MAXB; j++)
                {
                    var goodMask = (~factor[j]) & (maxMask - 1);
                    var delta = Math.Abs(a[i] - j);
                    for (int old = goodMask; ; old = (old - 1) & goodMask)
                    {
                        var newMask = old | factor[j];
                        var newResult = prev[old] + delta;
                        if (newResult < current[newMask])
                        {
                            current[newMask] = newResult;
                            back[i, newMask] = j;
                        }

                        if (old == 0)
                            break;
                    }
                }

                Array.Copy(current, prev, current.Length);
            }

            var res = new int[n];
            var cmask = maxMask - 1;
            for (int i = n - 1; i >= 0; i--)
            {
                res[i] = back[i, cmask];
                cmask = cmask & ~factor[res[i]];
            }

            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                    Console.Write(" ");
                Console.Write(res[i]);
            }
        }
    }
}

using System;
using System.IO;
using System.Linq;

namespace Codeforces.R259
{
    public class Task_B
    {
        private static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private const int MAXB = 60;
        private int[] factor = new int[MAXB + 1];

        private void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int maxMask = 1 << prime.Length;
            var cmask = maxMask - 1;

            for (int i = 1; i <= MAXB; i++)
            {
                int mask = 0;
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                    {
                        mask |= 1 << j;
                    }
                }
                factor[i] = mask;
            }

            var prev = new int[maxMask];
            var current = new int[maxMask];
            var back = new byte[100, maxMask];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < current.Length; j++)
                    current[j] = 100000;

                for (byte j = 1; j <= MAXB; j++)
                {
                    var delta = Math.Abs(a[i] - j);
                    var factor_j = factor[j];
                    for (int old = 0; old < maxMask; old++)
                    {
                        if ((old & factor_j) != 0)
                            continue;

                        var newMask = old | factor[j];
                        var newResult = prev[old] + delta;
                        if (newResult < current[newMask])
                        {
                            current[newMask] = newResult;
                            back[i, newMask] = j;
                        }
                    }

                    //var goodMask = (~factor[j]) & (maxMask - 1);
                    //for (int old = goodMask; ; old = (old - 1) & goodMask)
                    //{
                    //    var newMask = old | factor[j];
                    //    var newResult = prev[old] + delta;
                    //    if (newResult < current[newMask])
                    //    {
                    //        current[newMask] = newResult;
                    //        back[i, newMask] = j;
                    //    }

                    //    if (old == 0)
                    //        break;
                    //}
                }

                Array.Copy(current, prev, current.Length);
            }

            var res = new int[n];
            for (int i = n - 1; i >= 0; i--)
            {
                res[i] = back[i, cmask];
                cmask = cmask & ~factor[res[i]];
            }

            for (int i = 0; i < n; i++)
            {
                if (i > 0)
                    Console.Write(" ");
                Console.Write(res[i]);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var a = sc.Integer(n);
            var prime = Sieve(60);
            var p = new List<int>();
            for (int i = 0; i < 60; i++)
            {
                if (prime[i]) p.Add(i);
            }
            var fac = new int[60];
            for (int i = 1; i < 60; i++)
            {
                var f = 0;
                for (int j = 0; j < p.Count; j++)
                {
                    if (i % p[j] == 0) f |= 1 << j;
                }
                fac[i] = f;
            }
            var dp = new int[n + 1, 1 << p.Count];
            for (int i = 0; i <= n; i++)
                for (int j = 0; j < 1 << p.Count; j++)
                    dp[i, j] = 1 << 20;
            var prev = new int[n + 1, 1 << p.Count];
            dp[0, 0] = 0;
            for (int i = 0; i < n; i++)
            {
                for (int k = 1; k < 60; k++)
                {
                    var x = (~fac[k]) & ((1 << p.Count) - 1);
                    for (int s = x; s >= 0; s = (s - 1) & x)
                    {
                        if (dp[i, s] + Math.Abs(a[i] - k) < dp[i + 1, fac[k] | s])
                        {
                            dp[i + 1, fac[k] | s] = dp[i, s] + Math.Abs(a[i] - k);
                            prev[i + 1, fac[k] | s] = k;
                        }
                        if (s == 0) break;
                    }
                }
            }
            var min = 1 << 20;
            var flag = -1;
            for (int i = 0; i < 1<<p.Count; i++)
                if (min > dp[n, i]) { min = dp[n, i]; flag = i; }
            var l = new List<int>();
            for (int i = n; i > 0; i--)
            {
                l.Add(prev[i, flag]);
                flag ^= fac[prev[i, flag]];
            }
            l.Reverse();
            IO.Printer.Out.WriteLine(l.AsJoinedString());

        }
        internal IO.StreamScanner sc;
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
        /// <summary>
        /// p以下の素数を列挙
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        static public bool[] Sieve(int p)
        {
            var isPrime = new bool[p + 1];
            for (int i = 2; i <= p; i++)
                isPrime[i] = true;
            for (int i = 2; i * i <= p; i++)
            {
                if (!isPrime[i])
                    continue;
                for (int j = i * i; j <= p; j += i)
                    isPrime[j] = false;
            }
            return isPrime;
        }
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}

#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
        public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
        public void Flush() { iStream.Flush(); }
    }
}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    }
}
#endregion

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int COUNT = 16;
    const int SCOUNT = 1 << COUNT;
    int[] primes = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
    IList<Tuple<int, int>> options = new List<Tuple<int, int>>();

    void GenerateOptions(int p, int x, int s)
    {
        if (p == COUNT)
        {
            options.Add(Tuple.Create(x, s));
            return;
        }
        for (int i = 0; x < 59; i++)
        {
            GenerateOptions(p + 1, x, s);
            x *= primes[p];
            s |= 1 << p;
        }
    }

    public object Solve()
    {
        int n = ReadInt();
        var a = ReadIntArray();

        GenerateOptions(0, 1, 0);

        var dp = new int[n + 1, SCOUNT];
        var path = new Tuple<int, int>[n + 1, SCOUNT];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < SCOUNT; j++)
                dp[i + 1, j] = int.MaxValue;
            foreach (var t in options)
            {
                int diff = Math.Abs(a[i] - t.Item1);
                for (int j = 0; j < SCOUNT; j++)
                    if (dp[i, j] < int.MaxValue && (j & t.Item2) == 0)
                    {
                        int x = dp[i, j] + diff;
                        int v = j | t.Item2;
                        if (dp[i + 1, v] > x)
                        {
                            dp[i + 1, v] = x;
                            path[i + 1, v] = Tuple.Create(j, t.Item1);
                        }
                    }
            }
        }

        int nmin = 0;
        for (int i = 1; i < SCOUNT; i++)
            if (dp[n, i] < dp[n, nmin])
                nmin = i;

        var ans = new int[n];
        for (int i = n - 1; i >= 0; i--)
        {
            ans[i] = path[i + 1, nmin].Item2;
            nmin = path[i + 1, nmin].Item1;
        }
        WriteArray(ans);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            var ts = DateTime.Now;
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read/Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    #endregion
}

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

namespace ConsoleApplication3
{
    public class CodeForces453B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var aArr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var primes = GetPrimes().ToArray();
            var mask = Fill(primes);

            var values = new int[n][];
            var paths = new int[n][];
            var pathValues = new int[n][];
            for (int i = 0; i < values.Length; ++i)
            {
                values[i] = new int[1 << 17];
                paths[i] = new int[1 << 17];
                pathValues[i] = new int[1 << 17];
                for (int j = 0; j < values[i].Length; ++j)
                {
                    values[i][j] = paths[i][j] = -1;
                }
            }

            for (int i = 0; i < n; ++i)
            {
                for (int p = 0; p < (1 << 17); ++p)
                {
                    var current = i == 0 ? 0 : values[i - 1][p];

                    for (int j = 1; j < 59; ++j)
                    {
                        if ((mask[j] & p) != 0) continue;

                        var newValue = current + Math.Abs(aArr[i] - j);
                        var newPosition = mask[j] | p;
                        if (values[i][newPosition] == -1 || values[i][newPosition] > newValue)
                        {
                            values[i][newPosition] = newValue;
                            paths[i][newPosition] = p;
                            pathValues[i][newPosition] = j;
                        }
                    }
                }
            }

            var min = values[n - 1].Where(x => x >= 0).Min();
            var list = new List<int>();
            var pos = values[n - 1].Select((x, i) => new {X = x, I = i}).Where(x => x.X == min).Select(x => x.I).First();
            for (int i = n-1; i >= 0; --i)
            {
                list.Add(pathValues[i][pos]);
                pos = paths[i][pos];
            }

            list.Reverse();
            Console.WriteLine(string.Join(" ", list));
        }

        private static IEnumerable<int> GetPrimes()
        {
            var arr = new bool[59];
            for (int i = 2; i < 59; ++i)
            {
                if (!arr[i])
                {
                    yield return i;
                    for (int j = i*2; j < 59; j += i)
                        arr[j] = true;
                }
            }
        }

        private static int[] Fill(int[] primes)
        {
            var result = new int[61];
            for (int i = 1; i <= 60; ++i)
                for(int j = 0; j < primes.Length; ++j)
                    if (i%primes[j] == 0)
                        result[i] |= 1 << j;

            return result;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            int n = ReadInt();
            var a = ReadIntArray();

            const int m = 59;
            List<long> primes = GetPrimes(m);
            int p = primes.Count;

            var mask = new int[m + 1];
            for (int i = 1; i <= m; i++)
            {
                for (int j = 0; j < p; j++)
                {
                    if (i % primes[j] == 0)
                    {
                        mask[i] |= (1 << j);
                    }
                }
            }

            const int MAX = int.MaxValue / 2;
            int q = 1 << p;
            var b = new int[n + 1][];
            var w = new int[n + 1][];
            for (int i = 0; i < n + 1; i++)
            {
                b[i] = Enumerable.Repeat(MAX, q).ToArray();
                w[i] = new int[q];
            }
            b[0][0] = 0;
            w[0][0] = -1;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    if (b[i][j] < MAX)
                    {
                        for (int k = 1; k <= m; k++)
                        {
                            if ((j & mask[k]) == 0)
                            {
                                if (b[i + 1][j | mask[k]] > b[i][j] + Math.Abs(k - a[i]))
                                {
                                    b[i + 1][j | mask[k]] = b[i][j] + Math.Abs(k - a[i]);
                                    w[i + 1][j | mask[k]] = k;
                                }
                            }
                        }
                    }
                }
            }

            int mini = 0;
            for (int i = 0; i < q; i++)
            {
                if (b[n][i] < b[n][mini])
                {
                    mini = i;
                }
            }

            // Writer.WriteLine(b[n][mini]);
            var ans = new List<int>();
            for (int i = n; i > 0; i--)
            {
                ans.Add(w[i][mini]);
                mini ^= mask[w[i][mini]];
            }
            ans.Reverse();
            WriteArray(ans);
        }

        public static List<long> GetPrimes(long n)
        {
            var primes = new List<long>();

            n = Math.Max(n, 2);
            bool[] isPrime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i <= n; i++)
            {
                if (isPrime[i])
                {
                    primes.Add(i);
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            isPrime[j] = false;
                        }
                    }
                }
            }

            return primes;
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            /*sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace CF453
{
    class B
    {
        readonly int[] _bad = { ' ', '\r', '\n', -1 };
        TextReader sr = Console.In;
        TextWriter sw = Console.Out;
        private string NextToken()
        {
            var sb = new StringBuilder();
            int i;

            while (Array.IndexOf(_bad, (i = sr.Read())) != -1) ;
            sb.Append((char)i);
            while (Array.IndexOf(_bad, (i = sr.Read())) == -1)
                sb.Append((char)i);
            return sb.ToString();
        }

        int NextInt()
        {
            return int.Parse(NextToken());
        }

        void run()
        {
            var n = NextInt();
            int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
            var a = new int[n];
            var np = primes.Length;
            var masks = new int[61];
            for (int i1 = 1; i1 < 61; ++i1)
            {
                var msk = 0;
                var i = i1;
                for (var ind = 0; ind < np; ++ind)
                {
                    if (i % primes[ind] == 0)
                    {
                        msk |= 1 << ind;
                        while (i % primes[ind] == 0)
                            i /= primes[ind];
                    }
                }
                masks[i1] = msk;
            }
            for (var i = 0; i < n; ++i)
                a[i] = NextInt();
            var d = new int[n, 1 << np];
            var prev = new int[n, 1 << np];
            for (var i = 0; i < n; ++i)
                for (var j = 0; j < 1 << np; ++j)
                {
                    d[i, j] = int.MaxValue / 2;
                    prev[i, j] = -1;
                }
            for (var i = 1; i < 61; ++i)
            {
                var b = masks[i];
                if (d[0, b] > Math.Abs(i - a[0]))
                {
                    d[0, b] = Math.Abs(i - a[0]);
                    prev[0, b] = i;
                }
            }
            for (var pref = 0; pref < n - 1; ++pref)
            {
                for (var i = 1; i < 61; ++i)
                {
                    var b = masks[i];
                    var x = ((1 << 17) - 1) & (~b);
                    for (var mask = x; mask >= 0; mask = x & (mask - 1))
                    {
                        if ((b & mask) != 0)
                            continue;
                        var nmask = mask | b;
                        if (d[pref, mask] + Math.Abs(i - a[pref + 1]) < d[pref + 1, nmask])
                        {
                            d[pref + 1, nmask] = d[pref, mask] + Math.Abs(i - a[pref + 1]);
                            prev[pref + 1, nmask] = i;
                        }
                        if (mask == 0)
                            break;
                        //if (pref <= 2)
                        //sw.WriteLine(pref + 1 + " " + nmask + " " + d[pref + 1, nmask]);
                    }
                }
            }
            var ans = int.MaxValue / 2;
            var ind1 = -1;
            for (var mask = 0; mask < 1 << np; ++mask)
            {
                if (d[n - 1, mask] < ans)
                {
                    ans = d[n - 1, mask];
                    ind1 = mask;
                }
            }

            var arr = new List<int>();
            var i2 = n - 1;
            while (i2 >= 0)
            {
                arr.Add(prev[i2, ind1]);
                ind1 = ind1 ^ masks[prev[i2, ind1]];
                --i2;
            }
            arr.Reverse();
            foreach (var x in arr)
                sw.Write(x + " ");
            sr.ReadLine();
            sr.ReadLine();
        }

        static void Main(string[] args)
        {
            new B().run();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            int n = ReadInt();
            var a = ReadIntArray();

            const int m = 59;
            List<long> primes = GetPrimes(m);
            int p = primes.Count;

            var mask = new int[m + 1];
            for (int i = 1; i <= m; i++)
            {
                for (int j = 0; j < p; j++)
                {
                    if (i % primes[j] == 0)
                    {
                        mask[i] |= (1 << j);
                    }
                }
            }

            const int MAX = int.MaxValue / 2;
            int q = 1 << p;
            var b = new int[n + 1][];
            var w = new int[n + 1][];
            for (int i = 0; i < n + 1; i++)
            {
                b[i] = Enumerable.Repeat(MAX, q).ToArray();
                w[i] = new int[q];
            }
            b[0][0] = 0;
            w[0][0] = -1;

            var allowed = new List<int>[q];
            for (int i = 0; i < q; i++)
            {
                allowed[i] = new List<int>();
                for (int j = 1; j <= m; j++)
                {
                    if ((i & mask[j]) == 0)
                    {
                        allowed[i].Add(j);
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    if (b[i][j] < MAX)
                    {
                        for (int l = 0; l < allowed[j].Count; l++)
                        {
                            int k = allowed[j][l];
                            if (b[i + 1][j | mask[k]] > b[i][j] + Math.Abs(k - a[i]))
                            {
                                b[i + 1][j | mask[k]] = b[i][j] + Math.Abs(k - a[i]);
                                w[i + 1][j | mask[k]] = k;
                            }
                        }
                    }
                }
            }

            int mini = 0;
            for (int i = 0; i < q; i++)
            {
                if (b[n][i] < b[n][mini])
                {
                    mini = i;
                }
            }

            // Writer.WriteLine(b[n][mini]);
            var ans = new List<int>();
            for (int i = n; i > 0; i--)
            {
                ans.Add(w[i][mini]);
                mini ^= mask[w[i][mini]];
            }
            ans.Reverse();
            WriteArray(ans);
        }

        public static List<long> GetPrimes(long n)
        {
            var primes = new List<long>();

            n = Math.Max(n, 2);
            bool[] isPrime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i <= n; i++)
            {
                if (isPrime[i])
                {
                    primes.Add(i);
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            isPrime[j] = false;
                        }
                    }
                }
            }

            return primes;
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            /*sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Little_Pony_and_Harmony_Chest
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static readonly int[] prime = new[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};

        private static IEnumerable<int[]> Gets(int maxl)
        {
            int max = 1 << prime.Length;

            for (int i = 0; i < max; i++)
            {
                int mask = i;
                var l = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if ((mask & 1) == 1)
                    {
                        l.Add(prime[j]);
                    }
                    mask >>= 1;
                }
                if (l.Count <= maxl)
                {
                    int[] array = l.ToArray();

                    if (array.Length > 0)
                    {
                        for (; array[0] < 60; array[0] *= l[0])
                        {
                            if (array.Length > 1)
                            {
                                for (array[1] = l[1]; array[1] < 60; array[1] *= l[1])
                                {
                                    if (array.Length > 2)
                                    {
                                        for (array[2] = l[2]; array[2] < 60; array[2] *= l[2])
                                        {
                                            if (array.Length > 3)
                                            {
                                                for (array[3] = l[3]; array[3] < 60; array[3] *= l[3])
                                                {
                                                    var res = (int[]) array.Clone();
                                                    Array.Sort(res);
                                                    yield return res;
                                                }
                                            }
                                            else
                                            {
                                                var res = (int[])array.Clone();
                                                Array.Sort(res);
                                                yield return res;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var res = (int[])array.Clone();
                                        Array.Sort(res);
                                        yield return res;
                                    }
                                }
                            }
                            else
                            {
                                var res = (int[])array.Clone();
                                Array.Sort(res);
                                yield return res;
                            }
                        }
                    }
                    else
                    {
                        yield return array;
                    }
                }
            }
        }

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            var indx = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
                indx[i] = i;
            }
            Array.Sort(nn, indx);

            int min = int.MaxValue;
            int[] mm = null;
            foreach (var m in Gets(n))
            {
                int i = 0;
                int sum = 0;
                for (; i < n - m.Length; i++)
                {
                    sum += Math.Abs(nn[i] - 1);
                }
                for (int j = 0; j < m.Length; j++)
                {
                    sum += Math.Abs(nn[i + j] - m[j]);
                }
                if (min > sum)
                {
                    min = sum;
                    mm = m;
                }
            }

            var ans = new int[n];
            {
                int i = 0;
                for (; i < n - mm.Length; i++)
                {
                    ans[i] = 1;
                }
                for (int j = 0; j < mm.Length; j++)
                {
                    ans[i + j] = mm[j];
                }
            }
            Array.Sort(indx, ans);
            foreach (int an in ans)
            {
                writer.Write(an);
                writer.Write(' ');
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Little_Pony_and_Harmony_Chest
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static readonly int[] prime = new[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};

        private static IEnumerable<int[]> Gets(int maxl)
        {
            int max = 1 << prime.Length;

            for (int i = 0; i < max; i++)
            {
                int mask = i;
                var l = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if ((mask & 1) == 1)
                    {
                        l.Add(prime[j]);
                    }
                    mask >>= 1;
                }
                if (l.Count <= maxl)
                {
                    int[] array = l.ToArray();

                    if (array.Length > 0)
                    {
                        for (; array[0] < 60; array[0] *= l[0])
                        {
                            if (array.Length > 1)
                            {
                                for (array[1] = l[1]; array[1] < 60; array[1] *= l[1])
                                {
                                    if (array.Length > 2)
                                    {
                                        for (array[2] = l[2]; array[2] < 60; array[2] *= l[2])
                                        {
                                            if (array.Length > 3)
                                            {
                                                for (array[3] = l[3]; array[3] < 60; array[3] *= l[3])
                                                {
                                                    var res = (int[]) array.Clone();
                                                    Array.Sort(res);
                                                    yield return res;
                                                }
                                            }
                                            else
                                            {
                                                var res = (int[])array.Clone();
                                                Array.Sort(res);
                                                yield return res;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        var res = (int[])array.Clone();
                                        Array.Sort(res);
                                        yield return res;
                                    }
                                }
                            }
                            else
                            {
                                var res = (int[])array.Clone();
                                Array.Sort(res);
                                yield return res;
                            }
                        }
                    }
                }
            }
        }

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            var indx = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
                indx[i] = i;
            }
            Array.Sort(nn, indx);

            int min = int.MaxValue;
            int[] mm = null;
            foreach (var m in Gets(n))
            {
                int i = 0;
                int sum = 0;
                for (; i < n - m.Length; i++)
                {
                    sum += Math.Abs(nn[i] - 1);
                }
                for (int j = 0; j < m.Length; j++)
                {
                    sum += Math.Abs(nn[i + j] - m[j]);
                }
                if (min > sum)
                {
                    min = sum;
                    mm = m;
                }
            }

            var ans = new int[n];
            {
                int i = 0;
                for (; i < n - mm.Length; i++)
                {
                    ans[i] = 1;
                }
                for (int j = 0; j < mm.Length; j++)
                {
                    ans[i + j] = mm[j];
                }
            }
            Array.Sort(indx, ans);
            foreach (int an in ans)
            {
                writer.Write(an);
                writer.Write(' ');
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

namespace Codeforces.R259
{
    public class Task_B
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private bool[] usedPrime = new bool[20];
        private bool[] usedNumber = new bool[65];
        private int[][] mn;
        private int[] a;
        private List<int> best;
        int n;
        int count = 0;
        int minSum = int.MaxValue;

        private void Solve()
        {
            n = int.Parse(Console.ReadLine());
            var aOrig = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a = aOrig.OrderByDescending(x => x).ToArray();

            mn = new int[61][];

            for (int i = 1; i <= 60; i++)
            {
                var div = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                        div.Add(j);
                }
                mn[i] = div.ToArray();
            }
            generate(60, 0, 0);

            foreach (var aItem in aOrig)
            {
                var fromBest = best.OrderBy(x => Math.Abs(x - aItem)).First();
                best.Remove(fromBest);
                Console.Write(fromBest);
                Console.Write(" ");
            }
            Console.WriteLine();
        }

        private void generate(int number, int numUsed, int diff)
        {
            count++;

            if (diff >= minSum || numUsed >= n)
                return;

            if (number < 2)
            {
                var newSum = diff;
                var newNumbers = new List<int>();
                for (int i = 2; i < usedNumber.Count(); i++)
                {
                    if (usedNumber[i])
                    {
                        newNumbers.Add(i);
                    }
                }
                var ones = n - newNumbers.Count;
                for (int i = newNumbers.Count; i < n; i++)
                {
                    newSum += Math.Abs(a[i] - 1);
                    newNumbers.Add(1);
                }

                if (newSum < minSum)
                {
                    minSum = newSum;
                    best = newNumbers;
                }

                return;
            }

            if (Match(number))
            {
                Mark(number, true);
                var delta = Math.Abs(a[numUsed] - number);
                generate(number - 1, numUsed + 1, diff + delta);
                Mark(number, false);
            }

            generate(number - 1, numUsed, diff);
        }

        private bool Match(int number)
        {
            var q = mn[number];
            for (int i = 0; i < q.Length; i++)
            {
                if (usedPrime[q[i]])
                    return false;
            }
            return true;
        }

        private void Mark(int number, bool value)
        {
            var q = mn[number];
            usedNumber[number] = value;
            for (int i = 0; i < q.Length; i++)
            {
                usedPrime[q[i]] = value;
            }
        }
    }
}

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

namespace Codeforces.R259
{
    public class Task_B
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private bool[] usedPrime = new bool[20];
        private bool[] usedNumber = new bool[65];
        private int[][] mn;
        private int[] a;
        private List<int> best;
        int n;
        int count = 0;
        int minSum = int.MaxValue;

        private void Solve()
        {
            n = int.Parse(Console.ReadLine());
            a = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToArray();

            mn = new int[61][];

            for (int i = 1; i <= 60; i++)
            {
                var div = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                        div.Add(j);
                }
                mn[i] = div.ToArray();
            }
            generate(60, 0, 0);

            foreach (var num in best.OrderByDescending(x => x))
            {
                Console.Write(num);
                Console.Write(" ");
            }
            Console.WriteLine();
        }

        private void generate(int number, int numUsed, int diff)
        {
            count++;

            if (diff >= minSum || numUsed >= n)
                return;

            if (number < 2)
            {
                var newSum = diff;
                var newNumbers = new List<int>();
                for (int i = 2; i < usedNumber.Count(); i++)
                {
                    if (usedNumber[i])
                    {
                        newNumbers.Add(i);
                    }
                }
                var ones = n - newNumbers.Count;
                for (int i = newNumbers.Count; i < n; i++)
                {
                    newSum += Math.Abs(a[i] - 1);
                    newNumbers.Add(1);
                }

                if (newSum < minSum)
                {
                    minSum = newSum;
                    best = newNumbers;
                }

                return;
            }

            if (Match(number))
            {
                Mark(number, true);
                var delta = Math.Abs(a[numUsed] - number);
                generate(number - 1, numUsed + 1, diff + delta);
                Mark(number, false);
            }

            generate(number - 1, numUsed, diff);
        }

        private bool Match(int number)
        {
            var q = mn[number];
            for (int i = 0; i < q.Length; i++)
            {
                if (usedPrime[q[i]])
                    return false;
            }
            return true;
        }

        private void Mark(int number, bool value)
        {
            var q = mn[number];
            usedNumber[number] = value;
            for (int i = 0; i < q.Length; i++)
            {
                usedPrime[q[i]] = value;
            }
        }
    }
}

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

namespace Codeforces.R259
{
    public class Task_B
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private bool[] usedPrime = new bool[20];
        private bool[] usedNumber = new bool[65];
        private int[][] mn;
        private Tuple<int, int>[] a;
        private List<int> best;
        int n;
        int count = 0;
        int minSum = int.MaxValue;

        private void Solve()
        {
            n = int.Parse(Console.ReadLine());
            a = Console.ReadLine().
                Split().
                Select((x, index) => new Tuple<int, int>(int.Parse(x), index)).
                OrderByDescending(x => x.Item1).
                ToArray();

            mn = new int[61][];

            for (int i = 1; i <= 60; i++)
            {
                var div = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                        div.Add(j);
                }
                mn[i] = div.ToArray();
            }
            generate(60, 0, 0);

            var ans = new int[n];
            for (int i = 0; i < n; i++)
            {
                var aItem = a[i];
                ans[aItem.Item2] = best[i];
            }

            for (int i = 0; i < n; i++)
            {
                Console.Write(ans[i]);
                Console.Write(" ");
            }
            Console.WriteLine();
        }

        private void generate(int number, int numUsed, int diff)
        {
            count++;

            if (diff >= minSum || numUsed >= n)
                return;

            if (number < 2)
            {
                var newSum = diff;
                var newNumbers = new List<int>();
                for (int i = 2; i < usedNumber.Count(); i++)
                {
                    if (usedNumber[i])
                    {
                        newNumbers.Add(i);
                    }
                }
                var ones = n - newNumbers.Count;
                for (int i = newNumbers.Count; i < n; i++)
                {
                    newSum += Math.Abs(a[i].Item1 - 1);
                    newNumbers.Add(1);
                }

                if (newSum < minSum)
                {
                    minSum = newSum;
                    best = newNumbers.OrderByDescending(x => x).ToList();
                }

                return;
            }

            if (Match(number))
            {
                Mark(number, true);
                var delta = Math.Abs(a[numUsed].Item1 - number);
                generate(number - 1, numUsed + 1, diff + delta);
                Mark(number, false);
            }

            generate(number - 1, numUsed, diff);
        }

        private bool Match(int number)
        {
            var q = mn[number];
            for (int i = 0; i < q.Length; i++)
            {
                if (usedPrime[q[i]])
                    return false;
            }
            return true;
        }

        private void Mark(int number, bool value)
        {
            var q = mn[number];
            usedNumber[number] = value;
            for (int i = 0; i < q.Length; i++)
            {
                usedPrime[q[i]] = value;
            }
        }
    }
}

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

namespace Codeforces.R259
{
    public class Task_B
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new StreamReader(@"input.txt"));
#endif
            new Task_B().Solve();
        }

        private int[] prime = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59 };
        private bool[] usedPrime = new bool[20];
        private bool[] usedNumber = new bool[65];
        private int[][] mn;
        private int[] a;
        private List<int> best;
        int n;
        int count = 0;
        int minSum = int.MaxValue;

        private void Solve()
        {
            n = int.Parse(Console.ReadLine());
            var aOrig = Console.ReadLine().Split().Select(int.Parse).ToArray();
            a = aOrig.ToArray();

            mn = new int[61][];

            for (int i = 1; i <= 60; i++)
            {
                var div = new List<int>();
                for (int j = 0; j < prime.Length; j++)
                {
                    if (i % prime[j] == 0)
                        div.Add(j);
                }
                mn[i] = div.ToArray();
            }
            generate(60, 0, 0);

            foreach (var aItem in aOrig)
            {
                var fromBest = best.OrderBy(x => Math.Abs(x - aItem)).First();
                best.Remove(fromBest);
                Console.Write(fromBest);
                Console.Write(" ");
            }
            Console.WriteLine();
        }

        private void generate(int number, int numUsed, int diff)
        {
            count++;

            if (diff >= minSum || numUsed >= n)
                return;

            if (number < 2)
            {
                var newSum = diff;
                var newNumbers = new List<int>();
                for (int i = 2; i < usedNumber.Count(); i++)
                {
                    if (usedNumber[i])
                    {
                        newNumbers.Add(i);
                    }
                }
                var ones = n - newNumbers.Count;
                for (int i = newNumbers.Count; i < n; i++)
                {
                    newSum += Math.Abs(a[i] - 1);
                    newNumbers.Add(1);
                }

                if (newSum < minSum)
                {
                    minSum = newSum;
                    best = newNumbers;
                }

                return;
            }

            if (Match(number))
            {
                Mark(number, true);
                var delta = Math.Abs(a[numUsed] - number);
                generate(number - 1, numUsed + 1, diff + delta);
                Mark(number, false);
            }

            generate(number - 1, numUsed, diff);
        }

        private bool Match(int number)
        {
            var q = mn[number];
            for (int i = 0; i < q.Length; i++)
            {
                if (usedPrime[q[i]])
                    return false;
            }
            return true;
        }

        private void Mark(int number, bool value)
        {
            var q = mn[number];
            usedNumber[number] = value;
            for (int i = 0; i < q.Length; i++)
            {
                usedPrime[q[i]] = value;
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int COUNT = 16;
    const int SCOUNT = 1 << COUNT;
    int[] primes = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
    IList<Tuple<int, int>> options = new List<Tuple<int, int>>();

    void GenerateOptions(int p, int x, int s)
    {
        if (p == COUNT)
        {
            if (x > 1)
                options.Add(Tuple.Create(x, s));
            return;
        }
        for (int i = 0; x < 59; i++)
        {
            GenerateOptions(p + 1, x, s);
            x *= primes[p];
            s |= 1 << p;
        }
    }

    public object Solve()
    {
        int n = ReadInt();
        var a = ReadIntArray();

        GenerateOptions(0, 1, 0);

        var dp = new int[n + 1, SCOUNT];
        var path = new Tuple<int, int>[n + 1, SCOUNT];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < SCOUNT; j++)
            {
                dp[i + 1, j] = dp[i, j] + a[i] - 1;
                path[i + 1, j] = Tuple.Create(j, 1);
            }
            foreach (var t in options)
            {
                int diff = Math.Abs(a[i] - t.Item1);
                for (int j = 1; j < SCOUNT; j++)
                    if (dp[i, j] < int.MaxValue && (j & t.Item2) == 0)
                    {
                        int x = dp[i, j] + diff;
                        int v = j | t.Item2;
                        if (dp[i + 1, v] > x)
                        {
                            dp[i + 1, v] = x;
                            path[i + 1, v] = Tuple.Create(j, t.Item1);
                        }
                    }
            }
        }

        int nmin = 0;
        for (int i = 1; i < SCOUNT; i++)
            if (dp[n, i] < dp[n, nmin])
                nmin = i;

        var ans = new int[n];
        for (int i = n - 1; i >= 0; i--)
        {
            ans[i] = path[i + 1, nmin].Item2;
            nmin = path[i + 1, nmin].Item1;
        }
        WriteArray(ans);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            var ts = DateTime.Now;
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read/Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    #endregion
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int COUNT = 16;
    const int SCOUNT = 1 << COUNT;
    int[] primes = new[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
    IList<Tuple<int, int>> options = new List<Tuple<int, int>>();

    void GenerateOptions(int p, int x, int s)
    {
        if (p == COUNT)
        {
            options.Add(Tuple.Create(x, s));
            return;
        }
        for (int i = 0; x < 59; i++)
        {
            GenerateOptions(p + 1, x, s);
            x *= primes[p];
            s |= 1 << p;
        }
    }

    public object Solve()
    {
        int n = ReadInt();
        var a = ReadIntArray();

        GenerateOptions(0, 1, 0);

        var dp = new int[n + 1, SCOUNT];
        var path = new Tuple<int, int>[n + 1, SCOUNT];

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < SCOUNT; j++)
            {
                dp[i + 1, j] = dp[i, j] + a[i] - 1;
                path[i + 1, j] = Tuple.Create(j, 1);
            }
            foreach (var t in options)
            {
                int diff = Math.Abs(a[i] - t.Item1);
                for (int j = 1; j < SCOUNT; j++)
                    if (dp[i, j] < int.MaxValue && (j & t.Item2) == 0)
                    {
                        int x = dp[i, j] + diff;
                        int v = j | t.Item2;
                        if (dp[i + 1, v] > x)
                        {
                            dp[i + 1, v] = x;
                            path[i + 1, v] = Tuple.Create(j, t.Item1);
                        }
                    }
            }
        }

        int nmin = 0;
        for (int i = 1; i < SCOUNT; i++)
            if (dp[n, i] < dp[n, nmin])
                nmin = i;

        var ans = new int[n];
        for (int i = n - 1; i >= 0; i--)
        {
            ans[i] = path[i + 1, nmin].Item2;
            nmin = path[i + 1, nmin].Item1;
        }
        WriteArray(ans);

        return null;
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = Console.In;
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            var ts = DateTime.Now;
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read/Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }

    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }

    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }

    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    #endregion
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;

namespace ReadWriteTemplate
{
    public static class Solver
    {
        private static void SolveCase()
        {
            int n = ReadInt();
            var a = ReadIntArray();

            const int m = 59;
            List<long> primes = GetPrimes(m);
            int p = primes.Count;

            var mask = new int[m + 1];
            for (int i = 1; i <= m; i++)
            {
                for (int j = 0; j < p; j++)
                {
                    if (i % primes[j] == 0)
                    {
                        mask[i] |= (1 << j);
                    }
                }
            }

            const int MAX = int.MaxValue / 2;
            int q = 1 << p;
            var b = new int[n + 1][];
            var w = new int[n + 1][];
            for (int i = 0; i < n + 1; i++)
            {
                b[i] = Enumerable.Repeat(MAX, q).ToArray();
                w[i] = new int[q];
            }
            b[0][0] = 0;
            w[0][0] = -1;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    if (b[i][j] < MAX)
                    {
                        for (int k = 1; k <= m; k++)
                        {
                            if ((j & mask[k]) == 0)
                            {
                                if (b[i + 1][j | mask[k]] > b[i][j] + Math.Abs(k - a[i]))
                                {
                                    b[i + 1][j | mask[k]] = b[i][j] + Math.Abs(k - a[i]);
                                    w[i + 1][j | mask[k]] = k;
                                }
                            }
                        }
                    }
                }
            }

            int mini = 0;
            for (int i = 0; i < q; i++)
            {
                if (b[n][i] < b[n][mini])
                {
                    mini = i;
                }
            }

            Writer.WriteLine(b[n][mini]);
            var ans = new List<int>();
            for (int i = n; i > 0; i--)
            {
                ans.Add(w[i][mini]);
                mini ^= mask[w[i][mini]];
            }
            ans.Reverse();
            WriteArray(ans);
        }

        public static List<long> GetPrimes(long n)
        {
            var primes = new List<long>();

            n = Math.Max(n, 2);
            bool[] isPrime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                isPrime[i] = true;
            }

            for (int i = 2; i <= n; i++)
            {
                if (isPrime[i])
                {
                    primes.Add(i);
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            isPrime[j] = false;
                        }
                    }
                }
            }

            return primes;
        }

        public static void Solve()
        {
            SolveCase();

            /*var sw = Stopwatch.StartNew();*/

            /*int T = ReadInt();
            for (int i = 0; i < T; i++)
            {
                // Writer.Write("Case #{0}: ", i + 1);
                SolveCase();
            }*/

            /*sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);*/
        }

        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

#if DEBUG
            //Reader = Console.In; Writer = Console.Out;
            Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");
#else
            Reader = Console.In; Writer = Console.Out;
#endif

            // Solve();
            Thread thread = new Thread(Solve, 64 * 1024 * 1024);
            thread.CurrentCulture = CultureInfo.InvariantCulture;
            thread.Start();
            thread.Join();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

        private static Queue<string> CurrentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (CurrentLineTokens.Count == 0)
                CurrentLineTokens = new Queue<string>(ReadAndSplitLine());
            return CurrentLineTokens.Dequeue();
        }

        public static string ReadLine()
        {
            return Reader.ReadLine();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++)
                lines[i] = Reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            Writer.WriteLine(string.Join(" ", array));
        }

        #endregion
    }
}