/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 16, 2012, 2:38 AM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

void loadData( void );
int proc( void );
void printRes( int );

vector<int> primes;
int primeDigits[10000][5];
int pow10[6];

int n;
int matrix[5][5];

void generatePrimeNumber( vector<int> &v , int range );
void initPow10( void );
void initPrimeDigits( void );

int dfs( int );

bool lyb_debug = false;

void printCurMatrix( void );

int main(int argc, char** argv) {

    loadData();

    return 0;
}

void printCurMatrix( void ){

    for( int i = 0 ; i < n ; i ++ ){
        for( int j = 0 ; j < n ; j ++ )
            printf("%d",matrix[i][j]);
        printf("\n");
    }
    return;
}

void initPow10( void ){

    pow10[0] = 1;
    for( int i = 1 ; i < 6 ; i ++ )
        pow10[i] = pow10[i-1]*10;
    return;
}

void generatePrimeNumber( vector<int> &v , int range ){

    v.clear();
    v.push_back( 2 );
    v.push_back( 3 );

    int j;
    int test_len;
    for( int i = 5 ; i <= range ; i += 2 ){

        //printf("i:%d\n",i);
        test_len = (int)sqrt( (double)i );
        for( j = 1 ; v[j] <= test_len ; j ++ )
            if( i%v[j] == 0 )
                break;

        if( v[j] > test_len )
            v.push_back(i);
    }

    if( lyb_debug ){
        printf("== %d prime numbers ==\n",v.size());
        //for( int i = 0 ; i < v.size() ; i ++ )
        //    printf("%d ",v[i]);
        printf("\n");
    }
    return;
}

void initPrimeDigits( void ){

    memset( primeDigits , 0 , sizeof( primeDigits ) );
    for( int i = 0 ; i < primes.size() ; i ++ ){

        int num = primes[i];
        int index = 0;
        while( num ){
            primeDigits[i][index] = num%10;
            num /= 10;
            index ++;
        }
    }
    return;
}

int dfs( int level ){

    if( level == n ){
        //if( lyb_debug ){
        //    printf("==a result:==\n");
        //    printCurMatrix();
        //    printf("\n");
        //}
        return 1;
    }

    int low_bound = 0;
    for( int i = 0 ; i < level ; i ++ )
        low_bound += matrix[level][i]*pow10[n-i-1];

    int up_bound = low_bound + pow10[n-level];

    vector<int>::iterator iter = upper_bound( primes.begin() , primes.end() , low_bound );

    //if( lyb_debug ){
    //    printf("*in level %d: low_bound=%d up_bound=%d startPrime=%d\n\n",level,low_bound,up_bound,*iter);
    //}
    int res = 0;
    for( ; iter != primes.end() ; iter ++ ){

        if( *iter > up_bound )
            break;

        for( int i = level ;i < n ; i ++ )
            matrix[level][i] = matrix[i][level] = primeDigits[ iter-primes.begin() ][ n-1-i ];

        res += dfs( level + 1 );
    }

    return res;
}

int proc( void ){

    return dfs( 1 );;
}

void loadData( void ){

    generatePrimeNumber( primes , 99999 );
    initPrimeDigits();
    initPow10();

    int T;
    char input[6],enter;
    scanf("%d%c",&T,&enter);
    while( T -- ){
        scanf("%s%c",input,&enter);
        n = strlen( input );

        memset( matrix , 0 , sizeof( matrix ) );
        for( int i = 0 ; i < n ; i ++ )
            matrix[0][i] = matrix[i][0] = input[i]-'0';

        if( lyb_debug ){
            printf("case %d:\n",T);
        }
        printRes( proc() );
    }

    return;
}

void printRes( int res ){

    printf("%d\n",res);
    return;
}


/*
 * File:   main.cpp
 * Author: liuyubo
 *
 * Created on March 16, 2012, 2:38 AM
 */

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>

#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <queue>
#include <map>

using namespace std;

void loadData( void );
int proc( void );
void printRes( int );

vector<int> primes;
int primeDigits[10000][5];
int pow10[6];

int n;
int matrix[5][5];

void generatePrimeNumber( vector<int> &v , int range );
void initPow10( void );
void initPrimeDigits( void );

int dfs( int );

bool lyb_debug = false;

void printCurMatrix( void );

int main(int argc, char** argv) {

    loadData();

    return 0;
}

void printCurMatrix( void ){

    for( int i = 0 ; i < n ; i ++ ){
        for( int j = 0 ; j < n ; j ++ )
            printf("%d",matrix[i][j]);
        printf("\n");
    }
    return;
}

void initPow10( void ){

    pow10[0] = 1;
    for( int i = 1 ; i < 6 ; i ++ )
        pow10[i] = pow10[i-1]*10;
    return;
}

void generatePrimeNumber( vector<int> &v , int range ){

    v.clear();
    v.push_back( 2 );
    v.push_back( 3 );

    int j;
    int test_len;
    for( int i = 5 ; i <= range ; i += 2 ){

        //printf("i:%d\n",i);
        test_len = (int)sqrt( (double)i );
        for( j = 1 ; v[j] <= test_len ; j ++ )
            if( i%v[j] == 0 )
                break;

        if( v[j] > test_len )
            v.push_back(i);
    }

    if( lyb_debug ){
        printf("== %d prime numbers ==\n",v.size());
        //for( int i = 0 ; i < v.size() ; i ++ )
        //    printf("%d ",v[i]);
        printf("\n");
    }
    return;
}

void initPrimeDigits( void ){

    memset( primeDigits , 0 , sizeof( primeDigits ) );
    for( int i = 0 ; i < primes.size() ; i ++ ){

        int num = primes[i];
        int index = 0;
        while( num ){
            primeDigits[i][index] = num%10;
            num /= 10;
            index ++;
        }
    }
    return;
}

int dfs( int level ){

    int low_bound = 0;
    for( int i = 0 ; i < level ; i ++ )
        low_bound += matrix[level][i]*pow10[n-i-1];

    int up_bound = low_bound + pow10[n-level];

    vector<int>::iterator iter = upper_bound( primes.begin() , primes.end() , low_bound );

    //if( lyb_debug ){
    //    printf("*in level %d: low_bound=%d up_bound=%d startPrime=%d\n\n",level,low_bound,up_bound,*iter);
    //}
    int res = 0;
    if( level == n - 1 ){
        for( ; iter != primes.end() ; iter ++ ){

            if( *iter > up_bound )
                break;
            res ++;
        }
    }
    else{
        for( ; iter != primes.end() ; iter ++ ){

            if( *iter > up_bound )
                break;

            for( int i = level ;i < n ; i ++ )
                matrix[level][i] = matrix[i][level] = primeDigits[ iter-primes.begin() ][ n-1-i ];

            res += dfs( level + 1 );
        }
    }

    return res;
}

int proc( void ){

    return dfs( 1 );;
}

void loadData( void ){

    generatePrimeNumber( primes , 99999 );
    initPrimeDigits();
    initPow10();

    int T;
    char input[6],enter;
    scanf("%d%c",&T,&enter);
    while( T -- ){
        scanf("%s%c",input,&enter);
        n = strlen( input );

        memset( matrix , 0 , sizeof( matrix ) );
        for( int i = 0 ; i < n ; i ++ )
            matrix[0][i] = matrix[i][0] = input[i]-'0';

        if( lyb_debug ){
            printf("case %d:\n",T);
        }
        printRes( proc() );
    }

    return;
}

