import java.util.Scanner;
public class zishoushu {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long x=sc.nextInt();
if(zishou(x)==1){
System.out.println("您输入的数"+x+"是自守数");
}else{
System.out.println("您输入的得数"+x+"不是自守数");
}
System.out.println("以下是1000以内自守数");
for(int i=2;i<1000;i++){
if(zishou(i)==1){
System.out.print(i+" ");
}}
}
public static int zishou(long n){
long temp,k,m;
int count;
k=1;
count=0;
while(k>0){
k=n-(long)Math.pow(10, count);
count++;
}
m=count-1;
temp=(n*n)%((long)Math.pow(10,m));
if(n==temp) return 1;
return 0;
}
}