#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = int(1e5) + 100;

int v[MAX_N],n;

bool good(const int &bit)
{
    int RES = ~0u >> 1;

    for(int i = 0 ; i < n ; ++ i)
        if(v[i] >> bit)
            RES &= v[i];

    const unsigned int bitmask = ( 1LL << (bit) )- 1;

    return (RES & bitmask) == 0;
}

int main()
{
    scanf("%d",&n);

    for(int i = 0 ; i < n ; ++ i)
        scanf("%d",v+i);

    int bit,i;

    for(i = 30 ; i >= 0 && !good(i); -- i);

    bit = i;

    vector<int> sol;

    for(i = 0 ; i < n ; ++ i)
        if(v[i] >> bit)
            sol.push_back(v[i]);

    printf("%d\n",sol.size());

    for(i = sol.size() - 1 ; i >= 0 ; -- i)
        printf("%d ",sol[i]);

    printf("\n");

    return 0;
}


#include <cstdio>
#include <vector>

using namespace std;

const int MAX_N = int(1e5) + 100;

int v[MAX_N],n;

bool good(const int &bit)
{
    int RES = ~0u >> 1;

    for(int i = 0 ; i < n ; ++ i)
        if(v[i] & (1 << bit))
            RES &= v[i];

    const unsigned int bitmask = ( 1LL << (bit) )- 1;

    return (RES & bitmask) == 0;
}

