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.util.*;
import java.io.*;

public class Main implements Runnable {

    int MOD = 1000000007; //10^9+7
    Integer[][] dp;
    int[] a;
    int[] factors;
    int[] primes = new int[]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
    int MAX = 60;
    int N;

    public void solve() throws IOException {
        factors = new int[MAX + 1];
        for (int i = 1; i <= MAX; i++) {
            for (int j = 0; j < primes.length; j++) {
                if ((i % primes[j]) == 0) {
                    factors[i] |= 1 << j;
                }
            }
            //System.out.println(i + " " + Integer.toBinaryString(factors[i]) + " " + factors[i]);
        }

        N = nextInt();
        a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = nextInt();
        }

        dp = new Integer[1 << primes.length][N];
        //System.out.println(dp[0][0]);



        int used = 0;
        int[] ret = new int[N];



        for (int bi = 0; bi < N; bi++) {
            for (int x = 1; x <= MAX; x++) {
                int f = factors[x];
                if ((used & f) > 0) {
                    continue;
                }
                int oldCost = f(used, bi);
                int newCost = Math.abs(a[bi] - x) + f(used | f, bi + 1);
                if (newCost == oldCost) {
                    ret[bi] = x;
                    used |= f;
                    break;
                }
            }
        }
        for (int i = 0; i < N; i++) {
            System.out.print(ret[i] + " ");
        }
        System.out.println();
    }

    int f(int used, int i) {
        if (i == N) {
            return 0;
        }
        if (dp[used][i] != null) {
            return dp[used][i];
        }
        int ans = 1000000;

        for (int x = 1; x <= MAX; x++) {
            int f = factors[x];
            if ((used & f) > 0) {
                continue;
            }
            ans = Math.min(ans, Math.abs(a[i] - x) + f(used | f, i + 1));
        }
        return dp[used][i] = ans;
    }

    int gcd(int m, int n) {
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }

    int[] alToIntArray(ArrayList<Integer> al) {
        int[] ret = new int[al.size()];
        for (int i = 0; i < al.size(); i++) {
            ret[i] = al.get(i);
        }
        return ret;
    }

    void print(Object... obj) {
        for (Object o : obj) {
            System.out.println(o);
        }
    }

    void print(boolean[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }

    void print(int[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    void print(long[] a) {
        System.out.println();
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    void print(int[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }

    void print(boolean[][] arr) {
        System.out.println();
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }

    //-----------------------------------------------------------
    public static void main(String[] args) {
        new Main().run();
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            tok = null;
            solve();
            in.close();
        } catch (IOException e) {
            System.exit(0);
        }
    }

    public String nextToken() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
    BufferedReader in;
    StringTokenizer tok;
}