void printRes( int res ){

    printf("%d\n",res);
    return;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<memory.h>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt((x)*1.)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define getar(m,n) for(int _=0;_<n;++_) cin>>(m)[_];
#define fill(m,v) memset(m,v,sizeof(m))
#define flush {cout.flush();fflush(stdout);}
#define random(x) (((rand()<<15)+rand())%(x))
#define pi 3.1415926535897932
#define y1 stupid_cmath
#define y0 stupid_cmath_make_me_cry
#define tm stupid_ctime
#define long long long
using namespace std;

int n,m;
int i,j,k,l;
bool u[100005];
int p[100000], d;
long ans;
char s[6][6], ss[6];
char q[100005][6];

int fnd(char *s, int t){
	int i=0, j=d, m;
	int l, o = -1;
	while(i<j){
		m = (i+j)>>1;

		for(l=0;s[l] && l<5 && q[m][l]==s[l]; ++l);

		if(s[l]==0){
			o = m;
			if(t<0) j = m; else i = m+1;
		}else
		if(q[m][l]<s[l]){
			i = m+1;
		}else{
			j = m;
		}
	}

	return o;
}

void g(int i){
	if(i==5){
		++ans;
		return;
	}

	int j,k1,k2,k;

	strcpy(ss, s[i]); ss[i] = 0;

	k1 = fnd(ss,-1);
	k2 = fnd(ss,+1);

	//cout<<ss<<' '<<k1<<' '<<k2<<endl;
	if(k1<0 || k2<0 || k1>k2) return;

	//cout<<q[k1]<<' '<<q[k2]<<endl;

	for(k=k1;k<=k2;++k){
		for(j=i;j<5;++j) s[i][j] = s[j][i] = q[k][j];
		g(i+1);
	}
}

int main(){
	//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

	for(i=2;i<1e5;++i) if(!u[i]){
		for(j=i*2;j<1e5;j+=i) u[j] = true;
		p[d++] = i;

		int t = 1e4, x = i;
		for(j=0;j<5;++j){
			q[d-1][j] = x/t+'0';
			x%=t;
			t/=10;
		}

		q[d-1][5] = 0;
	}

	int tn,ti;
	scanf("%d\n",&tn);
	for(ti=1;ti<=tn;++ti){

		cin>>ss; n = strlen(ss);

		for(i=0;i<5;++i)
		for(j=0;j<5;++j) s[i][j] = '0';

		for(i=0;i<n;++i) s[5-n][5-n+i] = s[5-n+i][5-n] = ss[i];

		ans = 0;
		g(5-n+1);

		cout<<ans<<endl;
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
typedef long long ll;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }

const int MAXP = 100111;
int pr[MAXP], npr;
bool is_pr[MAXP + 1];
int sieve() {
    int i, j, d;
    if (npr) return npr;
    for (i = 3; i <= MAXP; i += 2) is_pr[i] = 1; is_pr[2] = 1;
    for (i = 3; i * i <= MAXP; i += 2) if (is_pr[i]) {
        for (j = i * i, d = i << 1; j <= MAXP; j += d) is_pr[j] = 0;
    }
    for (i = 2; i <= MAXP; i++) if (is_pr[i]) pr[npr++] = i;
    return npr;
}

int mat[6][6], res, n;

void dfs(int x, int y) {
    // printf("%d %d\n", x, y);
    int i, j, k;
    if (y == n) {
        if (x == n) {
            res++;
            return;
        }
        int d = 0;
        for (i = 0; i < n; i++) d = d * 10 + mat[x][i];
        if (is_pr[d] == 0) return;
        dfs(x + 1, x + 1);
        return;
    }
    for (i = 0; i < 10; i++) {
        mat[x][y] = i;
        mat[y][x] = i;
        dfs(x, y + 1);
    }
}

int main () {
    sieve();
    int i, j, tcc, tc = getint();
    for (tcc = 0; tcc < tc; tcc++) {
        res = 0;
        int ds[10], nd = 0, p = getint();
        for (; p; p /= 10) ds[nd++] = p % 10;
        reverse(ds, ds + nd);
        n = nd;
        memset(mat, ~0, sizeof(mat));
        for (i = 0; i < n; i++) mat[0][i] = ds[i];
        for (i = 0; i < n; i++) mat[i][0] = ds[i];
        dfs(1, 1);
        printf("%d\n", res);
    }
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
typedef long long ll;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }

const int MAXP = 100111;
int pr[MAXP], npr;
bool is_pr[MAXP + 1];
int sieve() {
    int i, j, d;
    if (npr) return npr;
    for (i = 3; i <= MAXP; i += 2) is_pr[i] = 1; is_pr[2] = 1;
    for (i = 3; i * i <= MAXP; i += 2) if (is_pr[i]) {
        for (j = i * i, d = i << 1; j <= MAXP; j += d) is_pr[j] = 0;
    }
    for (i = 2; i <= MAXP; i++) if (is_pr[i]) pr[npr++] = i;
    return npr;
}

int mat[6][6], res, n;

void solve(int row) {
    int i, j, mn = 0, mx = 1000000, tmp[6][6];
    if (row == n) { res++; return; }
    for (i = 0; i < n; i++) {
        if (~mat[row][i]) {
            mn = 10 * mn + mat[row][i];
        } else {
            if (mx == 1000000) {
                mx = mn + 1;
            }
            mn = 10 * mn, mx = 10 * mx;
        }
    }
    memcpy(tmp, mat, sizeof(tmp));
    int p1 = distance(pr, lower_bound(pr, pr + npr, mn));
    int p2 = distance(pr, lower_bound(pr, pr + npr, mx));
    for (i = p1; i < p2; i++) {
        int ds[6] = {}, p = pr[i];
        for (j = 0; j < n; j++) {
            ds[n - 1 - j] = p % 10, p /= 10;
        }
        for (j = 0; j < n; j++) {
            mat[row][j] = ds[j];
            mat[j][row] = ds[j];
        }
        solve(row + 1);
    }
    memcpy(mat, tmp, sizeof(tmp));
}

int main () {
    sieve();
    int i, j, tcc, tc = getint();
    for (tcc = 0; tcc < tc; tcc++) {
        res = 0;
        int ds[10], nd = 0, p = getint();
        for (; p; p /= 10) ds[nd++] = p % 10;
        reverse(ds, ds + nd);
        n = nd;
        memset(mat, ~0, sizeof(mat));
        for (i = 0; i < n; i++) mat[0][i] = ds[i];
        for (i = 0; i < n; i++) mat[i][0] = ds[i];
        solve(1);
        printf("%d\n", res);
    }
    return 0;
}


#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <string>

#define For(i,a,n) for(int i = a ; i < n ; ++i )
#define n(x) (int)x.size()
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()

using namespace std;
const int maxn  = 100*1010;
bool mark[maxn];
int p10[6] = {1,10,100,1000,10000,100*1000};
vector<int> pri;
vector<int> suf[maxn][6];
int le[maxn][6];
int mo[maxn];
int nu[6];
int n;
int k;
int t;
int ln(int x)
{
	int ret =0 ;
	while(x)
	{
		ret++;
		x/=10;
	}
	return ret;
}
void garb()
{
	mark[0] = mark[1] = true;
	For(i,2,100*1000)
		if(!mark[i])
		{
			pri.pb(i);
			for(int j = 2 ; j*i < 100*1010 ; ++j)
				mark[j*i] = true;
		}
}

int bt(int v)
{
//	cerr << "BT IN " << v << endl;
//	For(i,0,k)
//		cerr << nu[i] << endl;
	int ans = 0;
	if(v == k)
		return 1;
	For(i,0,n(suf[nu[v]][k-v]))
	{
		bool bo = true;
		For(j,v+1,k)
		{
			nu[j]=nu[j]*10+mo[(le[suf[nu[v]][k-v][i]][k-j-1])];
			if(suf[nu[j]][k-v-1].empty())
				bo =false;
		}
		nu[v] = suf[nu[v]][k-v][i];
		if(bo)
			ans+=bt(v+1);
		nu[v] = le[nu[v]][k-v];
		For(j,v+1,k)
			nu[j]=le[nu[j]][1];
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	For(i,0,maxn)
	{
		mo[i] = i%10;
		For(j,0,6)
			le[i][j] = i/p10[j];
	}
	garb();
	For(i,0,n(pri))
	{
		int x = pri[i];
		For(j,0,6)
		{
			suf[x][j].pb(pri[i]);
			x/=10;
		}
	}
//	For(i,0,n(suf[2][2]) )
//		cerr << suf[2][2][i] << endl;
	cin >> t;
	For(it,0,t)
	{
		cin >> n;
		if(mark[n])
		{
			cout << 0 << endl;
			continue;
		}
		k = ln(n);
		For(i,0,k)
			nu[i]=(n/p10[k-1-i])%10;
		nu[0] = n;
		cout << bt(1) << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <string>

#define For(i,a,n) for(int i = a ; i < n ; ++i )
#define n(x) (int)x.size()
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()

using namespace std;
const int maxn  = 100*1010;
bool mark[maxn];
int p10[6] = {1,10,100,1000,10000,100*1000};
vector<int> pri;
vector<int> suf[maxn][6];
int le[maxn][6];
int d[maxn];
bool dm[maxn];
int mo[maxn];
int nu[6];
int n;
int k;
int t;
int ln(int x)
{
	int ret =0 ;
	while(x)
	{
		ret++;
		x/=10;
	}
	return ret;
}
void garb()
{
	mark[0] = mark[1] = true;
	For(i,2,100*1000)
		if(!mark[i])
		{
			pri.pb(i);
			for(int j = 2 ; j*i < 100*1010 ; ++j)
				mark[j*i] = true;
		}
}

int bt(int v)
{
//	cerr << "BT IN " << v << endl;
//	For(i,0,k)
//		cerr << nu[i] << endl;
	int ans = 0;
	if(v == k)
		return 1;
	For(i,0,n(suf[nu[v]][k-v]))
	{
		bool bo = true;
		For(j,v+1,k)
		{
			nu[j]=nu[j]*10+mo[(le[suf[nu[v]][k-v][i]][k-j-1])];
			if(suf[nu[j]][k-v-1].empty())
				bo =false;
		}
		nu[v] = suf[nu[v]][k-v][i];
		if(bo)
			ans+=bt(v+1);
		nu[v] = le[nu[v]][k-v];
		For(j,v+1,k)
			nu[j]=le[nu[j]][1];
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	For(i,0,maxn)
	{
		mo[i] = i%10;
		For(j,0,6)
			le[i][j] = i/p10[j];
	}
	garb();
	For(i,0,n(pri))
	{
		int x = pri[i];
		For(j,0,6)
		{
			suf[x][j].pb(pri[i]);
			x/=10;
		}
	}
//	For(i,0,n(suf[2][2]) )
//		cerr << suf[2][2][i] << endl;
	cin >> t;
	For(it,0,t)
	{
		cin >> n;
		if(dm[n])
		{
			cout << d[n] << endl;
			continue;
		}
		if(mark[n])
		{
			cout << 0 << endl;
			continue;
		}
		dm[n] = true;
		k = ln(n);
		For(i,0,k)
			nu[i]=(n/p10[k-1-i])%10;
		nu[0] = n;
		d[n] = bt(1);
		cout << d[n] << endl;
	}
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <string>

#define For(i,a,n) for(int i = a ; i < n ; ++i )
#define n(x) (int)x.size()
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()

using namespace std;
const int maxn  = 100*1010;
bool mark[maxn];
int p10[6] = {1,10,100,1000,10000,100*1000};
vector<int> pri;
vector<int> suf[maxn][6];
int nu[6];
int n;
int k;
int t;
int ln(int x)
{
	int ret =0 ;
	while(x)
	{
		ret++;
		x/=10;
	}
	return ret;
}
void garb()
{
	mark[0] = mark[1] = true;
	For(i,2,100*1000)
		if(!mark[i])
		{
			pri.pb(i);
			for(int j = 2 ; j*i < 100*1010 ; ++j)
				mark[j*i] = true;
		}
}

int bt(int v)
{
//	cerr << "BT IN " << v << endl;
//	For(i,0,k)
//		cerr << nu[i] << endl;
	int ans = 0;
	if(v == k)
		return 1;
	For(i,0,n(suf[nu[v]][k-v]))
	{
		bool bo = true;
		For(j,v+1,k)
		{
			nu[j]=nu[j]*10+(suf[nu[v]][k-v][i]/p10[k-j-1])%10;
			if(suf[nu[j]][k-v-1].empty())
				bo =false;
		}
		nu[v] = suf[nu[v]][k-v][i];
		if(bo)
			ans+=bt(v+1);
		nu[v] /= p10[k-v];
		For(j,v+1,k)
			nu[j]/=10;
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	garb();
	For(i,0,n(pri))
	{
		int x = pri[i];
		For(j,0,6)
		{
			suf[x][j].pb(pri[i]);
			x/=10;
		}
	}
//	For(i,0,n(suf[2][2]) )
//		cerr << suf[2][2][i] << endl;
	cin >> t;
	For(it,0,t)
	{
		cin >> n;
		if(mark[n])
		{
			cout << 0 << endl;
			continue;
		}
		k = ln(n);
		For(i,0,k)
			nu[i]=(n/p10[k-1-i])%10;
		nu[0] = n;
		cout << bt(1) << endl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ 200000 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val*11+r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h*11+r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size();
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j) r.pb(j%11),j/=11;
            while(r.size()<m)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]*11+r[j]].empty()) break;
            }
            if(j==m){
                 for(j=0;j<m;++j) s[j]=s[j]*11+r[j];
                 gao(dep+1);
                 for(j=0;j<m;++j) s[j]/=11;
            }
     }
}

void gao(){
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ 200000 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val*11+r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h*11+r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size();
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j) r.pb(j%11),j/=11;
            while(r.size()<m)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]*11+r[j]].empty()) break;
            }
            if(j==m){
                 for(j=0;j<m;++j) s[j]=s[j]*11+r[j];
                 gao(dep+1);
                 for(j=0;j<m;++j) s[j]/=11;
            }
     }
}