int main()
{
    scanf("%d",&n);

    for(int i = 0 ; i < n ; ++ i)
        scanf("%d",v+i);

    int bit,i;

    for(i = 30 ; i > 0 && !good(i); -- i);

    if(i == 0){
        printf("-1\n");
        return 0;
    }

    bit = i;

    vector<int> sol;

    for(i = 0 ; i < n ; ++ i)
        if(v[i] >> bit)
            sol.push_back(v[i]);

    printf("%d\n",sol.size());

    for(i = sol.size() - 1 ; i >= 0 ; -- i)
        printf("%d ",sol[i]);

    printf("\n");

    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

const int MAX_N = int(1e6) + 100;

int v[MAX_N],n;

bool good(const int &bit)
{
    int RES = (1 << 30 )- 1;

    for(int i = 0 ; i < n ; ++ i)
        if(v[i] & (1 << bit))
            RES &= v[i];

    return RES % (1 << bit) == 0;

}

int main()
{
    scanf("%d",&n);

    for(int i = 0 ; i < n ; ++ i)
        scanf("%d",v+i);

    int bit,i;

    for(i = 30 ; i > 0 && !good(i); -- i);

    if(i == 0){
        printf("-1\n");
        return 0;
    }

    bit = i;

    vector<int> sol;

    for(i = 0 ; i < n ; ++ i)
        if(v[i] & (1 << bit))
            sol.push_back(v[i]);

    printf("%d\n",sol.size());

    sort(sol.begin(),sol.end(),greater<int>());

    for(i = sol.size() - 1 ; i >= 0 ; -- i)
        printf("%d ",sol[i]);

    printf("\n");

    return 0;
}


/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. KEE O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */

const ll mod = 1000000009;
int log2(int x){
    int res = 0;
    while(x){
        res++;
        x>>=1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur;
    V<int> a,res;
    cin>>n;
    while(n--){cin>>cur;a.pb(cur);}
    int max_log = log2(a.back());
    res.pb(a.back());
    For(i,a.size()-1,0){
        if(log2(a[i]) == max_log)
            res.pb(a[i]);
        else
            break;
    }
    cout<<res.size()<<endl;
    For(i,0,res.size())
        cout<<res[i]<<" \n"[i==res.size()-1];
    return 0;
}
/**/


/**/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(v) v.begin(),v.end()
#define V vector
typedef long long ll;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted. KEE O.o
 *      ____________
 *     /         __ \
 *    /   __    |  | \
 *   /   |__|   |  |  \
 *  (           |__|   )
 *   \                /
 *    \      ___     /
 *     \____________/
 */

const ll mod = 1000000009;
int log2(int x){
    int res = 0;
    while(x){
        res++;
        x>>=1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,cur;
    V<int> a,res,ans;
    cin>>n;
    while(n--){
        cin>>cur;
        a.pb(cur);
    }
    For(i,0,31){
        int cur = INT_MAX;
        res.clear();
        For(j,0,a.size()){
            if((a[j] & (1<<i))){
                res.pb(a[j]);
                cur&=a[j];
            }
        }
        if((cur % (1<<i)) == 0){
            ans = res;
        }
    }
    cout<<ans.size()<<endl;
    For(i,0,ans.size())
        cout<<ans[i]<<" \n"[i==ans.size()-1];
    return 0;
}
/**/


#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;

int N, A[100010];

int main() {
    scanf("%d", &N);
    for (int i=0; i<N; i++) scanf("%d", A+i);

    for (int i=32; i--;) {
	vector<int>B;
	int M=-1;
	for (int j=0; j<N; j++) {
	    if (A[j] & (1<<i)) {
		M &= A[j];
		B.push_back(A[j]);
	    }
	}
	if (M & ((1<<i)-1)) continue;

	printf("%d\n", B.size());
	for (int j=0; j<int(B.size()); j++) {
	    printf("%d\n", B[j]);
	}
	return 0;
    }
    puts("0");
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int k=0;
    int ans=1;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j])==pows[j])
            {
                if(pows[j]>ans)
                {
                    ans=pows[j];
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if((a[i]&ans)==ans)
        {
            k++;
            answer.push_back(a[i]);
        }
    }
    cout<<k<<endl;
    for(int i=0;i<answer.size();i++)
    {
        cout<<answer[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <list>
using namespace std;
int pows[32];
list<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=-1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=0;j<32;j++)
        {
            if(x&pows[j])
            {
                st[j].push_back(x);
            }
        }
    }
    int max1=0;
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size())
        {
            tmp=*st[i].begin();
            for_each(st[i].begin(),st[i].end(),[&](int n){
                tmp&=n;
            });
            if(tmp==pows[i]&& max1<pows[i])
            {
                max1=pows[i];
                ans=i;
            }
            else
                for(int j=0;j<32;j++)
                {
                    if(tmp%pows[j]==0)
                    {
                        if(pows[j]>max1)
                        {
                            max1=pows[j];
                            ans=i;
                        }
                    }
                }
        }
        else continue;
    }
    cout<<st[ans].size()<<endl;
    for_each(st[ans].begin(),st[ans].end(),[](int n)
    {
        cout<<n<<" ";
    });
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=-1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j]))
            {
                st[j].push_back(a[i]);
            }
        }
    }
    int max1=0;
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size()>0)
        {
            tmp=st[i][0];
            for(int j=1;j<st[i].size();j++)
            {
                tmp=tmp&st[i][j];
            }
            if(tmp==pows[i]&& max1<pows[i])
            {
                max1=pows[i];
                ans=i;
            }
            else
                for(int j=0;j<32;j++)
                {
                    if(tmp%pows[j]==0)
                    {
                        if(pows[j]>max1)
                        {
                            max1=pows[j];
                            ans=i;
                        }
                    }
                }
        }
        else continue;
    }
    if(ans==-1)
    {
        int max=0;
        int answ=0;
        for(int i=0;i<n;i++)
        {
            for(int j=1;j<32;j++)
            {
                if(a[i]%pows[j]==0)
                {
                    if (pows[j]>max)
                    {
                        max=pows[j];
                        answ=a[i];
                    }
                }
            }
        }
        if(max>0)
        {
            cout<<1<<endl;
            cout<<answ;
        }
        else
            cout<<-1;
        return 0;
    }
   // unique(st[ans].begin(), st[ans].end());
    sort(st[ans].begin(),st[ans].end());
    for(int i=1;i<st[ans].size();i++)
    {
        if(st[ans][i]==st[ans][i-1])st[ans][i-1]=0;
    }
    vector<int> ss;
    for(int i=0;i<st[ans].size();i++)
    {
        if(st[ans][i]!=0){
            ss.push_back(st[ans][i]);
        }
    }
    cout<<ss.size()<<endl;
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j]))
            {
                st[j].push_back(a[i]);
            }
        }
    }
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size()>0)
        {
            tmp=st[i][0];
            for(int j=1;j<st[i].size();j++)
            {
                tmp=tmp&st[i][j];
            }
            if(tmp==pows[i])
            {
                ans=i;
            }
        }
        else continue;
    }
   // unique(st[ans].begin(), st[ans].end());
    sort(st[ans].begin(),st[ans].end());
    for(int i=1;i<st[ans].size();i++)
    {
        if(st[ans][i]==st[ans][i-1])st[ans][i-1]=0;
    }
    vector<int> ss;
    for(int i=0;i<st[ans].size();i++)
    {
        if(st[ans][i]!=0){
            ss.push_back(st[ans][i]);
        }
    }
    cout<<ss.size()<<endl;
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=-1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j]))
            {
                st[j].push_back(a[i]);
            }
        }
    }
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size()>0)
        {
            tmp=st[i][0];
            for(int j=1;j<st[i].size();j++)
            {
                tmp=tmp&st[i][j];
            }
            if(tmp==pows[i])
            {
                ans=i;
            }
        }
        else continue;
    }
    if(ans==-1)
    {
        int max=0;
        int answ=0;
        for(int i=0;i<n;i++)
        {
            for(int j=1;j<32;j++)
            {
                if(a[i]%pows[j]==0)
                {
                    if (pows[j]>max)
                    {
                        max=pows[j];
                        answ=a[i];
                    }
                }
            }
        }
        if(max>0)
        {
            cout<<1<<endl;
            cout<<answ;
        }
        else
            cout<<-1;
        return 0;
    }
   // unique(st[ans].begin(), st[ans].end());
    sort(st[ans].begin(),st[ans].end());
    for(int i=1;i<st[ans].size();i++)
    {
        if(st[ans][i]==st[ans][i-1])st[ans][i-1]=0;
    }
    vector<int> ss;
    for(int i=0;i<st[ans].size();i++)
    {
        if(st[ans][i]!=0){
            ss.push_back(st[ans][i]);
        }
    }
    cout<<ss.size()<<endl;
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int k=0;
    int ans=1;
    int tmp=0;
    int t_ans=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j])==pows[j])
            {
                st[j].push_back(a[i]);
            }
        }
    }
    for(int i=0;i<32;i++)
    {
        if(st[i].size()>0){tmp=st[i][0];
        for(int j=0;j<st[i].size();j++)
        {
            tmp&=st[i][j];
        }
        if(tmp==pows[i])
        {
            ans=i;
        }
        }
    }
    cout<<st[ans].size()<<endl;
    for(int i=0;i<st[ans].size();i++)
    {
        cout<<st[ans][i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int k=0;
    int ans=1;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=31;j>0;j--)
        {
            if((a[i]&pows[j])==pows[j])
            {
                if(pows[j]>ans)
                {
                    ans=pows[j];
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if((a[i]&ans)==ans)
        {
            k++;
            answer.push_back(a[i]);
        }
    }
    cout<<k<<endl;
    for(int i=0;i<answer.size();i++)
    {
        cout<<answer[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <list>
using namespace std;
int pows[32];
int a[100001];
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=-1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=0;j<32;j++)
        {
            if(x&pows[j])
            {
                st[j].push_back(x);
            }
        }
    }
    int max1=0;
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size())
        {
            tmp=st[i][0];
            for(int j=1;j<st[i].size();j++)
            {
                tmp=tmp&st[i][j];
            }
            if(tmp==pows[i]&& max1<pows[i])
            {
                max1=pows[i];
                ans=i;
            }
            else
                for(int j=0;j<32;j++)
                {
                    if(tmp%pows[j]==0)
                    {
                        if(pows[j]>max1)
                        {
                            max1=pows[j];
                            ans=i;
                        }
                    }
                }
        }
        else continue;
    }
      // unique(st[ans].begin(), st[ans].end());
    sort(st[ans].begin(),st[ans].end());
    for(int i=1;i<st[ans].size();i++)
    {
        if(st[ans][i]==st[ans][i-1])st[ans][i-1]=0;
    }
    vector<int> ss;
    for(int i=0;i<st[ans].size();i++)
    {
        if(st[ans][i]!=0){
            ss.push_back(st[ans][i]);
        }
    }
    cout<<ss.size()<<endl;
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j])==pows[j])
            {
                st[j].push_back(a[i]);
            }
        }
    }
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size()>0){tmp=st[i][0];
        for(int j=0;j<st[i].size();j++)
        {
            tmp&=st[i][j];
        }
        if(tmp==pows[i])
        {
            ans=i;
        }
        }
    }
    cout<<st[ans].size()<<endl;
    for(int i=0;i<st[ans].size();i++)
    {
        cout<<st[ans][i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int k=0;
    int ans=1;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=31;j>0;j--)
        {
            if(a[i]%pows[j]==0)
            {
                if(pows[j]>ans)
                {
                    ans=pows[j];
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if((a[i]&ans)==ans)
        {
            k++;
            answer.push_back(a[i]);
        }
    }
    cout<<k<<endl;
    for(int i=0;i<answer.size();i++)
    {
        cout<<answer[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
int pows[32];
int a[100001];
vector<int>answer;
vector<int>  tt;
vector<int> st[32];
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int ans=-1;
    int tmp=0;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        for(int j=31;j>=0;j--)
        {
            if((a[i]&pows[j]))
            {
                st[j].push_back(a[i]);
            }
        }
    }
    for(int i=0;i<32;i++)
    {
        tmp=0;
        if(st[i].size()>0)
        {
            tmp=st[i][0];
            for(int j=1;j<st[i].size();j++)
            {
                tmp=tmp&st[i][j];
            }
            if(tmp==pows[i])
            {
                ans=i;
            }
        }
        else continue;
    }
    if(ans==-1)
    {
        cout<<-1;
        return 0;
    }
   // unique(st[ans].begin(), st[ans].end());
    sort(st[ans].begin(),st[ans].end());
    for(int i=1;i<st[ans].size();i++)
    {
        if(st[ans][i]==st[ans][i-1])st[ans][i-1]=0;
    }
    vector<int> ss;
    for(int i=0;i<st[ans].size();i++)
    {
        if(st[ans][i]!=0){
            ss.push_back(st[ans][i]);
        }
    }
    cout<<ss.size()<<endl;
    for(int i=0;i<ss.size();i++)
    {
        cout<<ss[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
struct point{
    int x,y;
};
int pows[32];
int a[100001];
vector<int>answer;
int main(int argc, const char * argv[])
{
    pows[0]=1;
    pows[1]=2;
    int k=0;
    int ans=1;
    for(int i=2;i<32;i++)
    {
        pows[i]=pows[i-1]*2;
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=32;j>0;j--)
        {
            if(a[i]%pows[j]==0)
            {
                if(pows[j]>ans)
                {
                    ans=pows[j];
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        if((a[i]&ans)==ans)
        {
            k++;
            answer.push_back(a[i]);
        }
    }
    cout<<k<<endl;
    for(int i=0;i<answer.size();i++)
    {
        cout<<answer[i]<<" ";
    }
    return 0;
}


/*
 *
 *  Author  :   fcbruce
 *
 *  Date    :
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10

#ifdef _WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

#define maxm
#define maxn 123456

using namespace std;

int a[maxn];
vector<int> v;
int bit[33];

int main()
{
    #ifdef FCBRUCE
        freopen("/home/fcbruce/code/t","r",stdin);
    #endif // FCBRUCE

    int n;

    scanf( "%d",&n);

    for (int i=0;i<n;i++)
        scanf( "%d",a+i);

    bit[0]=1;
    for (itn i=1;i<=30;i++)
        bit[i]=bit[i-1]|(1<<i);

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<=30;j++)
        {
            if (a[i]>=(1<<j))
            {
                bit[j]&=a[i];
            }
        }

//      for (int i=0;i<5;i++)
//          printf( "%d %d\n",i,bit[i]);

    }

    bool ok=false;

    for (int i=30;i>=0;i--)
    {
//      printf( "%d %d\n",i,bit[i]);
        if (bit[i]==(1<<i))
        {
            ok=true;
            for (int j=0;j<n;j++)
            {
                if ( a[j]>=(1<<i))
                    v.push_back(a[j]);
            }
            break;
        }
    }

    if (ok)
    {
        printf( "%d\n",v.size());
        for (auto i : v)
            printf( "%d ",i);
    }
    else
        puts( "-1");

    return 0;
}


/*
 *
 *  Author  :   fcbruce
 *
 *  Date    :
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10

#ifdef _WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

#define maxm
#define maxn 123456

using namespace std;

int a[maxn];
vector<int> v;
int bit[33];

int main()
{
    #ifdef FCBRUCE
        freopen("/home/fcbruce/code/t","r",stdin);
    #endif // FCBRUCE

    int n;

    scanf( "%d",&n);

    for (int i=0;i<n;i++)
        scanf( "%d",a+i);

    bit[0]=1;
    for (itn i=1;i<=30;i++)
        bit[i]=bit[i-1]|(1<<i);

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<=30;j++)
        {
            if (a[i]&(1<<j))
            {
                bit[j]&=a[i];
            }
        }

//      for (int i=0;i<5;i++)
//          printf( "%d %d\n",i,bit[i]);

    }

    bool ok=false;

    for (int i=30;i>=0;i--)
    {
//      printf( "%d %d\n",i,bit[i]);
        if (bit[i]==(1<<i))
        {
            ok=true;
            for (int j=0;j<n;j++)
            {
                if ( a[j]&(1<<i))
                    v.push_back(a[j]);
            }
            break;
        }
    }

    if (ok)
    {
        printf( "%d\n",v.size());
        for (auto i : v)
            printf( "%d ",i);
    }
    else
        puts( "-1");

    return 0;
}


/*
 *
 *  Author  :   fcbruce
 *
 *  Date    :
 *
 */
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cctype>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10

#ifdef _WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

#define maxm
#define maxn 123456

using namespace std;

int a[maxn];
vector<int> v;
int bit[33];

int main()
{
    #ifdef FCBRUCE
        freopen("/home/fcbruce/code/t","r",stdin);
    #endif // FCBRUCE

    int n;

    scanf( "%d",&n);

    for (int i=0;i<n;i++)
        scanf( "%d",a+i);

    bit[0]=1;
    for (itn i=1;i<=30;i++)
        bit[i]=bit[i-1]|(1<<i);

    for (int i=0;i<n;i++)
    {
        for (int j=0;j<=30;j++)
        {
            if (a[i]<(1<<j+1)&& a[i]>=(1<<j))
            {
                bit[j]&=a[i];
            }
        }

//      for (int i=0;i<5;i++)
//          printf( "%d %d\n",i,bit[i]);

    }

    bool ok=false;

    for (int i=30;i>=0;i--)
    {
//      printf( "%d %d\n",i,bit[i]);
        if (bit[i]==(1<<i))
        {
            ok=true;
            for (int j=0;j<n;j++)
            {
                if (a[j]<(1<<i+1) && a[j]>=(1<<i))
                    v.push_back(a[j]);
            }
            break;
        }
    }

    if (ok)
    {
        printf( "%d\n",v.size());
        for (auto i : v)
            printf( "%d ",i);
    }
    else
        puts( "-1");

    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 1e5;

int ar[MAXN];
int ands[MAXN];

vector<int> ans;

int n;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> ar[i];

    for (int i = 29; i >= 0; i--)
    {
        int andres = ((1 << 30) - 1);

        ans.clear();

        for (int j = 0; j < n; j++)
            if (ar[j] & (1 << i))
            {
                andres &= ar[j];
                ans.push_back(ar[j]);
            }

        if (!ans.empty())
            if ((andres & ((1 << i) - 1)) == 0)
            {
                cout << ans.size() << endl;
                for (vector<int>::iterator it = ans.begin(); it != ans.end(); it++)
                    cout << *it << ' ';
                cout << endl;
                return 0;
            }
    }
}


#include <algorithm>
#include <iostream>

using namespace std;

const int MAXN = 1e5;

int ar[MAXN];
int ands[MAXN];
int n;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n;

    for (int i = 0; i < n; i++)
        cin >> ar[i];

    ands[n - 1] = ar[n - 1];
    for (int i = n - 2; i >= 0; i--)
        ands[i] = ands[i + 1] & ar[i];

    for (int i = 30; i >= 0; i--)
    {
        int x = lower_bound(ar, ar + n, (1 << i)) - ar;

        if (x < n)
            if ((ands[x] & ((1 << i) - 1)) == 0)
            {
                cout << n - x << endl;
                for (int j = x; j < n; j++)
                    cout << ar[j] << ' ';
                cout << endl;
                return 0;
            }
    }
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <complex>
#include <ctime>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < n; ++i)
#define RREP(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(int i = x; i <= y; ++i)
#define RFOR(i, x, y) for(int i = x; i >= y; --i)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x, 0, sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mk make_pair
#define sqr(x) (x)*(x)
#define X first
#define Y second
const long double pi=acos(-1.0);
const long double eps = 1e-6;
const int inf = 1e+9;
const int N = 1e+5;

int n;
int mas[100100];
int main () {
    cin >> n;
    REP (i, n)
        cin >> mas[i];
    int p = -1;
    RREP (i, 30) {
        int mask = (1<<i);
        REP (j, n)
            if (mas[j] & mask) {
                p = mask;
                break;
            }
        if (p >= 0) {
            set<int> st;
            int ans = p * 2 - 1;
            REP (j, n)
                if (mas[j] & p) {
                    ans = mas[j] & ans;
                    st.insert(mas[j]);
                }
            if (ans % p == 0) {
                cout << SZ(st) << endl;
                for (auto it = st.begin(); it != st.end(); it++)
                    cout << (*it) << " ";
                return 0;
            } else
                p = -1;
        }
    }
    cout << p ;
    return 0;
}
/*
6
325*4405
324-99
0*0
325*0
324-324
125+0
*/


#include <bits/stdc++.h>
using namespace std;
vector<int> nums[40];
int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int n;
        cin >> n;
        for (int k = 30; k >= 0; --k) {
            if ((n >> k) & 1) {
                nums[k].push_back(n);
                break;
            }
        }
    }
    for (int i = 30; i >= 0; --i) {
        int z = 0;
        for (int j = 0; j < nums[i].size(); ++j) {
            for (int k = 0; k < i; ++k) {
                if (!((nums[i][j] >> k) & 1))
                    z |= (1 << k);
            }
        }
        if (z == ((1 << i) - 1)) {
            cout << nums[i].size() << endl;
            for (int j = 0; j < nums[i].size(); ++j)
                cout << nums[i][j] << " ";
            cout << endl;
            return 0;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
vector<int> nums[40];
int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int n;
        cin >> n;
        for (int k = 30; k >= 0; --k) {
            if ((n >> k) & 1) {
                nums[k].push_back(n);
//              break;
            }
        }
    }
    for (int i = 30; i >= 0; --i) {
        int z = 0;
        for (int j = 0; j < nums[i].size(); ++j) {
            for (int k = 0; k < i; ++k) {
                if (!((nums[i][j] >> k) & 1))
                    z |= (1 << k);
            }
        }
        if (z == ((1 << i) - 1)) {
            cout << nums[i].size() << endl;
            for (int j = 0; j < nums[i].size(); ++j)
                cout << nums[i][j] << " ";
            cout << endl;
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
main() {

    int n;
    scanf("%d", &n);
    int a[n];
    for( int i = 0; i < n; i++ )
        scanf("%d", &a[i]);

    for( int i = 30; ; i-- ) {
        vector<int> tmp;
        for( int j = 0; j < n; j++ )
            if( a[j]&(1<<i) ) tmp.push_back(a[j]);
        if( tmp.empty() ) continue;
        int x = tmp[0];
        for( int y : tmp )
            x &= y;
        if( x%(1<<i) ) continue;
        printf("%d\n", tmp.size());
        for( int x : tmp )
            printf("%d ", x);
        return 0;
    }
}


#include<bits/stdc++.h>
using namespace std;
main() {

    int n;
    scanf("%d", &n);
    int a[n];
    for( int i = 0; i < n; i++ )
        scanf("%d", &a[i]);

    for( int i = 30; i >= 0; i-- ) {
        vector<int> tmp;
        for( int j = 0; j < n; j++ )
            if( a[j]&(1<<i) ) tmp.push_back(a[j]);
        if( tmp.empty() ) continue;
        int x = a[0];
        for( int y : tmp )
            x &= y;
        if( x%(1<<i) ) continue;
        printf("%d\n", tmp.size());
        for( int x : tmp )
            printf("%d ", x);
        return 0;
    }

    printf("-1");
    return 0;
}


#include <functional>/*{{{*/
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;typedef long long ll;typedef long double real;void run();int main(){ios::sync_with_stdio(0);run();}/*}}}*/

ll v[100000];

void run(){
  ll n; cin>>n;
  for (ll i=n; i--;) cin>>v[i];
  for (ll i=40; i--;){
    ll r=-1,m=0;
    for (int j=n; j--;) if (v[j]&(1ll<<i)) ++m, r&=v[j];
    if ((r&((1ll<<i)-1))==0 and m){
      cout<<m<<endl;
      for (int j=n; j--;) if (v[j]&(1ll<<i)) cout<<v[j]<<(--m?' ':'\n');
      return;
    }
  }
}


#include <bits/stdc++.h>

typedef unsigned long long uLong;
typedef long long Long;
typedef std::vector<Long> Vector;
typedef std::vector< Vector > Vector2;
typedef std::pair<Long, Long> Pair;
typedef std::map<Long, Long> Map;
typedef std::set<Long> Set;

#define pb push_back
#define mp make_pair
#define ins insert
#define for0(i,n) for(Long i = 0; i<(Long)(n); i++)
#define for0n(i,n) for(Long i = 0; i<=(Long)(n); i++)
#define for1n(i,n) for(Long i = 1; i<=(Long)(n); i++)
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define alli(v) (v).begin() + (i), (v).end()
#undef int
#define int Long
#define ONE 1LL
#define M_PI        3.14159265358979323846

using namespace std;
template<class T> inline T ceil(T a, T b){ return a/b + ( a%b ? 1 : 0 ); }
template<class T> string to_string(T a){ stringstream ss; ss<<a; return ss.str(); }
template<class T> int to_int(T a){ int n;  stringstream ss; ss<<a; ss>>n; return n; }
bool good(int x, int y, int n){ return x>=0 && x<n && y>=0 && y<n; }
bool overlap(int x1, int x2, int y1, int y2){ return x1 <= y2 && y1 <= x2; }

template<class T>
void debug(T it1, T it2){ for(T it = it1; it!=it2; it++) cout<<*it<<" "; cout<<endl; }

int sx, sy;
//int n, m, earea;
#define MOD 1000000007
#define LEN 100001

int a[LEN];

bool bit(int pos, int b){
    //cerr<<(ONE<<(b-1))<<" "<<(a[pos])<<endl;
    return (ONE<<(b-1)) & (a[pos]);
}

void _main(){
    int n, nbit = 30;
    cin>>n;
    for0(i,n) cin>>a[i];

    //cerr<<nbit<<endl;
    for(int i = nbit; i>=1; i--){
        set<int> st;
        for(int j = i-1; j>=1; j--)
            st.ins(j);
        //debug(all(st));
        for(int j = 0; j<n && sz(st); j++){
            if(bit(j, i)){
                for(set<int>::iterator it = st.begin(); it!=st.end();){
                    if(!bit(j, *it)) st.erase(it++);
                    else it++;
                }
            }
        }
        if(!sz(st)){
            stringstream ss;
            int cnt = 0;
            ss<<"\n";
            for(int j = 0; j<n; j++)if(bit(j, i)){
                ss<<a[j]<<" ";
                cnt++;
            }
            cout<<cnt<<ss.str();
            return;
        }
    }
    cout<<-1;
}

#undef int
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //while(true)
        _main();
    return 0;
}


#include <bits/stdc++.h>
#define forn(i, n) for(int i = 0; i < (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; ++i)
#define For(i, st, en) for(int i = (int)st; i <= (int)en; ++i)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

/**
 * The code starts here.
 */
ll mod = 1000000009;

ll pw(ll a, ll n)
{
    ll ret = 1;
    while(n)
    {
        if (n & 1ll) ret = ret * a % mod;
        a = a * a % mod;
        n >>= 1ll;
    }
    return ret;
}

int main()
{
    //freopen("in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    int a[n];
    int res = ~0;
    forn(i, n)
    {
        cin >> a[i];
        res &= a[i];
    }

    for (int v = 31; v >= 0; --v)
    {
        int res = ~0;
        int cnt = 0;
        forn(i, n)
        {
            if (a[i] & (1 << v))
            {
                res &= a[i];
                ++cnt;
            }
        }

        if (cnt && ((res & ((1 << v) - 1)) == 0))
        {
            VI ans;
            forn(i, n)
            {
                if (a[i] & (1 << v))
                {
                    ans.pb(a[i]);
                }
            }

            sort(all(ans));
            ans.resize(unique(all(ans)) - ans.begin());

            cout << ans.size() << endl;
            forn(i, ans.size())
            {
                cout << ans[i] << " ";
            }
            cout << endl;
            return 0;
        }
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <set>
using namespace std;
typedef pair<int, int> pii;

int main(int argc, char const *argv[])
{
 //  freopen("c.in", "r", stdin);
    int n;
    cin>>n;
    vector<int> A;
    A.resize(n+5);
    for(int i=0; i<n; ++i)
        cin>>A[i];
    vector<vector<int> > R;
    R.resize(35);
    int maxk = 0;
    for(int i=0; i<n; ++i)
    {
        for(int k=31; k>=0; --k)
            if((A[i]>>k) & 1)
            {
                R[k].push_back(A[i]);
                // printf("%d ", k);
            }
    }
    int i;
    for(i=30; i>=0; --i)
    {
        int ok=-1;
        for(int j=0; j<R[i].size(); ++j)
            ok = ok & R[i][j];
        if(ok%(1<<i)==0)
            break;
    }
    if(i>=0)
    {
        printf("%d\n", R[i].size());
        for(int j=0; j<R[i].size(); ++j)
            printf("%d ", R[i][j]);
        puts("");
    }
    else
        puts("-1");
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pi acos(-1.0)
#define EPS 1e-9
#define mem(n,x) memset(n,x,sizeof(n))
typedef long long ll;

using namespace std;

int main()
{
	int n;scanf("%d",&n);
	vector<int> v(n),ans;
	for(int &x:v)scanf("%d",&x);

	for(int i=30;i>=0;i--){
		int z=INT_MAX;
		ans.clear();
		for(int j=0;j<n;j++){
			if((v[j] & (1<<i)))ans.pb(v[j]),z&=v[j];
		}
		if(z%(1<<i)==0)goto end;
	}
	end:;
	printf("%d\n",int(ans.size()));
	for(int &x:ans)printf("%d ",x);
	printf("\n");
	return 0;
}


#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <ctime>

#define rep(i,n)	for(int i = 0;i < (n);i++)
#define rep2(i,n)	for(int i = 1;i <= (n);i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<unsigned int> ary(n);
	rep(i,n)cin>>ary[i];
	vector<unsigned int> ands(31,0xFFFFFFFF);
	unsigned int j = 1;
	rep(i,n)
	{
		for(;j<=30;j++)
		{
			if(ary[i] < (1 << j))
				break;
		}
		ands[j] &= ary[i];
		for(unsigned int k = 1;k < j;k++)
		{
			if((1 << (k-1)) & ary[i])
			{
				ands[k] &= ary[i];
			}
		}
	}
	//rep2(i,30)
	//	cout << ands[i] << endl;;
	int maxj = 0;
	rep2(i,30)
	{
		if(ands[i] >= (1 << (i-1)) && ands[i] < 0xFFFFFFFF)
		{
			maxj = i;
		}
	}
	if(maxj)
	{
		int cnt = 0;
		vector<unsigned int> outputs;
		rep(i,n)
		{
			if(ary[i] & (1 << (maxj-1)))
			{
				cnt++;
				outputs.push_back(ary[i]);
			}
		}
		int s = outputs.size();
		cout << s << endl;
		rep(i,s-1)
		{
			cout << outputs[i] << ' ';
		}
		cout << outputs[s-1] << endl;
	}
	else
	{
		cout << n << endl;
		rep(i,n-1)
		{
			cout << ary[i] << ' ';
		}
		cout << ary[n-1] << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <ctime>

#define rep(i,n)	for(int i = 0;i < (n);i++)
#define rep2(i,n)	for(int i = 1;i <= (n);i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<unsigned int> ary(n);
	rep(i,n)cin>>ary[i];
	vector<unsigned int> ands(31,0xFFFFFFFF);
	unsigned int j = 1;
	rep(i,n)
	{
		for(;j<=30;j++)
		{
			if(ary[i] < (1 << j))
				break;
		}
		ands[j] &= ary[i];
		for(unsigned int k = 1;k < j;k++)
		{
			if((1 << (k-1)) & ary[i])
			{
				ands[k] &= ary[i];
			}
		}
	}
	//rep2(i,30)
	//	cout << ands[i] << endl;;
	int maxj = 0;
	rep2(i,30)
	{
		if(ands[i] >= (1 << (i-1)) && !(ands[i] & ((1 << (i-1))-1)))
		{
			maxj = i;
		}
	}
	if(maxj)
	{
		int cnt = 0;
		vector<unsigned int> outputs;
		rep(i,n)
		{
			if(ary[i] & (1 << (maxj-1)))
			{
				cnt++;
				outputs.push_back(ary[i]);
			}
		}
		int s = outputs.size();
		cout << s << endl;
		rep(i,s-1)
		{
			cout << outputs[i] << ' ';
		}
		cout << outputs[s-1] << endl;
	}
	else
	{
		cout << n << endl;
		rep(i,n-1)
		{
			cout << ary[i] << ' ';
		}
		cout << ary[n-1] << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <ctime>

#define rep(i,n)	for(int i = 0;i < (n);i++)
#define rep2(i,n)	for(int i = 1;i <= (n);i++)
#define each(i,x)	for(auto & i : x)

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<unsigned int> ary(n);
	rep(i,n)cin>>ary[i];
	vector<unsigned int> ands(31,0xFFFFFFFF);
	unsigned int j = 1;
	rep(i,n)
	{
		for(;j<=30;j++)
		{
			if(ary[i] < (1 << j))
				break;
		}
		ands[j] &= ary[i];
		for(unsigned int k = 1;k < j;k++)
		{
			if((1 << (k-1)) & ary[i])
			{
				ands[k] &= ary[i];
			}
		}
	}
	int maxj = 0;
	rep2(i,30)
	{
		if(ands[i] == (1 << (i-1)))
		{
			maxj = i;
		}
	}
	if(maxj)
	{
		int cnt = 0;
		vector<unsigned int> outputs;
		rep(i,n)
		{
			if(ary[i] & (1 << (maxj-1)))
			{
				cnt++;
				outputs.push_back(ary[i]);
			}
		}
		int s = outputs.size();
		cout << s << endl;
		rep(i,s-1)
		{
			cout << outputs[i] << ' ';
		}
		cout << outputs[s-1] << endl;
	}
	else
	{
		cout << n << endl;
		rep(i,n-1)
		{
			cout << ary[i] << ' ';
		}
		cout << ary[n-1] << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:16777216")
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#ifndef ONLINE_JUDGE
#define Eo(x) { cerr << #x << " = " << (x) << endl; }
#else
#define Eo(x)
#endif

typedef long long int64;
const int inf = 0x3f3f3f3f;
const int64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int64> pip;

int64 gcd(int64 a, int64 b) {
  return a ? gcd(b%a,a) : b;
}

template <typename A,typename B>
ostream& operator<<(ostream& os, const pair<A,B>& p) {
                 return os << p.first << "," << p.second;
}

template <typename A>
ostream& operator<<(ostream& os, const vector<A>& v) {
                 for (int i = 0; i < v.size(); i++) {
                   os << v[i] << ";";
                 }
                 return os;
}

template <typename A>
ostream& operator<<(ostream& os, const set<A>& v) {
                 for (typename set<A>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << *it << ";";
                 }
                 return os;
}

template <typename A, typename B>
ostream& operator<<(ostream& os, const map<A,B>& v) {
                 for (typename map<A,B>::const_iterator it = v.begin(); it != v.end(); ++it) {
                   os << it->first << "=" << it->second << ";";
                 }
                 return os;
}

inline int64 bit(int64 k) {
  return int64(1)<<k;
}

int SolveSquareEquation(real a, real b, real c, real& x1, real& x2) {
  real desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc = sqrt(desc);
  x1 = (-b+sqrt_desc)/(2*a);
  x2 = (-b-sqrt_desc)/(2*a);
  if (desc<eps) {
    return 1;
  }
  return 2;
}

int SolveSquareEquationInt(int64 a, int64 b, int64 c, int64& x1, int64& x2) {
  int64 desc = b*b-4*a*c;
  if (desc<0) return 0;
  real sqrt_desc_r = sqrt(real(desc));
  int64 sqrt_desc = sqrt_desc_r;
  for (;sqrt_desc*sqrt_desc<desc; sqrt_desc++);
  for (;sqrt_desc*sqrt_desc>desc; sqrt_desc--);
  if (sqrt_desc*sqrt_desc != desc) {
    return 0;
  }
  int64 u1 = -b+sqrt_desc;
  int64 u2 = -b-sqrt_desc;
  int64 a2 = a*2;
  vector<int64> res;
  if (!(u1%a2)) {
    res.push_back(u1/a2);
  }
  if (!(u2%a2)) {
    res.push_back(u2/a2);
  }
  int oldsize = res.size();
  res.resize(2);
  x1=res[0];
  x2=res[1];
  return oldsize;
}

const int maxn = 100100;
int a[maxn];
int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    int x; scanf("%d",&x);
    a[i]=x;
  }
  for (int k = 35; k >= 0; k--) {
    int64 z = (bit(40)-1);
    for (int i = 0; i < n; i++) if (a[i] & bit(k)) {
      z &= a[i];
    }
    bool bad = false;
    for (int l = k-1; l >= 0; l--) {
      if (bit(l)&z) {
        bad=true;
        break;
      }
    }
    if (bad) continue;
    vector<int> r;
    for (int i = 0; i < n; i++) if (a[i] & bit(k)) {
      r.push_back(a[i]);
    }
    printf("%d\n",r.size());
    for (int x : r) {
      printf("%d ",x);
    }
    puts("");
    return 0;
  }
  puts("-1");
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int a[100500];
int n;

bool func(int x) {
     int ans = -1;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       if (ans == -1) ans = a[i];
                       ans = ans & a[i];
             }
     }
     for(int i = 0; i < x; i++) {
             if ((ans >> i) & 1) return 0;
     }
     return 1;
}

void restore(int x) {
     vector<int> ans;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       ans.push_back(a[i]);
             }
     }
     cout << ans.size() << endl;
     for(int i = 0; i < ans.size(); i++) {
             cout << ans[i] << " ";
     }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
            cin >> a[i];
    }
    int lf = -1;
    int rg = 25;
    while(rg - lf > 1) {
             int mid = (lf + rg) >> 1;
             if (func(mid)) {
                            lf = mid;
             } else rg = mid;
    }
    restore(lf);
    return 0;

}


#include <iostream>
#include <vector>
using namespace std;

int a[100500];
int n;

bool func(int x) {
     int ans = 1 << 30 - 1;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       ans = ans & a[i];
             }
     }
     for(int i = 0; i < x; i++) {
             if ((ans >> i) & 1) return 0;
     }
     return 1;
}

void restore(int x) {
     vector<int> ans;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       ans.push_back(a[i]);
             }
     }
     cout << ans.size() << endl;
     for(int i = 0; i < ans.size(); i++) {
             cout << ans[i] << " ";
     }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
            cin >> a[i];
    }
    int lf = -1;
    int rg = 30;
    while(rg - lf > 1) {
             int mid = (lf + rg) >> 1;
             if (func(mid)) {
                            lf = mid;
             } else rg = mid;
    }
    restore(lf);
    return 0;

}


#include <iostream>
#include <vector>
#include <set>
using namespace std;

int a[100500];
int n;

bool func(int x) {
     int ans = -1;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       if (ans == -1) ans = a[i];
                       ans = ans & a[i];
             }
     }
     for(int i = 0; i < x; i++) {
             if ((ans >> i) & 1) return 0;
     }
     return 1;
}

void restore(int x) {
     set<int> ans;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       ans.insert(a[i]);
             }
     }
     cout << ans.size() << endl;
     for(auto i = ans.begin(); i != ans.end(); i++) {
              cout << *i << " ";
     }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
            cin >> a[i];
    }
    int lf = -1;
    int rg = 25;
    while(rg - lf > 1) {
             int mid = (lf + rg) >> 1;
             if (func(mid)) {
                            lf = mid;
             } else rg = mid;
    }
    restore(lf);
    return 0;

}


