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.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TaskB {

	FastIO scan = new FastIO();
	PrintWriter cout = new PrintWriter(System.out);

	final int inf = 1 << 29;
	int[] hehe = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
	int[][] dp = new int[111][1 << 16];
	int[][] f = new int[111][1 << 16];
	int[] p = new int[111];
	int[] ans = new int[111];

	class Point implements Comparable<Point> {
		int x, pos;

		@Override
		public int compareTo(Point o) {
			// TODO Auto-generated method stub
			return x - o.x;
		}
	}

	int[] __ = new int[111];

	public void run() {
		int n = scan.nextInt();
		Point[] p = new Point[111];
		int[] a = new int[111];
		for (int i = 1; i <= n; i++) {
			p[i] = new Point();
			p[i].x = scan.nextInt();
			a[i] = p[i].x;
			p[i].pos = i;
		}
		Arrays.sort(p, 1, n + 1);
		// for (int i = 1; i <= n; i ++) {
		// System.out.println(p[i].x + " " + p[i].pos);
		// }
		for (int i = n; i + 16 > n && i >= 1; i--) {
			__[p[i].pos] = 1;
		}
		ArrayList<Integer> v = new ArrayList<Integer>();
		for (int i = 1; i <= n; i++) {
			if (__[i] > 0)
				v.add(i);
		}
		for (int i = 1; i <= n; i++) {
			if (__[i] == 0)
				ans[i] = 1;
		}
		int mask = 1 << 16;

		for (int i = 0; i < mask; i++) {
			dp[0][i] = inf;
		}
		dp[0][0] = 0;

		int[][] _ = new int[mask][66];
		for (int i = 0; i < mask; i++) {
			for (int j = 1; j < 59; j++) {
				int k = 0;
				for (k = 0; k < 16; k++) {
					if ((1 << k & i) > 0 && j % hehe[k] == 0)
						break;
				}
				if (k != 16)
					_[i][j] = 1;
			}
		}

		int[] $ = new int[111];
		int top = 0;
		// ArrayList<Integer> q = new ArrayList<Integer>();
		for (int i = 1; i <= n; i++) {
			if (__[i] > 0)
				$[++top] = a[i];
		}
		for (int i = 0; i < top; i++) {

			// }
			// for (int i = 1; i <= n; i++) {
			for (int j = 0; j < mask; j++) {
				dp[i + 1][j] = inf;
			}
			for (int j = 0; j < mask; j++) {
				if (dp[i][j] == inf)
					continue;
				for (int k = 1; k < $[i + 1] * 2; k++) {
					if (_[j][k] > 0 || k == 59)
						continue;
					int l = 0;
					// for (l = 0; l < 10; l++) {
					// if (((1 << l & j) > 0) && k % hehe[l] == 0)
					// break;
					// }
					// if (l != 10)
					// continue;
					int bit = j;
					for (l = 0; l < 16; l++) {
						if (k % hehe[l] == 0)
							bit |= 1 << l;
					}
					if (dp[i + 1][bit] > dp[i][j] + Math.abs(k - $[i + 1])) {
						dp[i + 1][bit] = dp[i][j] + Math.abs(k - $[i + 1]);

						// System.out.println(i + " " + bit + " " + f[i][bit]);
						f[i + 1][bit] = k;
					}
				}
			}
		}
		// for (int i = 1; i <= n; i++) {
		// for (int j = 0; j < 1 << 10; j++) {
		// System.out.println(i + " " + j + " " +f[i][j]);
		// }
		// }
		int $$ = 0;
		for (int i = 0; i < mask; i++) {
			if (dp[top][i] < dp[top][$$])
				$$ = i;
		}
		// / System.out.println(start);
		// System.out.println(f[n][start]);
		ArrayList<Integer> answer = new ArrayList<Integer>();
		for (int i = top; i > 0; i--) {
			// System.out.println(f[i][start]);
			answer.add(f[i][$$]);
			int tmp = f[i][$$];
			for (int j = 0; j < 16; j++) {
				if (tmp % hehe[j] == 0)
					$$ ^= 1 << j;
			}
		}
		for (int i = answer.size() - 1; i >= 0; i--) {
			ans[v.get(i)] = answer.get(answer.size() - 1 - i);
			// System.out.print(answer.get(i) + " ");
		}
		for (int i = 1; i <= n; i++) {
			System.out.print(ans[i] + " ");
		}

	}

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

	public class FastIO {
		BufferedReader br;
		StringTokenizer st;
		PrintWriter out;

		public FastIO(InputStream in, OutputStream o) {
			br = new BufferedReader(new InputStreamReader(in));
			out = new PrintWriter(new OutputStreamWriter(o));
			eat("");
		}

		public FastIO() {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			eat("");
		}

		public void eat(String s) {
			st = new StringTokenizer(s);
		}

		public String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				throw new IOError(e);
			}
		}

		public boolean hasNext() {
			while (!st.hasMoreTokens()) {
				String s = nextLine();
				if (s == null)
					return false;
				eat(s);
			}
			return true;
		}

		public String next() {
			hasNext();
			return st.nextToken();
		}

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public void print(String ans) {
			out.print(ans);
			out.flush();
		}

		public void println(String ans) {
			out.println(ans);
			out.flush();
		}

		public void close() {
			out.close();
		}
	}
}