void gao(){
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ (1<<20) + 5 ];
int n,m;
int s[ 7 ], ans ;
int tp[7]={1};
short sum[6][ (1<<20) + 5 ][ 10 ];
#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val<<4|r[i];
     for(int i=r.size()-1;i>=0;--i){
            ++ sum[ r.size()][ h ][ r[i] -1 ] ;
            h=h<<4|r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
     for(int i=1;i<7;++i) tp[i]=tp[i-1]<<4;
}
int lasf[99],lid=0,ct[99];

void gao(int dep) {
     if(dep == m-1){
            ans+=v[m][s[m-1]].size();
            return;
     }
     if(dep == m-2){
            ++lid;
            for(int i=0;i<v[m][s[m-2]].size();++i) {
                    int now = v[m][s[m-2]][i];
                    if( lasf[  now &0xf ] == lid) ++ ct[ now & 0xf];
                    else lasf[ now&0xf]=lid, ct[now&0xf]=1;
            }
            for(int i=1;i<11;++i) if(lasf[i] == lid) ans += sum[m][ s[m-1] ][ i -1 ]*ct[i];
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     int sz = v[m][ s[dep] ].size();
     vector< int > &w = v[m][ s[dep] ];
     for(int i=0;i< sz; ++ i) {
            int j= w[ i ];
            vector< int > r;
            while(j && r.size() < m-dep-1) r.pb(j&0xf),j>>=4;
            while(r.size()<m-dep-1)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]<<4|r[j-dep-1]].empty()) {
                      int pre = w[i]>>(4*(m-j-1)), M=4*(m-j-1);
                      while(i+1<sz ){
                          if((w[i+1] >> M) == pre) ++ i;
                          else break;
                      }
                      break;
                 }
            }
            if(j==m){
                 for(j=dep+1;j<m;++j) s[j]=s[j]<<4|r[j-dep-1];
                 gao(dep+1);
                 for(j=dep+1;j<m;++j) s[j]>>=4;
            }
     }
}

void gao(){
     //int t0=clock();
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
     //cout <<clock()-t0<<"ms"<<endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}
//97303


#include<iostream>
#include<vector>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ 200000 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val*11+r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h*11+r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size();
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j) r.pb(j%11),j/=11;
            while(r.size()<m)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]*11+r[j]].empty()) break;
            }
            if(j==m){
                 for(j=0;j<m;++j) s[j]=s[j]*11+r[j];
                 gao(dep+1);
                 for(j=0;j<m;++j) s[j]/=11;
            }
     }
}

void gao(){
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ (1<<20) + 5 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val<<4|r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h<<4|r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size();
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j) r.pb(j&0xf),j>>=4;
            if(r.size()>m) break;
            while(r.size()<m)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]<<4|r[j]].empty()) break;
            }
            if(j==m){
                 for(j=dep+1;j<m;++j) s[j]=s[j]<<4|r[j];
                 gao(dep+1);
                 for(j=dep+1;j<m;++j) s[j]>>=4;
            }
     }
}

void gao(){
     //int t0=clock();
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
     //cout <<clock()-t0<<" ms" << endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}
//97303


#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ (1<<20) + 5 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val<<4|r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h<<4|r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }

}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size() ;
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j && r.size() < m-dep-1) r.pb(j&0xf),j>>=4;
            while(r.size()<m-dep-1)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]<<4|r[j-dep-1]].empty()) break;
            }
            if(j==m){
                 for(j=dep+1;j<m;++j) s[j]=s[j]<<4|r[j-dep-1];
                 gao(dep+1);
                 for(j=dep+1;j<m;++j) s[j]>>=4;
            }
     }
}

void gao(){
     //int t0=clock();
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
     //cout <<clock()-t0<<"ms"<<endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}
//97303


#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;

typedef long long LL;
typedef double db;

const db EPS = 1e-8;
#define pb push_back
#define mp make_pair

const int maxn = 100001;
bool ss[ maxn ] = { 1, 1 };
int p[ maxn ], plen = 0;
map< string, vector<int> > M[6];

string tos(int x){
     vector< int > v;
     while(x) v.pb(x%10),x/=10;
     reverse(v.begin(),v.end());
     string s="";
     for(int i=0;i<v.size();++i) s+= v[i]+'0';
     return s;
}

void pre(){
     for(int i=2;i*i<maxn;++i) if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
}

void pan( string s){
     int e=0;
     for(int i=0;i<s.length();++i) e=e*10+s[i]-'0';
     string ss="";
     for(int i=0;i<s.length();++i){
           ss += s[i];
           M[s.length()][ ss ].pb( e );
     }
}

void gao(){
     for(int i=0;i<plen;++i){
           string now = tos( p[i]);
           while(now.length() < 5) pan(now), now = "0" + now ;
           pan(now);
     }
}

char mat[ 22 ][ 22 ];
int m, ans;

void gao(int dep) {
     if(dep == m) {
          ++ans;
          return ;
     }

     string pre = "";
     for(int i=0;i<dep;++i) pre += mat[i][dep];
     map< string, vector<int> >::iterator p;
     p = M[m].find( pre );
     if(p == M[m].end()) return ;
     for(int i=0;i< p->second.size();++i){
           string now = tos(p->second[i]);
           //cout <<"now="<<now<<endl;
           if(now.length() > m) break;
           while(now.length() < m) now = "0" + now;
           //cout <<"now = " << now << endl;
           for(int j=dep;j<m;++j) mat[dep][j]=mat[j][dep]=now[j];
           //while(1);
           gao(dep + 1);
     }
}

int main(){
    pre();
    gao();
    int T;
    cin >> T;
    while(T --) {
          int n;
          scanf("%d", &n);
          string s = tos(n);
          m=s.length();
          memset(mat,0,sizeof mat);
          for(int i=0;i<s.length();++i) mat[0][i] = mat[i][0] = s[i];
          ans = 0;
          gao(1);
          cout << ans << endl;
    }
	return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 100001;
bool ss[ maxn ] = {1,1};
int p[ maxn ], plen = 0;
vector< int > v[ 6 ][ (1<<20) + 5 ];
int n,m;
int s[ 7 ], ans ;

#define pb push_back
#define mp make_pair

void pan( vector< int > r){
     int h=0,val=0;
     for(int i=r.size()-1;i>=0;--i) val=val<<4|r[i];
     for(int i=r.size()-1;i>=0;--i){
            h=h<<4|r[i];
            v[r.size()][ h ].pb( val );
     }
}

void pre(){
     for(int i=2;i*i<maxn;++i)if(!ss[i]) for(int j=i;j*i<maxn;++j) ss[i*j]=1;
     for(int i=2;i<maxn;++i) if(!ss[i]) p[plen++]=i;
     for(int i=0;i<plen;++i){
           vector<int> r;
           int j=p[i];
           while(j) r.pb(j%10+1),j/=10;
           while(r.size() <= 5) {
               pan(r);
               r.pb( 1 );
           }
     }
}

void gao(int dep) {
     if(dep == m-1){
            ans += v[m][ s[m-1] ].size();
            return ;
     }
     for(int i=dep;i<m;++i) if(v[m][s[i]].size()==0) return ;
     for(int i=0;i<v[m][ s[dep] ].size(); ++ i) {
            int j= v[m][ s[dep] ][ i ];
            vector< int > r;
            while(j) r.pb(j&0xf),j>>=4;
            if(r.size()>m) break;
            while(r.size()<m)r.pb(1);
            reverse(r.begin(),r.end());
            for(j=dep+1;j<m;++j){
                 if(v[m][s[j]<<4|r[j]].empty()) break;
            }
            if(j==m){
                 for(j=dep+1;j<m;++j) s[j]=s[j]<<4|r[j];
                 gao(dep+1);
                 for(j=dep+1;j<m;++j) s[j]>>=4;
            }
     }
}

void gao(){
     int t0=clock();
     int j=n;
     m=0;
     vector<int> r;
     while(j) r.pb(j%10+1),j/=10,++m;
     reverse(r.begin(),r.end());
     for(int i=0;i<m;++i) s[i]=r[i];
     ans = 0;
     gao(1);
     cout << ans << endl;
     //cout <<clock()-t0<<" ms" << endl;
}

int main(){
    pre();
    int T;
    cin >> T;
    while(T --) {
          scanf("%d", &n);
          gao();
    }
    return 0;
}
//97303


#include<stdio.h>
#include<string.h>
int n;
bool f[6][11*11*11*11*11];
const int p10[7]={1,10,100,1000,10000,100000};
bool isprime(int x){
	for(int i=2; i*i<=x; i++)
		if(x%i==0)return false;
	return true;
}
int ans;
int a[9][9];
bool check(int s){
	for(int i=s; i<n; i++){
		int now=0;
		for(int j=0; j<n; j++)
			now=now*11+a[i][j];
		if(!f[n][now])return false;
	}
	return true;
}
void dfs(int x,int y){
	if(x==n){
		ans++;
		return;
	}
	if(y==n){
		dfs(x+1,x+1);
		return;
	}
	for(int i=0; i<10; i++){
		a[x][y]=a[y][x]=i;
		if(check(x))
			dfs(x,y+1);
	}
	a[x][y]=a[y][x]=10;
}
int main(){
	int _;
	char s[9];
	int dig[9];
	for(int x=2; x<100000; x++)
		if(isprime(x)){
			for(int i=0; i<5; i++)
				dig[i]=x/p10[i]%10;
			for(int k=2; k<=5; k++)if(x<p10[k]){
				for(int mask=0; mask<(1<<k); mask++){
					int tmp=0;
					for(int j=k-1; j>=0; j--)
						if(mask&(1<<j))
							tmp=tmp*11+dig[j];
						else
							tmp=tmp*11+10;
					f[k][tmp]=true;
				}
			}
		}
	for(scanf("%d",&_); _--;){
		scanf("%s",s);
		n=strlen(s);
		for(int i=0; i<n; i++){
			for(int j=0; j<i; j++)
				a[i][j]=a[j][i];
			for(int j=i; j<n; j++){
				a[i][j]=i==0?s[j]-'0':10;
			}
		}
		ans=0;
		dfs(1,1);
		printf("%d\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int MaxN = 100500;
const int MaxP = 9632;
const int MaxK = 6;
const int MaxM = MaxP * MaxK;

bool fd[MaxN];
int p[MaxP], pn;
int mp[MaxK][MaxK];
int N, K;

struct Node
{
	int cnt;
	Node* next[10];
} memo[MaxM], *cur, *root;

Node* new_node()
{
	cur->cnt = 0;
	fill(cur->next, cur->next + 10, (Node*) NULL);
	return cur++;
}

void insert(int N)
{
	int d[MaxK];
	for (int i = K - 1; i >= 0; i--)
	{
		d[i] = N % 10;
		N /= 10;
	}
	Node* ptr = root;
	for (int i = 0; i < K; i++)
	{
		if (ptr->next[d[i]] == NULL)
			ptr->next[d[i]] = new_node();
		ptr = ptr->next[d[i]];
		ptr->cnt++;
	}
}

int getD(int N)
{
	int ret = 0;
	while (N)
	{
		ret++;
		N /= 10;
	}
	return ret;
}

void init()
{
	cur = memo;
	root = new_node();

	for (int i = 0; i < pn; i++)
	{
		if (getD(p[i]) > K)
			break;
		insert(p[i]);
	}
}

void init_p()
{
	fd[0] = fd[1] = true;
	for (int i = 2; i < MaxN; i++)
	{
		if (!fd[i])
			p[pn++] = i;
		for (int j = 0; j < pn && i * p[j] < MaxN; j++)
		{
			fd[i * p[j]] = true;
			if (i % p[j] == 0)
				break;
		}
	}
}

void getH(int* d, int N)
{
	for (int i = K - 1; i >= 0; i--)
	{
		d[i] = N % 10;
		N /= 10;
	}
}

int ret;

void DFS(int k);
void DFS(int k, int p, Node* ptr)
{
	if (k == K - 1)
	{
		ret += ptr->cnt;
		return;
	}
	if (p == K)
	{
		DFS(k + 1);
		return;
	}
	for (int i = 0; i < 10; i++)
	{
		if (ptr->next[i])
		{
			mp[k][p] = mp[p][k] = i;
			DFS(k, p + 1, ptr->next[i]);
		}
	}
}

void DFS(int k)
{
	Node* ptr = root;
	for (int i = 0; i < k; i++)
		if (ptr->next[mp[k][i]])
			ptr = ptr->next[mp[k][i]];
		else
			return;
	DFS(k, k, ptr);
}

int main()
{
#ifdef __FISH__
	freopen("in.txt", "r", stdin);
#endif
	int T;

	init_p();
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d", &N);
		K = getD(N);
		init();
		ret = 0;
		getH(mp[0], N);
		for (int i = 1; i < K; i++)
			mp[i][0] = mp[0][i];
		DFS(1);
		printf("%d\n", ret);
	}

	return 0;
}


import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main implements Runnable {

    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
     int a;
     String b;
     String [] arr,output;

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }

    private void read() {

        a=Integer.parseInt(in.nextLine());
        b=in.nextLine();
    }

    private void solve() {
    	arr=new String[a];
    	output=new String[a];
    	arr=b.split(" ");
    	int counter=1;
    	for(int i=0;i<arr.length;i++)
    	{
    		output[Integer.parseInt(arr[i])-1]=counter+"";
    		counter++;
    	}
    }

    public void write()
    {
    	for(int i=0;i<output.length;i++)
    		out.print(output[i]+" ");
    }

    @Override
    public void run() {
        read();
        solve();
        write();
        in.close();
        out.flush();
        out.close();
    }
}


import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main implements Runnable {

    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
     int a;
     String b;
     String [] arr,output;

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }

    private void read() {

        a=Integer.parseInt(in.nextLine());
        b=in.nextLine();
    }

    private void solve() {
    	arr=new String[a];
    	output=new String[a];
    	arr=b.split(" ");

    	if(a%2==0&&a>2)
    	{
    		int x=a/2,c=0;

    		for(int i=x;i<arr.length;i++)
    		{
    			output[c]=arr[i];
    			c++;
    		}
    		for(int i=0;i<x;i++)
    		{
    			output[c]=arr[i];
    		c++;
    		}
    	}
    	else
    		output=arr;
    }

    public void write()
    {
    	for(int i=0;i<output.length;i++)
    		out.print(output[i]+" ");
    }

    @Override
    public void run() {
        read();
        solve();
        write();
        in.close();
        out.flush();
        out.close();
    }
}


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.Console;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;

/**
 *
 * @author KID
 */
public class test {

     public static void main(String[] args) {
    ///////////////////////////////////////////////////////////////////////////
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt(),position;

        int[] list = new int[n+1];

        for(int i = 1 ; i<=n ; i++){
            list[sc.nextInt()]=i;

        }
        for(int i = 1 ; i<=n ; i++){
            System.out.print(list[i]+" ");

        }

     }
}


/*
 Author: Togrul Gasimov
 Mail: ttogrul30@gmail.com
 */

import java.util.Collection;
import java.util.Comparator;
import java.util.Locale;
import java.util.Scanner;
import java.util.Vector;
import java.util.Arrays;
import java.math.BigInteger;
import java.util.Stack;

public class Main {

 //asda

static double u(double x1,double y1,double x2,double y2){
return Math.sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)  );
}
static int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}