#include <iostream>
#include <vector>
#include <set>
using namespace std;

int a[100500];
int n;

bool func(int x) {
     int ans = -1;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       if (ans == -1) ans = a[i];
                       ans = ans & a[i];
             }
     }
     for(int i = 0; i < x; i++) {
             if ((ans >> i) & 1) return 0;
     }
     return 1;
}

void restore(int x) {
     set<int> ans;
     for(int i = 1; i <= n; i++) {
             if ((a[i] >> x) & 1) {
                       ans.insert(a[i]);
             }
     }
     cout << ans.size() << endl;
     for(auto i = ans.begin(); i != ans.end(); i++) {
              cout << *i << " ";
     }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
            cin >> a[i];
    }
    int lf = -1;
    int rg = 25;
    for(int i = 29; i >= 0; i--) {
            if (func(i)) {
                         restore(i);
                         return 0;
            }
    }
    restore(lf);
    return 0;

}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,a[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin>>n;
	rep(i,n)cin>>a[i];
	for(int ans=29;ans>=0;ans--){
		int mask=-1;
		int num=0;
		rep(i,n)if(a[i]>>ans&1){
			mask&=a[i];
			num++;
		}
		if((mask&((1<<ans)-1)) == 0){
			cout<<num<<endl;
			rep(i,n)if(a[i]>>ans&1)cout<<a[i]<<" ";
			return 0;
		}
	}
}


