Problem:
Construction Set
問題
$N$ 個の相異なる正の整数 $A_1, A_2, \cdots , A_N$ が与えられます。
これら$N$個の整数の中からいくつかの数を選んで、以下の条件全てを満たす集合を考えます。
どの要素も $6$ で割ったあまりは $1$ でない
どの相異なる $2$ つの要素も、 $6$ で割ったあまりは等しい
どの要素も約数の個数は $4$ 個である
どの相異なる $2$ つの要素も、最大公約数は $1$ である
上記の条件を満たす集合のうち、集合に含まれる要素の個数が最大となるものを構築してください。
答えが複数ある場合はどれを出力しても構いません。
ただし空集合の場合は
-1
を出力してください。
制約
$1 \leq N \leq 5000$
$1 \leq A_i \leq 10^9 (1 \leq i \leq N)$
$A_i < A_j (i < j)$
入力
$N$
$A_1$ $A_2$ $\cdots$ $A_N$
出力
条件を満たす集合のうち、集合に含まれる要素の個数が最大となるものを次の形式で出力してください。
$M$
$B_1$ $B_2$ $\cdots$ $B_M$
ここで、 $M$ は出力する集合の要素の個数。 $\{B_1, B_2, \cdots , B_M\}$ は集合の要素です。条件を満たしている集合であればどんな順序で出力しても問題ありません。
ただし、空集合の場合は次のように
-1
を $1$ 行で出力してください。
-1
入力例 1
4
5 35 64 209
出力例 1
2
35 209
集合 $\{35,209\}$ は、上記の条件を満たします。また要素の個数が $2$ より大きい集合は作れません。
入力例 2
3 
8 13 35
出力例 2
1
35
入力例 3
3
1 2 3
出力例 3
-1

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> Graph;
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

//https://github.com/atcoder/ac-library/tree/master/atcoder
#ifndef ATCODER_INTERNAL_QUEUE_HPP
#define ATCODER_INTERNAL_QUEUE_HPP 1

#include <vector>

namespace atcoder {

namespace internal {

template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_QUEUE_HPP

#ifndef ATCODER_MAXFLOW_HPP
#define ATCODER_MAXFLOW_HPP 1

#include <algorithm>
#include <cassert>
#include <limits>
#include <queue>
#include <vector>


namespace atcoder {

template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    explicit mf_graph(int n) : _n(n), g(n) {}

    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        int from_id = int(g[from].size());
        int to_id = int(g[to].size());
        if (from == to) to_id++;
        g[from].push_back(_edge{to, to_id, cap});
        g[to].push_back(_edge{from, from_id, 0});
        return m;
    }

    struct edge {
        int from, to;
        Cap cap, flow;
    };

    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }

    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
        assert(s != t);

        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;

        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) return res;
            }
            level[v] = _n;
            return res;
        };

        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            Cap f = dfs(dfs, t, flow_limit - flow);
            if (!f) break;
            flow += f;
        }
        return flow;
    }

    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }

  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};

}  // namespace atcoder

#endif  // ATCODER_MAXFLOW_HPP

using namespace atcoder;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
}Sieve(35000);

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];
    vec memo;
    vec M;
    vec M2;
    rep(i,n){
        if(a[i]%6==1)continue;
        if(a[i]%6==5)memo.push_back(a[i]);
        else{
            ll tot=0;
            for(ll j=1;j*j<a[i];j++){
                if(a[i]%j)continue;
                tot+=2;
            }
            if(tot==4)M2={a[i]};
        }
    }
    vector<P> v;
    map<ll,ll> ng;
    rep(i,memo.size()){
        vector<pair<ll,int>> now=Sieve.factor(memo[i]);
        if(now.size()==1){
            if(now[0].second==3){
                ng[now[0].first]=1;
                M.push_back(memo[i]);
            }
        }
        else if(now.size()==2){
            if(now[0].second==1&&now[1].second==1){
                v.push_back({now[0].first,now[1].first});
            }
        }
    }
    mf_graph<ll> g(10002);
    vec ids(10002);
    map<ll,ll> mp;
    ll i1=2,i2=5002;
    rep(i,v.size()){
        auto[x,y]=v[i];
        if(x%6==5)swap(x,y);
        if(ng.count(x)||ng.count(y))continue;
        if(mp.count(x))x=mp[x];
        else{
            mp[x]=i1;
            ids[i1]=x;
            x=i1;
            i1++;
            g.add_edge(0,x,1);
        }
        if(mp.count(y))y=mp[y];
        else{
            mp[y]=i2;
            ids[i2]=y;
            y=i2;
            i2++;
            g.add_edge(y,1,1);
        }
        g.add_edge(x,y,1);
    }
    g.flow(0,1);
    auto e=g.edges();
    for(auto u:e){
        ll s=u.from;
        ll t=u.to;
        ll f=u.flow;
        if(f==0||s==0||t==1)continue;
        M.push_back(ids[s]*ids[t]);
    }
    if(M.size()==0)swap(M,M2);
    if(M.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<M.size()<<endl;
    rep(i,M.size()){
        cout<<M[i]<<" ";
    }
    cout<<endl;
    return 0;
}
accuracy: 1
time_ms: 430
memory_kb: 4464
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}


//Nの正の約数を列挙する
vector<long long> Divisors(long long N){
    vector<long long> p,q;
    long long i=1,K=0;
    while(i*i<N){
        if(N%i==0){
            p.push_back(i);
            q.push_back(N/i);
            K++;
        }
        i++;
    }
    if(i*i==N) p.push_back(i);
    for(int i=K-1;i>=0;i--){
        p.push_back(q[i]);
    }
    return p;
}

namespace atcoder {
 
namespace internal {
 
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
 
}  // namespace internal
 
}  // namespace atcoder
namespace atcoder {
 
template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    mf_graph(int n) : _n(n), g(n) {}
 
    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
 
    struct edge {
        int from, to;
        Cap cap, flow;
    };
 
    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
 
    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
 
        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;
 
        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) break;
            }
            return res;
        };
 
        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                Cap f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
 
    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
 
  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};
 
}  // namespace atcoder
using namespace atcoder;

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
	//while(1) solve();
}

void solve(){
	int N,ans=0,tmp=-1;
	cin>>N;
	map<int,int> m1,m2;
	vector<int> A(N),B(N,-1),C(N,-1);
	rep(i,N){
		ll a;
		cin>>a;
		A[i]=a;
		auto p=Divisors(a);
		if((int)(p.size())==4&&a%6!=5) ans=1,tmp=a;
		if(a%6==5){
			if((int)(p.size())==4){
				int x=p[1],y=p[2];
				if(x%6==5) swap(x,y);
				if(!m1.count(x)){
					m1[x]=m1.size();
				}
				if(!m2.count(y)){
					m2[y]=m2.size();
				}
				B[i]=m1[x];
				C[i]=m2[y];
			}
		}
	}
	int X=m1.size(),Y=m2.size();
	mf_graph<int> G(X+Y+2);
	rep(i,X) G.add_edge(X+Y,i,1);
	rep(i,Y) G.add_edge(X+i,X+Y+1,1);
	rep(i,N){
		if(B[i]==-1) continue;
		G.add_edge(B[i],C[i]+X,1);
	}
	int ans2=G.flow(X+Y,X+Y+1),ind=0;
	if(ans2==0&&ans==0){
		cout<<"-1\n";
	}
	else if(ans2<ans){
		cout<<"1\n"<<tmp<<"\n";
	}
	else{
		cout<<ans2<<"\n";
		auto E=G.edges();
		for(auto x:E){
			if(x.from<X){
				while(B[ind]==-1) ind++;
				ind++;
				if(x.flow==0) continue;
				cout<<A[ind-1];
				ans2--;
				if(ans2==0) cout<<"\n";
				else cout<<" ";
			}
		}
	}
}
accuracy: 1
time_ms: 620
memory_kb: 4000
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}