// static double PI=3.1415926535897932384626433832795;
static int[] a = new int[100000];

public static void main(String[] args) {
 Scanner scan = new Scanner(System.in);
    int n,t;

    n=scan.nextInt();

    for(int i=1;i<=n;i++){
    	t=scan.nextInt();
    	a[t]=i;
    }

    for(int i=1;i<=n;i++){

    	if(i!=n){
    		System.out.print(a[i]+" ");
    	}else{
    		System.out.println(a[i]);
    	}
    }

}
}


import java.util.*;

public class Presents
{
   public static void main(String[] args)
   {
      // Set up scanner
      Scanner sc = new Scanner(System.in);
      // System.out.println("Number of people?");
      int people = sc.nextInt();
      int[] answerarray = new int[people+1];

      for (int i=1; i<=people; i++)
      {
          // System.out.println("Enter number " + i);
          int num = sc.nextInt();
          answerarray[num] = i;
      }

      for (int j=1; j<=people; j++)
      {
          System.out.print(answerarray[j] + " ");
      }
   }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Presents {
    public static String[] gift(String s)
    {
        String gift_sequence = null;
        String [] temp = s.split(" ");
        String [] result = new String[temp.length];
        int t =Integer.valueOf(temp[0])-1;
        int m = 0;
        for(int i = 0;i<temp.length;i++)
        {
            result[Integer.valueOf(temp[i])-1]=String.valueOf(i+1);
        }
        for(int j =0;j<temp.length;j++)
        {
            System.out.print(result[j]+" ");
        }
        System.out.println();
        return temp;
    }
    public static void main(String []args)
    {
        int num = 0;
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String s1 = br.readLine();
            String s2 = br.readLine();
            while((s1!=null)&&(s2!=null))
            {
                gift(s2);
                s1 = br.readLine();
                s2 = br.readLine();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Presents {
    public static String[] gift(String s)
    {
        String gift_sequence = null;
        String [] temp = s.split(" ");
        int t =Integer.valueOf(temp[0])-1;
        int m = 0;
        for(int i = 0;i<temp.length;i++)
        {
             m = Integer.valueOf(temp[t]);
             if(m==(t+1))
                 continue;
             temp[t]=String.valueOf(i+1);
             t = m-1;;
        }
        for(int j =0;j<temp.length;j++)
        {
            System.out.print(temp[j]+" ");
        }
        System.out.println();
        return temp;
    }
    public static void main(String []args)
    {
        int num = 0;
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String s1 = br.readLine();
            String s2 = br.readLine();
            while((s1!=null)&&(s2!=null))
            {
                gift(s2);
                s1 = br.readLine();
                s2 = br.readLine();
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int x;
		int[] a = new int[105];
		int[] b = new int[105];
		Scanner in = new Scanner(System.in);
		x = in.nextInt();
		for (int i = 0; i < x; i++) {
			a[i] = in.nextInt();
		}
		for (int i = 0; i < x; i++) {
			b[a[i]] = i + 1;
		}
		for (int i = 1; i <= x; i++) {
			if (i != x) System.out.print(b[i] + " ");
			else System.out.println(b[i]);
		}
	}
}


import java.util.HashMap;
import java.util.Scanner;

public class NewClass
{
    public static void main(String[] args)

    {

       Scanner cs= new Scanner(System.in) ;
         int frind = cs.nextInt() ;

         int [] x = new int[frind] ;
         int [] array2 = new int[frind] ;

         int d ;
         for (int i = 0; i < frind; i++)
         {
            x [i] = cs.nextInt() ;

         }
         for (int i = 0; i < frind; i++)
         {
             d = x[i] ;
             array2 [d-1] = i+1 ;

        }
         for (int i = 0; i < frind; i++)
         {
             System.out.println(array2[i]);

        }

    }

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

public class tAXI {

    static class IntStreamReader {

        private BufferedInputStream inp = null;
        private int offset = 0;
        private int size = 25600;
        private byte[] buff = new byte[size];

        public IntStreamReader(InputStream in) throws IOException {
            inp = new BufferedInputStream(in);
            inp.read(buff, 0, size);
        }

        public int getNextInt() throws IOException {
            int parsedInt = 0;
            int i = offset;
            int flag = 0;
            while (i < buff.length && buff[i] != '-' && (buff[i] < '0' || buff[i] > '9')) {
                i++;
            }
            if (i < buff.length && buff[i] == '-') {
                i++;
                flag = 1;
            }
            while (i < buff.length && (buff[i] >= '0' && buff[i] <= '9')) {
                parsedInt *= 10;
                parsedInt += buff[i] - '0';
                i++;
            }

            if (i == buff.length) {

                int j = 0;
                for (; offset < buff.length; j++, offset++) {
                    buff[j] = buff[offset];
                }

                inp.read(buff, j, size - j);

                offset = 0;
                parsedInt = getNextInt();
            } else {
                offset = i;
            }
            if (flag == 0) {
                return parsedInt;
            } else {
                return -parsedInt;
            }
        }
    }

    public static void main(String arg[]) throws IOException {

        IntStreamReader r = new IntStreamReader(System.in);
       int n=r.getNextInt();
       int i=0;
       int a[]=new int[n];
       while(i<n)
       {
           a[r.getNextInt()-1]=i+1;

       }
       for(int j=0;j<n;j++)
       {System.out.print(a[i]+" ");

       }
    }
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

public class tAXI {

    static class IntStreamReader {

        private BufferedInputStream inp = null;
        private int offset = 0;
        private int size = 25600;
        private byte[] buff = new byte[size];

        public IntStreamReader(InputStream in) throws IOException {
            inp = new BufferedInputStream(in);
            inp.read(buff, 0, size);
        }

        public int getNextInt() throws IOException {
            int parsedInt = 0;
            int i = offset;
            int flag = 0;
            while (i < buff.length && buff[i] != '-' && (buff[i] < '0' || buff[i] > '9')) {
                i++;
            }
            if (i < buff.length && buff[i] == '-') {
                i++;
                flag = 1;
            }
            while (i < buff.length && (buff[i] >= '0' && buff[i] <= '9')) {
                parsedInt *= 10;
                parsedInt += buff[i] - '0';
                i++;
            }

            if (i == buff.length) {

                int j = 0;
                for (; offset < buff.length; j++, offset++) {
                    buff[j] = buff[offset];
                }

                inp.read(buff, j, size - j);

                offset = 0;
                parsedInt = getNextInt();
            } else {
                offset = i;
            }
            if (flag == 0) {
                return parsedInt;
            } else {
                return -parsedInt;
            }
        }
    }

    public static void main(String arg[]) throws IOException {

        IntStreamReader r = new IntStreamReader(System.in);
       int n=r.getNextInt();
       int i=0;
       int a[]=new int[n];
       while(i<n)
       {
           a[r.getNextInt()-1]=i+1;
                   i++;

       }
       for(int j=0;j<n;j++)
       {System.out.print(a[j]+" ");

       }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		(new Main()).solve();
	}

	public Main() {
	}

	MyReader in = new MyReader();
	PrintWriter out = new PrintWriter(System.out);

	void solve() throws IOException {
		//BufferedReader in = new BufferedReader(new
		//InputStreamReader(System.in));
		//Scanner in = new Scanner(System.in);

		//Scanner in = new Scanner(new FileReader("forbidden-triples.in"));
		//PrintWriter out = new PrintWriter("forbidden-triples.out");

		int n = in.nextInt();
		int[] a = new int[n];

		for (int i = 0; i < n; i++) {
			a[in.nextInt() - 1] = i + 1;
		}

		for (int i = 0; i < n; i++) {
			out.print(a[i] + " ");
		}

		out.close();

	}

};

class MyReader {
	private BufferedReader in;
	String[] parsed;
	int index = 0;

	public MyReader() {
		in = new BufferedReader(new InputStreamReader(System.in));
	}

	public int nextInt() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Integer.parseInt(parsed[index++]);
	}

	public long nextLong() throws NumberFormatException, IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return Long.parseLong(parsed[index++]);
	}

	public String nextString() throws IOException {
		if (parsed == null || parsed.length == index) {
			read();
		}
		return parsed[index++];
	}

	private void read() throws IOException {
		parsed = in.readLine().split(" ");
		index = 0;
	}

	public String readLine() throws IOException {
		return in.readLine();
	}
};


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class GiftsProblem {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(in.readLine());
		StringTokenizer tokenizer = new StringTokenizer(in.readLine());

		int[] result = new int[n];

		for (int i = 0; i < n; ++i) {
			result[Integer.parseInt(tokenizer.nextToken()) - 1] = i + 1;
		}

		for (int i = 0; i < n; ++i) {
			System.out.print(result[i] + " ");
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class GiftsProblem {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(in.readLine());
		StringTokenizer tokenizer = new StringTokenizer(in.readLine());

		int[] result = new int[n];

		for (int i = 0; i < n; ++i) {
			result[Integer.parseInt(tokenizer.nextToken()) - 1] = i + 1;
		}

		for (int i = 0; i < n; ++i) {
			System.out.print(String.valueOf(result[i]) + (i < n - 1 ? " " : ""));
		}

	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;
public class a{
    public static void main(String args[]) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken());
        int[] a=new int[n];
        st=new StringTokenizer(br.readLine());
        for(int i=0;i<n;i++) a[Integer.parseInt(st.nextToken())-1]=i+1;
        for(int i=0;i<n-1;i++) System.out.print(a[i]+" ");
        System.out.println(a[n-1]);
    }
}


#include<iostream>
using namespace std;
int main() {
    int n,a[500],b[500],d;
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        d=a[i];
        d[b]=i+1;

    }
    for(int i=1;i<n+1;i++){
        cout<<b[i]<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    for (int i = 0; i < n; ++i) {
        a[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

int main (){
    long n, tmp;
    cin >> n;
    long ans[n+1];
    for (long i =0; i< n;i++){
        cin >> tmp;
        ans[tmp-1] = i;
    }
    for (long i =0; i < n;i++){
        cout << ans[i]+1;
        cout << " ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i;
    cin>>n;
    int a[n+1];
    for(i=1; i<=n; i++)
    {
        cin>>m;
        a[m]=i;
    }
    cout<<a[1]<<" ";
    for(i=2; i<=n; i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int c[101]={0};
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i+1==a[j])
            {
                c[i]=j+1;
            }

        }
    }
    for(int i=0;i<n;i++)
    {
       printf("%d ",c[i]);
    }
 return 0;
}


#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<=n;i++){
		for(int j=0;j<n;j++){
			if(a[j]==i)cout<<j+1<<" ";
			else continue;
		}
	}
	return 0;
}


#include <iostream>
using namespace std;
 int main()
 {
 	int n;
 	cin>>n;
 	int a[n],b[n];
 	 for (int i=0;i<n;i++)
 	 {
 	 	cin>>a[i];
 	 	b[a[i]-1]=i+1;
	  }
	  for (int i=0;i<n;i++)
	  {
	  	cout <<b[i]<<" ";
	  }
	  return 0;
 }


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, p;
    cin >> n;
    vector<int> f(n+1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << f[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, p;
    cin >> n;
   int f[n+1];
    for (int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }

    for (int i = 1; i <= n; ++i)
    {
        cout  << f[i]<< " ";
    }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[a[i]-1]=i+1;
    }
    for(int i=0; i<n; i++){
        cout<<b[i]<<" ";
    }

    return 0;
}


#include<iostream>
  using namespace std;

  int main()
  {
      int n;
      cin>>n;
      int i,j,a[n];

      for ( i=0; i<n; i++) cin>>a[i];

       for ( j=1;j<=n; j++)
         for ( i=0; i<n; i++)

        {
          if(a[i]==j) { cout<<(i+1)<<" "; break; }
        }
  }


#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n,p;
    cin >> n;
    vector<int> f(n+1);
    for(int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for(int i = 2;i <= n; ++i)
    {
        cout << " "<<f[i];
    }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

int a,b,x;
cin >>a;
int arr[a];
for (b=1;b<=a;b++)
{
    cin>>x;
    arr[x-1]=b;
}
for (b=0;b<a;b++)
{
    cout<<arr[b]<<" ";
}
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n],b[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        b[a[i]-1]=i+1;
    }
    for(int i=0;i<n;i++){
        printf("%d",b[i]);
        if(i!=(n-1))printf(" ");
    }
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int n, a1[101], a2[101];
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a1[i];
		a2[a1[i]] = i;
	}
	for (int i = 1; i <= n; ++i) {
		cout << a2[i];
		if (i != n )
			cout << " ";
	}
	return 0;
}


#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main() {
	int n, a1[100], a2[100];
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a1[i];
		a2[a1[i]] = i;
	}
	for (int i = 1; i <= n; ++i) {
		cout << a2[i];
		if (i != n )
			cout << " ";
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;

int main() {
    int n, x;
    map<int, int> m;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        m[x - 1] = i;
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", m[i] + 1);
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        b[a[i]-1]=i+1;
    }
    for(int i=0;i<n;i++)
    {
        cout<<b[i]<<" ";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	int a[101],b[101];
    cin>>n;
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
    	b[a[i]-1]=i+1;
    }
    for(int i=0;i<n;i++)
    {
    	cout<<b[i]<<"\t";
    }
  return 0;
}


#include <iosttream>
#include <vector>
using namespace std;
int main()
{
    int n,p;
    cin >> n;
    vector<int> f(n+1);
    for( int i = 1 ;i <= n; i++)
    {
        cin >> p;
        f[p] = i;

    }
    cout << f[1];
    for(int i=2; i <= n; i++)
    {
        cout<<" " << f[i];
    }
    cout << endl;
    return 0;
}


#include <iosttream>
#include <vector>
using namespace std;
int main()
{
    int n,p;
    cin>>n;
    vector<int>f(n+1);
    for( int i=0;i<=n;i++)
    {
        cin>>p;
        f[p]=i;

    }
    cout<<f[1];
    for(int i=2;i<=n;i++)
    {
        cout<<" " <<f[i];
    }
    cout<<endl;
    return 0;
}


#include <iosttream>
#include <vector>
using namespace std;
int main()
{
    int n,p;
    cin >> n;
    vector<int> f(n+1);
    for( int i=1;i<=n;i++)
    {
        cin>>p;
        f[p]=i;

    }
    cout<<f[1];
    for(int i=2;i<=n;i++)
    {
        cout<<" " <<f[i];
    }
    cout<<endl;
    return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
    int a[1000],b[1000],i,j,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
    cin>>a[i];
    b[i]=a[i];
    }
    sort(b,b+n);
    for(i=0;i<n;i++)
    {
    for(j=0;j<n;j++)
    {
    if(b[i]==a[j])
    cout<<j+1<<" ";
    }
    }
    return 0;
}


#include <iostream>
using namespace std;
int n, b, mas[105];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> b;
        mas[b] = i;
    }
    for (int i = 1; i <= n; i++) {
        cout << mas[i] << " ";
    }
}