#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map>
#include<set>
#include<tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define LL long long

int vet[100000];
int n;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> vet[i];
	}

	for(unsigned int v=30;v>=0;v--)
	{
		unsigned int AND=INT_MAX;
		set<int> sol;
		for(int i=0;i<n;i++)
			if((vet[i]&(1<<v))!=0||v==31)
			{
				sol.insert(vet[i]);
				AND&=vet[i];
			}
		//cout << v << " " << AND << endl;
		if(AND%(1<<v)==0)
		{
			cout << sol.size() << endl;
			for(auto it=sol.begin();it!=sol.end();it++)
				cout << *it << " ";
			break;
		}
	}
}


#include<iostream>
#include<vector>
#include<climits>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<map>
#include<set>
#include<tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define LL long long

int vet[100000];
int n;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> vet[i];
	}

	for(unsigned int v=30;v>=0;v--)
	{
		unsigned int AND=INT_MAX;
		set<int> sol;
		for(int i=0;i<n;i++)
			if((vet[i]&(1<<v))!=0||v==31)
			{
				sol.insert(vet[i]);
				AND&=vet[i];
			}
		cout << v << " " << AND << endl;
		if(AND%(1<<v)==0)
		{
			cout << sol.size() << endl;
			for(auto it=sol.begin();it!=sol.end();it++)
				cout << *it << " ";
			break;
		}
	}
}


