#include <iostream>
using namespace std;
int main()
{int n, p, k, i, v[100];
cout<<"n=";cin>>n;
cout<<"p=";cin>>p;
cout<<"k=";cin>>k;
for(i=1;i<=n;i++)
{
cout<<"v["<<i<<"]=";
cin>>v[i];
}
for(i=1;i<=n;i++)
if(v[i]%p==0 && v[i]%k==0)
cout<<v[i]<<" ";
return 0;
}