#include<stdio.h>
#include<string.h>

int main()
{
    int i,j,k,c1,n,b,c;
    scanf("%d",&n);
    int ara[n],cnt[n];
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
        cnt[ara[i]-1]=i+1;
    }
    for(i=0;i<n;i++){
        printf("%d ",cnt[i]);
    }
    printf("\n");
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<n;j++){
            if(a[j]==i){
                cout<<j+1<<" ";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    for (int i = 0; i < n; ++i) {
        a[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, p;
    cin >> n;
    vector<int> f(n+1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << f[i];
    }
    cout << endl;
    return 0;
}


#include<iostream.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    for (int i = 0; i < n; ++i) {
        a[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, p;
    cin >> n;
    vector<int> f(n+1);
    for (int i=1;i<=n;i++)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << f[i];
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, temp;
	cin >> n;
	vector <int> p(102);
	for (int i = 1; i < n + 1; ++i)
	{
		cin >> temp;
		p[temp] = i;
	}
	for (int i = 1; i < n + 1; ++i)
	{
		cout << p[i] << " ";
	}
	cout <<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int B[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>B[i];
    }
    for (int i = 0; i < n; ++i) {
        B[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<B[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n]={0};
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n];
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<iostream>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n]={0};
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<iostream>
using namespace std;
int main()
{
	int n,x,i=1;
	cin>>n;
	int a[n];
	while(i<=n)
	{
		cin>>x;
		a[x]=i++;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<iostream>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n];
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<iostream>
using namespace std;
int main()
{
	int n,x,a[101];
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	int n,x;
	cin>>n;
	int a[n]={0};
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return(0);
}


#include<bits/stdc++.h>
using namespace std;
int x[110]
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;++i)
        {
            x[a[i]]=i;
        }
        for(i=1;i<=n;++i)
        {
            cout<<x[i]<<" ";
        }
}


#include<bits/stdc++.h>
using namespace std;
int x[1100];
int main()
{
    int n,i;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;++i)
        {
            x[a[i]]=i;
        }
        for(i=1;i<=n;++i)
        {
            cout<<x[i]<<" ";
        }
}


#include<bits/stdc++.h>
using namespace std;
int x[110];
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;++i)
        {
            x[a[i]]=i;
        }
        for(i=1;i<=n;++i)
        {
            cout<<x[i]<<" ";
        }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n],x[n];
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;++i)
        {
            x[a[i]]=i;
        }
        for(i=1;i<=n;++i)
        {
            cout<<x[i]<<" ";
        }
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    for (int i = 0; i < n; ++i) {
        a[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, p;
    cin >> n;
    vector<int> f(n+1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << f[i];
    }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n ;
    cin >> n ;
    int ar[101];
     for (int i = 1; i <= n ;i++ )
     {
         int  x ;  cin >> x ;
         ar[x] = i;
     }

     for (int i = 1; i <=n ; i++)
     {
         cout << ar[i] << " ";
     }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n ;
    cin >> n ;

    map <int , int >mp;
     for (int i = 1; i <= n ;i++ )
     {
         int  x ;  cin >> x ;
         mp[x] = i;
     }

     for (int i = 1; i <=n ; i++)
     {
         cout << mp[i] << " ";
     }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n ;
    cin >> n ;
    int ar[n];
    map<int , int> st;
    for(int i =1; i <=n ; i++)
    {
        cin >> ar[i];
    }
    for(int i = 1 ;i <= n ; i++)
    {
        st[ar[i]] = i;
    }

    for(auto i:st)
    {
        cout  <<i.second << " " ;
    }


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n ;
    cin >> n ;
    int ar[n];
    map<int , int> st;
    for(int i =1; i <=n ; i++)
    {
        cin >> ar[i];
    }
    for(int i = 1 ;i <= n ; i++)
    {
        st[ar[i]] = i;
    }

    for(auto i:st)
    {
        cout  <<i.second << " " ;
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n ;
    cin >> n ;
    int ar[n];
    map<int , int> st;
    for(int i =1; i <=n ; i++)
    {
        cin >> ar[i];
        st[ar[i]] = i;

    }
    for(auto i:st)
    {
        cout  <<i.second << " " ;
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    int a[n],b[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]-1]=i+1;
    }
    for(ll i=0;i<n;i++)
    cout<<b[i]<<" ";
    cout<<endl;

}


#include <iostream>
using namespace std;
int main()
{
	int i,j,n;
	cin>>n;
	int a[n],b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[a[i]-1]=i+1;
	}
	for(i=0;i<n;i++)
		cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr[10000];
int main(void)
{
    int n;
    cin>>n;
    int bucket[n];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        bucket[arr[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<bucket[i]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 1; i <= n; ++i) {
        cin>>x[i];
    }
    for (int i = 1; i <= n; ++i) {
        a[x[i]]=i;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(void)
{
    int n;
    cin>>n;
    int arr[n];
    int bucket[n];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        bucket[arr[i]]=i;

    }
    for(int i=1;i<=n;i++)
    {
        cout<<bucket[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main(void)
{
    int n;
    cin>>n;
    int arr[n];
    int bucket[n];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        bucket[arr[i]]=i;

    }
    for(int i=1;i<=n;i++)
    {
        cout<<bucket[i]<<" ";
    }
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main(void)
{
    int n;
    cin>>n;
    int arr[n];
    int bucket[n];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    for(int i=1;i<=n;i++)
    {
        bucket[arr[i]]=i;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<bucket[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
 int a[101];
 int n,e;
 cin>>n;
 int x[n+10];
 for(int i=0;i<n;i++)
 {
     cin>>x[i];
 }
 for(int i=0;i<n;i++)
 {
     a[x[i]]=i+1;

 }
 for(int i=1;i<=n;i++)
 {
     cout<<a[i]<<" ";
 }
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
 int a[101];
 int n;
 cin>>n;
 int x[n+10];
 for(int i=0;i<n;i++)
 {
     cin>>x[i];
 }
 for(int i=0;i<n;i++)
 {
     a[x[i]]=i+1;

 }
 for(int i=1;i<=n;i++)
 {
     cout<<a[i]<<" ";
 }
}


#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    cin >> n;
    int a[100];
    int b[100];
    for(int i=0; i<n; i++) {
        cin >> a[i];
        b[a[i]-1] = i+1;
    }
    for(int i=0; i<n; i++) {
        if(i>0) cout << " ";
        cout << b[i];
    }
    cout << endl;

    return 0;
}


#include <iostream>

int main(){
  int n;
  std::cin >> n;
  int *a = new int[n];
  int *b = new int[n];
  for(int i = 0; i < n; i++)
    {
      std::cin >> a[i];
    }
  for(int i = 0; i < n; i++)
    {
      b[a[i] - 1] = i + 1;
    }
  for(int i = 0; i < n; i++)
    {
      std::cout << b[i] << " ";
    }
  delete[] a;
  delete[] b;
  return(0);
}


#include <iostream>

using namespace std;
int main() {
    int n;
    cin>>n;
    int in [n];
    int out [n];
    for(int i=0 ;i<n ; i++){
        cin>>in[i];
        out[in[i]-1]=i+1;
    }
    for(int i=0 ;i<n ;i++)
        cout<<out[i]<<" ";

return 0;
}


#include<bits/stdc++.h>
#include <map>
using namespace std;

int main () {
  int n, num;
  cin>>n;
  map<int, int> MAP;
  map<int, int>::iterator it;
  for(int i=1; i<=n; i++){
    cin>>num;
    MAP.insert(pair(num, i));
  }
  for(int i=1; i<=n; i++){
    cout<<MAP.find(i)->second<<" ";
  }
}


#include<bits/stdc++.h>
using namespace std;

int main()

{
    int arr[1000],n,i,j,br[1000];
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
        br[arr[i]]=i;
    }
    for(j=1;j<n;j++)
        printf("%d ",br[j]);
    printf("%d\n",br[n]);
    return 0;

}


#include <iostream>
#include <unordered_map>
using namespace std;
int main(void) { int n;
    cin >> n;
    unordered_map<int, int> m;
    for (int i = 0; i < n;i++) {
        int a;
        cin >> a;
        m[a] = i;
    }
    for (int i = 1; i <= n;i++) {
        cout << ++m[i] << endl;
    }
    return EXIT_SUCCESS;
}


#include <iostream>

#include <vector>

using namespace std;

int main()

{

    int n, p;

    cin >> n;

    vector<int> f(n+1);

    for (int i = 1; i <= n; ++i)

    {

        cin >> p;

        f[p] = i;

    }

    cout << f[1];

    for (int i = 2; i <= n; ++i)

    {

        cout << " " << f[i];

    }

    cout << endl;

    return 0;

}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, p;
    cin >> n;
    vector<int> f(n+1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> p;
        f[p] = i;
    }
    cout << f[1];
    for (int i = 2; i <= n; ++i)
    {
        cout << " " << f[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main(){
    int n, x;
    cin >> n;
    vector<int> friend(n);
    for(int i = 1; i <= n; i++){
        cin >> x;
        friend[x-1] = i;
    }

    for(int i = 0; i < n; i++){
        cout << friend[i];
        if(i == n - 1) cout << "\n";
        else cout << " ";
    }
}


#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, x;
    cin >> n;
    vector<int> teman(n);
    for(int i = 1; i <= n; i++){
        cin >> x;
        teman[x-1] = i;
    }

    for(int i = 0; i < n; i++){
        cout << teman[i];
        if(i == n - 1) cout << "\n";
        else cout << " ";
    }
}


#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;

int main()
{
 int a[100] ,n,i=0,b=0;
cin >>n;
for (int i =0 ;i<n;i++)cin>>a[i];

for (int i =1 ;i<=n;i++){

    for (int j =0 ;j<n;j++){

        if (a[j] ==i) break;
        else b++;

    }
    cout<<b+1;
    b=0;
}

}


#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;

int main()
{
 int a[100] ,n,i=0,b=0;
cin >>n;
for (int i =0 ;i<n;i++)cin>>a[i];

for (int i =1 ;i<=n;i++){

    for (int j =0 ;j<n;j++){

        if (a[j] ==i) break;
        else b++;

    }
    cout<<b+1<<" ";
    b=0;
}

}


#include<bits/stdc++.h>
using namespace std;

int main()
    {
        int n;
        cin>>n;
        map<int,int> m;
        int c=1;
        for(int i=0;i<n;i++)
        {
            int a;
            cin>>a;
            m[a] = c++;
        }
        for(int i=1;i<=n;i++)
                cout<<m[i]<<" ";

        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main() {
    int n,e;
    cin>>n;
    int x[n+10];
    for (int i = 0; i < n; ++i) {
        cin>>x[i];
    }
    for (int i = 0; i < n; ++i) {
        a[x[i]]=i+1;
    }
    for (int i = 1; i <= n; ++i) {
        cout<<a[i]<<" ";
    }
    return 0;
}


/*ufiw*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
using namespace std;
const int maxn = 110;
int n, k, a[maxn], b[maxn], w[maxn], d[maxn][20010];
int main() {
//    freopen("mainin.txt", "r", stdin);
    while (scanf("%d%d", &n, &k) != EOF) {
        for (int i = 1; i <= n; i++)    scanf("%d", a + i);
        for (int i = 1; i <= n; i++)    scanf("%d", b + i);
        for (int i = 1; i <= n; i++)    w[i] = a[i] - b[i] * k;
        for (int i = 1; i <= 20000; i++)    d[0][i] = -100000;
        d[0][10000] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 20000; j >= 1; j--) {
                d[i][j] = d[i - 1][j];
                if (j - w[i] >= 1 && j - w[i] <= 20000)
                    d[i][j] = max(d[i][j], d[i - 1][j - w[i]] + a[i]);
            }
        }
        int ans = -1;
        if (d[n][10000] > 0)   ans = d[n][10000];
        printf("%d\n", ans);
    }
    return 0;
}


/*c8xh*/
#include <bits/stdc++.h>

using namespace std;
int n,k;
int a[105],b[105];
int fzheng[10005],ffu[10005];
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=n;i++)
        scanf("%d",&b[i]);

     for (int j=10000;j>=0;j--)
        fzheng[j]=ffu[j]=-10000000;

    fzheng[0]=ffu[0]=0;
    for (int i=1;i<=n;i++)
        if (k*b[i]>=a[i])
    {
        for (int j=10000;j>=0;j--)
            if (j>=(k*b[i]-a[i]))
            fzheng[j]=max(fzheng[j-(k*b[i]-a[i])]+a[i],fzheng[j]);
    }
    else
    {
        for (int j=10000;j>=0;j--)
            if (j>=(a[i]-k*b[i]))
            ffu[j]=max(ffu[j-(a[i]-k*b[i])]+a[i],ffu[j]);
    }
    int ans=0;
    for (int i=0;i<=10000;i++)
        ans=max(ans,fzheng[i]+ffu[i]);
    if (ans) printf("%d\n",ans);
else puts("-1");
    return 0;
}


/*y5uo*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

const double pi = acos(-1.0);

int n, k;
struct gg {
    int a, b, c;
    gg(){}
    gg(int a, int b) : a(a), b(b){}
    c = a - k * b;
    bool operator < (const gg &g) const {
        return c < g.c;}
} g[105];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].a);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].b);
    sort(g + 1, g + n + 1);
    int i = 1, x1 = 0, x2 = 0;
    while (i <= n && g[i].c < 0) ++i;
    x1 = i - 1;
    while (i <= n && g[i].c == 0) ++i;
    x2 = i;

    return 0;
}


/*gv6u*/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int n, m, x, a[101], b[101], f[101][2001];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &b[i]);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &x);
        a[i] = b[i] - m * x;
    }
    memset(f, -1, sizeof(f));
    f[0][1000] = 0;
    for (int i = 1; i <= n; i++)
        for (int j = a[i] + 1000; j <= 2000; j++)
        {
            if (f[i - 1][j] > -1)
                f[i][j] = max(f[i][j], f[i - 1][j]);
            if (f[i - 1][j - a[i]] > - 1)
                f[i][j] = max(f[i][j], f[i - 1][j - a[i]] + b[i]);
        }
    printf("%d\n", f[n][1000] ? f[n][1000] : -1);
    return 0;
}


/*1f57*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=105;
const int maxm=1e5+5;
int dp[maxn][maxm], a[maxn], b[maxn];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    while(~scanf("%d%d", &n, &m)){
        for(int i=1; i<=n; i++)cin>>a[i];
        for(int i=1; i<=n; i++)cin>>b[i], b[i]=a[i]-m*b[i];
        memset(dp, -inf, sizeof(dp));
        int summ=n*1000;
        dp[0][summ]=0;
        for(int i=1; i<=n; i++){
            for(int j=2*summ; j>=b[i]; j--){
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-b[i]]+a[i]);
            }
        }
        // for(int i=summ-n; i<=summ+n; i++)printf("%d ", dp[n][i]);
        // printf("\n");
        if(dp[n][summ]>0){
            printf("%d\n", dp[n][summ]);
        }
        else printf("-1\n");
    }
    return 0;
}


/*tbae*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=105;
const int maxm=1e5+5;
int dp[maxn][maxm], a[maxn], b[maxn];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    while(~scanf("%d%d", &n, &m)){
        for(int i=1; i<=n; i++)cin>>a[i];
        for(int i=1; i<=n; i++)cin>>b[i], b[i]=a[i]-m*b[i];
        memset(dp, -inf, sizeof(dp));
        int summ=n*1000;
        dp[0][summ]=0;
        for(int i=1; i<=n; i++){
            for(int j=2*summ; j>=b[i]; j--){
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-b[i]]+a[i]);
            }
        }
        for(int i=summ-n; i<=summ+n; i++)printf("%d ", dp[n][i]);
        printf("\n");
        if(dp[n][summ]>0){
            printf("%d\n", dp[n][summ]);
        }
        else printf("-1\n");
    }
    return 0;
}


/*r8jk*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

const double pi = acos(-1.0);

int n, k;
struct gg {
    int a, b, c;
    gg(){}
    gg(int a, int b) : a(a), b(b){}
    //c = a - k * b;
    bool operator < (const gg &g) const {
        return c < g.c;}
} g[105];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].a);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].b);
    sort(g + 1, g + n + 1);
    int i = 1, x1 = 0, x2 = 0;
    while (i <= n && g[i].c < 0) ++i;
    x1 = i - 1;
    while (i <= n && g[i].c == 0) ++i;
    x2 = i;

    return 0;
}


/*rta5*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
using namespace std;
int i,j,k,l,n,m,p,q,a[110],b[110],f[1010][1010];
int main(){
	scanf("%d%d",&n,&m);p=q=0;
	for(i=1;i<=n;i++)scanf("%d",&a[i]),p+=a[i];
	for(i=1;i<=n;i++)scanf("%d",&b[i]),b[i]*=m,q+=b[i];
	f[0][0]=1;
	for(i=1;i<=n;i++)
		for(j=p-a[i];j>=0;j--)
			for(k=q-b[i];k>=0;k--)
				if(f[j][k])	f[j+a[i]][k+b[i]]=1;
	for(i=1;i<=q&&i<=p;i++)
		if(f[i][i])l=i;
	if(l)printf("%d\n",l);
	else printf("-1\n");
}


/*g0jo*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 107

using namespace std;

int dp[MAX*MAX],dd[MAX*MAX];

int n,k,a[MAX],b[MAX],c[MAX];

int main ( )
{
    while ( ~scanf ( "%d%d" , &n , &k ) )
    {
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &a[i] );
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &b[i] );
        for ( int i = 0 ; i < n ; i++ )
            c[i] = a[i]-b[i]*k;
        memset ( dp , -0x3f , sizeof ( dp ) );
        memset ( dd , -0x3f , sizeof ( dd ) );
        dp[0] = dd[0] = 0;
        for ( int i = 0 ; i < n ; i++ )
            if ( c[i] >= 0 )
                for ( int j = 10000 ; j >= c[i] ; j-- )
                    dp[j] = max ( dp[j-c[i]]+a[i] , dp[j] );
        for ( int i = 0 ; i < n ; i++ )
            if ( c[i] < 0 )
            {
                c[i] = -c[i];
                for ( int j = 10000 ; j >= c[i] ; j-- )
                    dd[j] = max ( dd[j-c[i]]+a[i] , dd[j] );
            }
        int ans = -1;
        for ( int i = 0; i <= 10000 ; i++ )
        {
            if ( dd[i] == 0 && dp[i] == 0 )
                continue;
            ans = max ( ans , dp[i]+dd[i] );
        }
        printf ( "%d\n" , ans );
    }
}


/*0rg4*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 107

using namespace std;

int dp[MAX*MAX],dd[MAX*MAX];

int n,k,a[MAX],b[MAX],c[MAX];

int main ( )
{
    while ( ~scanf ( "%d%d" , &n , &k ) )
    {
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &a[i] );
        for ( int i = 0 ; i < n ; i++ )
            scanf ( "%d" , &b[i] );
        for ( int i = 0 ; i < n ; i++ )
            c[i] = a[i]-b[i]*k;
        memset ( dp , -0x3f , sizeof ( dp ) );
        memset ( dd , -0x3f , sizeof ( dd ) );
        dp[0] = dd[0] = 0;
        for ( int i = 0 ; i < n ; i++ )
            if ( c[i] >= 0 )
                for ( int j = 10000 ; j >= c[i] ; j-- )
                    dp[j] = max ( dp[j-c[i]]+a[i] , dp[j] );
        for ( int i = 0 ; i < n ; i++ )
            if ( c[i] < 0 )
            {
                c[i] = -c[i];
                for ( int j = 10000 ; j >= c[i] ; j-- )
                    dd[j] = max ( dd[j-c[i]]+a[i] , dd[j] );
            }
        int ans = -1;
        for ( int i = 0; i <= 10000 ; i++ )
        {
            if ( dd[i] == 0 && dp[i] == 0 )
                continue;
            ans = max ( ans , dp[i]+dd[i] );
        }
        printf ( "%d\n" , ans );
    }
}


/*8bzs*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const double eps = 1e-8;

const int MAXN=110;
int n,k;
int a[MAXN],b[MAXN];
int ff[MAXN][200010];
int f(int x,int y)
{
	if(x==0)
	{
		if(y==10000) return 0;
		else return -100000;
	}
	if(ff[x][y]!=-1) return ff[x][y];
	return (ff[x][y]=max(f(x-1,y),a[x]+f(x-1,y-(a[x]-k*b[x]))));
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","rb",stdin);
    //freopen("out.txt","wb",stdout);
#endif
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	memset(ff,-1,sizeof(ff));
	int ans=f(n,10000);
	if(ans>0) printf("%d\n",ans);
	else printf("%d\n",-1);
    return 0;
}


/*g1im*/
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #define N 3010005
    using namespace std;
    int a[N],b[N],c[N],dp[N],f[N];

    int main(){
    	int n,k;
    	scanf("%d%d",&n,&k);
    	int minx,maxx,sumx1=0,sumx2=0,sumx3=0;
    	minx=1000000007;
    	maxx=-1;
    	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    	for(int i=1;i<=n;i++) {
    		c[i]=a[i]-k*b[i];
    		if(c[i]>0) sumx1+=c[i];
    		if(c[i]<0) sumx2+=(-c[i]);
    		if(c[i]==0)  sumx3+=a[i];
    	}
    	for(int i=1;i<=sumx1+1;i++) dp[i]=-1000000007;
    	dp[0]=0;
    	for(int i=1;i<=n;i++) {
    		if(c[i]<=0) continue;
    		for(int j=sumx1;j>=c[i];j--)
    			dp[j]=max(dp[j],dp[j-c[i]]+a[i]);
    	}
    	for(int i=1;i<=sumx2+1;i++) f[i]=-1000000007;
    	for(int i=1;i<=n;i++){
    		if(c[i]>=0) continue;
    		int p=-c[i];
    		for(int j=sumx2;j>=p;j--){
    			f[j]=max(f[j],f[j-p]+a[i]);
    		}
    	}
    	int ans=0;
    	for(int i=1;i<=min(sumx1,sumx2);i++){
    		ans=max(ans,dp[i]+f[i]);
    	}
    	ans+=sumx3;
    	if(ans!=0) printf("%d\n",ans); else printf("-1\n");
    	return 0;
    }


/*2tl8*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

const double pi = acos(-1.0);

int n, k;
struct gg {
    int a, b, c;
    gg(){}
    gg(int a, int b) : a(a), b(b){}
    c = a - k * b;
    bool operator < (const gg &g) const {
        return c < g.c;}
} g[105];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].a);
    for (int i = 1; i <= n; ++i) scanf("%d", &g[i].b);
    sort(g + 1, g + n + 1);
    int i = 1, x1 = 0, x2 = 0;
    while (i <= n && g[i].c < 0) ++i;
    x1 = i - 1;
    while (i <= n && g[i].c == 0) ++i;
    x2 = i;

    return 0;
}


/*8jv2*/
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int N = 105;
const int LEN = 20000;
int ai[N], bi[N], wi[N];
int dp[LEN];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; ++ i)
    {
        scanf("%d", &ai[i]);
    }
    for(int i = 0; i < n; ++ i)
    {
        scanf("%d", &bi[i]);
        wi[i] = ai[i] - k * bi[i];
    }
    for(int i = 0; i < LEN; ++ i)
    {
        dp[i] = -0x3f3f3f3f;
    }
    dp[LEN / 2] = 0;
    for(int i = 0; i < n; ++ i)
    {
        if(wi[i] >= 0)
        {
            for(int j = LEN - 1; j >= wi[i]; -- j)
            {
                if(dp[j - wi[i]] != -0x3f3f3f3f)
                {
                    dp[j] = max(dp[j], dp[j - wi[i]] + ai[i]);
                }
            }
        }
        else
        {
            for(int j = wi[i]; j < LEN; ++ j)
            {
                if(dp[j - wi[i]] != -0x3f3f3f3f)
                {
                    dp[j] = max(dp[j], dp[j - wi[i]] + ai[i]);
                }
            }
        }
    }
    if(dp[LEN / 2] == 0)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n", dp[LEN / 2]);
    }
    return 0;
}