#include <cstdio>

int main()
{
    int n, a[100000], count[32] = {0};
    bool b[32][32] = {false};
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
        int x = a[i], index = 0, zero[32], zerocount = 0;
        while (x != 0)
        {
            if (x % 2 == 1)
            {
                count[index] += 1;
                for (int j = 0; j < zerocount; ++j)
                {
                    b[index][zero[j]] = true;
                }
            }
            else
            {
                zero[zerocount++] = index;
            }
            x /= 2;
            index += 1;
        }
    }

    int v = 31;
    for (;;)
    {
        int j = 0;
        for (; j < v; ++j)
        {
            if (!b[v][j])
            {
                break;
            }
        }
        if (j == v)
        {
            break;
        }
        --v;
    }
    int k = count[v];
    printf("%d\n", k);

    int pv = 1 << v;
    for (int i = 0; i < n; ++i)
    {
        if ((a[i] & pv) != 0)
        {
            printf((--k != 0 ? "%d " : "%d\n"), a[i]);
        }
    }

    return 0;
}


#include <cstdio>

using namespace std;

int main()
{
    int n, a[100000], count[32] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &a[i]);
        int x = a[i], index = 0;
        while (x != 0)
        {
            if (x % 2 == 1)
            {
                count[index] += 1;
            }
            x /= 2;
            index += 1;
        }
    }

    int v = 31;
    while (count[v] == 0)
    {
        --v;
    }
    int k = count[v];
    printf("%d\n", k);

    int pv = 1 << v;
    for (int i = 0; i < n; ++i)
    {
        if ((a[i] & pv) != 0)
        {
            printf((k-- != 0 ? "%d " : "%d\n"), a[i]);
        }
    }

    return 0;
}


#include <iostream>
#include <vector>
#define MAX 100000

using namespace std;

long long N, a[MAX], inf = 1LL << 50;
int main(){
	cin >> N;

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

	for(int v = 40; v >= 0; v--){
		vector<int> list;
		long long c = inf - 1;
		for(int i = 0; i < N; i++){
			if((a[i] & (1LL << v)) != 0){
				list.push_back(a[i]);
				c &= a[i];
			}
		}

		if((c & ((1LL << v) - 1)) == 0){
			cout << list.size() << endl;
			for(auto x : list)
				cout << x << endl;
			break;
		}
	}
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v = 0;
	int k = 0;
	for (v = 30; v > 0; v--) {
		int sum = -1;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum < 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && !(sum & (1 << v - 1))) {
			break;
		}
	}
	printf("%d\n", k);
	for (int i = 0; i < n; i++)
		if ((vec[i]>>v)&1) {
			printf("%d ", vec[i]);
		}
		printf("\n");
	return 0;
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v = 0;
	int k = 0;
	for (v = 30; v > 0; v--) {
		int sum = -1;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum < 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && !(sum & (1 << v - 1))) {
			break;
		}
	}
	if (k == 0) {
		printf("%d\n", -1);
		return 0;
	}
	printf("%d\n", k);
	for (int i = 0; i < n; i++)
		if ((vec[i]>>v)&1) {
			printf("%d ", vec[i]);
		}
		printf("\n");
	return 0;
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v = 0;
	int k = 0;
	for (v = 30; v >= 0; v--) {
		int sum = -1;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum < 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && !(sum & (1 << v - 1))) {
			break;
		}
	}
	/*
	if (v == 0) {
		printf("%d\n", -1);
		return 0;
	}
	*/
	printf("%d\n", k);
	for (int i = 0; i < n; i++)
		if ((vec[i] >>v ) & 1) {
			printf("%d ", vec[i]);
		}
		printf("\n");
	return 0;
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v;
	int k;
	for (v = 30; v >= 0; v--) {
		int sum = 0;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum == 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && (v == 0 || !(sum&(1 << v - 1)))) {
			break;
		}
	}
	if (v < 0) {
		k = -1;
			printf("-1\n");
	} else {
		printf("%d\n", k);
		for (int i = 0; i < n; i++)
			if ((vec[i]>>v)&1) {
				printf("%d ", vec[i]);
			}
			printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v = 0;
	int k = 0;
	for (v = 30; v >= 0; v--) {
		int sum = -1;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum < 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && !(sum & (1 << v - 1))) {
			break;
		}
	}
	if (v == 0) {
		printf("%d\n", -1);
		return 0;
	}
	printf("%d\n", k);
	for (int i = 0; i < n; i++)
		if ((vec[i] >>v ) & 1) {
			printf("%d ", vec[i]);
		}
		printf("\n");
	return 0;
}


#include <stdio.h>
#include <vector>

void PrintBinary(int x) {
	for (int j = 0; j <= 30; j++) {
		printf("%d", x&1);
		x >>= 1;
	}
	printf("\n");
}

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v = 0;
	int k = 0;
	for (v = 30; v >= 0; v--) {
		int sum = -1;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum < 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum & (1 << v)) && !(sum & (1 << v) - 1)) {
			break;
		}
	}
	/*
	if (v == 0) {
		printf("%d\n", -1);
		return 0;
	}
	*/
	printf("%d\n", k);
	for (int i = 0; i < n; i++)
		if ((vec[i] >>v ) & 1) {
			printf("%d ", vec[i]);
		}
		printf("\n");
	return 0;
}


