#include <iostream>
#include <cstdio>
#include <cstring>
#define N 200002
using namespace std;
int head[N],ver[N*2],nxt[N*2],l;
int n,m,q,i,p[N],a[N],minp[N],pos[N],to[N],top,s[N];
bool vis[N];
int read()
{
    char c=getchar();
    int w=0;
    while(c<'0'||c>'9') c=getchar();
    while(c<='9'&&c>='0'){
        w=w*10+c-'0';
        c=getchar();
    }
    return w;
}
void insert(int x,int y)
{
    l++;
    ver[l]=y;
    nxt[l]=head[x];
    head[x]=l;
}
void dfs(int x)
{
    vis[x]=1;
    s[++top]=x;
    if(top>=n) minp[x]=s[top-n+1];
    for(int i=head[x];i;i=nxt[i]){
        int y=ver[i];
        if(!vis[y]) dfs(y);
    }
    top--;
}
int main()
{
    n=read();m=read();q=read();
    for(i=1;i<=n;i++) p[i]=read();
    for(i=1;i<=m;i++) a[i]=read();
    for(i=1;i<=n;i++) to[p[i]]=p[i%n+1];
    for(i=m;i>=1;i--){
        if(pos[a[i]]==0||pos[a[i]]>i) pos[a[i]]=i;
        if(pos[to[a[i]]]!=0){
            insert(pos[to[a[i]]],i);
        }
    }
    memset(minp,0x3f,sizeof(minp));
    for(i=m;i>=1;i--){
        if(!vis[i]) dfs(i);
    }
    for(i=m-1;i>=1;i--) minp[i]=min(minp[i],minp[i+1]);
    for(i=1;i<=q;i++){
        int l=read(),r=read();
        if(minp[l]<=r) printf("1");
        else printf("0");
    }
    return 0;
}