//Nの正の約数を列挙する
vector<long long> Divisors(long long N){
    vector<long long> p,q;
    long long i=1,K=0;
    while(i*i<N){
        if(N%i==0){
            p.push_back(i);
            q.push_back(N/i);
            K++;
        }
        i++;
    }
    if(i*i==N) p.push_back(i);
    for(int i=K-1;i>=0;i--){
        p.push_back(q[i]);
    }
    return p;
}

namespace atcoder {
 
namespace internal {
 
template <class T> struct simple_queue {
    std::vector<T> payload;
    int pos = 0;
    void reserve(int n) { payload.reserve(n); }
    int size() const { return int(payload.size()) - pos; }
    bool empty() const { return pos == int(payload.size()); }
    void push(const T& t) { payload.push_back(t); }
    T& front() { return payload[pos]; }
    void clear() {
        payload.clear();
        pos = 0;
    }
    void pop() { pos++; }
};
 
}  // namespace internal
 
}  // namespace atcoder
namespace atcoder {
 
template <class Cap> struct mf_graph {
  public:
    mf_graph() : _n(0) {}
    mf_graph(int n) : _n(n), g(n) {}
 
    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }
 
    struct edge {
        int from, to;
        Cap cap, flow;
    };
 
    edge get_edge(int i) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        auto _e = g[pos[i].first][pos[i].second];
        auto _re = g[_e.to][_e.rev];
        return edge{pos[i].first, _e.to, _e.cap + _re.cap, _re.cap};
    }
    std::vector<edge> edges() {
        int m = int(pos.size());
        std::vector<edge> result;
        for (int i = 0; i < m; i++) {
            result.push_back(get_edge(i));
        }
        return result;
    }
    void change_edge(int i, Cap new_cap, Cap new_flow) {
        int m = int(pos.size());
        assert(0 <= i && i < m);
        assert(0 <= new_flow && new_flow <= new_cap);
        auto& _e = g[pos[i].first][pos[i].second];
        auto& _re = g[_e.to][_e.rev];
        _e.cap = new_cap - new_flow;
        _re.cap = new_flow;
    }
 
    Cap flow(int s, int t) {
        return flow(s, t, std::numeric_limits<Cap>::max());
    }
    Cap flow(int s, int t, Cap flow_limit) {
        assert(0 <= s && s < _n);
        assert(0 <= t && t < _n);
 
        std::vector<int> level(_n), iter(_n);
        internal::simple_queue<int> que;
 
        auto bfs = [&]() {
            std::fill(level.begin(), level.end(), -1);
            level[s] = 0;
            que.clear();
            que.push(s);
            while (!que.empty()) {
                int v = que.front();
                que.pop();
                for (auto e : g[v]) {
                    if (e.cap == 0 || level[e.to] >= 0) continue;
                    level[e.to] = level[v] + 1;
                    if (e.to == t) return;
                    que.push(e.to);
                }
            }
        };
        auto dfs = [&](auto self, int v, Cap up) {
            if (v == s) return up;
            Cap res = 0;
            int level_v = level[v];
            for (int& i = iter[v]; i < int(g[v].size()); i++) {
                _edge& e = g[v][i];
                if (level_v <= level[e.to] || g[e.to][e.rev].cap == 0) continue;
                Cap d =
                    self(self, e.to, std::min(up - res, g[e.to][e.rev].cap));
                if (d <= 0) continue;
                g[v][i].cap += d;
                g[e.to][e.rev].cap -= d;
                res += d;
                if (res == up) break;
            }
            return res;
        };
 
        Cap flow = 0;
        while (flow < flow_limit) {
            bfs();
            if (level[t] == -1) break;
            std::fill(iter.begin(), iter.end(), 0);
            while (flow < flow_limit) {
                Cap f = dfs(dfs, t, flow_limit - flow);
                if (!f) break;
                flow += f;
            }
        }
        return flow;
    }
 
    std::vector<bool> min_cut(int s) {
        std::vector<bool> visited(_n);
        internal::simple_queue<int> que;
        que.push(s);
        while (!que.empty()) {
            int p = que.front();
            que.pop();
            visited[p] = true;
            for (auto e : g[p]) {
                if (e.cap && !visited[e.to]) {
                    visited[e.to] = true;
                    que.push(e.to);
                }
            }
        }
        return visited;
    }
 
  private:
    int _n;
    struct _edge {
        int to, rev;
        Cap cap;
    };
    std::vector<std::pair<int, int>> pos;
    std::vector<std::vector<_edge>> g;
};
 
}  // namespace atcoder
using namespace atcoder;

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
	//while(1) solve();
}