/*c9c0*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
using namespace std;
const int maxn = 110;
int n, k, a[maxn], b[maxn], w[maxn], d[maxn][20010];
int main() {
//    freopen("mainin.txt", "r", stdin);
    while (scanf("%d%d", &n, &k) != EOF) {
        for (int i = 1; i <= n; i++)    scanf("%d", a + i);
        for (int i = 1; i <= n; i++)    scanf("%d", b + i);
        for (int i = 1; i <= n; i++)    w[i] = a[i] - b[i] * k;
        for (int i = 1; i <= 20000; i++)    d[0][i] = -100000;
        d[0][10000] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 20000; j >= 1; j--) {
                d[i][j] = d[i - 1][j];
                if (j - w[i] >= 1 || j - w[i] <= 20000)
                    d[i][j] = max(d[i][j], d[i - 1][j - w[i]] + a[i]);
            }
        }
        int ans = -1;
        if (d[n][10000] > 0)   ans = d[n][10000];
        printf("%d\n", ans);
    }
    return 0;
}


/*1aso*/
#include "iostream"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "string"
#include "algorithm"
#include "queue"
#include "cmath"
using namespace std;
int dp[110][40000],a[110],b[110],n,k;
int f(int x,int y){
    if(x==0){
        if(y==20000)return 0;
        else return -1;
    }
    if(dp[x][y]!=-1)return dp[x][y];
    else{
        dp[x][y]=max(f(x-1,y),a[x]+f(x-1,y-b[x]));
        return dp[x][y];
    }
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        scanf("%d",&b[i]);
        b[i]=a[i]-k*b[i];
    }
    memset(dp,-1,sizeof(dp));
    int ans=f(n,20000);
    if(ans>0)printf("%d\n",ans);
    else printf("-1\n");
    return 0;
}


