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.*;

public class CF453B{
    static class NumSet{
        public int primeMap;
        public int sum;
        public long numMap;
        public int pre;

        public NumSet(){
            primeMap = 0;
            sum = 0;
            numMap = 0L;
            pre = MAX;
        }

        public NumSet(NumSet ns){
            this.primeMap = ns.primeMap;
            this.sum = ns.sum;
            this.numMap = ns.numMap;
            this.pre = ns.pre;
        }

        public boolean addNum(int x, int diff){
            if (x<1||x>MAX||(factor[x]&primeMap)>0){
                return false;
            }
            primeMap |= factor[x];
            numMap |= (1L<<x);
            sum += diff;
            return true;
        }
    }

    static class Input{
        public int num;
        public int idx;
        public int ans;

        public Input(int num, int idx){
            this.num = num;
            this.idx = idx;
        }
    }

    static final int MAX = 60;
    static List<Integer> prime = new ArrayList<>();
    static int[] factor = new int[MAX];

    public static void generatePrime(){
        prime.add(2);
        prime.add(3);
        prime.add(5);
        for (int i=7; i<MAX; i++){
            boolean isp = true;
            for (int j=0; ; j++){
                int now = prime.get(j);
                if (now*now>i){
                    break;
                }
                if (i%now==0){
                    isp = false;
                    break;
                }
            }
            if (isp){
                prime.add(i);
            }
        }
    }

    static void generateTail(NumSet old, Map<Integer, NumSet> now, int num, int x){
        int diff = Math.abs(num-x);
        NumSet tail = new NumSet(old);
        if (tail.addNum(x, diff)){
            tail.pre = x;
            int key = tail.primeMap;
            if (!now.containsKey(key)||now.get(key).sum>tail.sum){
                now.put(key, tail);
            }
        }
    }

    static void generateFactor(){
        for (int i=1; i<MAX; i++){
            factor[i] = 0;
            for (int j=0; j<prime.size(); j++){
                if (i%prime.get(j)==0){
                    factor[i] |= (1<<j);
                }
            }
        }
    }

    public static void main(String[] args){
        generatePrime();
        generateFactor();
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int n = scn.nextInt();
            Input[] in = new Input[n];
            for (int i=0; i<n; i++){
                int t = scn.nextInt();
                in[i] = new Input(t, i);
            }
            Arrays.sort(in, (i1, i2) -> i2.num-i1.num);
            int[] sum1 = new int[n];
            sum1[n-1] = in[n-1].num-1;
            for (int i=n-2; i>=0; i--){
                sum1[i] = sum1[i+1]+in[i].num-1;
            }
            int min = -1;
            NumSet ans = new NumSet();
            List<Map<Integer, NumSet>> list = new ArrayList<>();
            Map<Integer, NumSet> map = new HashMap<>();
            map.put(0, new NumSet());
            list.add(map);
            for (int i=1; i<=n; i++){
                Map<Integer, NumSet> now = new HashMap<>();
                list.add(now);
                int upper = in[i-1].num+in[i-1].num-1;
                for (NumSet ns : list.get(i-1).values()){
                    int x = Math.min(ns.pre-1, upper);
                    if (x<1){
                        if (min<0||ns.sum+sum1[i-1]<min){
                            min = ns.sum+sum1[i-1];
                            ans = ns;
                        }
                    }
                    for (; x>=1; x--){
                        generateTail(ns, now, in[i-1].num, x);
                    }
                }
            }
            for (NumSet ns : list.get(n).values()){
                if (min<0||ns.sum<min){
                    min = ns.sum;
                    ans = ns;
                }
            }
            int idx = 0;
            for (int i=MAX; i>1; i--){
                if ((ans.numMap&(1L<<i))>0){
                    in[idx].ans = i;
                    idx ++;
                }
            }
            while (idx<n){
                in[idx].ans = 1;
                idx ++;
            }
            Arrays.sort(in, (i1, i2) -> i1.idx-i2.idx);
            for (int i=0; i<n; i++){
                if (i>0){
                    System.out.print(" ");
                }
                System.out.print(in[i].ans);
            }
            System.out.println();
        }
    }
}