void solve(){
	int N,ans=0,tmp=-1;
	cin>>N;
	map<int,int> m1,m2;
	vector<int> A(N),B(N,-1),C(N,-1);
	rep(i,N){
		ll a;
		cin>>a;
		A[i]=a;
		if(a==8||a==27||a==6){
			ans=1;
			tmp=a;
		}else if(a%6==5){
			auto p=Divisors(a);
			if((int)(p.size())==4){
				int x=p[1],y=p[2];
				if(x%6==5) swap(x,y);
				if(!m1.count(x)){
					m1[x]=m1.size();
				}
				if(!m2.count(y)){
					m2[y]=m2.size();
				}
				B[i]=m1[x];
				C[i]=m2[y];
			}
		}
	}
	int X=m1.size(),Y=m2.size();
	mf_graph<int> G(X+Y+2);
	rep(i,X) G.add_edge(X+Y,i,1);
	rep(i,Y) G.add_edge(X+i,X+Y+1,1);
	rep(i,N){
		if(B[i]==-1) continue;
		G.add_edge(B[i],C[i]+X,1);
	}
	int ans2=G.flow(X+Y,X+Y+1),ind=0;
	if(ans2==0&&ans==0){
		cout<<"-1\n";
	}
	else if(ans2<ans){
		cout<<"1\n"<<tmp<<"\n";
	}
	else{
		cout<<ans2<<"\n";
		auto E=G.edges();
		for(auto x:E){
			if(x.from<X){
				while(B[ind]==-1) ind++;
				ind++;
				if(x.flow==0) continue;
				cout<<A[ind-1];
				ans2--;
				if(ans2==0) cout<<"\n";
				else cout<<" ";
			}
		}
	}
}
accuracy: 0.02631578947368421
time_ms: 220
memory_kb: 3908
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.assign(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.assign(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(q % p == 0 || pow3_primes.count(p) || pow3_primes.count(q))  continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 4180
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.assign(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int a = que.front();
            que.pop();
            for(auto& b : graph[a]){
                int c = match[b];
                if(c >= 0 && dist[c] == -1){
                    dist[c] = dist[a] + 1;
                    que.emplace(c);
                }
            }
        }
    }

    bool dfs(int a){
        visited[a] = true;
        for(auto& b : graph[a]){
            int c = match[b];
            if(c < 0 || (!visited[c] && dist[c] == dist[a] + 1 && dfs(c))){
                match[b] = a;
                used[a] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.assign(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(q % p == 0 || pow3_primes.count(p) || pow3_primes.count(q))  continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 4172
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
  vector< vector< int > > graph;
  vector< int > dist, match;
  vector< bool > used, vv;

  HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

  void add_edge(int u, int v) {
    graph[u].push_back(v);
  }

  void bfs() {
    dist.assign(graph.size(), -1);
    queue< int > que;
    for(int i = 0; i < graph.size(); i++) {
      if(!used[i]) {
        que.emplace(i);
        dist[i] = 0;
      }
    }

    while(!que.empty()) {
      int a = que.front();
      que.pop();
      for(auto &b : graph[a]) {
        int c = match[b];
        if(c >= 0 && dist[c] == -1) {
          dist[c] = dist[a] + 1;
          que.emplace(c);
        }
      }
    }
  }

  bool dfs(int a) {
    vv[a] = true;
    for(auto &b : graph[a]) {
      int c = match[b];
      if(c < 0 || (!vv[c] && dist[c] == dist[a] + 1 && dfs(c))) {
        match[b] = a;
        used[a] = true;
        return (true);
      }
    }
    return (false);
  }

  int bipartite_matching() {
    int ret = 0;
    while(true) {
      bfs();
      vv.assign(graph.size(), false);
      int flow = 0;
      for(int i = 0; i < graph.size(); i++) {
        if(!used[i] && dfs(i)) ++flow;
      }
      if(flow == 0) return (ret);
      ret += flow;
    }
  }

  void output() {
    for(int i = 0; i < match.size(); i++) {
      if(~match[i]) {
        cout << match[i] << "-" << i << endl;
      }
    }
  }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(q % p == 0 || pow3_primes.count(p) || pow3_primes.count(q))  continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 4176
final_rank: 5

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<ll> A(N), ones, fives, ans;
    vector<vector<ll>> div(N);
    set<ll> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            ll p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        ll p = div[i][1], q = div[i][2];
        if(q % p == 0 || pow3_primes.count(p) || pow3_primes.count(q))  continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 0.06578947368421052
time_ms: 500
memory_kb: 4240
final_rank: 17

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(q % p == 0 || pow3_primes.count(p) || pow3_primes.count(q))  continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 0.06578947368421052
time_ms: 140
memory_kb: 3924
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(pow3_primes.count(p) || pow3_primes.count(q))    continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0 && o < O){
            ans.emplace_back(ones[o] * fives[f]);
        }
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 0.06578947368421052
time_ms: 140
memory_kb: 4048
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(ans.size() == 0) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(pow3_primes.count(p) || pow3_primes.count(q))    continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    if(M == 0)  cout << -1 << '\n';
    else{
        cout << M << '\n';
        for(int i = 0; i < M; ++i){
            cout << ans[i] << (i == M - 1 ? '\n' : ' ');
        }
    }
    
    return 0;
}
accuracy: 0.06578947368421052
time_ms: 140
memory_kb: 3852
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        if(!ans.size()) cout << -1 << '\n';
        else    cout << 1 << '\n' << ans[0] << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(pow3_primes.count(p) || pow3_primes.count(q))    continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    cout << M << '\n';
    for(int i = 0; i < M; ++i){
        cout << ans[i] << (i == M - 1 ? '\n' : ' ');
    }
    
    return 0;
}
accuracy: 0.06578947368421052
time_ms: 140
memory_kb: 4168
final_rank: 16

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];
        if(A[i] % 6 == 1)   continue;

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        cout << (ans.size() ? ans[0] : -1) << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(pow3_primes.count(p) || pow3_primes.count(q))    continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    cout << M << '\n';
    for(int i = 0; i < M; ++i){
        cout << ans[i] << (i == M - 1 ? '\n' : ' ');
    }
    
    return 0;
}
accuracy: 0.013157894736842105
time_ms: 140
memory_kb: 4016
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

struct HopcroftKarp {
    vector<vector<int>> graph;
    vector<int> dist, match;
    vector<bool> used, visited;
    
    HopcroftKarp(int n, int m) : graph(n), match(m, -1), used(n) {}

    void add_edge(int u, int v){
        graph[u].emplace_back(v);
    }

    void bfs(){
        dist.resize(graph.size(), -1);
        queue<int> que;
        for(int i = 0; i < (int)graph.size(); ++i){
            if(!used[i]){
                que.emplace(i);
                dist[i] = 0;
            }
        }
        while(!que.empty()){
            int from = que.front();
            que.pop();
            for(auto& to : graph[from]){
                int v = match[to];
                if(v >= 0 && dist[v] == -1){
                    dist[v] = dist[from] + 1;
                    que.emplace(v);
                }
            }
        }
    }

    bool dfs(int s){
        visited[s] = true;
        for(auto& u : graph[s]){
            int v = match[u];
            if(v < 0 || (!visited[v] && dist[v] == dist[s] + 1 && dfs(v))){
                match[u] = s;
                used[s] = true;
                return true;
            }
        }
        return false;
    }

    int bipartite_matching(){
        int ret = 0;
        while(true){
            bfs();
            visited.resize(graph.size(), false);
            int flow = 0;
            for(int i = 0; i < (int)graph.size(); ++i){
                if(!used[i] && dfs(i))  ++flow;
            }
            if(flow == 0)   return ret;
            ret += flow;
        }
    }

    void output(){
        for(int i = 0; i < (int)match.size(); ++i){
            if(~match[i]){
                cout << match[i] << '-' << i << '\n';
            }
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N), ones, fives, ans;
    vector<vector<int>> div(N);
    set<int> pow3_primes;

    for(int i = 0; i < N; ++i){
        cin >> A[i];

        for(int j = 1; j * j <= A[i]; ++j){
            if(A[i] % j == 0){
                div[i].emplace_back(j);
                if(j * j != A[i])   div[i].emplace_back(A[i] / j);
            }
        }
        if(div[i].size() != 4)  continue;

        if(A[i] % 6 != 5)   ans.emplace_back(A[i]);
        else{
            sort(begin(div[i]), end(div[i]));
            int p = div[i][1], q = div[i][2];
            if(q % p == 0){
                pow3_primes.emplace(p);
            }
            else{
                if(p % 6 == 5)  swap(p, q);
                ones.emplace_back(p);
                fives.emplace_back(q);
            }
        }
    }

    if(pow3_primes.size() == 0 && ones.size() == 0){
        cout << (ans.size() ? ans[0] : -1) << '\n';
        return 0;
    }

    ans.clear();
    for(auto p : pow3_primes)   ans.emplace_back(p * p * p);
    int M = ans.size();

    sort(ones.begin(), ones.end());
    ones.erase(unique(ones.begin(), ones.end()), ones.end());
    sort(fives.begin(), fives.end());
    fives.erase(unique(fives.begin(), fives.end()), fives.end());

    int O = ones.size(), F = fives.size();
    HopcroftKarp g(O, F);
    for(int i = 0; i < N; ++i){
        if(A[i] % 6 != 5 || div[i].size() != 4) continue;

        int p = div[i][1], q = div[i][2];
        if(pow3_primes.count(p) || pow3_primes.count(q))    continue;

        if(p % 6 == 5)  swap(p, q);
        int u = lower_bound(ones.begin(), ones.end(), p) - ones.begin();
        int v = lower_bound(fives.begin(), fives.end(), q) - fives.begin();
        g.add_edge(u, v);
    }

    M += g.bipartite_matching();
    for(int f = 0; f < F; ++f){
        int o = g.match[f];
        if(o >= 0)  ans.emplace_back(ones[o] * fives[f]);
    }

    cout << M << '\n';
    for(int i = 0; i < M; ++i){
        cout << ans[i] << (i == M - 1 ? '\n' : ' ');
    }
    
    return 0;
}
accuracy: 0.013157894736842105
time_ms: 160
memory_kb: 4076
final_rank: 20

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

vector<int> primes(const int upper) {
	vector<bool> is_prime(upper + 1, true);
	for (auto i = 2; i * i <= upper; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper; j += i) {
				is_prime[j] = false;
			}
		}
	}
	vector<int> result;
	for (auto i = 2; i <= upper; ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}