#include <stdio.h>
#include <vector>

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
	}
	int v;
	int k;
	for (v = 30; v >= 0; v--) {
		int sum = 0;
		k = 0;
		for (int i = 0; i < n; i++) {
			if ((vec[i] >> v) & 1) {
				k++;
				if (sum == 0) {
					sum = vec[i];
				} else {
					sum &= vec[i];
				}
			}
		}
		if ((sum&(1 << v)) && !(sum&(1 << k - 1))) {
			break;
		}
	}
	if (v < 0) {
		k = -1;
			printf("-1\n");
	} else {
		printf("%d\n", k);
		for (int i = 0; i < n; i++)
			if ((vec[i]>>v)&1) {
				printf("%d ", vec[i]);
			}
			printf("\n");
	}
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int n;
int a[100006];
void solve(){
 set<int>ss;
 set<int>::iterator it;
 int j,i,v,ans;
 for(v=30;v>=0;v--){
  __int64 tem=1<<v;
  ss.clear();
  for(j=1;j<=n;j++){
  if(a[j]&tem)
  {
	  if(ss.size()==0)
		  ans=a[j];
   else
	   ans&=a[j];
   ss.insert(a[j]);
  }
  }
 if(ss.size()&&ans%tem==0){
   printf("%d\n",ss.size());
   printf("%d",*ss.begin());
   for(it=ss.begin();it!=ss.end();it++)
	   if(it!=ss.begin())
	   printf(" %d",*it);
   printf("\n");
   return;
  }
 }
 printf("-1\n");
}
int main(){
	while(cin>>n){
	int i;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	solve();
	}
	return 0;
}


import java.io.*;
import java.util.*;

public class D {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        String[] arr = new String[n];
        for(int i=0;i<n;i++)arr[i] = sc.next();
        HashMap<String,Integer>h = new HashMap<>();
        for(int i=0;i<n;i++){
            for(int j=0;j<arr[i].length();j++){
                String res = "";
                for(int k=j;k<arr[i].length();k++){
                    res+=arr[i].charAt(k)+"";
                    h.put(res,h.getOrDefault(res,0)+1);
                }
            }
        }
        for(int i=0;i<n;i++){
            TreeMap<String,Integer> tr = new TreeMap<>();
            for(int j=0;j<arr[i].length();j++){
                String res = "";
                for(int k=j;k<arr[i].length();k++){
                    res+=arr[i].charAt(k)+"";
                    h.put(res,h.getOrDefault(res,0)-1);
                    tr.put(res,tr.getOrDefault(res,0)+1);
                }
            }
            int min = 10;
            String r = arr[i];
            while (!tr.isEmpty()){
                String tmp = tr.firstKey();
                int val = tr.pollFirstEntry().getValue();
                if(h.get(tmp)==0 && tmp.length()<min){
                    //pw.println(">>"+tmp + " " + val);
                    min = tmp.length();
                    r = tmp;
                }
                h.put(tmp,h.getOrDefault(tmp,0)+val);
            }
            pw.println(r);
        }
        pw.flush();
        pw.close();
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        int z;
        int d;
        public Pair(int x,int y,int z){
            this.x= x;
            this.y = y;
            this.z =z;
            d = z-y;
        }
        public int compareTo(Pair p){
            if(this.d==p.d)
                return Long.compare(p.x,this.x);
            return Long.compare(this.d,p.d);
        }

    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();

        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			Input in = new Input(inputStream);
			PrintWriter out = new PrintWriter(outputStream);
			DPolycarpsPhoneBook solver = new DPolycarpsPhoneBook();
			solver.solve(1, in, out);
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<29);
		thread.start();
		thread.join();
	}
	static class DPolycarpsPhoneBook {
		public DPolycarpsPhoneBook() {
		}

		public void solve(int testNumber, Input in, PrintWriter pw) {
			int n = in.nextInt();
			HashMap<String, Integer> hm = new HashMap<>();
			String[] arr = new String[n];
			for(int i = 0; i<n; i++) {
				arr[i] = in.next();
				HashSet<String> hs = new HashSet<>();
				for(int l = 0; l<arr[i].length(); l++) {
					for(int r = l; r<arr[i].length(); r++) {
						hs.add(arr[i].substring(l, r+1));
					}
				}
				for(String s: hs) {
					hm.put(s, hm.getOrDefault(s, 0)+1);
				}
			}
			for(int i = 0; i<n; i++) {
				loop:
				for(int j = 1; j<arr[i].length(); j++) {
					for(int k = 0; k<arr[i].length()&&k+j<=arr[i].length(); k++) {
						if(hm.get(arr[i].substring(k, j+k))==1) {
							pw.println(arr[i].substring(k, j+k));
							break loop;
						}
					}
				}
			}
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is), 1<<16);
			st = null;
		}

		public boolean hasNext() {
			try {
				while(st==null||!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken();
		}

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

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			Input in = new Input(inputStream);
			PrintWriter out = new PrintWriter(outputStream);
			DPolycarpsPhoneBook solver = new DPolycarpsPhoneBook();
			solver.solve(1, in, out);
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<29);
		thread.start();
		thread.join();
	}
	static class DPolycarpsPhoneBook {
		public DPolycarpsPhoneBook() {
		}

		public void solve(int testNumber, Input in, PrintWriter pw) {
			int n = in.nextInt();
			HashMap<String, Integer> hm = new HashMap<>();
			String[] arr = new String[n];
			for(int i = 0; i<n; i++) {
				arr[i] = in.next();
				HashSet<String> hs = new HashSet<>();
				for(int l = 0; l<arr[i].length(); l++) {
					for(int r = l; r<arr[i].length(); r++) {
						hs.add(arr[i].substring(l, r+1));
					}
				}
				for(String s: hs) {
					hm.put(s, hm.getOrDefault(s, 0)+1);
				}
			}
			loop:
			for(int i = 0; i<n; i++) {
				for(int j = 1; j<=arr[i].length(); j++) {
					for(int k = 0; k<arr[i].length()&&k+j<=arr[i].length(); k++) {
						if(hm.get(arr[i].substring(k, j+k))==1) {
							pw.println(arr[i].substring(k, j+k));
							continue loop;
						}
					}
				}
				throw new AssertionError();
			}
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is), 1<<16);
			st = null;
		}

		public boolean hasNext() {
			try {
				while(st==null||!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken();
		}

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

	}
}


	import java.io.*;
	import java.util.*;
	import java.math.*;

	 public class Main	{
	   static class Pair implements Comparable<Pair>{
	   int a;
	   int b;
	   public Pair(){}
	   public Pair(int x,int y){a=x;b=y;}
	   public int compareTo(Pair p){
		 return Integer.compare(a, p.a);
	   }
//		   long a,b;
//		   public Pair(long x,long y){a=x;b=y;}
//		   public int compareTo(Pair p){
//				 return Long.compare(a, p.a);
//		   }
//
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + a;
			result = prime * result + b;

			return result;
		}
		@Override
		public boolean equals(Object obj) {
			Pair cur = (Pair)obj;
			if((a==cur.a && b==cur.b))return true;
			return false;
		}
	 }
	static class TrieNode{
		int cnt;
		TrieNode[]child;
		public TrieNode() {
			cnt = 0;
			child = new TrieNode[10];
		}
	}
	  public static long gcd(long a,long b)
	  {
	    if(a<b)
	      return gcd(b,a);
	    if(b==0)
	      return a;
	    return gcd(b,a%b);

	  }
	  static int lcm(int a,int b) {
		  return  a*b / (int)gcd(a,b);
	  }

	  static long mod = 998244353;//(long)(1e9+7); //

	    public static void main(String[] args) throws Exception {
	       new Thread(null, null, "Anshum Gupta", 99999999) {
	            public void run() {
	                try {
	                    solve();
	                } catch(Exception e) {
	                    e.printStackTrace();
	                    System.exit(1);
	                }
	            }
	        }.start();
	    }

	static long pow(long x,long y){
	    if(y == 0)return 1;
	    if(y==1)return x;
	    long a = pow(x,y/2);
	    a = (a*a)%mod;
	    if(y%2==0){
	        return a;
	    }
	    return (a*x)%mod;
	}

	static long mxx;
	static int mxN = (int)(2e6+5);
	static int mxV = (int)(2e5);
	static long[]fact,inv_fact;
	static long my_inv(long a) {
		return pow(a,mod-2);
	}
	static long bin(int a,int b) {
		if(a < b || a<0 || b<0)return 0;
	    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
	}
		static ArrayList<ArrayList<Integer>>adj;
		static boolean[]vis;
	static void make_facts() {
	  fact=new long[mxN];
	  inv_fact = new long[mxN];
	  fact[0]=inv_fact[0]=1L;
	  for(int i=1;i<mxN;i++) {
		   fact[i] = (i*fact[i-1])%mod;
		   inv_fact[i] = my_inv(fact[i]);
	  }
	}
	 static void insert(TrieNode head, String str) {
		 TrieNode cur = head;
		 for(int i=0;i<str.length();i++) {
			 int x = str.charAt(i) - '0';
			 if(cur.child[x] == null) {
				 cur.child[x] = new TrieNode();
			 }
			 cur.child[x].cnt++;
			 cur = cur.child[x];
		 }
	 }
	 static String query(TrieNode head, String str) {
		 TrieNode cur = head;
		 String res = "";
		 for(int i=0;i<str.length();i++) {
			 int x = str.charAt(i) - '0';
			 res += str.charAt(i);
			 if(cur.child[x].cnt == 0) {
				 return res;
			 }
			 cur = cur.child[x];
		 }
		 return "";
	 }
	 static void remove(TrieNode head, String str) {
		 TrieNode cur = head;
		 for(int i=0;i<str.length();i++) {
			 int x = str.charAt(i) - '0';
			 cur.child[x].cnt--;
			 cur = cur.child[x];
		 }
	 }
	 public static void solve() throws Exception {
	   // solve the problem here
	   MyScanner s = new MyScanner();
	        out = new PrintWriter(new BufferedOutputStream(System.out), true);
	        int tc = 1;//s.nextInt();
	        mxx = (long)(1e18+5);
	//	        make_facts();
	//	        int mod = (int)1e9+7;
	        while(tc-->0){
	        	int n = s.nextInt();
	        	String[]arr = new String[n];
	        	TrieNode head = new TrieNode();
	        	for(int i=0;i<n;i++) {
	        		arr[i] = s.next();
	        		for(int j=arr[i].length()-1;j>=0;j--) {
	        			String cur = arr[i].substring(j);
	        			insert(head, cur);
	        		}
	        	}
	        	for(int i=0;i<n;i++) {
	        		for(int j=arr[i].length()-1;j>=0;j--) {
	        			String cur = arr[i].substring(j);
	        			remove(head, cur);
	        		}
	        		int ans = 10;
	        		String res = "";
	        		for(int j=arr[i].length()-1;j>=0;j--) {
	        			String cur = arr[i].substring(j);
	        			String val = query(head, cur);
	        			if(val.length() == 0)continue;
	        			if(val.length() < ans) {
	        				ans = val.length();
	        				res = val;
	        			}
	        		}
	        		out.println(res);
	        		for(int j=arr[i].length()-1;j>=0;j--) {
	        			String cur = arr[i].substring(j);
	        			insert(head, cur);
	        		}
	        	}

	        }

	        out.flush();
	}

	    //-----------PrintWriter for faster output---------------------------------
	    public static PrintWriter out;

	    //-----------MyScanner class for faster input----------
	    public static class MyScanner {
	        BufferedReader br;
	        StringTokenizer st;

	        public MyScanner() {
	            br = new BufferedReader(new InputStreamReader(System.in));
	        }

	        String next() {
	            while (st == null || !st.hasMoreElements()) {
	                try {
	                    st = new StringTokenizer(br.readLine());
	                } catch (IOException e) {
	                    e.printStackTrace();
	                }
	            }
	            return st.nextToken();
	        }

	        int nextInt() { return Integer.parseInt(next()); }
	        long nextLong() { return Long.parseLong(next()); }
	        double nextDouble() { return Double.parseDouble(next()); }

	        String nextLine(){
	            String str = "";
	            try {
	                str = br.readLine();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            return str;
	        }
	    }
	    //--------------------------------------------------------
	}


