#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int prime(int i){
int j;
if(i<2)
return 0;
else
{
for(j=2;j<i;j++)
{
if(i%j==0)
return 0;
}
return 1;
}
}
int main(int argc, char *argv[]) {
int n,m,i,j,k,a,sum;
int b[999];
int arr[999];
while(scanf("%d",&n)!=EOF)
{
a=0;
sum=0;
for(i=0;i<n;i++)
{
scanf("%d",&m);
b[i]=m;
if(prime(arr[b[i]])==1)
{
arr[a]=m;
a++;
}
}
for(j=0;j<a;j++)
{
printf("%d ",arr[j]);
}
for(k=0;k<a;k++)
{
sum+=arr[k];
}
printf("%d\n",sum);
}
return 0;
}