struct Edge {
	int to, flow, pair;
};
void bfs(const int source, const vector<vector<Edge>>& nodes, vector<int> &depth, queue<int> &queue) {
	fill(depth.begin(), depth.end(), -1); depth[source] = 0;
	queue.push(source);
	while (!queue.empty()) {
		const auto front = queue.front(); queue.pop();
		for (const auto [to, flow, _] : nodes[front]) {
			if (flow <= 0) continue;
			if (depth[to] >= 0) continue;
			depth[to] = depth[front] + 1;
			queue.push(to);
		}
	}
}
bool dfs(const int current, vector<vector<Edge>>& nodes, const vector<int>& depth, vector<int> &searching) {
	if (current + 1 == nodes.size()) return 1;
	while (searching[current] < nodes[current].size()) {
		const auto [to, flow, pair] = nodes[current][searching[current]];
		if (flow > 0 && depth[to] > depth[current]) {
			if (dfs(to, nodes, depth, searching)) {
				nodes[current][searching[current]].flow -= 1;
				nodes[to][pair].flow += 1;
				return true;
			}
		}
		++searching[current];
	}
	return false;
}
void push_flow(vector<vector<Edge>>& node, const int source, const int destination) {
	vector<int> depth(node.size()), searching(node.size(), 0);
	queue<int> queue;
	bool has_flow{ true };
	while (has_flow) {
		has_flow = false;
		bfs(source, node, depth, queue);
		fill(searching.begin(), searching.end(), 0);
		while (dfs(source, node, depth, searching)) { has_flow = true; }
	}
}
vector<int> max_matching(const vector<pair<int, int>> pair15) {
	vector<int> value1, value2; value1.reserve(pair15.size()); value2.reserve(pair15.size());
	for (auto [p1, p5] : pair15) {
		if (p1 % 6 == 5) swap(p1, p5);
		assert(p1 % 6 == 1 && p5 % 6 == 5);
		value1.push_back(p1);
		value2.push_back(p5);
	}
	sort(value1.begin(), value1.end()); sort(value2.begin(), value2.end());
	value1.erase(unique(value1.begin(), value1.end()), value1.end());
	value2.erase(unique(value2.begin(), value2.end()), value2.end());
	const int source = value1.size() + value2.size();
	const int destination = source + 1;
	vector<vector<Edge>> nodes(value1.size() + value2.size() + 2);
	unordered_map<int, int> map, rev;
	for (auto i = 0; i < value1.size(); ++i) {
		map[value1[i]] = i;
		rev[i] = value1[i];
	}
	for (auto i = 0; i < value2.size(); ++i) {
		map[value2[i]] = i + value1.size();
		rev[i + value1.size()] = value2[i];
	}
	for (auto [p1, p5] : pair15) {
		if (p1 % 6 == 5) swap(p1, p5);
		nodes[map[p1]].push_back(Edge{ map[p5], 1, (int)nodes[map[p5]].size() });
		nodes[map[p5]].push_back(Edge{ map[p1], 0, (int)nodes[map[p1]].size() - 1 });
	}
	for (auto i = 0; i < value1.size(); ++i) {
		nodes[source].push_back(Edge{ i, 1, (int)nodes[i].size() });
		nodes[i].push_back(Edge{ source, 0, (int)nodes[source].size() - 1 });
	}
	for (auto i = 0; i < value2.size(); ++i) {
		nodes[destination].push_back(Edge{ (int)value1.size() + i, 0, (int)nodes[value1.size() + i].size() });
		nodes[value1.size() + i].push_back(Edge{ destination, 1, (int)nodes[destination].size() - 1 });
	}
	push_flow(nodes, source, destination);
	vector<int> result;
	for (auto i = 0; i < value1.size(); ++i) {
		for (const auto [to, flow, _] : nodes[i]) {
			if (to == source) continue;
			if (flow > 0) continue;
			result.emplace_back(rev[i] * rev[to]);
		}
	}
	return result;
}
int main() {
	int n; cin >> n;
	vector<int> values(n); for (auto& a : values) cin >> a;
	values.erase(remove_if(values.begin(), values.end(), [](const int a) {return a % 6 == 1; }), values.end());
	const auto prime = primes(sqrt(1000000000));
	vector<vector<int>> prime_factors(values.size());
	for (auto i = 0; i < values.size(); ++i) {
		auto a = values[i];
		for (const auto p : prime) {
			if (a < p) break;
			while (a % p == 0) {
				prime_factors[i].push_back(p);
				a /= p;
			}
		}
		if (a != 1) prime_factors[i].push_back(a);
	}
	vector<pair<int, int>> pair15;
	for (const auto& p : prime_factors) {
		if (p.size() == 2 && p[0] % 6 * p[1] % 6 == 5) {
			if (p[0] % 6 == 1) pair15.emplace_back(p[0], p[1]);
			else pair15.emplace_back(p[1], p[0]);
		}
	}
	vector<int> cube5;
	set<int> used;
	for (const auto p : prime_factors) {
		if (p.size() == 3 && p[0] == p[2] && p[0] % 6 == 5) {
			cube5.push_back(p[0] * p[1] * p[2]);
			used.insert(p[0]);
		}
	}
	if (pair15.empty() && cube5.empty()) {
		for (const auto& p : prime_factors) {
			if (p.size() == 2 && p[0] != p[1]) {
				cout << "1\n";
				cout << p[0] * p[1] << '\n';
				return 0;
			}
			if (p.size() == 3 && p[0] == p[2]) {
				cout << "1\n";
				cout << p[0] * p[1] * p[2] << '\n';
				return 0;
			}
		}
		cout << "-1\n";
	}
	else {
		pair15.erase(remove_if(pair15.begin(), pair15.end(), [&used](const pair<int, int> p) {return used.find(p.second) != used.end(); }), pair15.end());
		auto selected = max_matching(pair15);
		copy(cube5.begin(), cube5.end(), back_inserter(selected));
		cout << selected.size() << '\n';
		for (auto i = 0; i < selected.size(); ++i) {
			if (i > 0) cout << ' ';
			cout << selected[i];
		}
		cout << '\n';
	}
}
accuracy: 1
time_ms: 20
memory_kb: 4320
final_rank: 2

code_snippet: #include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

vector<int> primes(const int upper) {
	vector<bool> is_prime(upper + 1, true);
	for (auto i = 2; i * i <= upper; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper; j += i) {
				is_prime[j] = false;
			}
		}
	}
	vector<int> result;
	for (auto i = 2; i <= upper; ++i) {
		if (is_prime[i]) result.push_back(i);
	}
	return result;
}

