import java.util.Scanner;

//This problem reminded me of Nabeatsu !!
public class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 }
} import java.util.Scanner; Scanner java.util public class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 }
} Main public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 } main {
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  } 3<=n&&n<=10000 3<=n 3 n n<=10000 n 10000 {
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  } for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   } {
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   } if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    } i%3==0 i%3 i 3 0 System.out.printf(" "+i) System.out.printf System.out System System.out " "+i " " i {
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    } int j=i; j i int count =0; count 0 do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication j>1&&count==0 j>1 j 1 count==0 count 0 {
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     } if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10; j%10==3 j%10 j 10 3 {
       System.out.printf(" "+i);
       count++;
     } System.out.printf(" "+i) System.out.printf System.out System System.out " "+i " " i count++ count j/=10 j 10 System.out.printf("\n") System.out.printf System.out System System.out "\n" String[] args args public class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 }
} public class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 }
} Main
import java.util.Scanner;

//This problem reminded me of Nabeatsu !!
public class Main{
 public static void main(String[] args){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();

  if(3<=n&&n<=10000){
 //NabeatsuNo. 1<=i<=n
  for(int i=1;i<=n;i++){
    if(i%3==0)  //Output if i is multiple of 3
     System.out.printf(" "+i);
    else{
     int j=i;
     int count =0;
     //Output if i has more than a digit which is 3
     do{
      if(j%10==3){
       System.out.printf(" "+i);
       count++;
     }
      else
       j/=10;
     }while(j>1&&count==0);   //Be careful the duplication
    }
   }
  }
 System.out.printf("\n");
 }
}