/*td7d*/
#include <bits/stdc++.h>

using namespace std;
int n,k;
int a[105],b[105];
int fzheng[10005],ffu[10005];
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (int i=1;i<=n;i++)
        scanf("%d",&b[i]);

     for (int j=10000;j>=0;j--)
        fzheng[j]=ffu[j]=-10000000;

    fzheng[0]=ffu[0]=0;
    for (int i=1;i<=n;i++)
        if (k*b[i]>=a[i])
    {
        for (int j=10000;j>=0;j--)
            if (j>=(k*b[i]-a[i]))
            fzheng[j]=max(fzheng[j-(k*b[i]-a[i])]+a[i],fzheng[j]);
    }
    else
    {
        for (int j=10000;j>=0;j--)
            if (j>=(a[i]-k*b[i]))
            ffu[j]=max(ffu[j-(a[i]-k*b[i])]+a[i],ffu[j]);
    }
    int ans=0;
    for (int i=0;i<10000;i++)
        ans=max(ans,fzheng[i]+ffu[i]);
    if (ans) printf("%d\n",ans);
else puts("-1");
    return 0;
}


/*n78t*/
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using namespace std;

#define pau system("pause")
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair

const double pi = acos(-1.0);

int n, k;
int a[105], b[105], c[105];
const int W = 100000;