struct Edge {
	int to, flow, pair;
};
void bfs(const int source, const vector<vector<Edge>>& nodes, vector<int> &depth, queue<int> &queue) {
	fill(depth.begin(), depth.end(), -1); depth[source] = 0;
	queue.push(source);
	while (!queue.empty()) {
		const auto front = queue.front(); queue.pop();
		for (const auto [to, flow, _] : nodes[front]) {
			if (flow <= 0) continue;
			if (depth[to] >= 0) continue;
			depth[to] = depth[front] + 1;
			queue.push(to);
		}
	}
}
bool dfs(const int current, vector<vector<Edge>>& nodes, const vector<int>& depth, vector<int> &searching) {
	if (current + 1 == nodes.size()) return 1;
	while (searching[current] < nodes[current].size()) {
		const auto [to, flow, pair] = nodes[current][searching[current]];
		if (flow > 0 && depth[to] > depth[current]) {
			if (dfs(to, nodes, depth, searching)) {
				nodes[current][searching[current]].flow -= 1;
				nodes[to][pair].flow += 1;
				return true;
			}
		}
		++searching[current];
	}
	return false;
}
void push_flow(vector<vector<Edge>>& node, const int source, const int destination) {
	vector<int> depth(node.size()), searching(node.size(), 0);
	queue<int> queue;
	bool has_flow{ true };
	while (has_flow) {
		has_flow = false;
		bfs(source, node, depth, queue);
		fill(searching.begin(), searching.end(), 0);
		while (dfs(source, node, depth, searching)) { has_flow = true; }
	}
}
vector<int> max_matching(const vector<pair<int, int>> pair15) {
	vector<int> value1, value2; value1.reserve(pair15.size()); value2.reserve(pair15.size());
	for (auto [p1, p5] : pair15) {
		if (p1 % 6 == 5) swap(p1, p5);
		assert(p1 % 6 == 1 && p5 % 6 == 5);
		value1.push_back(p1);
		value2.push_back(p5);
	}
	sort(value1.begin(), value1.end()); sort(value2.begin(), value2.end());
	value1.erase(unique(value1.begin(), value1.end()), value1.end());
	value2.erase(unique(value2.begin(), value2.end()), value2.end());
	const int source = value1.size() + value2.size();
	const int destination = source + 1;
	vector<vector<Edge>> nodes(value1.size() + value2.size() + 2);
	unordered_map<int, int> map, rev;
	for (auto i = 0; i < value1.size(); ++i) {
		map[value1[i]] = i;
		rev[i] = value1[i];
	}
	for (auto i = 0; i < value2.size(); ++i) {
		map[value2[i]] = i + value1.size();
		rev[i + value1.size()] = value2[i];
	}
	for (auto [p1, p5] : pair15) {
		if (p1 % 6 == 5) swap(p1, p5);
		nodes[map[p1]].push_back(Edge{ map[p5], 1, (int)nodes[map[p5]].size() });
		nodes[map[p5]].push_back(Edge{ map[p1], 0, (int)nodes[map[p1]].size() - 1 });
	}
	for (auto i = 0; i < value1.size(); ++i) {
		nodes[source].push_back(Edge{ i, 1, (int)nodes[i].size() });
		nodes[i].push_back(Edge{ source, 0, (int)nodes[source].size() - 1 });
	}
	for (auto i = 0; i < value2.size(); ++i) {
		nodes[destination].push_back(Edge{ (int)value1.size() + i, 0, (int)nodes[value1.size() + i].size() });
		nodes[value1.size() + i].push_back(Edge{ destination, 1, (int)nodes[destination].size() - 1 });
	}
	push_flow(nodes, source, destination);
	vector<int> result;
	for (auto i = 0; i < value1.size(); ++i) {
		for (const auto [to, flow, _] : nodes[i]) {
			if (to == source) continue;
			if (flow > 0) continue;
			result.emplace_back(rev[i] * rev[to]);
		}
	}
	return result;
}
int main() {
	int n; cin >> n;
	vector<int> values(n); for (auto& a : values) cin >> a;
	values.erase(remove_if(values.begin(), values.end(), [](const int a) {return a % 6 == 1; }), values.end());
	const auto prime = primes(sqrt(1000000000));
	vector<vector<int>> prime_factors(values.size());
	for (auto i = 0; i < values.size(); ++i) {
		auto a = values[i];
		for (const auto p : prime) {
			if (a < p) break;
			while (a % p == 0) {
				prime_factors[i].push_back(p);
				a /= p;
			}
		}
		if (a != 1) prime_factors[i].push_back(a);
	}
	vector<pair<int, int>> pair15;
	for (const auto& p : prime_factors) {
		if (p.size() == 2 && p[0] % 6 * p[1] % 6 == 5) {
			if (p[0] % 6 == 1) pair15.emplace_back(p[0], p[1]);
			else pair15.emplace_back(p[1], p[0]);
		}
	}
	if (pair15.empty()) {
		for (const auto& p : prime_factors) {
			if (p.size() == 2 && p[0] != p[1]) {
				cout << "1\n";
				cout << p[0] * p[1] << '\n';
				return 0;
			}
			if (p.size() == 3 && p[0] == p[2]) {
				cout << "1\n";
				cout << p[0] * p[1] * p[2] << '\n';
				return 0;
			}
		}
		cout << "-1\n";
	}
	else {
		vector<int> cube;
		set<int> used;
		for (const auto p : prime_factors) {
			if (p.size() == 3 && p[0] == p[2] && p[0] % 6 == 5) {
				cube.push_back(p[0] * p[1] * p[2]);
				used.insert(p[0]);
			}
		}
		pair15.erase(remove_if(pair15.begin(), pair15.end(), [&used](const pair<int, int> p) {return used.find(p.second) != used.end(); }), pair15.end());
		auto selected = max_matching(pair15);
		copy(cube.begin(), cube.end(), back_inserter(selected));
		cout << selected.size() << '\n';
		for (auto i = 0; i < selected.size(); ++i) {
			if (i > 0) cout << ' ';
			cout << selected[i];
		}
		cout << '\n';
	}
}
accuracy: 0.42105263157894735
time_ms: 20
memory_kb: 4156
final_rank: 10

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

struct flow_edge{
    int to,rev;
    long long int cap;
    bool valid=true;
    int elem=-1;
    flow_edge(int a,long long int b,int d,int e):to(a),cap(b),rev(d),elem(e){}
    flow_edge(int a,long long int b,int d):to(a),cap(b),rev(d){}
};

class FordFulkerson{
    typedef long long int type;
    const type infty=1LL<<60;
    typedef pair<type,int> TP;
    vector<vector<flow_edge>> flow_path;
    vector<type> pot,dis;
    vector<int> prevv,preve;
    vector<char> used;
public:
    FordFulkerson(){};
    FordFulkerson(vector<vector<flow_edge>>& path_tmp):flow_path(path_tmp){}
    FordFulkerson(int n){
        flow_path.assign(n,vector<flow_edge>());
    }

