Problem: Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.

<image>

A sequence of positive integers bi is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence bi which minimizes the following expression:

<image>

You are given sequence ai, help Princess Twilight to find the key.

Input

The first line contains an integer n (1 ≤ n ≤ 100) — the number of elements of the sequences a and b. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 30).

Output

Output the key — sequence bi that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.

Examples

Input

5
1 1 1 1 1


Output

1 1 1 1 1 

Input

5
1 6 4 2 8


Output

1 5 3 1 8 

Solution (in JAVA):

Solution:

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


public class G {
    static int n;
    static int[] numbers, primes, mask;
    static int[][] dp;

    public static void main(String args[]) throws Exception {
        Reader reader = new Reader();
        reader.initConsoleReading();
        primes = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
        mask = new int[60];
        for (int i = 2; i <= 59; i++) {
            for (int j = 0; j < primes.length; j++) {
                if (i % primes[j] == 0) {
                    mask[i] |= (1 << j);
                }
            }
        }
        n = reader.nextInt();
        numbers = new int[n];
        for (int i = 0; i < n; i++) {
            numbers[i] = reader.nextInt();
        }
        dp = new int[n][1 << primes.length];
        for (int i = 0; i < n; i++) {
            for (int j = (1 << primes.length) - 1; j >= 0; j--) {
                dp[i][j] = -1;
            }
        }
        int cost = rec(0, 0);
        printPath(0, 0, cost, true);
        reader.dispose();

    }

    private static void printPath(int pos, int m, int cost, boolean firstInt) {
        if (pos == n) return;
        for (int i = 1; i <= 59; i++) {
            if((m&mask[i])==0){
                if (cost == Math.abs(i - numbers[pos]) + rec(pos + 1, (m | mask[i]))) {
                    if (!firstInt) System.out.print(" ");
                    System.out.print(i);
                    printPath(pos + 1, (m | mask[i]), cost - Math.abs(i - numbers[pos]), false);
                    break;
                }
            }
        }
    }


    private static int rec(int pos, int m) {
        if (pos == n) return 0;
        if (dp[pos][m] != -1) return dp[pos][m];
        dp[pos][m] = 1 << 20;
        for (int i = 1; i <= 59; i++) {
            if((m&mask[i])==0){
                dp[pos][m] = Math.min(dp[pos][m], Math.abs(i - numbers[pos]) + rec(pos + 1, (m | mask[i])));
            }
        }
        return dp[pos][m];
    }

    /************************************Helper Methods Begin Here**********************************************/
    private static String reverse(String toRev) {
        return new StringBuilder(toRev).reverse().toString();
    }

    public static class Pair<F extends Comparable<F>, S extends Comparable<S>> implements Comparable<Pair<F, S>> {
        static final int prime = 31;
        private F first;
        private S second;

        public Pair(F f, S s) {
            this.first = f;
            this.second = s;
        }

        @Override
        public int hashCode() {
            int result = 1;
            result = prime * result + this.first.hashCode();
            result = prime * result + this.second.hashCode();
            return result;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Pair<F, S> s = (Pair<F, S>) obj;
            return this.first.equals(s.first) && this.second.equals(s.second);
        }

        @Override
        public int compareTo(Pair<F, S> p) {
            int c1 = this.first.compareTo(p.first);
            if (c1 == 0) {
                return this.second.compareTo(p.second);
            }
            return c1;
        }
    }

    public static int swap(int a, int b) {
        /*a = Main.swap(b,b=a); goes from left to right*/
        return a;
    }

    public static long swap(long a, long b) {
        /*a = Main.swap(b,b=a); goes from left to right*/
        return a;
    }

    private static <T1, T2> void init6d(T1[][][][][][] sixD, T2 val) {
        for (T1[][][][][] fiveD : sixD) init5d(fiveD, val);
    }

    private static <T1, T2> void init5d(T1[][][][][] fiveD, T2 val) {
        for (T1[][][][] fourD : fiveD) init4d(fourD, val);
    }

    private static <T1, T2> void init4d(T1[][][][] fourD, T2 val) {
        for (T1[][][] threeD : fourD) init3d(threeD, val);
    }

    private static <T1, T2> void init3d(T1[][][] threeD, T2 val) {
        for (T1[][] twoD : threeD) init2d(twoD, val);
    }

    private static <T1, T2> void init2d(T1[][] twoD, T2 val) {
        for (T1[] oneD : twoD) init1d(oneD, val);
    }

    private static <T1, T2> void init1d(T1[] oneD, T2 val) {
        Arrays.fill(oneD, val);
    }

    public static boolean next_permutation(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
            if (p[a] < p[a + 1])
                for (int b = p.length - 1; ; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        return false;
    }

    public static long gcd(long a, long b) {
        if (a < 0) a *= -1;
        if (b < 0) b *= -1;
        return b == 0 ? a : gcd(b, a % b);
    }

    public static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public Reader() {
        }

        public Reader initConsoleReading() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
            return this;
        }

        public Reader initFileReading(String filePath) throws FileNotFoundException {
            reader = new BufferedReader(new FileReader(filePath), 32768);
            tokenizer = null;
            return this;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() throws IOException {
            return reader.readLine();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public void dispose() throws IOException {
            this.reader.close();
        }
    }
    /************************************Helper Methods Ends Here**********************************************/
}