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.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class main {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long mod = 1000000000 + 7;
	private static int MAX=1000001;
	private static long k;
	private static int block;
	private static void soln(){
		int n=nextInt();
		int[] arr=nextIntArray(n);
		int[] prime={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53};
		int[] facmask=new int[59];
		for(int i=1;i<59;i++){
			for(int j=0;j<16;j++)
				if(i%prime[j]==0)
					facmask[i]|=(1<<j);
		}
		int[][] dp=new int[n+1][1<<16];
		int[][] ans=new int[n+1][1<<16];
		for(int i=1;i<=n;i++){
			for(int mask=(1<<16)-1;mask>=0;mask--){
				dp[i][mask]=dp[i-1][mask]+Math.abs(arr[i-1]-1);
				ans[i][mask]=1;
				for(int j=2;j<59;j++){
					if((mask&facmask[j])==facmask[j]){
						int val=dp[i-1][mask^facmask[j]]+Math.abs(arr[i-1]-j);
						if(val<dp[i][mask]){
							dp[i][mask]=val;
							ans[i][mask]=j;
						}
					}
				}
			}
		}
		int min=Integer.MAX_VALUE;
		int mask1=-1;
		for(int mask=(1<<16)-1;mask>=0;mask--){
			if(dp[n][mask]<min){
				min=dp[n][mask];
				mask1=mask;
			}
		}
		int[] ans1=new int[n];
		for(int i=n;i>0;i--){
			ans1[i-1]=ans[i][mask1];
			mask1^=facmask[ans[i][mask1]];
		}
		for(int i=0;i<n;i++)
			pw.print(ans1[i]+" ");
	}
	private static class Treap{
		Node root;
		int[] random;
		int cnt;
		Random rnd=new Random();
		private static class Node{
			int cnt;
			int prio;
			int val;
			int max=Integer.MIN_VALUE;
			Node left;
			Node right;
		}
		private int count(Node p){
			return p==null?0:p.cnt;
		}
		private int max(Node p){
			return p==null?Integer.MIN_VALUE:p.max;
		}
		void update(Node p){
			p.cnt=1+count(p.left)+count(p.right);
			p.max=Math.max(p.val,Math.max(max(p.left),max(p.right)));
		}
		Node merge(Node l,Node r){
			Node tmp;
			if(l==null)
				tmp=r;
			else if(r==null)
				tmp=l;
			else if(l.prio<r.prio){
				l.right=merge(l.right,r);
				tmp=l;
			}else{
				r.left=merge(l,r.left);
				tmp=r;
			}
			update(tmp);
			return tmp;
		}
		Node L,R;
		void split(Node t,int key){
			if(t==null){
				L=R=null;
				return;
			}
			if(key<=count(t.left)){
				split(t.left,key);
				t.left=R;
				R=t;
			}else{
				split(t.right,key-count(t.left)-1);
				t.right=L;
				L=t;
			}
			update(t);
		}
		private Node add(Node t,Node it,int ind){
			if(t==null){
				it.prio=rnd.nextInt();
				return it;
			}
			/*else if(it.prio<t.prio){
				split(t,ind);
				it.left=L;
				it.right=R;
				tmp=it;
			}else{*/
			else if(ind<=count(t.left)){
				t.left=add(t.left,it,ind);
				if(t.left.prio>t.prio)
					t=rotate(t,t.left);
			}
			else{
				t.right=add(t.right,it,ind-count(t.left)-1);
				if(t.right.prio>t.prio)
					t=rotate(t,t.right);
			}
			//System.out.println(t+" "+t.left);
			update(t);
			//System.out.println("s");
			return t;
		}
		public void add(int ind,int val){
			Node it=new Node();
			it.val=val;
			//it.prio=random[cnt++];
			it.cnt=1;
			it.max=val;
			root=add(root,it,ind);
			//System.out.println("s");
		}
		public int max(int a,int b){
			split(root,b);
			Node R1=R;
			split(L,a-1);
			int res=max(R);
			root=merge(merge(L,R),R1);
			return res;
		}
		public int query(Node root,int i,int j,int qi,int qj){
			if(root==null || i>=qj || j<=qi)return Integer.MIN_VALUE;
			if(qi<=i && qj>=j)return root.max;
			int res=Integer.MIN_VALUE;
			res=Math.max(res,query(root.left,i,i+count(root.left),qi,qj));
			res=Math.max(res,query(root.right,i+count(root.left)+1,j,qi,qj));
			if(i+count(root.left)>=qi && i+count(root.left)<qj)
				res=Math.max(res,root.val);
			return res;
		}
		private Node rotate(Node p,Node s){
			if(p.left!=null && p.left.equals(s)){
				p.left=s.right;
				s.right=p;
			}else{
				p.right=s.left;
				s.left=p;
			}
			update(p);
			update(s);
			return s;
		}
		public int[] getRandomPermutation(int n) {
			Random rnd=new Random();
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = i;
			}
			for (int i = res.length; i > 1; i--) {
				int j = rnd.nextInt(i);
				int t = res[i - 1];
				res[i - 1] = res[j];
				res[j] = t;
			}
			return res;
		}
	}
	private static class DSU{
		int[] parent;
		public DSU(int n){
			parent=new int[n];
			for(int i=0;i<n;i++)
				parent[i]=i;
		}
		int find(int i){
	        while(parent[i] !=i){
	        	parent[i]=parent[parent[i]];
	        	i=parent[i];
	        }
	        return i;
	    }
		void Union(int x, int y){
	        int xset = find(x);
	        int yset = find(y);
	        parent[yset]=yset;
	        parent[xset] = yset;
	    }
	}
	/*private static void dfs(int cur,LinkedList<Edge>[] l,int[] val,int n){
		HashSet<Integer> mst=new HashSet<>();
		int[] par=new int[n];
		PriorityQueue<Pair> key=new PriorityQueue<>();
		key.add(new Pair());
		par[0]=-1;
		for(int count=0;count<n-1;count++){
			
		
	}*/
	private static class Edge{
		int x;
		int y;
		public Edge(int a,int b){
			x=a; y=b;
		}
	}
	private static long pow(long a, long b, long c) {
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}
	
	private static class Mo implements Comparable<Mo>{
		int l;
		int r;
		int i;
		public Mo(int a,int b,int ind) {
			l=a;r=b;i=ind;
		}
		@Override
		public int compareTo(Mo arg0) {
			int b1=this.l/block;
			int b2=arg0.l/block;
			return (b1!=b2)?(b1-b2):(this.r-arg0.r);
		}
	}

	private static long gcd(long n, long l) {
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}

	private static long max(long a, long b) {
		if (a > b)
			return a;
		return b;
	}

	private static long min(long a, long b) {
		if (a < b)
			return a;
		return b;
	}

	public static void main(String[] args) throws Exception {
		new Thread(null,new Runnable(){
			@Override
			public void run() {
				/*try {
					InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\C-small-1-attempt1.in"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				InputReader(System.in);
				pw = new PrintWriter(System.out);
				/*try {
					pw=new PrintWriter(new FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				soln();
				pw.close();
			}
		},"1",1<<26).start();
	}

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

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

	private static void pArray(long[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}
	private static char nextChar() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1=(char)c;
		while(!isSpaceChar(c))
			c=read();
		return c1;
}
	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}