    void add_edge(int from,int to,int cap,int elem){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j,elem));
        flow_path[to].push_back(flow_edge(from,0,i));
    }
    void add_bidirectional_edge(int from,int to,int cap){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j));
        flow_path[to].push_back(flow_edge(from,cap,i));
    }

    type dfs(int pos,int t,type f){
        if(pos==t)return f;
        if(f==0)return 0;
        used[pos]=true;
        for(auto& edge:flow_path[pos]){
            if(used[edge.to] || edge.cap==0)continue;
            type d=dfs(edge.to,t,min(f,(type)edge.cap));
            if(d>0){
                edge.cap-=d,flow_path[edge.to][edge.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }

    type calc(int ps,int pt){
        type s=0;
        int n=flow_path.size();
        while(1){
            used.assign(n,0);
            type f=dfs(ps,pt,infty);
            if(f==0)return s;
            s+=f;
        }
        return s;
    }

    vector<int> construct(){
        vector<int> vs;
        for(auto& v:flow_path){
            for(auto& node:v){
                if(node.elem!=-1 && node.cap==0)vs.push_back(node.elem);
            }
        }
        return vs;
    }
};

const int N=4e4;
bool prd[42000];

int main(){
    LL n,m;
    LL i,j,k;
    LL a,b,c;
    vector<int> prim;
    for(i=2;i<N;i++){
        if(prd[i])continue;
        prim.push_back(i);
        for(j=2*i;j<N;j+=i)prd[j]=true;
    }
    cin>>n;
    FordFulkerson flow(2*n+10);
    const int start_pos=2*n+5,end_pos=2*n+6;
    map<int,int> m1;
    LL p=-1;
    for(i=0;i<n;i++){
        cin>>a;
        b=-1,c=0;
        for(auto num:prim){
            if(a%num==0)b=num,c++;
        }
        if(b*b*b==a){
            if(a%6==5){
                if(m1.find(b)==m1.end())m1[b]=n+i;
                b=m1[b];
                flow.add_edge(2*n+1,b,1,a);
            }else if(a%6!=1)p=a;
            continue;
        }
        if(c==0 || c>2)continue;
        if(!(c==1 && a/b>N && a%(b*b)!=0) && !(c==2 && a/b<N && !prd[a/b]))continue;
        c=a/b;
        if(b<4 || c<4){
            p=a;
            continue;
        }
        if(a%6!=5)continue;
        if(b%6==5)swap(b,c);
        if(m1.find(b)==m1.end())m1[b]=i;
        if(m1.find(c)==m1.end())m1[c]=n+i;
        b=m1[b],c=m1[c];
        flow.add_edge(b,c,1,a);
    }
    for(i=0;i<n;i++){
        flow.add_edge(start_pos,i,1,-1);
        flow.add_edge(n+i,end_pos,1,-1);
    }
    flow.add_edge(start_pos,2*n+1,n,-1);
    a=flow.calc(start_pos,end_pos);
    vector<int> vs=flow.construct();
    if(a==0){
        if(p!=-1){
            cout<<1<<endl;
            cout<<p<<endl;
            return 0;
        }
        cout<<-1<<endl;
        return 0;
    }
    cout<<a<<endl;
    array_show(vs);
}
accuracy: 1
time_ms: 160
memory_kb: 4260
final_rank: 7

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

struct flow_edge{
    int to,rev;
    long long int cap;
    bool valid=true;
    int elem=-1;
    flow_edge(int a,long long int b,int d,int e):to(a),cap(b),rev(d),elem(e){}
    flow_edge(int a,long long int b,int d):to(a),cap(b),rev(d){}
};

class FordFulkerson{
    typedef long long int type;
    const type infty=1LL<<60;
    typedef pair<type,int> TP;
    vector<vector<flow_edge>> flow_path;
    vector<type> pot,dis;
    vector<int> prevv,preve;
    vector<char> used;
public:
    FordFulkerson(){};
    FordFulkerson(vector<vector<flow_edge>>& path_tmp):flow_path(path_tmp){}
    FordFulkerson(int n){
        flow_path.assign(n,vector<flow_edge>());
    }

    void add_edge(int from,int to,int cap,int elem){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j,elem));
        flow_path[to].push_back(flow_edge(from,0,i));
    }
    void add_bidirectional_edge(int from,int to,int cap){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j));
        flow_path[to].push_back(flow_edge(from,cap,i));
    }

    type dfs(int pos,int t,type f){
        if(pos==t)return f;
        if(f==0)return 0;
        used[pos]=true;
        for(auto& edge:flow_path[pos]){
            if(used[edge.to] || edge.cap==0)continue;
            type d=dfs(edge.to,t,min(f,(type)edge.cap));
            if(d>0){
                edge.cap-=d,flow_path[edge.to][edge.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }

    type calc(int ps,int pt){
        type s=0;
        int n=flow_path.size();
        while(1){
            used.assign(n,0);
            type f=dfs(ps,pt,infty);
            if(f==0)return s;
            s+=f;
        }
        return s;
    }

    vector<int> construct(){
        vector<int> vs;
        for(auto& v:flow_path){
            for(auto& node:v){
                if(node.elem!=-1 && node.cap==0)vs.push_back(node.elem);
            }
        }
        return vs;
    }
};

const int N=4e4;
bool prd[42000];

int main(){
    LL n,m;
    LL i,j,k;
    LL a,b,c;
    vector<int> prim;
    for(i=2;i<N;i++){
        if(prd[i])continue;
        prim.push_back(i);
        for(j=2*i;j<N;j+=i)prd[j]=true;
    }
    cin>>n;
    FordFulkerson flow(2*n+10);
    const int start_pos=2*n+5,end_pos=2*n+6;
    map<int,int> m1;
    LL p=-1;
    for(i=0;i<n;i++){
        cin>>a;
        b=-1,c=0;
        for(auto num:prim){
            if(a%num==0)b=num,c++;
        }
        if(b*b*b==a){
            if(a%6==5){
                if(m1.find(b)==m1.end())m1[b]=n+i;
                b=m1[b];
                flow.add_edge(2*n+1,b,1,a);
                continue;
            }else if(a%6!=1)p=a;
        }
        if(c==0 || c>2)continue;
        if(!(c==1 && a/b>N) && !(c==2 && a/b<N && !prd[a/b]))continue;
        c=a/b;
        if(b<4 || c<4){
            p=a;
            continue;
        }
        if(a%6!=5)continue;
        if(b%6==5)swap(b,c);
        if(m1.find(b)==m1.end())m1[b]=i;
        if(m1.find(c)==m1.end())m1[c]=n+i;
        b=m1[b],c=m1[c];
        flow.add_edge(b,c,1,a);
    }
    for(i=0;i<n;i++){
        flow.add_edge(start_pos,i,1,-1);
        flow.add_edge(n+i,end_pos,1,-1);
    }
    flow.add_edge(start_pos,2*n+1,n,-1);
    a=flow.calc(start_pos,end_pos);
    vector<int> vs=flow.construct();
    if(a==0){
        if(p!=-1){
            cout<<1<<endl;
            cout<<p<<endl;
            return 0;
        }
        cout<<-1<<endl;
        return 0;
    }
    cout<<a<<endl;
    array_show(vs);
}
accuracy: 0.11842105263157894
time_ms: 170
memory_kb: 4220
final_rank: 12

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

struct flow_edge{
    int to,rev;
    long long int cap;
    bool valid=true;
    int elem=-1;
    flow_edge(int a,long long int b,int d,int e):to(a),cap(b),rev(d),elem(e){}
    flow_edge(int a,long long int b,int d):to(a),cap(b),rev(d){}
};

class FordFulkerson{
    typedef long long int type;
    const type infty=1LL<<60;
    typedef pair<type,int> TP;
    vector<vector<flow_edge>> flow_path;
    vector<type> pot,dis;
    vector<int> prevv,preve;
    vector<char> used;
public:
    FordFulkerson(){};
    FordFulkerson(vector<vector<flow_edge>>& path_tmp):flow_path(path_tmp){}
    FordFulkerson(int n){
        flow_path.assign(n,vector<flow_edge>());
    }

    void add_edge(int from,int to,int cap,int elem){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j,elem));
        flow_path[to].push_back(flow_edge(from,0,i));
    }
    void add_bidirectional_edge(int from,int to,int cap){
        int n=flow_path.size();
        assert(0<=from && from<n);
        assert(0<=to && to<n);
        int i=flow_path[from].size(),j=flow_path[to].size();
        flow_path[from].push_back(flow_edge(to,cap,j));
        flow_path[to].push_back(flow_edge(from,cap,i));
    }

    type dfs(int pos,int t,type f){
        if(pos==t)return f;
        if(f==0)return 0;
        used[pos]=true;
        for(auto& edge:flow_path[pos]){
            if(used[edge.to] || edge.cap==0)continue;
            type d=dfs(edge.to,t,min(f,(type)edge.cap));
            if(d>0){
                edge.cap-=d,flow_path[edge.to][edge.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }

    type calc(int ps,int pt){
        type s=0;
        int n=flow_path.size();
        while(1){
            used.assign(n,0);
            type f=dfs(ps,pt,infty);
            if(f==0)return s;
            s+=f;
        }
        return s;
    }

    vector<int> construct(){
        vector<int> vs;
        for(auto& v:flow_path){
            for(auto& node:v){
                if(node.elem!=-1 && node.cap==0)vs.push_back(node.elem);
            }
        }
        return vs;
    }
};

const int N=4e4;
bool prd[42000];

int main(){
    LL n,m;
    LL i,j,k;
    LL a,b,c;
    vector<int> prim;
    for(i=2;i<N;i++){
        if(prd[i])continue;
        prim.push_back(i);
        for(j=2*i;j<N;j+=i)prd[j]=true;
    }
    cin>>n;
    FordFulkerson flow(2*n+10);
    const int start_pos=2*n+5,end_pos=2*n+6;
    map<int,int> m1;
    LL p=-1;
    for(i=0;i<n;i++){
        cin>>a;
        b=-1,c=0;
        for(auto num:prim){
            if(a%num==0)b=num,c++;
        }
        if(b*b*b==a){
            if(a%6==5){
                if(m1.find(b)==m1.end())m1[b]=n+i;
                b=m1[b];
                flow.add_edge(2*n+1,b,1,a);
                continue;
            }
            p=a;
        }
        if(c==0 || c>2)continue;
        if(!(c==1 && a/b>N) && !(c==2 && a/b<N && !prd[a/b]))continue;
        c=a/b;
        if(b<4 || c<4){
            p=a;
            continue;
        }
        if(a%6!=5)continue;
        if(b%6==5)swap(b,c);
        if(m1.find(b)==m1.end())m1[b]=i;
        if(m1.find(c)==m1.end())m1[c]=n+i;
        b=m1[b],c=m1[c];
        flow.add_edge(b,c,1,a);
    }
    for(i=0;i<n;i++){
        flow.add_edge(start_pos,i,1,-1);
        flow.add_edge(n+i,end_pos,1,-1);
    }
    flow.add_edge(start_pos,2*n+1,n,-1);
    a=flow.calc(start_pos,end_pos);
    vector<int> vs=flow.construct();
    if(a==0){
        if(p!=-1){
            cout<<1<<endl;
            cout<<p<<endl;
            return 0;
        }
        cout<<-1<<endl;
        return 0;
    }
    cout<<a<<endl;
    array_show(vs);
}
accuracy: 0.11842105263157894
time_ms: 170
memory_kb: 4188
final_rank: 11

code_snippet: //
// Created by yamunaku on 2020/12/14.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

template<typename flow_t>
struct Dinic {
    const flow_t INF;

    struct edge {
        int to;
        flow_t cap;
        int rev;
        bool isrev;
        int idx;
    };

    vector<vector<edge> > graph;
    vector<int> min_cost, iter;

    Dinic(int V) : INF(numeric_limits<flow_t>::max()), graph(V) {}

    void add_edge(int from, int to, flow_t cap, int idx = -1) {
        graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false, idx});
        graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true, idx});
    }

    bool bfs(int s, int t) {
        min_cost.assign(graph.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while (!que.empty() && min_cost[t] == -1) {
            int p = que.front();
            que.pop();
            for (auto &e : graph[p]) {
                if (e.cap > 0 && min_cost[e.to] == -1) {
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }

    flow_t dfs(int idx, const int t, flow_t flow) {
        if (idx == t) return flow;
        for (int &i = iter[idx]; i < graph[idx].size(); i++) {
            edge &e = graph[idx][i];
            if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
                flow_t d = dfs(e.to, t, min(flow, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    flow_t max_flow(int s, int t) {
        flow_t flow = 0;
        while (bfs(s, t)) {
            iter.assign(graph.size(), 0);
            flow_t f = 0;
            while ((f = dfs(s, t, INF)) > 0) flow += f;
        }
        return flow;
    }

    void output() {
        for (int i = 0; i < graph.size(); i++) {
            for (auto &e : graph[i]) {
                if (e.isrev) continue;
                auto &rev_e = graph[e.to][e.rev];
                cout << i << "->" << e.to << " (flow: " << rev_e.cap << "/" << e.cap + rev_e.cap << ")" << endl;
            }
        }
    }
};

int main() {
    //CFS;
    int n;
    cin >> n;
    mti a(6);
    map<int, vi> p;
    set<int> st;
    rep(i, n) {
        int x;
        cin >> x;
        if (x == 8) a[2].push_back(8);
        if (x == 27) a[3].push_back(27);
        int tmp = x;
        repl(k, 2, 40000) {
            if (tmp % k == 0) {
                int c = 0;
                while (tmp % k == 0) tmp /= k, c++;
                if (c == 3 && tmp == 1 && p[x].size() == 0) {
                    if (k % 6 == 5) st.insert(k);
                    goto next;
                }
                if(c != 1) goto next;
                p[x].push_back(k);
            }
        }
        if (tmp != 1) p[x].push_back(tmp);
        if (p[x].size() != 2) goto next;
        a[x % 6].push_back(x);
        next:;
    }
    vi ans;
    if (a[0].size() > 0) ans = {a[0][0]};
    if (a[2].size() > 0) ans = {a[2][0]};
    if (a[3].size() > 0) ans = {a[3][0]};
    if (a[4].size() > 0) ans = {a[4][0]};
    map<int, int> left, right;
    for (auto &x : a[5]) {
        if (p[x][0] % 6 == 5) swap(p[x][0], p[x][1]);
        left[p[x][0]] = 0;
        right[p[x][1]] = 0;
    }
    int lsz = 0, rsz = 0;
    for (auto &pa : left) pa.second = lsz++;
    for (auto &pa : right) pa.second = rsz++;
    Dinic<int> dc(lsz + rsz + 2);
    int s = lsz + rsz, t = s + 1;
    rep(i, lsz) dc.add_edge(s, i, 1);
    rep(i, rsz) dc.add_edge(lsz + i, t, 1);
    for (auto &x : a[5]) {
        if (st.find(p[x][1]) == st.end())
            dc.add_edge(left[p[x][0]], lsz + right[p[x][1]], 1, x);
    }
    dc.max_flow(s, t);
    vi tmp;
    rep(i, lsz) {
        for (auto &e : dc.graph[i]) {
            if (!e.isrev && e.cap == 0) {
                tmp.push_back(e.idx);
            }
        }
    }
    for (auto &x : st){
        tmp.push_back(x * x * x);
    }
    if (tmp.size() > ans.size()) ans = tmp;
    if (ans.size() == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans.size() << endl;
    for (auto &x : ans) cout << x << " ";
    cout << endl;
    return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 3768
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template <typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#else
#define dbg(x) {}
#endif

// Sieve of Eratosthenes
// (*this)[i] = (divisor of i, greater than 1)
// Example: [0, 1, 2, 3, 2, 5, 3, 7, 2, 3, 2, 11, ...]
// Complexity: Space O(MAXN), Time (construction) O(MAXNloglogMAXN)
struct SieveOfEratosthenes : std::vector<int> {
    std::vector<int> primes;
    SieveOfEratosthenes(int MAXN) : std::vector<int>(MAXN + 1) {
        std::iota(begin(), end(), 0);
        for (int i = 2; i <= MAXN; i++) {
            if ((*this)[i] == i) {
                primes.push_back(i);
                for (int j = i; j <= MAXN; j += i) (*this)[j] = i;
            }
        }
    }
    using T = long long int;
    // Prime factorization for x <= MAXN^2
    // Complexity: O(log x)          (x <= MAXN)
    //             O(MAXN / logMAXN) (MAXN < x <= MAXN^2)
    std::map<T, int> Factorize(T x) {
        assert(x <= 1LL * (int(size()) - 1) * (int(size()) - 1));
        std::map<T, int> ret;
        if (x < int(size())) {
            while (x > 1) {
                ret[(*this)[x]]++;
                x /= (*this)[x];
            }
        } else {
            for (auto p : primes) {
                while (!(x % p)) x /= p, ret[p]++;
                if (x == 1) break;
            }
            if (x > 1) ret[x]++;
        }
        return ret;
    }
    std::vector<T> Divisors(T x) {
        std::vector<T> ret{1};
        for (auto p : Factorize(x)) {
            int n = ret.size();
            for (int i = 0; i < n; i++) {
                for (T a = 1, d = 1; d <= p.second; d++) {
                    a *= p.first;
                    ret.push_back(ret[i] * a);
                }
            }
        }
        return ret; // Not sorted
    }
    // Moebius function Table
    // return: [0=>0, 1=>1, 2=>-1, 3=>-1, 4=>0, 5=>-1, 6=>1, 7=>-1, 8=>0, ...]
    std::vector<int> GenerateMoebiusFunctionTable() {
        std::vector<int> ret(size());
        for (int i = 1; i < int(size()); i++) {
            if (i == 1)
                ret[i] = 1;
            else if ((i / (*this)[i]) % (*this)[i] == 0)
                ret[i] = 0;
            else
                ret[i] = -ret[i / (*this)[i]];
        }
        return ret;
    }
};
SieveOfEratosthenes sieve(1 << 15);

// Bipartite matching of undirected bipartite graph (Hopcroft-Karp)
// <https://ei1333.github.io/luzhiled/snippets/graph/hopcroft-karp.html>
// Comprexity: O(EsqrtV)
// int solve(): enumerate maximum number of matching / return -1 (if graph is not bipartite)
struct BipartiteMatching {
    int V;
    std::vector<std::vector<int>> to; // Adjacency list
    std::vector<int> dist;            // dist[i] = (Distance from i'th node)
    std::vector<int> match;           // match[i] = (Partner of i'th node) or -1 (No parter)
    std::vector<int> used, vv;        //
    std::vector<int> color;           // color of each node(checking bipartition): 0/1/-1(not determined)

    BipartiteMatching() = default;
    BipartiteMatching(int V_) : V(V_), to(V_), match(V_, -1), used(V_), color(V_, -1) {}

    void add_edge(int u, int v) {
        assert(u >= 0 and u < V and v >= 0 and v < V and u != v);
        to[u].push_back(v);
        to[v].push_back(u);
    }

    void bfs() {
        dist.assign(V, -1);
        std::queue<int> q;
        for (int i = 0; i < V; i++) {
            if (!color[i] and !used[i]) { q.emplace(i), dist[i] = 0; }
        }

        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (auto nxt : to[now]) {
                int c = match[nxt];
                if (c >= 0 and dist[c] == -1) { q.emplace(c), dist[c] = dist[now] + 1; }
            }
        }
    }

    bool dfs(int now) {
        vv[now] = true;
        for (auto nxt : to[now]) {
            int c = match[nxt];
            if (c < 0 or (!vv[c] and dist[c] == dist[now] + 1 and dfs(c))) {
                match[nxt] = now, match[now] = nxt;
                used[now] = true;
                return true;
            }
        }
        return false;
    }

    bool _color_bfs(int root) {
        color[root] = 0;
        std::queue<int> q;
        q.emplace(root);
        while (!q.empty()) {
            int now = q.front(), c = color[now];
            q.pop();
            for (auto nxt : to[now])
                if (color[nxt] == -1)
                    color[nxt] = !c, q.emplace(nxt);
                else if (color[nxt] == c)
                    return false;
        }
        return true;
    }

    int solve() {
        for (int i = 0; i < V; i++)
            if (color[i] == -1) {
                if (!_color_bfs(i)) return -1;
            }
        int ret = 0;
        while (true) {
            bfs();
            vv.assign(V, false);
            int flow = 0;
            for (int i = 0; i < V; i++)
                if (!color[i] and !used[i] and dfs(i)) flow++;
            if (!flow) break;
            ret += flow;
        }
        return ret;
    }

    friend std::ostream &operator<<(std::ostream &os, const BipartiteMatching &bm) {
        os << "{N=" << bm.V << ':';
        for (int i = 0; i < bm.V; i++)
            if (bm.match[i] > i) { os << '(' << i << '-' << bm.match[i] << "),"; }
        os << '}';
        return os;
    }
};

int main()
{
    int N;
    cin >> N;
    array<vector<pint>, 6> A;
    while (N--) {
        int a;
        cin >> a;
        if (a % 6 != 1) {
            auto f = sieve.Divisors(a);
            sort(f.begin(), f.end());
            if (f.size() == 4) A[a % 6].emplace_back(f[1], f[2]);
        }
    }
    vector<int> ret;
    REP(d, 6) {
        if (A[d].size() and ret.empty()) ret = {A[d][0].first * A[d][0].second};

        if (d == 1 or d == 5) {
            vector<int> vs;
            for (auto [u, v] : A[d]) vs.emplace_back(u), vs.emplace_back(v);
            vs = sort_unique(vs);
            BipartiteMatching bm(vs.size());
            for (auto [u, v] : A[d]) {
                u = lower_bound(vs.begin(), vs.end(), u) - vs.begin();
                v = lower_bound(vs.begin(), vs.end(), v) - vs.begin();
                bm.add_edge(u, v);
            }
            int tmp = bm.solve();
            if (tmp > ret.size()) {
                ret.clear();
                REP(i, vs.size()) if (bm.match[i] >= 0) ret.emplace_back(vs[i] * vs[bm.match[i]]);
                ret = sort_unique(ret);
            }
        }
    }

    if (ret.size()) {
        cout << ret.size() << '\n';
        for (auto x : ret) cout << x << ' ';
        cout << '\n';
    } else {
        puts("-1");
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3552
final_rank: 1