int dp[105][2 * W + 10005];
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
    for (int i = 1; i <= n; ++i) c[i] = a[i] - k * b[i];

    memset(dp, -0x3f, sizeof(dp));
    dp[0][W] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 2 * W; j >= c[i]; --j) {
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - c[i]] + a[i]);
        }
    }
    printf("%d\n", dp[n][W] > 0 ? dp[n][W] : -1);
    return 0;
}


/*slas*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=105;
const int maxm=1e5+5;
int dp[maxn][maxm], a[maxn], b[maxn];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("in.txt", "r", stdin);
#endif
    int n, m;
    while(~scanf("%d%d", &n, &m)){
        for(int i=1; i<=n; i++)cin>>a[i];
        for(int i=1; i<=n; i++)cin>>b[i], b[i]=a[i]-m*b[i];
        memset(dp, -inf, sizeof(dp));
        int summ=n*1000;
        dp[0][summ]=0;
        for(int i=1; i<=n; i++){
            for(int j=2*summ; j>=b[i]; j--){
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-b[i]]+a[i]);
            }
        }
        // for(int i=summ-n; i<=summ+n; i++)printf("%d ", dp[n][i]);
        // printf("\n");
        if(dp[n][summ]>0){
            printf("%d\n", dp[n][summ]);
        }
        else printf("-1\n");
    }
    return 0;
}


/*gazk*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
using namespace std;
int i,j,k,l,n,m,p,q,a[110],b[110],f[1010][1010];
int main(){
	scanf("%d%d",&n,&m);p=q=0;
	for(i=1;i<=n;i++)scanf("%d",&a[i]),p+=a[i];
	for(i=1;i<=n;i++)scanf("%d",&b[i]),q+=b[i];
	f[0][0]=1;
	for(i=1;i<=n;i++)
		for(j=p-a[i];j>=0;j--)
			for(k=q-b[i];k>=0;k--)
				if(f[j][k])	f[j+a[i]][k+b[i]]=1;
	for(i=1;i<=q&&i*m<=p;i++)
		if(f[i*m][i])l=i*m;
	if(l)printf("%d\n",l);
	else printf("-1\n");
}


/*09my*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define ull unsigned long long
#define max(A, B) ((A) > (B) ? (A) : (B))
#define min(A, B) ((A) < (B) ? (A) : (B))
using namespace std;
const int maxn = 110;
int n, k, a[maxn], b[maxn], w[maxn], d[maxn][20010];
int main() {
//    freopen("mainin.txt", "r", stdin);
    while (scanf("%d%d", &n, &k) != EOF) {
        for (int i = 1; i <= n; i++)    scanf("%d", a + i);
        for (int i = 1; i <= n; i++)    scanf("%d", b + i);
        for (int i = 1; i <= n; i++)    w[i] = a[i] - b[i] * k;
        for (int i = 1; i <= 20000; i++)    d[0][i] = -100000;
        d[0][10000] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 20000; j >= 1; j--) {
                d[i][j] = d[i - 1][j];
                if (j - w[i] >= 1 || j - w[i] <= 20000)
                    d[i][j] = max(d[i][j], d[i - 1][j - w[i]] + a[i]);
            }
        }
        int ans = -1;
        if (d[n][10000] > 0)   ans = d[n][10000];
        printf("%d\n", ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int dp[100][200000],n,k,a[100],b[100],sh=200000;

int solve(int i,int bala)
{
	if(i>=n)
	{
		if(bala==sh)
			return 0;
		return -1e9;
	}
	if(dp[i][bala]!=-1)
		return dp[i][bala];
	int ret=0;
	ret=max(solve(i+1,bala),solve(i+1,bala+(b[i]*k)-a[i])+a[i]);
	return dp[i][bala]=ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(cin>>n>>k)
    {
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	memset(dp,-1,sizeof(dp));
    	int ans=solve(0,sh);
    	if(ans<=0)
    		cout<<-1<<endl;
    	else
    		cout<<ans<<endl;
    }
   	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int dp[100][100000],n,k,a[100],b[100],sh=200000;

int solve(int i,int bala)
{
	if(i>=n)
	{
		if(bala==sh)
			return 0;
		return -1e9;
	}
	if(dp[i][bala+sh]!=-1)
		return dp[i][bala+sh];
	int ret=0;
	ret=max(solve(i+1,bala),solve(i+1,bala+(b[i]*k)-a[i])+a[i]);
	return dp[i][bala+sh]=ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(cin>>n>>k)
    {
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	memset(dp,-1,sizeof(dp));
    	int ans=solve(0,sh);
    	if(ans<=0)
    		cout<<-1<<endl;
    	else
    		cout<<ans<<endl;
    }
   	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int dp[100][200000],n,k,a[100],b[100],sh=100000;

int solve(int i,int bala)
{
	if(i>=n)
	{
		if(bala==sh)
			return 0;
		return -1e9;
	}
	if(dp[i][bala+sh]!=-1)
		return dp[i][bala+sh];
	int ret=0;
	ret=max(solve(i+1,bala),solve(i+1,bala+(b[i]*k)-a[i])+a[i]);
	return dp[i][bala+sh]=ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(cin>>n>>k)
    {
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	memset(dp,-1,sizeof(dp));
    	int ans=solve(0,sh);
    	if(ans<=0)
    		cout<<-1<<endl;
    	else
    		cout<<ans<<endl;
    }
   	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    int n,k;
    while(cin>>n>>k)
    {
    	int a[n],b[n];
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	int ans=-1;
    	for(int i=0;i<n;i++)
    	{
    		int sum1=a[i],sum2=b[i];
    		for(int j=i+1;j<n;j++)
    		{
    			sum1+=a[j];
    			sum2+=b[j];
    			//cout<<sum1<<" "<<sum2<<endl;
    			double x=sum1/sum2;
    			if(x==k)
    				ans=max(ans,sum1);
    		}
    	}
    	cout<<ans<<endl;
    }
   	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int dp[100][100000],n,k,a[100],b[100],sh=20000;

int solve(int i,int bala)
{
	if(i>=n)
	{
		if(bala==sh)
			return 0;
		return -1e9;
	}
	if(dp[i][bala]!=-1)
		return dp[i][bala];
	int ret=0;
	ret=max(solve(i+1,bala),solve(i+1,bala+(b[i]*k)-a[i])+a[i]);
	return dp[i][bala]=ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(cin>>n>>k)
    {
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	memset(dp,-1,sizeof(dp));
    	int ans=solve(0,sh);
    	if(ans<=0)
    		cout<<-1<<endl;
    	else
    		cout<<ans<<endl;
    }
   	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int dp[100][201000],n,k,a[100],b[100],sh=100000;

int solve(int i,int bala)
{
	if(i>=n)
	{
		if(!bala)
			return 0;
		return -1e9;
	}
	if(dp[i][bala+sh]!=-1)
		return dp[i][bala+sh];
	int ret=0;
	ret=max(solve(i+1,bala),solve(i+1,bala+(b[i]*k)-a[i])+a[i]);
	return dp[i][bala+sh]=ret;
}

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    while(cin>>n>>k)
    {
    	for(int i=0;i<n;i++)
    		cin>>a[i];
    	for(int i=0;i<n;i++)
    		cin>>b[i];
    	memset(dp,-1,sizeof(dp));
    	int ans=solve(0,0);
    	if(ans<=0)
    		cout<<-1<<endl;
    	else
    		cout<<ans<<endl;
    }
   	return 0;
}