#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class ColorfulCards { public:
	vector <int> theCards(int N, string colors) 
	{
		vector<bool> isPrime(N+1, true);
		isPrime[1] = false;
		for(int p=2; p<=N; ++p)
			if( isPrime[p] )
				for(int q=p+p; q<=N; q+=p)
					isPrime[q] = false;

		vector<int> result(colors.size(), 0);
		for(int i=0; i<colors.size(); ++i)
			for(int n=1; n<=N; ++n)
				if( canItBe(i, n, colors, isPrime) )
					if( result[i] > 0 )
						{result[i] = -1; break;}
					else
						result[i] = n;
		return result;
	}

	bool canItBe(int i, int n, const string& colors, vector<bool>& isPrime)
	{
		if( colors[i]=='R' && !isPrime[n] )
			return false;
		if( colors[i]=='B' &&  isPrime[n] )
			return false;
		return greedyDown(i-1, n-1, colors, isPrime) && greedyUp(i+1, n+1, colors, isPrime);
	}

	bool greedyUp(int i, int n, const string& colors, vector<bool>& isPrime)
	{
		while( i<colors.size() )
		{
			if( n >= isPrime.size() )
				return false;
			if( colors[i]=='R' && isPrime[n] )
				{++i; ++n;}
			else
			if( colors[i]=='B' && !isPrime[n] )
				{++i; ++n;}
			else
				++n;
		}
		return true;
	}

	bool greedyDown(int i, int n, const string& colors, vector<bool>& isPrime)
	{
		while( i>=0 )
		{
			if( n < 1 )
				return false;
			if( colors[i]=='R' && isPrime[n] )
				{--i; --n;}
			else
			if( colors[i]=='B' && !isPrime[n] )
				{--i; --n;}
			else
				--n;
		}
		return true;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <int>& Expected, const vector <int>& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, ColorfulCards().theCards(N, colors));}
int main(){

CASE(0)
	int N = 5; 
	string colors = "RRR"; 
	int __[] = {2, 3, 5 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int N = 7; 
	string colors = "BBB"; 
	int __[] = {1, 4, 6 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int N = 6; 
	string colors = "RBR"; 
	int __[] = {-1, 4, 5 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int N = 58; 
	string colors = "RBRRBRBBRBRRBBRRBBBRRBBBRR"; 
	int __[] = {-1, -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 47, 53 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int N = 495; 
	string colors = "RBRRBRBBRBRRBBRRBBBRRBBBRR"; 
	int __[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int N = 1000; 
	string colors = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"; 
	int __[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	int N = 1; 
	string colors = "B"; 
	int __[] = {1};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	int N = 2; 
	string colors = "R"; 
	int __[] = {2};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	int N = 2; 
	string colors = "B"; 
	int __[] = {1};
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
}
// END CUT HERE
