You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps.
Step 0: 6 4 2 3 7 (given sequence)
Step 1: 2 4 6 3 7 (elements 6 and 2 swapped)
Step 2: 2 6 4 3 7 (elements 4 and 6 swapped)
Step 3: 2 3 4 6 7 (elements 6 and 3 swapped)


Depending on the nature of the sequence, however, this approach may fail to complete the sorting. You have given a name "Coprime sort" to this approach and are now examining if a given sequence is coprime-sortable.

Make a program to determine if a given sequence can be sorted in increasing order by iterating an arbitrary number of swapping operations of two elements that have a common prime number.



Input

The input is given in the following format.


$N$
$a_1$ $a_2$ $...$ $a_N$


The first line provides the number of elements included in the sequence $N$ ($2 \leq N \leq 10^5$). The second line provides an array of integers $a_i$ ($2 \leq a_i \leq 10^5$) that constitute the sequence.

Output

Output "1" if the sequence is coprime-sortable in increasing order, or "0" otherwise.

Examples

Input

5
6 4 2 3 7


Output

1


Input

7
2 9 6 5 6 7 3


Output

0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

vector<int> f(int x){
    vector<int> ret;
    int t = x;
    for(int i=2; i*i<=x; ++i){
        if(t%i==0){
            ret.pb(i);
            while(t%i==0) t/=i;
        }
    }
    if(t>1) ret.pb(t);
    return ret;
}

int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    map<int,vector<int>> m;
    rep(i,n){
        vector<int> d = f(a[i]);
        for(int j:d) m[j].pb(i);
    }

    UF uf(n);
    for(const auto &p:m){
        int k = p.fi;
        vector<int> v = p.se;
        int V = v.size();
        rep(i,V) uf.unite(v[0],v[i]);
    }

    vector<int> sa(a);
    sort(all(sa));
    map<int,int> pos;
    for(int i=n-1; i>=0; --i) pos[sa[i]] = i;

    int ans = 1;
    rep(i,n){
        int v = a[i];
        int p = pos[v];
        if(!uf.same(i,p)){
            ans = 0;
            break;
        }
        ++pos[v];
    }
    cout << ans << endl;
    return 0;
}

