#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 600000


int main() {
	int n, k;
	scanf("%d", &n);
	printf("%d\n", n*n*n);

	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a;
	for(int i=3;i<=a;i++){
		b=0;
		if(i%3==0 || i%10==3){
			cout<<" "<<i;
			b=1;
		}
		if(i>=30 && b==0){
			for(int j=i;j>=9;){
			j=j/10;
			if(j%10==3){
				cout<<" "<<i;
				break;
				}
			}
		}
	}
	cout<<endl;
}