#include<bits/stdc++.h>
#define ri register int
#define ll long long
#define rl register ll
#define go(i,a,b) for(ri i=a;i<=b;i++)
#define back(i,a,b) for(ri i=a;i>=b;i--)
#define g() getchar()
#define il inline
#define pf printf
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
il int fr(){
	ri w=0,q=1;char ch=g();
	while(ch<'0'||ch>'9'){if(ch=='-')q=-1;ch=g();}
	while(ch>='0'&&ch<='9')w=(w<<1)+(w<<3)+ch-'0',ch=g();
	return w*q;
}
const int N=2e5+2;
int n,m,q,p[N],id[N],a[N],pre[N],f[N][20],lst[N];
bool ans[N];
struct Tree{
	int l,r,mx;
}t[N<<2];
il void build(int p,int l,int r){
	if(l>r)return;
	if(l==r){t[p]=(Tree){l,r,pre[l]};return;}
	t[p]=(Tree){l,r,0};
	int mid=(l+r)>>1;
	build(p<<1,l,mid);build(p<<1|1,mid+1,r);
	t[p].mx=max(t[p<<1].mx,t[p<<1|1].mx);
	return;
}
il bool ask(int p,int l,int r){
	if(t[p].l>=l&&t[p].r<=r)return t[p].mx>=l;
	int mid=(t[p].l+t[p].r)>>1;bool as=0;
	if(l<=mid)as|=ask(p<<1,l,r);
	if(r>mid)as|=ask(p<<1|1,l,r);
	return as;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=fr();m=fr();q=fr();
	go(i,1,n)p[i]=fr(),id[p[i]]=i;
	go(i,1,m){
		a[i]=fr();lst[a[i]]=i;
		if(i==1)continue;
		int ID=id[a[i]]-1;if(ID<=0)ID+=n;
		if(lst[p[ID]]==0)continue;
		f[i][0]=lst[p[ID]];
		go(j,1,19)f[i][j]=f[f[i][j-1]][j-1];
	}
	go(i,n,m){
		int x=n-1,to=i;
		back(j,19,0)if((1<<j)<=x)to=f[to][j],x-=(1<<j);
		pre[i]=to;
	}
	//go(i,1,m)cout<<"pre["<<i<<"]="<<pre[i]<<endl;
	build(1,1,m);
	go(t,1,q){
		int l=fr(),r=fr();
		if(r-l+1<n){ans[t]=0;continue;}
		ans[t]=ask(1,l,r);
	}
	go(t,1,q)pf("%d",ans[t]?1:0);puts("");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <utility>
#include <algorithm>
#include <vector>
#define rg register
#define il inline
#define ll long long
using namespace std;
il void read(int &x){
    rg char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    x=c^48;
	c=getchar();
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
}

const int N=2e5+5;
struct Edge{
	int to,nxt;
}edge[N];
int cnt,head[N];
int n,m,q,l,r;
int p[N],a[N];
int dep[N],anc[N];
int pre[N],lst[N];
int s[N],val[N],k[N];

il void add_edge(int u,int v){
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
il void dfs(int u){
    anc[dep[u]]=u;
	if(dep[u]>=n)
		val[u]=anc[dep[u]-n+1];
	else
		val[u]=m+1;
    for(rg int i=head[u];i;i=edge[i].nxt){
    	int v=edge[i].to;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

signed main(){
	read(n);
	read(m);
	read(q);
	for(rg int i(1);i<=n;++i){
		read(p[i]);
		k[p[i]]=p[i-1];
	}
	k[p[1]]=p[n];
	for(rg int i(1);i<=m;++i){
		read(a[i]);
		pre[i]=lst[a[i]];
		lst[a[i]]=i;
        for(rg int j(lst[k[a[i]]]);j&&(s[j]==0);j=pre[j])
			s[j]=i;
	}
	for(rg int i(1);i<=m;++i)
		if(!s[i])
			s[i]=m+1;
	for(rg int i(1);i<=m;++i){
		add_edge(s[i],i);
		dfs(m+1);
	}
	for(rg int i(m-1);i;--i)
		val[i]=min(val[i],val[i+1]);
	while(q--){
		read(l);
		read(r);
		putchar('0'+(val[l]<=r));
	}
	return 0;
}


#include <bits/stdc++.h>
#define add push_back
#define ll long long
using namespace std;
const int N = 200005;
int n, m, q, log2n;
int f[N][50], a[N], b[N], c[N], pos[N], ps[N];
vector<int> p[N];
int father(int u, int k){
	for (int i = 0; k; i++, k >>= 1) if (k&1) u = f[u][i];
	return u;
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	memset(pos, 0, sizeof(pos));
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++) cin >> a[i], ps[a[i]] = i;
	for (int i = 1; i <= m; i++) cin >> b[i];
	a[n+1] = a[1];
	for (int i = m; i >= 1; i--){
		if (pos[a[ps[b[i]]+1]] != 0) f[i][0] = pos[a[ps[b[i]]+1]];
		pos[b[i]] = i;
	}
	log2n = round(log2(m));
	for (int j = 1; j <= log2n; j++)
		for (int i = 1; i <= m; i++)
			f[i][j] = f[f[i][j-1]][j-1];
	for (int i = 1; i <= m; i++) c[i] = father(i, n-1);
	for (int i = 1; i <= m; i++) if (c[i] == 0) c[i] = 0x3f3f3f3f;
	for (int i = m-1; i >= 1; i--) c[i] = min(c[i+1], c[i]);
	for (int i = 0; i < q; i++){
		int u, v;
		cin >> u >> v;
		cout << (v >= c[u]);
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200005

int n;  int m;  int q;  int a[N];  int lst[N];  int f[N][20];  int lg[N];  int book[N];  int b[N];
int c[N];  int st[N][20];

int maxn(int l,int r){
    if(l==r) return st[l][0];
    int k=lg[r-l+1]-1;
    return max(st[l][k],st[r-(1<<k)+1][k]);
}

int main(){
    for(int i=1;i<N;i++) lg[i]=lg[i-1]+(1<<lg[i-1]==i?1:0);
    scanf("%d %d %d",&n,&m,&q);
    for(int i=1;i<=n;++i) scanf("%d",a+i);  a[0]=a[n];
    for(int i=1;i<=n;++i) lst[a[i]]=a[i-1];
    for(int i=1;i<=m;++i){
        scanf("%d",b+i);
        f[i][0]=book[lst[b[i]]];
        book[b[i]]=i;
    }
    for(int i=1;i<=lg[n]-1;++i) for(int j=1;j<=m;++j) f[j][i]=f[ f[j][i-1] ][i-1];
    for(int i=1;i<=m;++i){
        int ed=i;
        for(int j=lg[n-1]-1;j>=0;--j) if( (n-1)&(1<<j) )  ed=f[ed][j];
        c[i]=ed;
    }

    for(int i=1;i<=m;i++) st[i][0]=c[i];
    for(int i=1;i<=lg[m]-1;i++) for(int j=1;j+(1<<i)-1<=m;j++) st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);

    while(q--){
        int l; int r; scanf("%d %d",&l,&r);
        if(maxn(l, r)>=l) printf("1");
        else              printf("0");
    }
    printf("\n");
    return 0;

}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=2e5+2;
int p[N],a[N],lst[N],inxt[N],pre[N],c[N],dep[N],nd[N],r[N],lj[N],nxt[N],fir[N];
int n,m,q,i,j,cc,bs;
inline void add(int x,int y)
{
	lj[++bs]=y;
	nxt[bs]=fir[x];
	fir[x]=bs;
}
inline void read(int &x)
{
	cc=getchar();
	while ((cc<48)||(cc>57)) cc=getchar();
	x=cc^48;cc=getchar();
	while ((cc>=48)&&(cc<=57))
	{
		x=x*10+(cc^48);
		cc=getchar();
	}
}
void dfs(int x)
{
	int i;nd[dep[x]]=x;if (dep[x]>=n) r[x]=nd[dep[x]-(n-1)]; else r[x]=m+1;
	for (i=fir[x];i;i=nxt[i])
	{
		dep[lj[i]]=dep[x]+1;
		dfs(lj[i]);
	}
}
int main()
{
	//freopen("shuju","r",stdin);
	read(n);read(m);read(q);
	for (i=1;i<=n;i++) {read(p[i]);inxt[p[i]]=p[i-1];}
	inxt[p[1]]=p[n];
//for (i=1;i<=n;i++) printf("%d ",inxt[i]);puts("");
	for (i=1;i<=m;i++)
	{
		read(a[i]);pre[i]=lst[a[i]];lst[a[i]]=i;
		for (j=lst[inxt[a[i]]];(j)&&(c[j]==0);j=pre[j]) c[j]=i;
	}for (i=1;i<=m;i++) if (!c[i]) c[i]=m+1;
	for (i=1;i<=m;i++) add(c[i],i);dfs(m+1);
	//for (i=1;i<=m;i++) printf("%d: c%d r%d\n",i,c[i],r[i]);puts("");
	for (i=m-1;i;i--) r[i]=min(r[i+1],r[i]);
	while (q--)
	{
		read(i);read(j);
		putchar(48+(r[i]<=j));
	}
}


// -*- coding: utf-8 -*-
// @Date    : 2019-04-28 16:55:39

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

const int N = 2e5 + 233;
int dp[N][20], lst[N], nxt[N], ans[N], a[N], b[N];

// #define local
int main()
{
#ifdef local
	freopen("data.in", "r", stdin);
	freopen("ans.out", "w", stdout);
#endif
	int n, m, t;
	scanf("%d%d%d", &n, &m, &t);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a+i);
	for(int i = 1; i <= n; ++i)
	{
		nxt[a[i-1]] = a[i];
		lst[i] = m+1;
	}
	nxt[a[n]] = a[1];
	for(int i = 1; i <= m; ++i)
		scanf("%d", b+i);
	for(int i = 0; i < 20; ++i)
		dp[m+1][i] = m+1;
	ans[m+1] = m+1;

	for(int i = m; i; --i)
	{
		dp[i][0] = lst[nxt[b[i]]];
		lst[b[i]] = i;
		for(int j = 1; j < 20; ++j)
			dp[i][j] = dp[dp[i][j-1]][j-1];
		int cnt = n-1;
		int p = i;
		for(int j = 19; j+1; --j)
			if(cnt >= (1<<j))
			{
				cnt -= (1<<j);
				p = dp[p][i];
			}
		ans[i] = min(ans[i+1], p);
	}

	while(t--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		if(ans[l] <= r)
			printf("1");
		else
			printf("0");
	}
	return 0;
}


//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;  typedef long long ll;
inline int qr(){
	register int ret=0,f=0;
	register char c=getchar();
	while(!isdigit(c))f|=c==45,c=getchar();
	while(isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=2e5+5;
int p[maxn],data[maxn];
int st[19][maxn],Pair[maxn],Min[19][maxn];
int lg[maxn];
int last[maxn];
int n,m,T;
const int inf=0x3f3f3f3f;
int main(){
	/*
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	*/
	m=qr(); n=qr();  T=qr();
	for(int t=2;t<=n;++t) lg[t]=lg[t>>1]+1;
	for(int t=1;t<=m;++t) p[qr()]=t;
	for(int t=1;t<=n;++t) data[t]=p[qr()];
	//for(int t=1;t<=n;++t) cerr<<data[t]<<' ';
	//cerr<<('\n');
	for(int t=n;t;--t){
		if(last[data[t]+1]) st[0][t]=last[data[t]+1];
		if(data[t]==m&&last[1]) st[0][t]=last[1];
		last[data[t]]=t;
	}
	//for(int t=1;t<=n;++t) cerr<<st[0][t]<<' ';
	//cerr<<endl;
	for(int t=1;t<=lg[m];++t)
		for(int i=1;i<=n;++i)
			st[t][i]=st[t-1][st[t-1][i]];
	memset(Min,0x3f,sizeof Min);
	for(int t=1;t<=n;++t){
		int k=t;
		for(int i=0;i<=lg[m-1];++i)
			if(((m-1)>>i&1))
				k=st[i][k];
		if(k) Min[0][t]=k;
	}
	for(int t=1;t<=lg[n];++t)
		for(int i=1;i<=n;++i)
			Min[t][i]=min(Min[t-1][i]?Min[t-1][i]:inf,Min[t-1][i+(1<<t>>1)]?Min[t-1][i+(1<<t>>1)]:inf);
	//for(int t=1;t<=n;++t) cerr<<Min[1][t]<<' ';
	//cerr<<endl;
	while(T--){
		int l=qr(),r=qr();
		//cerr<<"min="<<Min[lg[r-l+1]][l]<<' '<<Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1] <<endl;
		if(min(Min[lg[r-l+1]][l],Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1])<=r) putchar(49);
		else putchar(48);
	}
	putchar(10);
	return 0;
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Threading;
using System.Collections;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
#if !ONLINE_JUDGE
            Console.SetIn(new System.IO.StreamReader(@"..\..\..\in"));
            Console.SetOut(new System.IO.StreamWriter(@"..\..\..\out"));
            for (int testN = 0; testN < 3; testN++)
            {
#endif
                //SetCulture();
                var n = NextInt();
                var a = ReadInts();
                int[,] m = new int[n, 33];
                int[] r = new int[33];
                int ai;
                int st;
                int[] cnt = new int[33];
                int xx = int.MaxValue;
                HashSet<int> hs = new HashSet<int>();
                for (int i = 0; i < 33; i++)
                {
                    cnt[i] = -1;
                    r[i] = 0;
                }
                int maxst = 0;
                for (int i = 0; i < n; i++)
                {
                    ai = a[i];
                    if (hs.Contains(ai))
                    {
                        continue;
                    }
                    else
                    {
                        hs.Add(ai);
                    }
                    st = 0;
                    while (ai > 0)
                    {
                        if (maxst < st)
                        {
                            maxst = st;
                        }
                        m[i, st] = ai % 2;
                        if (m[i, st] == 1)
                        {
                            r[st]++;
                            //cnt[st] &= a[i];
                            if (cnt[st] == -1)
                            {
                                cnt[st] = a[i];
                            }
                            else
                            {
                                cnt[st] = cnt[st] & a[i];
                            }
                        }
                        ai /= 2;
                        st++;
                    }
                }
                int maxind = -1;
                int maxlen = 0;
                int li;
                for (int i = 1; i <= maxst; i++)
                {
                    if (r[i] > 0)
                    {
                        ai = cnt[i];
                        li = 0;
                        while (ai % 2 == 0)
                        {
                            li++;
                            ai /= 2;
                        }
                        if (li > maxlen || (maxlen > 0 && li == maxlen && r[i] > r[maxind]))
                        {
                            maxlen = li;
                            maxind = i;
                        }
                    }
                }
                if (maxind == -1)
                {
                    Console.WriteLine(-1);
                }
                else
                {
                    Console.WriteLine(r[maxind]);
                    for (int i = 0; i < n; i++)
                    {
                        if (m[i, maxind] == 1)
                        {
                            Console.Write(a[i].ToString() + " ");
                        }
                    }
                }

                //Console.WriteLine(string.Format(NumberFormatInfo.InvariantInfo, "{0:F4}", res));
#if !ONLINE_JUDGE
                Console.WriteLine("");
                Console.WriteLine("");
                Console.ReadLine();
            }
            Console.In.Close();
            Console.Out.Close();
#endif
        }

        private static char[] _defaultSplitter = new char[] { ' ', '\t' };

        private static void SetCulture()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        }

        private static char[] ReadChars(int n)
        {
            char[] buffer = new char[n];
            Console.In.ReadBlock(buffer, 0, n);
            return buffer;
        }

        private static string[] ReadAll()
        {
            return Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadWords(char[] splitter)
        {
            return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadWords()
        {
            return ReadWords(_defaultSplitter);
        }

        private static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        private static int[] ReadInts(char[] splitter)
        {
            return Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        private static int[] ReadInts()
        {
            return ReadInts(_defaultSplitter);
        }

        private static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        private static double ReadDouble()
        {
            return double.Parse(Console.ReadLine(), NumberFormatInfo.InvariantInfo);
        }

        private static int _pos = 0;
        private static string[] _inputLine = new string[0];

        private static void CheckInputLine()
        {
            if (_pos >= _inputLine.Length)
            {
                _inputLine = ReadWords();
                _pos = 0;
            }
        }

        private static string NextWord()
        {
            CheckInputLine();
            return _inputLine[_pos++];
        }

        private static int NextInt()
        {
            CheckInputLine();
            return int.Parse(_inputLine[_pos++]);
        }

        private static long NextLong()
        {
            CheckInputLine();
            return long.Parse(_inputLine[_pos++]);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                new Program().Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
#if DEBUG
            Console.ReadKey();
#endif

        }

        public void Run()
        {
            var n = int.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToList();

            for (int i = 31; i >= 0; i--)
            {
                int mask = 1 << i;
                var l = list.Where(a => (a & mask) == mask).ToList();
                if (l.Count == 0)
                    continue;
                int result = l.Aggregate((a, b) => a & b);
                if (result % mask == 0)
                {
                    Console.WriteLine(l.Count);
                    Console.WriteLine(string.Join(" ", l));
                    return;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                new Program().Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #if DEBUG
            Console.ReadKey();
            #endif

        }

        public void Run()
        {
            HashSet<int>[] l = new HashSet<int>[33];
            for (int i = 0; i < 33; i++)
                l[i] = new HashSet<int>();

            var n = int.Parse(Console.ReadLine());
            var line = Console.ReadLine().Split(' ');
            foreach (var k in line)
            {
                var a = int.Parse(k);
                int b = (int)Math.Floor(Math.Log(a, 2)) + 1;
                l[b].Add(a);
            }

            for (int i = 31; i > 0; i--)
            {
                if (l[i].Count == 0)
                    continue;
                var sum = l[i].First();
                foreach (var a in l[i])
                    sum &= a;
                if (sum == (1 << (i - 1)))
                {
                    Console.WriteLine(l[i].Count);
                    foreach (var t in l[i])
                        Console.Write(t + " ");
                    return;
                }
            }

            // all = -1
            var max = l.Max(s => s.Count);
            var set = l.Where(s => s.Count == max).First();
            Console.WriteLine(set.Count);
            foreach (var t in set)
                Console.Write(t + " ");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                new Program().Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #if DEBUG
            Console.ReadKey();
            #endif

        }

        public void Run()
        {
            HashSet<int>[] list = new HashSet<int>[33];
            for (int i = 0; i < 33; i++)
                list[i] = new HashSet<int>();

            var n = int.Parse(Console.ReadLine());
            var line = Console.ReadLine().Split(' ');
            foreach (var k in line)
            {
                var num = int.Parse(k);
                int bits = (int)Math.Floor(Math.Log(num, 2)) + 1;
                list[bits].Add(num);
            }

            for (int i = 31; i > 0; i--)
            {
                if (list[i].Count == 0)
                    continue;
                var sum = list[i].First();
                foreach (var a in list[i])
                    sum &= a;
                if (sum == (1 << (i - 1)))
                {
                    Console.WriteLine(list[i].Count);
                    Console.WriteLine(string.Join(" ", list[i]));
                    return;
                }
            }

            // all = -1
            var max = list.Max(s => s.Count);
            var set = list.Where(s => s.Count == max).First();
            Console.WriteLine(set.Count);
            Console.WriteLine(string.Join(" ", set));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                new Program().Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
#if DEBUG
            Console.ReadKey();
#endif

        }

        public void Run()
        {
            var n = int.Parse(Console.ReadLine());
            var list = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToList();

            for (int i = 31; i >= 0; i--)
            {
                int mask = 1 << i;
                var l = list.Where(a => (a & mask) == mask).ToList();
                if (l.Count == 0)
                    continue;
                int result = l.Aggregate((a, b) => a & b);
                if (result == mask)
                {
                    Console.WriteLine(l.Count);
                    Console.WriteLine(string.Join(" ", l));
                    return;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace a1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                new Program().Run();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #if DEBUG
            Console.ReadKey();
            #endif

        }

        public void Run()
        {
            HashSet<int>[] list = new HashSet<int>[32];
            int[] sums = new int[32];

            for (int i = 0; i < 32; i++)
                list[i] = new HashSet<int>();

            var n = int.Parse(Console.ReadLine());
            var line = Console.ReadLine().Split(' ');
            foreach (var k in line)
            {
                var num = int.Parse(k);
                int bits = (int)Math.Floor(Math.Log(num, 2)) + 1;
                list[bits].Add(num);
            }

            for (int i = 0; i < 32; i++)
            {
                if (list[i].Count == 0)
                {
                    sums[i] = -2;
                    continue;
                }
                var sum = list[i].First();
                foreach (var a in list[i])
                    sum &= a;

                int bits = 1;
                while (sum % 2 == 0)
                {
                    bits++;
                    sum >>= 1;
                }
                sums[i] = bits;
            }

            var maxbits = sums.Max();
            var maxcount = list.Where((l, i) => sums[i] == maxbits).Max(l => l.Count);
            var set = list.Where((s, i) => sums[i] == maxbits && s.Count == maxcount).First();
            Console.WriteLine(set.Count);
            Console.WriteLine(string.Join(" ", set));
        }
    }
}


using System;
using System.Collections.Generic;

namespace B {
    internal class Program {
        private static void Main(string[] args) {
            var n = Convert.ToInt32(Console.ReadLine());
            var s = Console.ReadLine().Split(' ');
            var a = new int[n];

            for (int i = 0; i < n; i++) {
                a[i] = Convert.ToInt32(s[i]);
            }

            var t = new List<int>[32];

            for (int i = 0; i < 32; i++) {
                t[i] = new List<int>();
                for (int j = 0; j < n; j++) {
                    if ((a[j] & (1 << i)) != 0) {
                        t[i].Add(a[j]);
                    }
                }
            }

            for (int i = 32 - 1; i >= 0; i--) {
                if (t[i].Count != 0) {
                    Console.WriteLine(t[i].Count);
                    Console.WriteLine(string.Join(" ", t[i]));
                    return;
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace B {
    internal class Program {
        private static void Main(string[] args) {
            var n = Convert.ToInt32(Console.ReadLine());
            var s = Console.ReadLine().Split(' ');
            var a = new int[n];

            for (int i = 0; i < n; i++) {
                a[i] = Convert.ToInt32(s[i]);
            }

            var t = new HashSet<int>[32];

            for (int i = 0; i < 32; i++) {
                t[i] = new HashSet<int>();
                for (int j = 0; j < n; j++) {
                    if ((a[j] & (1 << i)) != 0) {
                        t[i].Add(a[j]);
                    }
                }
            }

            var max = 0;

            for (int i = 32 - 1; i >= 0; i--) {
                if (t[i].Count == 0) continue;
                ;
                for (int j = 0; j < 32; j++) {
                    if (t[i].IsSubsetOf(t[j])) {
                        max = Math.Max(max, j);
                        break;
                    }
                }
            }

            Console.WriteLine(t[max].Count);

            Console.WriteLine(string.Join(" ",t[max]));
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Vasily_the_Bear_and_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int index = 0;
            int mask = 1;
            int max = -1;
            int maxmask = 0;
            int countmax = 0;
            for (int k = 0; k < 32; k++)
            {
                int sum = int.MaxValue;
                int count = 0;
                while (index < n && (nn[index] & mask) == mask && (nn[index] ^ mask) < mask)
                {
                    sum &= nn[index];
                    index++;
                    count++;
                }

                if (sum != int.MaxValue)
                {
                    int ss = sum - (sum & (sum - 1));
                    if (ss > max)
                    {
                        max = ss;
                        maxmask = mask;
                        countmax = count;
                    }
                    else if (ss == max && countmax < count)
                    {
                        maxmask = mask;
                        countmax = count;
                    }
                }

                mask <<= 1;
            }

            if (max == 1)
            {
                writer.WriteLine("-1");
            }
            else
            {
                var list = new List<int>();
                for (int i = 0; i < nn.Length; i++)
                {
                    if ((nn[i] & maxmask) == maxmask && (nn[i] ^ maxmask) < maxmask)
                    {
                        list.Add(nn[i]);
                    }
                }
                writer.WriteLine(list.Count);
                foreach (int i in list)
                {
                    writer.Write(i);
                    writer.Write(' ');
                }
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Vasily_the_Bear_and_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int mask = 1;
            int max = -1;
            int maxmask = 0;
            int countmax = 0;
            for (int k = 0; k < 32; k++)
            {
                int sum = int.MaxValue;
                int count = 0;
                for (int index = 0; index < n; index++)
                {
                    if ((nn[index] & mask) == mask)
                    {
                        sum &= nn[index];
                        count++;
                    }
                }

                if (sum != int.MaxValue)
                {
                    int ss = sum - (sum & (sum - 1));
                    if (ss > max)
                    {
                        max = ss;
                        maxmask = mask;
                        countmax = count;
                    }
                    else if (ss == max && countmax < count)
                    {
                        maxmask = mask;
                        countmax = count;
                    }
                }

                mask <<= 1;
            }

            if (max == 1)
            {
                writer.WriteLine("-1");
            }
            else
            {
                var list = new List<int>();
                for (int i = 0; i < nn.Length; i++)
                {
                    if ((nn[i] & maxmask) == maxmask)
                    {
                        list.Add(nn[i]);
                    }
                }
                writer.WriteLine(list.Count);
                foreach (int i in list)
                {
                    writer.Write(i);
                    writer.Write(' ');
                }
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Vasily_the_Bear_and_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int mask = 1;
            int max = -1;
            int maxmask = 0;
            int countmax = 0;
            for (int k = 0; k < 32; k++)
            {
                int sum = int.MaxValue;
                int count = 0;
                for (int index = 0; index < n; index++)
                {
                    if ((nn[index] & mask) == mask)
                    {
                        sum &= nn[index];
                        count++;
                    }
                }

                if (sum != int.MaxValue)
                {
                    int ss = sum - (sum & (sum - 1));
                    if (ss > max)
                    {
                        max = ss;
                        maxmask = mask;
                        countmax = count;
                    }
                    else if (ss == max && countmax < count)
                    {
                        maxmask = mask;
                        countmax = count;
                    }
                }

                mask <<= 1;
            }

            var list = new List<int>();
            for (int i = 0; i < nn.Length; i++)
            {
                if ((nn[i] & maxmask) == maxmask)
                {
                    list.Add(nn[i]);
                }
            }
            writer.WriteLine(list.Count);
            foreach (int i in list)
            {
                writer.Write(i);
                writer.Write(' ');
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Vasily_the_Bear_and_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int index = 0;
            int mask = 1;
            int max = -1;
            int maxmask = 0;
            int countmax = 0;
            for (int k = 0; k < 32; k++)
            {
                int sum = int.MaxValue;
                int count = 0;
                while (index < n && (nn[index] & mask) == mask && (nn[index] ^ mask) < mask)
                {
                    sum &= nn[index];
                    index++;
                    count++;
                }

                if (sum != int.MaxValue)
                {
                    int ss = sum - (sum & (sum - 1));
                    if (ss > max)
                    {
                        max = ss;
                        maxmask = mask;
                        countmax = count;
                    }
                    else if (ss == max && countmax < count)
                    {
                        maxmask = mask;
                        countmax = count;
                    }
                }

                mask <<= 1;
            }

            if (max == 1)
            {
                writer.WriteLine("-1");
            }
            else
            {
                for (int i = 0; i < 33; i++)
                {
                    max >>= 1;
                    if (max == 0)
                    {
                        writer.WriteLine(i);
                        break;
                    }
                }

                for (int i = 0; i < nn.Length; i++)
                {
                    if ((nn[i] & maxmask) == maxmask && (nn[i] ^ maxmask) < maxmask)
                    {
                        writer.Write(nn[i]);
                        writer.Write(' ');
                    }
                }
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Vasily_the_Bear_and_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            int mask = 1;
            int max = -1;
            int maxmask = 0;
            int countmax = 0;
            for (int k = 0; k < 32; k++)
            {
                int sum = int.MaxValue;
                int count = 0;
                for (int index = 0; index < n; index++)
                {
                    if ((nn[index] & mask) == mask && (nn[index] ^ mask) < mask)
                    {
                        sum &= nn[index];
                        count++;
                    }
                }

                if (sum != int.MaxValue)
                {
                    int ss = sum - (sum & (sum - 1));
                    if (ss > max)
                    {
                        max = ss;
                        maxmask = mask;
                        countmax = count;
                    }
                    else if (ss == max && countmax < count)
                    {
                        maxmask = mask;
                        countmax = count;
                    }
                }

                mask <<= 1;
            }

            if (max == 1)
            {
                writer.WriteLine("-1");
            }
            else
            {
                var list = new List<int>();
                for (int i = 0; i < nn.Length; i++)
                {
                    if ((nn[i] & maxmask) == maxmask && (nn[i] ^ maxmask) < maxmask)
                    {
                        list.Add(nn[i]);
                    }
                }
                writer.WriteLine(list.Count);
                foreach (int i in list)
                {
                    writer.Write(i);
                    writer.Write(' ');
                }
            }
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            for (int bit = 29; bit >= 0; bit--)
            {
                var b = a.Where(x => (x >> bit) == 1).ToList();
                if (!b.Any())
                    continue;

                var and = b.Aggregate((l, r) => l & r);
                for (int BIT = 0; BIT < bit; BIT++)
                {
                    if ((and & 1) == 1)
                    {
                        b.RemoveAll(x => ((x >> BIT) & 1) == 1);
                        and = b.Aggregate((l, r) => l & r);
                        and = and >> BIT;
                    }

                    and = and >> 1;
                }

                if (b.Any())
                {
                    Console.WriteLine(b.Count);
                    Console.WriteLine(String.Join(" ", b));

                    return;
                }
            }

            Console.WriteLine(a.Count);
            Console.WriteLine(String.Join(" ", a));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            for (int bit = 29; bit >= 0; bit--)
            {
                var b = a.Where(x => (x >> bit) == 1).ToList();
                if (!b.Any())
                    continue;

                var and = b.Aggregate((l, r) => l & r);
                for (int BIT = 0; BIT < bit; BIT++)
                {
                    if ((and & 1) == 1)
                    {
                        b.RemoveAll(x => (x >> BIT) == 1);
                    }

                    and = and >> 1;
                }

                if (b.Any())
                {
                    Console.WriteLine(b.Count);
                    Console.WriteLine(String.Join(" ", b));

                    return;
                }
            }

            Console.WriteLine(a.Count);
            Console.WriteLine(String.Join(" ", a));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static int HighestOrderBitSet(long l)
        {

            if(l == 0)
                return -1;

            int bit = 0;
            while ((l & 1) != 1)
            {
                bit++;
                l = l >> 1;
            }
            return bit;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).Select(x => new { order = HighestOrderBitSet(x), value = x }).ToList();
            var max = a.Max(x => x.order);
            List<long> b = new List<long>();
            if (max == -1)
                b.AddRange(a.Select(x => x.value));
            else
                b.AddRange(a.Where(x => (x.value >> max) == 1).Select(x => x.value));

            Console.WriteLine(b.Count);
            Console.WriteLine(String.Join(" ", b));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            for (int bit = 29; bit >= 0; bit--)
            {
                bool good = true;
                var b = a.Where(x => (x >> bit) == 1).ToList();
                if (b.Count == 0)
                    continue;

                var and = b.Aggregate((l, r) => l & r);
                for (int BIT = 0; BIT < bit; BIT++)
                {
                    if ((and & 1) == 1)
                    {
                        good = false;
                        break;
                    }

                    and = and >> 1;
                }

                if (good)
                {
                    Console.WriteLine(b.Count);
                    Console.WriteLine(String.Join(" ", b));

                    return;
                }
            }

            Console.WriteLine(a.Count);
            Console.WriteLine(String.Join(" ", a));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static int HighestOrderBitSet(long l)
        {
            int bit = 29;
            while ((l & 0x20000000) != 0x20000000)
            {
                if (bit == 0)
                    return -1;

                bit--;
                l = l << 1;
            }

            return bit;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).Select(x => new { order = HighestOrderBitSet(x), value = x });
            var max = a.Max(x => x.order);
            List<long> b = new List<long>();
            if (max == -1)
                b.AddRange(a.Select(x => x.value));
            else
                b.AddRange(a.Where(x => x.order == max).Select(x => x.value));

            Console.WriteLine(b.Count);
            Console.WriteLine(String.Join(" ", b));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            for (int bit = 29; bit >= 0; bit--)
            {
                var b = a.Where(x => ((x >> bit)&1) == 1).ToList();
                if (!b.Any())
                    continue;

                var and = b.Aggregate((l, r) => l & r);
                for (int BIT = 0; BIT < bit; BIT++)
                {
                    if ((and & 1) == 1)
                    {
                        b.RemoveAll(x => ((x >> BIT) & 1) == 1);
                        if (!b.Any())
                            break;
                        and = b.Aggregate((l, r) => l & r);
                        and = and >> BIT;
                    }

                    and = and >> 1;
                }

                if (b.Any())
                {
                    Console.WriteLine(b.Count);
                    Console.WriteLine(String.Join(" ", b));

                    return;
                }
            }

            Console.WriteLine(a.Count);
            Console.WriteLine(String.Join(" ", a));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem195C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            for (int bit = 29; bit >= 0; bit--)
            {
                var b = a.Where(x => (x >> bit) == 1).ToList();
                if (!b.Any())
                    continue;

                var and = b.Aggregate((l, r) => l & r);
                for (int BIT = 0; BIT < bit; BIT++)
                {
                    if ((and & 1) == 1)
                    {
                        b.RemoveAll(x => ((x >> BIT) & 1) == 1);
                        if (!b.Any())
                            break;
                        and = b.Aggregate((l, r) => l & r);
                        and = and >> BIT;
                    }

                    and = and >> 1;
                }

                if (b.Any())
                {
                    Console.WriteLine(b.Count);
                    Console.WriteLine(String.Join(" ", b));

                    return;
                }
            }

            Console.WriteLine(a.Count);
            Console.WriteLine(String.Join(" ", a));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var powers = new List<long>();
            var values = new List<long>();
            var answers = new List<List<long>>();

            // 1000000000
            // 1073741824
            powers.Add(1);
            values.Add(-1);
            answers.Add(new List<long>());

            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                values.Add(-1);
                answers.Add(new List<long>());
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value = long.Parse(numbers[i]);

                for (int j = 0; j < powers.Count; j++)
                {
                    if ((powers[j] & value) != 0)
                    {
                        if (values[j] == -1) values[j] = value;
                        values[j] &= value;

                        answers[j].Add(value);
                    }
                }
            }

            int index = -1;
            int max = -1;

            for (int i = powers.Count - 1; i >= 0; i--)
            {
                // Console.WriteLine("{0} {1}", powers[i], values[i]);

                if (values[i] != -1)
                {
                    long v = values[i];
                    int p = 0;

                    while (v % 2 == 0)
                    {
                        v /= 2;
                        p++;
                    }

                    // Console.WriteLine(answers[i].Count);

                //    for (int j = 0; j < answers[i].Count; j++)
                //        Console.Write("{0} ", answers[i][j]);

                //    break;
                    if (index == -1) index = i;
                    if (max == -1) max = p;

                    if (max < p)
                    {
                        index = i;
                        max = p;
                    }
                }

            }

            Console.WriteLine(answers[index].Count);

            for (int j = 0; j < answers[index].Count; j++)
                Console.Write("{0} ", answers[index][j]);

            //Console.WriteLine(count);
            //Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var value = new StringBuilder();

            var powers = new List<long>();

            // 1000000000
            // 1073741824
            for (long i = 2; i < (1L << 31); i <<= 1)
            {
                powers.Add(i);
                // Console.WriteLine("{0} ", i);
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value2 = long.Parse(numbers[i]);

                if (powers.Contains(value2))
                {
                    value1 = value2;
                    count = 1;
                    value.Clear();
                    value.Append(value2.ToString()).Append(" ");

                    powers.Clear();

                    for (long j = value2; j < (1L << 18); j <<= 1)
                    {
                        powers.Add(j);
                        // Console.WriteLine("{0} ", i);
                    }

                    continue;
                }

                if ((value1 & value2) != 0)
                {
                    count += 1;
                    value.Append(numbers[i].ToString()).Append(" ");
                }
            }

            Console.WriteLine(count);
            Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var powers = new List<long>();
            var values = new List<long>();
            var answers = new List<List<long>>();

            // 1000000000
            // 1073741824
            powers.Add(1);
            values.Add(-1);
            answers.Add(new List<long>());

            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                values.Add(-1);
                answers.Add(new List<long>());
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value = long.Parse(numbers[i]);

                for (int j = 0; j < powers.Count; j++)
                {
                    if ((powers[j] & value) != 0)
                    {
                        if (values[j] == -1) values[j] = value;
                        values[j] &= value;

                        answers[j].Add(value);
                    }
                }
            }

            for (int i = powers.Count - 1; i >= 0; i--)
            {
                if (powers[i] == values[i])
                {
                    Console.WriteLine(answers[i].Count);

                    for (int j = 0; j < answers.Count; j++)
                        Console.Write("{0} ", answers[j]);
                    break;
                }
            }
            //Console.WriteLine(count);
            //Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var powers = new List<long>();
            var values = new List<long>();
            var answers = new List<List<long>>();

            // 1000000000
            // 1073741824
            powers.Add(1);
            values.Add(-1);
            answers.Add(new List<long>());

            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                values.Add(-1);
                answers.Add(new List<long>());
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value = long.Parse(numbers[i]);

                for (int j = 0; j < powers.Count; j++)
                {
                    if ((powers[j] & value) != 0)
                    {
                        if (values[j] == -1) values[j] = value;
                        values[j] &= value;

                        answers[j].Add(value);
                    }
                }
            }

            for (int i = powers.Count - 1; i >= 0; i--)
            {
                //Console.WriteLine("{0} {1}", powers[i], values[i]);

                if (values[i] != -1)
                {
                    Console.WriteLine(answers[i].Count);

                    for (int j = 0; j < answers[i].Count; j++)
                        Console.Write("{0} ", answers[i][j]);

                    break;
                }
            }

            //Console.WriteLine(count);
            //Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var value = new StringBuilder();

            var powers = new List<long>();

            // 1000000000
            // 1073741824
            for (long i = 2; i < (1L << 31); i <<= 1)
            {
                powers.Add(i);
                // Console.WriteLine("{0} ", i);
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value2 = long.Parse(numbers[i]);

                if (powers.Contains(value2))
                {
                    value1 = value2;
                    count = 1;
                    value.Clear();
                    value.Append(value2.ToString()).Append(" ");

                    powers.Clear();

                    for (long j = value2; j < (1L << 31); j <<= 1)
                    {
                        powers.Add(j);
                        // Console.WriteLine("{0} ", i);
                    }

                    continue;
                }

                if ((value1 & value2) != 0)
                {
                    count += 1;
                    value.Append(numbers[i].ToString()).Append(" ");
                }
            }

            Console.WriteLine(count);
            Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var value = new StringBuilder();

            var powers = new List<long>();

            // 1000000000
            // 1073741824
            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                // Console.WriteLine("{0} ", i);
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value2 = long.Parse(numbers[i]);

                if (powers.Contains(value2))
                {
                    value1 = value2;
                    count = 1;
                    value.Clear();
                    value.Append(value2.ToString()).Append(" ");

                    continue;
                }

                if ((value1 & value2) != 0)
                {
                    count += 1;
                    value.Append(numbers[i].ToString()).Append(" ");
                }
            }

            Console.WriteLine(count);
            Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var powers = new List<long>();
            var values = new List<long>();
            var answers = new List<List<long>>();

            // 1000000000
            // 1073741824
            powers.Add(1);
            values.Add(-1);
            answers.Add(new List<long>());

            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                values.Add(-1);
                answers.Add(new List<long>());
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value = long.Parse(numbers[i]);

                for (int j = 0; j < powers.Count; j++)
                {
                    if ((powers[j] & value) != 0)
                    {
                        if (values[j] == -1) values[j] = value;
                        values[j] &= value;

                        answers[j].Add(value);
                    }
                }
            }

            for (int i = powers.Count - 1; i >= 0; i--)
            {
                if (powers[i] == values[i])
                {
                    Console.WriteLine(answers[i].Count);

                    for (int j = 0; j < answers[i].Count; j++)
                        Console.Write("{0} ", answers[i][j]);

                    break;
                }
            }

            //Console.WriteLine(count);
            //Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            long count = 0;
            long value1 = 1;

            var powers = new List<long>();
            var values = new List<long>();
            var answers = new List<List<long>>();

            // 1000000000
            // 1073741824
            powers.Add(1);
            values.Add(-1);
            answers.Add(new List<long>());

            for (long i = 2; i < (1L << 32); i <<= 1)
            {
                powers.Add(i);
                values.Add(-1);
                answers.Add(new List<long>());
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                long value = long.Parse(numbers[i]);

                for (int j = 0; j < powers.Count; j++)
                {
                    if ((powers[j] & value) != 0)
                    {
                        if (values[j] == -1) values[j] = value;
                        values[j] &= value;

                        answers[j].Add(value);
                    }
                }
            }

            int index = -1;
            int max = -1;

            for (int i = powers.Count - 1; i >= 0; i--)
            {
                // Console.WriteLine("{0} {1}", powers[i], values[i]);

                if (values[i] != -1)
                {
                    long v = values[i];
                    int p = 0;

                    while (v % 2 == 0)
                    {
                        v /= 2;
                        p++;
                    }

                    // Console.WriteLine(answers[i].Count);

                //    for (int j = 0; j < answers[i].Count; j++)
                //        Console.Write("{0} ", answers[i][j]);

                //    break;
                    if (index == -1) index = i;
                    if (max == -1) max = p;

                    if (max < p)
                    {
                        index = i;
                        max = p;
                    }
                    else if (max == p && answers[index].Count < answers[i].Count)
                    {
                        index = i;
                        max = p;
                    }
                }

            }

            Console.WriteLine(answers[index].Count);

            for (int j = 0; j < answers[index].Count; j++)
                Console.Write("{0} ", answers[index][j]);

            //Console.WriteLine(count);
            //Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            int count = 0;
            int value1 = 1;
            var value = new StringBuilder();

            var powers = new List<int>();

            for (int i = 2; i < (1 << 18); i <<= 1)
            {
                powers.Add(i);
                // Console.WriteLine("{0} ", i);
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                int value2 = int.Parse(numbers[i]);

                if (powers.Contains(value2))
                {
                    value1 = value2;
                    count = 1;
                    value.Clear();
                    value.Append(value2.ToString()).Append(" ");

                    powers.Clear();

                    for (int j = value2; j < (1 << 18); j <<= 1)
                    {
                        powers.Add(j);
                        // Console.WriteLine("{0} ", i);
                    }
                    continue;
                }

                if ((value1 & value2) != 0)
                {
                    count += 1;
                    value.Append(numbers[i].ToString()).Append(" ");
                }
            }

            Console.WriteLine(count);
            Console.WriteLine(value);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    public class Decision
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public String Palindrom { get; set; }
    }

    public class State
    {
        public int Left { get; set; }

        public int Right { get; set; }

        public int InnerLeft { get; set; }

        public int InnerRight { get; set; }

        public String Palindrom { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int n = int.Parse(str);

            str = Console.ReadLine();

            var numbers = str.Split(new char[] { ' ' });

            // var a = new int[n];

            // 65536
            // 100000

            int count = 0;
            int value1 = 1;
            var value = new StringBuilder();

            var powers = new List<int>();

            for (int i = 2; i < (1 << 19); i <<= 1)
            {
                powers.Add(i);
                // Console.WriteLine("{0} ", i);
            }

            for (int i = 0; i < numbers.Length; i++)
            {
                int value2 = int.Parse(numbers[i]);

                if (powers.Contains(value2))
                {
                    value1 = value2;
                    count = 1;
                    value.Clear();
                    value.Append(value2.ToString()).Append(" ");

                    //powers.Clear();

                    //for (int j = value2; j < (1 << 18); j <<= 1)
                    //{
                    //    powers.Add(j);
                    //    // Console.WriteLine("{0} ", i);
                    //}

                    continue;
                }

                if ((value1 & value2) != 0)
                {
                    count += 1;
                    value.Append(numbers[i].ToString()).Append(" ");
                }
            }

            Console.WriteLine(count);
            Console.WriteLine(value);
        }
    }
}


#define Online

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
using System.Numerics;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    partial class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            C();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {

        }

        static void B()
        {

        }

        static void C()
        {
            int n = ReadInt();
            int[] a = new int[n];
            ReadArray(' ');
            for (int i = 0; i < n; i++)
                a[i] = NextInt();
            Dictionary<int, int> hash = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                if (!hash.ContainsKey(a[i]))
                    hash.Add(a[i], 0);
            }
            a = new int[hash.Count];
            int _i = 0;
            foreach (int key in hash.Keys)
            {
                a[_i++] = key;
            }
            n = a.Length;
            int max = 1073741824;
            int e = 30;
            int[] c = new int[31];
            while (e >= 0)
            {
                int m = max;
                int _e = 30;
                int[] res = new int[31];
                for (int i = 0; i < 31; i++)
                    res[i] = int.MaxValue;

                while (_e >= e)
                {
                    for (int i = 0; i < n; i++)
                    {
                        if ((a[i] & m) == m)
                        {
                            c[_e]++;
                            res[_e] &= a[i];
                        }
                    }
                    _e--;
                    m >>= 1;
                }
                m = int.MinValue;
                int p = 0;
                for (int i = 0; i < c.Length; i++)
                {
                    if (m < c[i])
                    {
                        if (res[i] == 0) continue;
                        if (res[i] % (1 << i) == 0)
                        {
                            m = c[i];
                            p = i;
                        }
                    }
                }

                if (m > 0)
                {
                    int[] ans = new int[m];
                    m = (1 << p);
                    for (int i = 0, j = 0; i < n; i++)
                        if ((a[i] & m) == m)
                            ans[j++] = a[i];
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < ans.Length; i++)
                        sb.Append(ans[i] + " ");
                    Console.WriteLine(ans.Length);
                    Console.WriteLine(sb);
                    return;
                }
                e--;
            }
        }

        static void D()
        {

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

    }

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R, comp);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(i, a.Length);
                temp = a[b];
                a[b] = a[i];
                a[i] = temp;
            }
        }
    }

    partial class Program
    {
        static string[] tokens;
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


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

int main() {
    vector<vector<int> > numByDigit;
    for (int i = 0; i < 32; i++) {
        numByDigit.push_back(vector<int>());
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int d = 0; d < 32; d++) {
            if ((x & 1 << d) != 0) {
                numByDigit[d].push_back(x);
            }
        }
    }

    for (int d = 31; d >= 0; d--) {
        vector<int>& nums = numByDigit[d];
        int andResult = 0xFFFFFFFF;
        for (int x: nums) {
            andResult &= x;
        }
        if ((andResult & ((1 << d) - 1)) == 0) {
            cout << nums.size() << endl;
            for (int x: nums) {
                cout << x << " ";
            }
            cout << endl;
            break;
        }
    }

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#if __cplusplus > 201103L
#include <initializer_list>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#ifndef ONLINE_JUDGE
#define DEBUG
#endif

#define oo 0x3F3F3F3F
#define car first
#define cdr second
#define PB push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define For(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i)
#define Rof(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; --i)
#define FOR(i, a, b) for (int _end_ = (b), i = (a); i != _end_; ++i)
#define ROF(i, a, b) for (int _end_ = (b), i = (a); i != _end_; --i)

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef long double real;

int64 fpm(int64 b, int64 e, int64 m) { int64 t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; }
template<class T> inline bool chkmin(T &a, T b) {return a > b ? a = b, true : false;}
template<class T> inline bool chkmax(T &a, T b) {return a < b ? a = b, true : false;}
template<class T> inline T sqr(T x) {return x * x;}
template <typename T> T gcd(T x, T y) {for (T t; x; t = x, x = y % x, y = t); return y; }

template<class edge> struct Graph {
    vector<vector<edge> > adj;
    Graph(int n) {adj.clear(); adj.resize(n + 5);}
    Graph() {adj.clear(); }
    void resize(int n) {adj.resize(n + 5); }
    void add(int s, edge e){adj[s].push_back(e);}
    void del(int s, edge e) {adj[s].erase(find(iter(adj[s]), e)); }
    vector<edge>& operator [](int t) {return adj[t];}
};

int main(int argc, char **argv) {
#ifndef ONLINE_JUDGE
    freopen("C.in" , "r", stdin);
    freopen("C.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);

    int wmax = -1, n; vector<int> ans;

    cin >> n;
    FOR (i, 0, n) {
        int w, x;
        cin >> x;
        FOR (i, 0, 32) {
            if (x >> i) {
                w = i;
            }
        }
        if (w > wmax) {
            wmax = w;
            ans.clear();
            ans.push_back(x);
        } else if (w == wmax) {
            ans.push_back(x);
        }
    }
    cout << SZ(ans) << endl;
    for (auto x : ans) {
        cout << x << " ";
    }

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#if __cplusplus > 201103L
#include <initializer_list>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#ifndef ONLINE_JUDGE
#define DEBUG
#endif

#define oo 0x3F3F3F3F
#define car first
#define cdr second
#define PB push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define For(i, a, b) for (int _end_ = (b), i = (a); i <= _end_; ++i)
#define Rof(i, a, b) for (int _end_ = (b), i = (a); i >= _end_; --i)
#define FOR(i, a, b) for (int _end_ = (b), i = (a); i != _end_; ++i)
#define ROF(i, a, b) for (int _end_ = (b), i = (a); i != _end_; --i)

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef long double real;

int64 fpm(int64 b, int64 e, int64 m) { int64 t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; }
template<class T> inline bool chkmin(T &a, T b) {return a > b ? a = b, true : false;}
template<class T> inline bool chkmax(T &a, T b) {return a < b ? a = b, true : false;}
template<class T> inline T sqr(T x) {return x * x;}
template <typename T> T gcd(T x, T y) {for (T t; x; t = x, x = y % x, y = t); return y; }

template<class edge> struct Graph {
    vector<vector<edge> > adj;
    Graph(int n) {adj.clear(); adj.resize(n + 5);}
    Graph() {adj.clear(); }
    void resize(int n) {adj.resize(n + 5); }
    void add(int s, edge e){adj[s].push_back(e);}
    void del(int s, edge e) {adj[s].erase(find(iter(adj[s]), e)); }
    vector<edge>& operator [](int t) {return adj[t];}
};

int main(int argc, char **argv) {
#ifndef ONLINE_JUDGE
    freopen("C.in" , "r", stdin);
    freopen("C.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);

    int n; vector<int> ans, vec;

    cin >> n;
    FOR (i, 0, n) {
        int x;
        cin >> x;
        vec.push_back(x);
    }
    ROF (i, 30, -1) {
        int now = -1;
        ans.clear();
        for (auto x : vec) {
            if (x >> i & 1) {
                now &= x;
                ans.push_back(x);
            }
        }
        if ((now & ((1 << i) - 1)) == 0) {
            cout << SZ(ans) << endl;
            for (auto x : ans) {
                cout << x << " ";
            }
            return 0;
        }
    }

    return 0;
}


# include <iostream>
# include <fstream>
# include <sstream>
# include <algorithm>
# include <functional> // greater<int>()
# include <vector>
# include <string>
# include <queue>
# include <stack>
# include <list>
# include <map>
# include <set>
# include <cstdio>
# include <cstdlib>
# include <cmath>
# include <ctime>
# include <cstring>
# include <cctype>
# include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN

/* MACROS */

# define  all(A)		(A).begin() , (A).end()
# define  rall(A)		(A).rbegin() , (A).rend()
# define  sz(A)			(int)(A).size()
# define  pb			push_back
# define  ppb			pop_back
# define  mp			make_pair
# define  bir			first
# define  iki			second
# define  rsz(A,X)		(A).resize(X)
# define  ln(A)			(int)(A).length()
# define  FILL(X, A)	memset((X), (A), sizeof(X))
# define  minof(X)		min_element(all(X))-X.begin()
# define  maxof(X)		max_element(all(X))-X.begin()
# define  square(X)		(X)*(X)
# define  cube(X)		(X)*(X)*(X)

# define  FOR(i, a, b)	for (int i=a; i<b; i++)
# define  FORD(i, a, b)	for (int i=a-1; i>=b; i--)
# define  REP(i,n)		for( int i=0 ; i<n ; i++ )
# define  REPD(i,n)		for( int i=n-1 ; i>=0 ; i-- )
# define  TR(it,container)  \
		for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
# define  setmap_found(container, element) (container.find(element) != container.end())
# define  vector_found(container, element) (find(all(container),element) != container.end())
# define  DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;

//time_t st=clock();

using namespace std;

/* TYPE DEFINITIONS */
typedef		long long		i64;
typedef		vector<int>		vi;
typedef		vector<vi>		vvi;
typedef		pair<int,int>	pi;
typedef		vector<pi>		vpi;
typedef		vector<vpi>		vvpi;
typedef		vector<i64>		v64;
typedef		vector<v64>		vv64;
typedef		pair<i64,i64>	p64;
typedef		vector<p64> 	vp64;
typedef		vector<vp64>	vvp64;
typedef		vector<string>	vs;
typedef		vector<vs>		vvs;
typedef		vector<bool>	vb;
typedef		vector<vb>		vvb;
typedef		vector<char>	vc;
typedef		vector<vc>		vvc;

/* TOOLS */
template <class T> inline T max(T a, T b, T c){   return max(a, max(b, c));   }
template <class T> inline T min(T a, T b, T c){   return min(a, min(b, c));   }
template <class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' '; cerr<<endl;}

/* ALGEBRA */
template <class T> T gcd (T a, T b){    return ( b==(T)0 ?a :gcd(b,a%b) );    }
template <class T> T lcm (T a , T b){    return a/gcd(a,b)*b;    }
template <class T> T mathround (T x){    i64 i64x=(i64)x; if( x<i64x+0.5 ) return (T)i64x; return (T)i64x+1;    }
template <class T> bool isprime(T x)
{
	int till = (T)sqrt(x+.0);
	if (x <= 1) return 0;
	if (x == 2) return 1;
	if (x%2 == 0) return 0;
	for (int i=3; i<=till; i+=2) if (x%i == 0) return 0;
	return 1;
}

/* CONSTANTS */
//const double Pi = 4.0 * atan(1.0); // 4*atan(1)
//int dir[8][2] = {{+1,+0},{-1,+0},{+0,+1},{+0,-1},{-1,-1},{+1,+1},{+1,-1},{-1,+1}};
//int mon[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

/* {END} */

int n, m;
int a[100010];
int b[100010];
int res;

int beat(int x) {
	int ret = 0;

	for (int i = 0, bit = 1; bit <= x; i++, bit <<= 1) {
		if (x & bit) {
			ret = i;
			break;
		}
	}

	if (ret == 0)
		ret = -1;

	return ret;
}

int main()
{
	cin >> m;

	for (int i = 0; i < m; i++)
		cin >> b[i];

	sort(b, b+m);

	for (int i = 0; i < m; i++)
		if (i == 0 || b[i-1] != b[i]) {
			a[n++] = b[i];
		}

	int mxb = -1;
	int mxt = 1;
	int mxk = n;
	for (int i = 0, two = 1; two <= a[n-1]; i++, two <<= 1)
	{
		int all = -1;
		int k = 0;

		for (int j = 0; j < n; j++)
			if (a[j] & two) {
				all = (all == -1 ?a[j] :(all & a[j]));
				k++;
			}

		int v = beat(all);

		if (v > mxb) {
			mxb = v;
			mxt = two;
			mxk = k;
		} else if (v == mxb && mxk < k) {
			mxb = v;
			mxt = two;
			mxk = k;
		}
	}

	cout << mxk << "\n";
	for (int i = 0; i < n; i++)
		if (a[i] & mxt)
			cout << a[i] << " ";

//	ios_base::sync_with_stdio(false);
//	freopen("input.txt", "r", stdin);		// needs disabled ios_base::sync_with_stdio(false);
//	freopen("output.txt", "w", stdout);		// needs disabled ios_base::sync_with_stdio(false);
//	cin >> noskipws;
//	cin >> skipws;

//	cout<<clock()-st;
	/*
	getchar();
	getchar();
	*/
	return EXIT_SUCCESS;
}


#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);

    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>

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] & (1 << 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 = (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());

    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(1e5) + 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);

    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 <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

const int MAX_N = int(1e5) + 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;
}