#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n; cin>>n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        set<string> r;
        for (int j = 0; j < 9; ++j) {
            for (int k = 1; k <= 9-j; ++k) {
                string b = a[i].substr(j, k);
                if(!r.count(b)) mp[b]++;
                r.insert(b);
            }
        }
    }
    vector<string> ans(n);
    for (int i = 0; i < n; ++i) {
        pair<int,int> add; int l = INT_MAX;
        for (int j = 0; j < 9; ++j) {
            for (int k = 0; k < 9; ++k) {
                string b = a[i].substr(j, k);
                if(mp[b]==1 && l > k) add = {j, k}, l = k;
            }
        }
        ans[i] = a[i].substr(add.first, add.second);
    }
    for(string x : ans) cout << x << "\n";
}


#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n; cin>>n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        set<string> r;
        for (int j = 0; j < 9; ++j) {
            for (int k = 1; k <= 9-j; ++k) {
                string b = a[i].substr(j, k);
                if(!r.count(b)) mp[b]++;
                r.insert(b);
            }
        }
    }
    vector<string> ans(n);
    for (int i = 0; i < n; ++i) {
        pair<int,int> add; int l = INT_MAX;
        for (int j = 0; j < 9; ++j) {
            for (int k = 0; k <= 9-j; ++k) {
                string b = a[i].substr(j, k);
                if(mp[b]==1 && l > k) add = {j, k}, l = k;
            }
        }
        ans[i] = a[i].substr(add.first, add.second);
    }
    for(string x : ans) cout << x << "\n";
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
ll n;
cin>>n;
vector <string> s;
map <string,ll> mp;
for (int i = 0;i < n;i++)
{
    string t;
    cin>>t;
    set <string> st;
    for (int i = 0;i < t.size();i++)
    {
        for (int j = 0;j + i - 1 < t.size();j++)
        {
            string f = t.substr(j,i);
            if (!st.count(f)) mp[f]++;
            st.insert(f);
        }
    }
    s.push_back(t);
}
for (int i = 0;i < n;i++)
{
    string h;
    h = s[i];
    ll ans1 = 1e18;
    string ans2 = "";
    for (int j = 0;j < h.size();j++)
    {
        for (int q = 0;j + q - 1 < h.size();q++)
        {
            string mah = h.substr(q,j);
            if (mp[mah]==1 && j<ans1) {ans1 = j;ans2 = mah;}
        }
    }
    cout<<ans2<<'\n';
}
return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main() {
ll n;
cin>>n;
vector <string> s;
map <string,ll> mp;
for (int i = 0;i < n;i++)
{
    string t;
    cin>>t;
    set <string> st;
    for (int i = 1;i <= t.size();i++)
    {
        for (int j = 0;j + i - 1 <= t.size();j++)
        {
            string f = t.substr(j,i);
            if (!st.count(f)) mp[f]++;
            st.insert(f);
        }
    }
    s.push_back(t);
}
for (int i = 0;i < n;i++)
{
    string h;
    h = s[i];
    ll ans1 = 1e18;
    string ans2 = "";
    for (int j = 1;j <= h.size();j++)
    {
        for (int q = 0;j + q - 1 <= h.size();q++)
        {
            string mah = h.substr(q,j);
            if (mp[mah]==1 && j<ans1) {ans1 = j;ans2 = mah;}
        }
    }
    cout<<ans2<<'\n';
}
return 0;
}


#include <bits/stdc++.h>
/*
Problem: D. Polycarp's phone book
Link   : https://codeforces.com/problemset/problem/858/D

Solution by: Mohamed Hisham El-Banna

Gmail   : Mohamed00Hisham@Gmail.com
Github  : www.github.com/Mhmd-Hisham
LinkedIn: www.linkedin.com/in/Mhmd-Hisham
*/

using namespace std;

typedef signed long long ll;
typedef unsigned long long ull;

#define PI acos(-1)
#define EPS 1e-10

#define FOR(i,to) for(i=0;i<(to);++i)
#define FORR(i,arr) for(auto& i:arr)
#define ITER(it,cont) for(__typeof(cont.begin()) it=cont.begin();it!=cont.end();it++)
#define ALL(v) (v.begin()),(v.end())
#define ZERO(arr) memset(arr,0,sizeof(arr))
#define MINUS(arr) memset(arr,0xff,sizeof(arr))
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int N;

string numbers[70001], ans, sub;
unordered_map<string, int> freq, tmp;

