#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int prim(int n){
if(n<=1) return 0;
if(n<=3) return 1;
if(n%2==0||n%3==0) return 0;
for(int i=5;i*i<=n;i=i+6) if(n%i==0||n%(i+2)==0) return 0;
return 1;
}
int main(){
int n, v[1001], s=0, max=-1;
cin>>n;
for(int i=1;i<=n;i++) {cin>>v[i]; max=v[i];}
for(int i=1;i<=n-1;i++){
char nr[11]="";
itoa(abs(v[i]), nr, 10);
if(strcmp(nr, strrev(nr))==0) if(v[i]>max) max=v[i];
}
for(int i=1;i<=n;i++) if(prim(v[i])==1) s+=v[i];
cout<<max<<' '<<s<<endl;
for(int i=1;i<=n;i++) if(v[i]!=0&&ceil(log2(v[i]))==floor(log2(v[i]))) cout<<v[i]<<' ';
}