int main () {
    fastio;

    cin >> N;

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

        for (int j = 0; j < 9; ++j){
            // j -> start point
            for (int k = 1; k <= 9-j; ++k){
                // k -> substring size
                sub = numbers[i].substr(j, k);
                tmp[sub] = 1;
            }
        }

        // Just to avoid duplicate substrings from one number
        for (auto key : tmp)
            freq[key.first]++;

        tmp.clear();
    }

    for (int i = 0; i < N; ++i){

        int min_size = INT_MAX;
        for (int j = 0; j < 9; ++j){
            for (int k = 1; k <= 9-j; ++k){
                sub = numbers[i].substr(j, k);

                if ((freq[sub] == 1) && (k < min_size)){
                    ans = sub;
                    min_size = k;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}
/*
Sample input:-
-----------------
3
123456789
100000000
100123456

Sample output:-
-----------------
7
000
01

Resources:-
-------------

Explanation:
---------------

*/


#include <bits/stdc++.h>
/*
Problem: D. Polycarp's phone book
Link   : https://codeforces.com/problemset/problem/858/D

Solution by: Mohamed Hisham El-Banna

Gmail   : Mohamed00Hisham@Gmail.com
Github  : www.github.com/Mhmd-Hisham
LinkedIn: www.linkedin.com/in/Mhmd-Hisham
*/

using namespace std;

typedef signed long long ll;
typedef unsigned long long ull;

#define PI acos(-1)
#define EPS 1e-10

#define FOR(i,to) for(i=0;i<(to);++i)
#define FORR(i,arr) for(auto& i:arr)
#define ITER(it,cont) for(__typeof(cont.begin()) it=cont.begin();it!=cont.end();it++)
#define ALL(v) (v.begin()),(v.end())
#define ZERO(arr) memset(arr,0,sizeof(arr))
#define MINUS(arr) memset(arr,0xff,sizeof(arr))
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int N;

int min_size = 10;
string numbers[70001], ans, sub;
unordered_map<string, int> freq, tmp;
unordered_map<string, int> ::iterator itr;

int main () {
    fastio;

    cin >> N;

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

        for (int j = 0; j <= 9; ++j){
            for (int k = 1; k <= 9-j; ++k){
                sub = numbers[i].substr(j, k);
                tmp[sub]++;
            }
        }

        for (auto key : tmp)
            freq[key.first]++;

        tmp.clear();
    }

    for (int i = 0; i < N; ++i){

        min_size = 10;
        for (int j = 0; j <= 9; ++j){
            for (int k = 1; k <= 9-j; ++k){
                sub = numbers[i].substr(j, k);
                itr = freq.find(sub);

                if ((itr->second == 1) && (k < min_size)){
                    ans = sub;
                    min_size = k;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}
/*
Sample input:-
-----------------
3
123456789
100000000
100123456

Sample output:-
-----------------

Resources:-
-------------

Explanation:
---------------

*/


#include<bits/stdc++.h>
using namespace std;

int main(){
   	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);

	map<string , int > m[700005],final;
	int n;
	cin>>n;

	string a[n];
	for(int i=0 ; i<n ; i++){
	    cin>>a[i];
	}

	for(int i=0 ; i<n ; i++){
	    for(int j=0 ; j<9 ; j++){
	        string sub;
	        for(int k=j ; k<9 ; k++){
	            sub += a[i][k];
	            m[i][sub]++;
	            final[sub]++;
	        }
	    }
	}

	for(int i=0 ; i<n ; i++){
	    string res= a[i];
	    for(auto  x : m[i]){
	        if(x.second == final[x.first]){
    	        if(x.first.size() < res.size()) res = x.first;
	        }
	    }
	    cout<<res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;

int32_t main(){
   	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);

	map<string , int > m[700005],final;
	int n;
	cin>>n;

	string a[n];
	for(int i=0 ; i<n ; i++){
	    cin>>a[i];
	}

	for(int i=0 ; i<n ; i++){
	    for(int j=0 ; j<9 ; j++){
	        string sub;
	        for(int k=j ; k<9 ; k++){
	            sub += a[i][k];
	            m[i][sub]++;
	            final[sub]++;
	        }
	    }
	}

	for(int i=0 ; i<n ; i++){
	    string res= a[i];
	    for(auto  x : m[i]){
	        if(final[x.first] == x.size()){
    	        if(x.first.size() < res.size()) res = x.first;
	        }
	    }
	    cout<<res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;

int32_t main(){
   	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);

	map<string , int > m[700005],final;
	int n;
	cin>>n;

	string a[n];
	for(int i=0 ; i<n ; i++){
	    cin>>a[i];
	}

	for(int i=0 ; i<n ; i++){
	    for(int j=0 ; j<9 ; j++){
	        string sub;
	        for(int k=j ; k<9 ; k++){
	            sub += a[i][k];
	            m[i][sub]++;
	            final[sub]++;
	        }
	    }
	}

	for(int i=0 ; i<n ; i++){
	    string res= a[i];
	    for(auto  x : m[i]){
	        if(final[x.first] == x.second){
    	        if(x.first.size() < res.size()) res = x.first;
	        }
	    }
	    cout<<res<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;

int32_t main(){
   	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);

	map<string , int > m[700005],final;
	int n;
	cin>>n;

	string a[n];
	for(int i=0 ; i<n ; i++){
	    cin>>a[i];
	}

	for(int i=0 ; i<n ; i++){
	    for(int j=0 ; j<9 ; j++){
	        string sub;
	        for(int k=j ; k<9 ; k++){
	            sub += a[i][k];
	            m[i][sub]++;
	            final[sub]++;
	        }
	    }
	}

	for(int i=0 ; i<n ; i++){
	    string res= a[i];
	    for(auto  x : m[i]){
	        if(x.second == final[x.first]){
    	        if(x.first.size() < res.size()) res = x.first;
	        }
	    }
	    cout<<res<<endl;
	}
	return 0;
}


// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 70000;
int n;
string s[MAX_N];
map<string, int> cnt;

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> s[i];
        set<string> temp;
        forn(j, s[i].size()) {
            for (int l = 1; j + l <= s[i].size(); l++) {
                temp.insert(s[i].substr(j, l));
            }
        }

        for (auto t : temp) {
            if (contains(cnt, t)) {
                cnt[t] = -1;
            } else {
                cnt[t] = i;
            }
        }
    }

    vec<string> ans(n);
    vi l(n, 20);
    for (auto& [t, i] : cnt) {
        if (i >= 0 && l[i] > t.size()) {
            ans[i] = t;
            l[i] = t.size();
        }
    }

    for (auto& t : ans) {
        cout << t << "\n";
    }

    return 0;
}


// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 70000;
int n;
string s[MAX_N];
map<string, int> cnt;

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> s[i];
        set<string> temp;
        forn(j, s[i].size()) {
            for (int l = 1; j + l <= s[i].size(); l++) {
                temp.insert(s[i].substr(j, l));
            }
        }

        for (auto t : temp) {
            //cout << i << " " << t << endl;
            cnt[t]++;
        }
    }

    forn(i, n) {
        string ans = s[i];
        forn(j, s[i].size()) {
            for (int l = 1; j + l <= s[i].size(); l++) {
                string t = s[i].substr(j, l);
                if (cnt[t] == 1 && t.size() < ans.size()) {
                    ans = t;
                }
            }
        }
        cout << ans << "\n";
    }

    return 0;
}


// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 70000;
int n;
string s[MAX_N];
map<string_view, int> cnt;

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> s[i];
        string_view t = s[i];
        set<string_view> temp;
        forn(j, t.size()) {
            for (int l = 1; j + l <= t.size(); l++) {
                temp.insert(t.substr(j, l));
            }
        }

        for (auto t : temp) {
            if (contains(cnt, t)) {
                cnt[t] = -1;
            } else {
                cnt[t] = i;
            }
        }
    }

    vec<string_view> ans(n);
    vi l(n, 20);
    for (auto& [t, i] : cnt) {
        if (i >= 0 && l[i] > t.size()) {
            ans[i] = t;
            l[i] = t.size();
        }
    }

    for (auto& t : ans) {
        cout << t << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 1000000007

void func()
{
    ll n;
    cin>>n;
    vector<string> v(n);
    loop(i,0,n) cin>>v[i];
    map<string,ll> m;
    loop(i,0,n){
        set<string> s;
        loop(k,1,10){
            loop(j,0,9){
                if(j+k<=9){
                    string t=v[i].substr(j,k);
                    s.insert(t);
                }
            }
            for(auto u:s){
                m[u]++;
            }
            s.clear();
        }
    }
    loop(i,0,n){
        bool flag=false;
        loop(k,1,10){
            loop(j,0,9){
                if(j+k<=9){
                    string t=v[i].substr(j,k);
                    if(m[t]==1){
                        cout<<t<<"\n";
                        flag=true;
                        break;
                    }
                }
            }
            if(flag) break;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif

    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 1000000007

void func()
{
    ll n;
    cin>>n;
    vector<string> v(n);
    loop(i,0,n) cin>>v[i];
    vector<multiset<string> > sub(10);
    loop(i,0,n){
        set<string> s;
        loop(k,1,9){
            loop(j,0,9){
                if(j+k<=9){
                    string t=v[i].substr(j,k);
                    s.insert(t);
                }
            }
            for(auto u:s){
                sub[k].insert(u);
            }
            s.clear();
        }
    }
    loop(i,0,n){
        bool flag=false;
        loop(k,1,9){
            loop(j,0,9){
                if(j+k<=9){
                    string t=v[i].substr(j,k);
                    if(sub[k].count(t)==1){
                        cout<<t<<"\n";
                        flag=true;
                        break;
                    }
                }
            }
            if(flag) break;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif

    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define clean(a,k) memset(a, k, sizeof(a))
#define runner(i,k,m) for(i=k;i<=m;i++)
#define cases(T) cin>>T;while(T--)
using namespace std;
int main()
{
     boost;
     ll N;
     cin>>N;
     set<string> S[N];
     map<string,ll>mp;
     for(ll i=0;i<N;i++)
     {
          string str;
          cin>>str;
          for(ll j=0;j<str.length();j++)
          {
               for(ll k=0;k<str.length();k++)
                    S[i].insert(str.substr(j,k));
          }
          for(string j:S[i])     mp[j]++;
     }
     for(ll i=0;i<N;i++)
     {
          ll prev = 1e9;
          string str;
          for(string j:S[i])
          {
               if(mp[j] == 1 && j.length()<prev)
               {
                    str = j;
                    prev = j.length();
               }
          }
          cout<<str<<endl;
     }
     // cout<<mp["6"]<<endl;
     // for(string j:S[0])  cout<<j<<" ";
}


    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>

    using namespace std;

    vector<string> v, a;

    int n;

    void build_v(){

    	for(int i= 0; i < n; i++){
    		set<string> temp;
    		for(int j = 0; j < 9; j++){
    			string s = a[i].substr(0, j+1);
    			temp.insert(s);
    			for(int k = j + 1; k < 9; k++){
    				s.erase(s.begin());
    				s.push_back(a[i][k]);
    				temp.insert(s);
    			}
    		}
    		set<string> :: iterator it;
    		for(it = temp.begin(); it != temp.end(); it++)
                v.push_back(*it);
    	}
    	sort(v.begin(), v.end());
    	return;
    }

    void print(){
        for(int j = 0; j < v.size(); j++)
            cout << v[j] << endl;
        return;
    }

    string query(int pos){
    	vector<string> :: iterator low, up;

    	for(int j = 0; j < 9; j++){
    		string s = a[pos].substr(0, j+1);
    		low = lower_bound(v.begin(), v.end(), s);
    		up = upper_bound(v.begin(), v.end(), s);
    		if(up - low == 1) return s;
    		for(int k = j + 1; k < 9; k++){
    			s.erase(s.begin());
    			s.push_back(a[pos][k]);
    			low = lower_bound(v.begin(), v.end(), s);
    			up = upper_bound(v.begin(), v.end(), s);
    			if(up - low == 1) return s;
    		}
    	}
    }

    int main(){
    	cin >> n;
    	for(int j = 0; j < n; j++){
            string temp;
    		cin >> temp;
    		a.push_back(temp);
        }
    	build_v();
    	//print();

    	for(int j = 0; j < n; j++)
    		cout << query(j) << endl;
    	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld double
#define lld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define clean(a,k) memset(a, k, sizeof(a))
#define runner(i,k,m) for(i=k;i<=m;i++)
#define cases(T) cin>>T;while(T--)
using namespace std;
int main()
{
     boost;
     ll N;
     cin>>N;
     set<string> S[N];
     map<string,ll>mp;
     for(ll i=0;i<N;i++)
     {
          string str;
          cin>>str;
          for(ll j=0;j<str.length();j++)
          {
               for(ll k=0;k<str.length();k++)
                    S[i].insert(str.substr(j,k));
          }
          for(string j:S[i])     mp[j]++;
     }
     for(ll i=0;i<N;i++)
     {
          ll prev = 1e9;
          string str;
          for(string j:S[i])
          {
               if(mp[j] == 1 && j.length()<prev && j.length() >= 1)
               {
                    str = j;
                    prev = j.length();
               }
          }
          cout<<str<<endl;
     }
     // cout<<mp["6"]<<endl;
     // for(string j:S[0])  cout<<j<<" ";
}