#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define NMax 7010

using namespace std;

int N, M, L;
int Min[NMax], Max[NMax];
vector<int> P[NMax];
vector< pair<int, int> > nodes;
unordered_set<int> sets[NMax];

struct operation {

    int type;
    int t;
    int l;
    int r;
    int x;

} v[NMax];

int main() {

#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
#endif // ONLINE_JUDGE

    scanf("%d%d", &N, &M);

    P[1].push_back(0);
    P[1].push_back(0);

    for ( int i = 1; i < N; ++ i ) {
        P[i + 1].push_back(0);
        for ( int j = 1; j < (int) P[i].size(); ++ j )
            if ( (j & ( j - 1 )) == 0 ) { // putere a lui 2
                P[i + 1].push_back(j);
                P[i + 1].push_back(j);
            } else {
                P[i + 1].push_back(j);
            }
    }

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

        scanf("%d", &v[i].type);

        if ( v[i].type == 1 ) {
            scanf("%d%d%d%d", &v[i].t, &v[i].l, &v[i].r, &v[i].x );
        } else {
            scanf("%d%d", &v[i].t, &v[i].x );
            nodes.push_back(make_pair( v[i].t, v[i].x));
        }

    }

    sort(nodes.begin(), nodes.end());
    nodes.resize(unique(nodes.begin(), nodes.end()) - nodes.begin());
    //sets.resize(nodes.size());

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

        if ( v[i].type == 1 ) {

            for ( int i = 1; i <= N; ++ i ) {
                Min[i] = 2 * N + 1;
                Max[i] = -1;
            }

            Min[v[i].t] = v[i].l;
            Max[v[i].t] = v[i].r;

            for ( int l = v[i].l, t = v[i].t; t > 0; l = P[t][l], -- t ) {
                Min[t] = l;
            }

            for ( int r = v[i].r, t = v[i].t; t > 0; r = P[t][r], -- t ) {
                Max[t] = r;
            }

            for ( int k = 0; k < (int) nodes.size(); ++ k )
                if ( Min[nodes[k].first] <= nodes[k].second && nodes[k].second <= Max[nodes[k].first] )
                    sets[k].insert(v[i].x);

        } else {
            int pos = lower_bound( nodes.begin(), nodes.end(), make_pair(v[i].t, v[i].x)) - nodes.begin();
            printf("%d\n", (int) sets[pos].size() );
        }

    }

    return 0;
}


#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <functional>
using namespace std;
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define SZ size()
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=(b);i++)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define RI(x) scanf("%d",&x)
#define DRI(x) int x;RI(x)
#define RII(x,y) scanf("%d%d",&x,&y)
#define DRII(x,y) int x,y;RII(x,y)
#define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define DRIII(x,y,z) int x,y,z;RIII(x,y,z)
#define RS(x) scanf("%s",x)
#define PI(x) printf("%d\n",x)
#define PIS(x) printf("%d ",x)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define BG begin()
#define ED end()
#define PQ priority_queue
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define SEP(x) ((x)?'\n':' ')

typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

#define MAX 7000

struct Segment {
  int l, r, x;
  Segment() {}
  Segment(int l, int r, int x) : l(l), r(r), x(x) {}
};

struct Node {
  short left, right;
  Node(): left(-1), right(-1) {}
  Node(int l, int r): left(l), right(r) {}
};

int cnt[MAX+1];
vector<Node> node[MAX+1];
vector<Segment> record[MAX+1];

int main() {
  DRII(n, m);
  cnt[1] = 1;
  for(int level = 1; level < n; level = level + 1){
    cnt[level + 1] = 0;
    node[level].EB();
    for(int position = 1; position <= cnt[level]; position = position + 1){
      if((position & (position - 1)) == 0){ // that is, 1, 2, 4, 8...
        node[level].EB(cnt[level + 1] + 1, cnt[level + 1] + 2);
        cnt[level + 1] += 2;
      } else {
        node[level].EB(-1, ++cnt[level + 1]);
      }
    }
  }
  REP(i, m) {
    DRII(type, level);
    if(type == 1) {
      DRIII(l, r, x);
      record[level].EB(l, r, x);
    } else {
      DRI(position);
      int l = position, r = position;
      unordered_set<int> ans;
      while(level <= n) {
        for(const Segment & seg : record[level])
          if(seg.l <= r && l <= seg.r)
            ans.insert(seg.x);
        if(level < n) {
          r = node[level].at(r).right;
          if(node[level].at(l).left >= 0)
            l = node[level].at(l).left;
          else
            l = node[level].at(l).right;
        }
        level++;
      }
      PI((int)ans.size());
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define inf 1e18
using namespace std;
const int N = 1123456;
int read()
{
    int x;
    scanf("%I64d", &x);
    return x;
}
int getrand()
{
    srand(time(0));
    int x = rand();
    while(x -- > 0)
        rand();
    return rand() % 732 + 1;
}
int cnt[N];
char t[66];
main()
{
    int n, m, i, j, k, x, y;
    cin >> n >> m >> k >> x >> y;
    if(n == 1)
    {
        cout << k / m + ((k % m) != 0) << " " << k / m << " ";
        int d = k / m;
        if(y <= k % m)
            d ++;
        cout << d;
        return 0;
    }
    int r = (n - 1) * m;
    int ans1 = k / r;
    int ans2 = ans1 / 2;
    int ans3 = ans1;
    if(x == 1 || x == n)
        ans3 = ans2;
    if(x == 1)
        ans3 += ans1 % 2;
    k %= r;
    if(ans1 % 2 == 0)
    {
        if((x - 1) * m + y <= k)
           ans3 ++;
    }
    else
    {
        if((n - x) * m + y <= k)
            ans3 ++;
    }
    if(k >= m && ans1 % 2 == 1)
        ans2 ++;
    if(n == 2)
        ans1 = ans1 / 2 + ans1 % 2;
    if(k > m)
        ans1 ++;
    cout << ans1 << " " << ans2 << " " << ans3;
}


#include <bits/stdc++.h>

using namespace std;

const int inf = 0x3f3f3f3f;

int n, m, x, y;
long long k;

int main( ) {
	scanf("%d %d %I64d %d %d", &n, &m, &k, &x, &y);
	if (n == 1 || n == 2) {
		long long p = k / (n * m), res = k % (n * m);
		long long num1 = p, num2 = p, ans = p;
		if (res) ++ num1;
		if (res >= (x - 1) * m + y) ++ ans;
		printf("%I64d %I64d %I64d\n", num1, num2, ans);
	}
	else {
		long long p = k / ((2 * n - 2) * m), res = k % ((2 * n - 2) * m);
		long long num1 = 2 * p, num2 = p;
		long long ans;
		if (x == n || x == 1) ans = num2;
		else ans = num1;
		if (res > m) {
			++ num1;
			if (res > (n - 1) * m) {
				++ num2;
				if (res > n * m) ++ num1;
			}
		}
		if (res >= (x - 1) * m + y) ++ ans;
		if (x != n && res > n * m) {
			res -= n * m;
			if (res >= (n - 1 - x) * m + y) ++ ans;
		}
		printf("%I64d %I64d %I64d\n", num1, num2, ans);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
using namespace std;
typedef long long ll;
ll n, m, k, x, y, f[101][101];
int main() {
	cin >> n >> m >> k >> x >> y;
	ll iter;
	if (n == 1)
		iter = m;
	else if (n == 2)
		iter = 2 * m;
	else iter = 2 * m + (n - 2) * m * 2;
	ll times = k / iter;
	k -= times * iter;
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= m; ++j){
			if (i == 1 || i == n)
				f[i][j] += times;
			else f[i][j] += 2 * times;
		}
	}
	ll r = 1, d = 1;
	while (k){
		for (int j = 1; j <= m && k; ++j){
			--k;
			++f[r][j];
		}
		r += d;
		if (r > n){
			r = n - 1;
			d = -1;
		}
		else if (r < 1){
			r = 1;
			d = 1;
		}
		r = max(r, 1ll);
		r = min(r, n);
	}
	ll mx = 0, mn = 1e15;
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= m; ++j){
			mx = max(mx, f[i][j]);
			mn = min(mn, f[i][j]);
		}
	}
	cout << mx << " " << mn << " " << f[x][y] << endl;
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    cin >>n;
    int a[100];
    for (int i=0;i<n;i++){
        cin >>a[i];
    }
     if (a[n-1]==0){
        cout <<"UP" <<endl;
        return 0;
        }
    if (n==1){
        if (a[n-1]==15){
            cout <<"DOWN" <<endl;
            return 0;
        }

        else {
            cout <<"-1"<<endl;
            return 0;
        }
    }
    if (a[n-1]==15){
        cout <<"DOWN"<<endl;
        return 0;
    }
    else if (a[n-1]<a[n-2]){
            cout << "DOWN" <<endl;
            return 0;
    }

    cout <<"UP"<<endl;

    return 0;
}


#include <iostream>
#include <conio.h>
#include <string>
#include<fstream>
using namespace std;
void main()
{
	int n, *m;
	cin >> n;
	m = new int[n];
	for (int i = 0; i <= n - 1; i++)
	{
		cin >> m[i];
	}
	if (m[n - 1] > m[n - 2] && m[n - 1] != 15 && n>1)
		cout << "UP";
	if (m[n - 1] > m[n - 2] && m[n - 1] == 15 && n>1)
		cout << "DOWN";
	if (m[n - 1] < m[n - 2])
		cout << "DOWN";
	if (m[n - 1] == 0 && n == 1)
		cout << "UP";
	if (m[n - 1] != 0 && n == 1)
		cout << "-1";
	getch();
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    scanf("%d" , &N);
    int ar[N];
    while(true)
    {
        for(int i = 0 ; i < N ; i++)
            {
                cin>>ar[i];
            }
        if(N < 2)
        {
            cout<<"-1"<<endl;
            break;
        }

        bool flag = true;

        if(ar[N-1] < ar[N-2])
         flag = false;

        if(flag == false)
            cout<<"DOWN"<<endl;
        else
            cout<<"UP" <<endl;
    }

    return 0;
}


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

int main() {
	int n,L,num;
	cin>>n>>L;
	int arr1[n],arr2[num];
	map<int,int> hmap1;
	map<int,int> hmap2;
	for(int i=0;i<n;i++)
	{
	 cin>>arr1[i];
	 hmap1[num]++;
	}

	for(int i=0;i<n;i++)
	{
	  cin>>arr2[i];
	  hmap2[num]++;
	}
	for(int i=0;i<n-1;i++)
	{
	  num=arr1[i+1]-arr1[i];
	  hmap1[num]++;
	  num=arr2[i+1]-arr2[i];
	  hmap2[num]++;
	}
	  num=L-(arr1[n-1]-arr1[0]);
	  hmap1[num]++;
	  num=L-(arr2[n-1]-arr2[0]);
	  hmap2[num]++;
	map<int,int>::iterator itr2=hmap2.begin();
	int flag=0;
	for(map<int,int>::iterator itr=hmap1.begin();itr!=hmap1.end();itr++)
	{
	    //cout<<itr->first<<"   "<<itr2->first<<endl;
	    //cout<<itr->second<<"   "<<itr2->second<<endl;
	    if(itr2==hmap2.end())
	    {
	        flag=1;
	        break;
	    }
	    if(itr->first!=itr2->first)
	    {
	         flag=1;
	        break;
	    }
	    else
	    {
	        if(itr->second!=itr2->second)
	        {
	            flag=1;
	            break;
	        }
	    }
	    itr2++;
	}
	if(flag==1)
	cout<<"NO";
	else
	cout<<"YES";

	return 0;
}


#include<bits/stdc++.h>

typedef long long int ll;
#define pp pair<ll,ll>
#define ppp pair<ll,pp>
#define dbg printf("x");
#define inf 1000000000000
#define max2(a,b) ((a<b)?b:a)
#define max3(a,b,c) max2(max2(a,b),c)
#define min2(a,b) ((a>b)?b:a)
#define min3(a,b,c) min2(min2(a,b),c)

using namespace std;

int main()
{
    freopen("in.txt","r",stdin);
    int i,j,k;
    int n,l;

    cin>>n>>l;
    int a[n],b[n];

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

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

    queue<int > ds;
    queue<int>  kf;

    for(i=1;i<n;i++)
    {
        ds.push(a[i]-a[i-1]);
    }

    ds.push(l-a[n-1]+a[0]);

    for(i=1;i<n;i++)
    {
        kf.push(b[i]-b[i-1]);
    }

    kf.push(l-b[n-1]+b[0]);

    while(n)
    {
        if(ds==kf)
        {
            cout<<"YES";
            return 0;
        }

        i=ds.front();ds.pop();ds.push(i);n--;
    }

    cout<<"NO";

    return 0;
}


#include <fstream>
#include <vector>
#include <string>
#include <deque>

using namespace std;

ifstream cin("input.txt");
ofstream cout("output.txt");

int main() {
	int n, l;
	cin >> n >> l;
	vector<int> a;
	vector<int> b;
	vector<int> aa;
	deque<int> bb;
	int z = 0;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		a.push_back(k);
		if (i > 0) {
			aa.push_back(a[i] - a[i - 1]);
		} else {
			aa.push_back(k);
		}
		z += aa[i];
	}
	aa.push_back(l - z);
	z = 0;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		b.push_back(k);
		if (i > 0) {
			bb.push_back(b[i] - b[i - 1]);
		} else {
			bb.push_back(k);
		}
		z += bb[i];
	}
	bb.push_back(l - z);
	aa[0] += aa[(int)aa.size() - 1];
	bb[0] += bb[(int)bb.size() - 1];
	aa.pop_back();
	bb.pop_back();
	for (int i = 0; i <= n; i++) {
		bool good = 1;
		for (int j = 0; j < n; j++) {
			if (aa[j] != bb[j]) {
				good = 0;
				break;
			}
		}
		if (good == 1) {
			cout << "YES";
			return 0;
		} else {
			int v = bb.front();
			bb.pop_front();
			bb.push_back(v);
		}
		// for (int j = 0; j < (int)bb.size(); j++) {
		// 	cout << bb[j] << " ";
		// }
		// cout << "\n";
	}
	cout << "NO";

	// for (int i = 0; i < (int)aa.size() - 1; i++) {
	// 	cout << aa[i] << " ";
	// }
	// cout << "\n";
	// for (int i = 0; i < (int)bb.size() - 1; i++) {
	// 	cout << bb[i] << " ";
	// }

}


#include<stdio.h>
#include<conio.h>

int main () {
	int sum = 0  ;
	char pole [5][5] ;
	for ( int i = 1 ;i<=4;i++) {
		for ( int j = 1 ; j<=5;j++){
			scanf("%c",&pole[i][j]);
		}
	}
	for ( int i = 1 ;i<=4;i++) {
		for ( int j = 1 ; j<=2;j++){
			sum = pole [i][j] + pole [i][j+1] + pole [i][j+2];
			if ( sum ==286 ){
				printf ("%d ",sum);
				getch() ;
				printf ("YES");
				goto end ;
			}
			sum = 0 ;
		}
	}
	for ( int i = 1 ;i<=2;i++) {
		for ( int j = 1 ; j<=4;j++){
		//	printf("%d %d %d",pole[i][j],pole[i+1][j],pole[i+2][j]);
			sum = pole[i][j] + pole[i+1][j] + pole[i+2][j];
			if ( sum ==286 ){
				printf ("YES");
				goto end ;
			}
			sum = 0 ;
		}
	}
	printf ("NO");
	end :
	return 0 ;

}


/*
 *
 ********************************************************************************************
 * AUTHOR : Vijju123                                                                        *
 * Language: C++14                                                                          *
 * Purpose: -                                                                               *
 * IDE used: Codechef IDE.                                                                  *
 ********************************************************************************************
 *
 Comments will be included in practice problems if it helps ^^
 */

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

int possible(int x,int arr[])
{
    int counter=0;
    for(int i=1;i<=100;i++)
    {
        counter+=arr[i]/x;
    }
    return counter;
}

int main() {
	// your code goes here
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m,i;
	cin>>n>>m;
	int arr[m],freq[101]={0};
	for(i=0;i<m;i++)
	{
	    cin>>arr[i];
	    freq[arr[i]]++;
	}

	int low=0,high=m/n;
	int ans=0;
	while(low<=high)
	{
	    int mid=(low+high)>>1;
	    if(possible(mid,freq)>=n)
	    {
	        ans=max(ans,mid);
	        low=mid+1;
	    }
	    else
	        high=mid-1;
	}
	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define in(n)       scanf("%d",&n)
#define in2(a,b)    scanf("%d%d",&a,&b)
#define inl(n)       scanf("%lld",&n)
#define inl2(a,b)    scanf("%lld%lld",&a,&b)
#define ou(n)       printf("%d",n)
#define oul(n)       printf("%lld",n)
#define f first
#define s second
using namespace std;

int main()
{
  //std::ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int a[n+5];
  map<int,int>mp;
  map<int,int>::iterator it;
  for(int i=0;i<m;i++){
    cin>>a[i];
    mp[a[i]]++;
  }

  if(m<n){
    cout<<"0"<<endl;
    return 0;
  }

  int d=m/n;
  int l=1,h=d,mid,ans;
  while(l<=h){
    mid=(l+h)/2;
    int k=0;
    for(it=mp.begin();it!=mp.end();it++){
      k+=(it->second)/mid;
    }
    // cout<<k<<endl;
    if(k>n){
      ans=mid;
      l=mid+1;
    }
    else if(k<n)
      h=mid-1;
    else {
      ans=mid;
      goto ab;
    }
  }
  ab:
  cout<<ans<<endl;
  return 0;
}


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

int N, M;

int a[110];
int b[110];
int c[110];
int x[100000000];
int main()
{

	cin >> N >> M;

	for (int i = 1; i <= M; ++i)
	{
		int x;
		cin >> x;

		a[x]++;
	}

	for (int i = 1; i <= 100; ++i)
		c[i] = a[i];

	int mn = 1 << 30;
	for (int i = 1; i <= N; ++i)
	{
		int pos;
		int mx = 0;
		for (int j = 1; j <= 100; ++j)
		{
			if (a[j] > mx)
			{
				mx = a[j];
				pos = j;
			}
		}
		b[pos]++;

		mn = min(mn, c[pos] / b[pos]);

		a[pos] = c[pos] / (b[pos] + 1);
	}

	cout << mn;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  unsigned n, m;
  cin>>n>>m;
  map<unsigned, unsigned> v;
  unsigned x;
  for(unsigned i = 0; i < m; i++) {
    cin>>x;
    if(v.find(x) == v.end()){
      v[x] = 1;
    }else {
      v[x]++;
    }
  }

  vector<unsigned> F(v.size(), 0);

  for(auto i : v) {
    unsigned value = i.second;
    for(unsigned k = n; k >= 1; k--) {
      F[k] = max(value / k, F[k]);
      for(unsigned j = 1; j < k; j++) {
	unsigned tmp = min(value / j, F[k-j]);
	F[k] = max(F[k], tmp);
      }
    }
  }

  cout<<F[n]<<endl;
  return 0;

    /*

  // F[i, k] = Max(Vi / j + F(i-1, n - j))
  vector<vector<unsigned> > F(s.size(), vector<unsigned>(n+1, 0));

  for(int i = 0;  i < s.size(); i++) {
    unsigned value = get<1>(s[i]);
    for(int k = 1; k <= n; k++) {
      F[i][k] = value / k;
    }
  }
  for(int i = 1;  i < s.size(); i++) {
    unsigned value = get<1>(s[i]);
    for(int k = 1; k <= n; k++){
      F[i][k] = max(F[i-1][k], F[i][k]);
      for(int j = 1; j < k; j++) {
	F[i][k] = max(F[i][k], min(F[i-1][k-j], value / j));
      }
    }
  }
  cout<< F[s.size()-1][n]<<endl;
    */
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
    cin>>x;
    cout<<2-x*x;
}


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

void solve() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int flag=0;
  for(int i=0;i<n;i++)
  {
    s[i]=='Q' ? flag++:flag--;
    if(flag<0) flag=0;
  }
 // cout<<flag<<endl;
  cout<<(flag ? "No":"Yes")<<endl;
}

int main() {
   int t;
   cin >> t;
   cout<<2-t*t<<endl;

   return 0;
}


#include <iostream>
using namespace std;

int main()
{
   int n;
   cin>>n;
   cout<<(2-(n*n))<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin >> x;
	cout << 2 - x * x << endl;
	return 0;
}


// qdd on Apr 12, 2018

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

const int MOD = 1e9 + 7;

long long powMod(long long a, long long b)
{
	long long sum = 1;
	while (b)
    {
		if (b & 1)
        {
			sum = (sum * a) % MOD;
			b--;
		}
		b /= 2;
		a = a * a % MOD;
	}
	return sum;
}

int inv(int a)
{
    return a == 1 ? 1 : (long long)(MOD - MOD / a) * inv(MOD % a) % MOD;
}

long long C(long long n, long long m)
{
    if(m < 0)return 0;
    if(n < m)return 0;
    if(m > n-m) m = n-m;
    long long up = 1, down = 1;
    for (long long i = 0 ; i < m ; i ++)
    {
        up = up * (n-i) % MOD;
        down = down * (i+1) % MOD;
    }
    return up * inv(down) % MOD;
}

int main()
{
    int n;
    cin >> n;
    long long ans = powMod(3, 3 * n);
    long long ans1 = 0;
    for (int i = 0; i <= n; i++)
    {
       ans1 += C(n, i) * powMod(6, n - i) % MOD;
    }
    printf("%lld\n", ((ans - ans1) % MOD + MOD) % MOD);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <limits.h>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <complex>
#include <bitset>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <iomanip>
#include <valarray>
#include <sstream>
#include <fstream>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi ;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef map<string,string> mss;
typedef map<int,char> mic;
typedef map<char,int> mci;

#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,n) for(int i=0; i<n; i++)
#define rlop(i,n) for(int i=n-1; i>=0; i--)
#define loop(i,start,n) for(int i=start; i<n; i++)
#define rloop(i,end,n) for(int i=n-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second
#define ord0(s) (int)(s-'0')
#define orda(s) (int)(s-'a')
#define ordA(s) (int)(s-'A')

const ll OO = (ll)1e18+9;
const ll MOD = 1000000007;
const int oo = 2147483647;
const double EPS = 1e-9;
const double PI=acos(-1.0);

//enum dir { u, r, d, l };
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, 1, 0, -1 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

char letters[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

int dot(int x, int y, int x2, int y2) {return x * x2 + y * y2; }
ll gcd (ll x, ll y){ return !y ? x : gcd(y, x%y); }
ll lcm (ll a, ll b) { return a * (b / gcd(a, b)); }
int ord(int r,int c,int nCol) { return (nCol*r) + c + 1; } //transform from 2-D matrix to 1-D array. (Zero-indexed)
//Compare Double Numbers
int cmpDouble(ld d1,ld d2){ return fabs(d1-d2)<=EPS?0:d1>d2?1:-1; }

bool isPrime(ll num){
	if(num == 2) return true;
	if(num < 2 || !(num % 2)) return false;

	for(int i=3; i*i<=num; i++) if(!(num%i))return false;
	return true;
}

ll _sieve_size, cnt=0;
bitset<10000010> bs;

ll sieve(ll upperbound) {
	_sieve_size = upperbound + 1;
	bs.set();
	bs[0] = bs[1] = 0;
	for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
		for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
		cnt++; if(cnt == 10001) return i;
	}
	return 0;
}

vector<vector<ii>> graph(110);
vvb vis(110,vb(110,false));
void dfs(int node, int color){
	vis[node][color]=1;
	lop(i,sz(graph[node])) if(color == graph[node][i].s && !vis[graph[node][i].f][graph[node][i].s]) dfs(graph[node][i].f, color);
}

ll calcPow(ll n, ll p){
	if(!p) return 1;
	ll ret = 1;
	for(ll i=1; i<=p; i++) ret*=n, ret%=MOD;
	return ret;
}

int main()
{
	//
	ll n,ans=0;
	cin>>n;
	loop(i,1,n+1){
		ans += 20 * calcPow(27,n-i) * calcPow(7,i-1);
		ans %= MOD;
	}
	cout<<ans<<endl;

	return 0;
}


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

long long modulo(int base,int exponent,int modwhat){//base^exponent mod modwhat;
    long long a = 1;
    for(int i=0;i<exponent;i++){
        a = a*base;
        a = a%modwhat;
    }
    return a;
}

int main(){
    int n;
    cin >> n;
    long long sum = 0;
    for(int i=0;i<n;i++){
        sum += (modulo(7,i,1000000007)*modulo(27,n-1-i,1000000007))%1000000007;
        sum = sum%1000000007;
    }
    sum = (sum*20)%1000000007;
    cout << sum;
    return 0;
}


#include <stdio.h>
#include <conio.h>
const long long r = 1000000007;

void main() {
	long long n, i, s, t, u;
	scanf_s("%I64d", &n);
	t = 1;
	u = 1;
	for (i = 1; i <= n; i++) {
		t = (t * 27) % r;
		u = (u * 7) % r;
	}
	s = (t - u + r) % r;
	printf("%I64d", s);
	_getch();
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int n=100;
vi f[n+1][n*n/2],g[n+1];

int main(){
	rep(i,4,n){
		rep(j,1,i) if(j%2==0) g[i].pb(j);
		rep(j,1,i) if(j%2==1) g[i].pb(j);
		if(i&1) swap(g[i][i-2],g[i][i-1]);
	}
	f[1][1]={1},f[2][3]={1,2};
	rep(i,1,n) rep(j,1,i*(i+1)/2){
		if(f[i][j].empty()) continue;
		rep(k,2,n-i+1){
			auto &r=f[i+k-1][j+k*(k+1)/2-1];
			if(!r.empty()) continue;
			r=f[i][j];
			if(r.back()==i) reverse(r.begin(),r.end());
			rep(p,1,k-1) r.pb(i+p);
		}
		rep(k,4,n-i+1){
			auto &r=f[i+k-1][j+k];
			if(!r.empty()) continue;
			for(auto p:g[k]){
				if(p==1) r.insert(r.end(),f[i][j].begin(),f[i][j].end());
				else r.pb(i+p-1);
			}
		}
	}
	int Q; read(Q);
	while(Q--){
		int n,k;
		read(n),read(k);
		if(f[n][k].empty()){
			puts("NO");
			continue;
		}
		puts("YES");
		for(auto x:f[n][k]) printf("%d ",x);
		puts("");
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
using namespace std;
vi ca[105][105]; // i个数分成j段，总贡献为k，第一段大小 + 贡献 * 1024  *j = 1 最后更新*
int dp[105][6000]; // i个数总贡献为k，总段数 + 1024 * 合点
int cal(int x) {
	return x * (x - 1) / 2;
}
int r[105];
void work(int L, int R, int k, int bg, int tp) {
	if (L == R) {
		r[L] = bg;
		return;
	}

	int n = R - L + 1;
	int l = dp[n][k] % 1024;
	vi ns(l), res(l);
	int rtp = dp[n][k] & 1024;
	if (rtp) k -= cal(l);
	else k--;
	int fk = k;
	for (int j = 0; j < l; j++)
		ns[j] = ca[n][l - j][k] % 1024,
		res[j] = ca[n][l - j][k] / 1024,
		n -= ns[j],
		k -= res[j];
	/*
	cout << "W" << L << ' ' << R << ' ' << fk << ' ' << bg << ' ' << tp << ' ' << l << endl;
	for (int j = 0; j < l; j++)
		cout << ns[j] << ' ';
	cout << endl;
	system("pause");
	*/
	if (rtp) {
		if (tp)
			for (int j = 0; j < l; j++)
				work(L, L + ns[j] - 1, res[j], bg, tp ^ 1),
				L += ns[j], bg += ns[j];
		else
			for (int j = l - 1; j >= 0; j--)
				work(R - ns[j] + 1, R, res[j], bg, tp ^ 1),
				R -= ns[j], bg += ns[j];
	}
	else {
		vi p(l), q(l);
		int k = l / 2;
		if (l % 2 == 0) {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
		}
		else {
			for (int j = 0; j < k; j++)
				p[j] = 2 * j + 1,
				p[j + k] = 2 * j;
			p[2 * k] = 2 * k;
			swap(p[l - 1], p[l - 2]);
		}
		for (int i = 0; i < l; i++) {
			int nl = L;
			for (int j = 0; j < l; j++) {
				if (p[j] == i) {
					work(nl, nl + ns[j] - 1, res[j], bg, tp);
					bg += ns[j];
					break;
				}
				nl += ns[j];
			}
		}
	}
}
int main() {
	for (int i = 1; i < 101; i++) {
		for (int j = 1; j <= i; j++) {
			ca[i][j].resize(j + cal(i + 2 - j));
			if (i == 1 && j == 1) ca[1][1][1] = 1025, dp[1][1] = 1;
			else
				if (j >= 2)
					for (int l = i; l < ca[i][j].size(); l++)
						for (int k = 1; k <= i / j; k++) {
							if (ca[i][j][l]) break;
							int mx1 = cal(k + 1), mx2 = ca[i - k][j - 1].size() - 1;
							int du = max(k, l - mx2);
							for (int s = du; s <= mx1; s++)
								if (dp[k][s] && ca[i - k][j - 1][l - s]) {
									ca[i][j][l] = k + s * 1024;
									break;
								}
						}
		}
		for (int l = i; l <= cal(i + 1); l++) {
			for (int m = 2; m <= i; m++) {
				int ed = l - cal(m);
				if (ca[i][m].size() > ed && ca[i][m][ed]) {
					dp[i][l] = 1024 + m;
					break;
				}
			}
			for (int m = 4; m <= i; m++)
				if (ca[i][m].size() > l - 1 && ca[i][m][l - 1]) {
					dp[i][l] = m;
					break;
				}
			if (dp[i][l]) ca[i][1][l] = i + l * 1024;
		}
	}
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n, k;
		cin >> n >> k;
		if (!dp[n][k]) cout << "NO" << endl;
		else {
			cout << "YES" << endl;
			work(1, n, k, 1, 0);
			for (int j = 1; j <= n; j++)
				printf("%d ", r[j]);
			printf("\n");
		}
	}
	return 0;
}


#include <cstdio>
#include <vector>
#include <cassert>
#include <cstring>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
int f[101][4951], ans[100];
std::vector<int> xi, he;
std::pair<int, int> g[101][4591];
void extract(int n, int k) {
	if(k==0) return;
	he.push_back(f[n][k]);
	extract(n-f[n][k]+1, k-f[n][k]*(f[n][k]-1)/2);
}
void answer(int n) {
	int ans[101], *pos=ans, l=1, r=n, side=0;
	for(; !xi.empty(); xi.pop_back()) {
		int d=xi.back();
		if(d%2) {
			for(int i=1; i<d/2; ++i) *pos++=r-(d/2-i)*2+1;
			*pos++=l++;
			for(int i=1; i<=d/2; ++i) *pos++=r-(d/2-i)*2;
			r-=d-2;
		} else {
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-1;
			*pos++=r--;
			for(int i=1; i<d/2; ++i) *pos++=l+i*2-2;
			l+=d-2;
		}
	}
	for(; !he.empty(); he.pop_back(), side^=1) {
		int d=he.back();
		if(side) {
			for(int i=1; i<d; ++i) *pos++=l++;
		} else {
			for(int i=1; i<d; ++i) *pos++=r--;
		}
	}
	*pos++=l;
	for(int i=0; i<n; ++i) printf("%d ", ans[i]);
	puts("");
}
int main() {
	int q, n, k;
	f[1][0]=-1;
	for(int i=1; i<=100; ++i)
		for(int j=0; j<=4950; ++j)
			if(f[i][j]) {
				for(int l=2; i+l<=100; ++l) f[i+l-1][j+l*(l-1)/2]=l;
				for(int l=1; i+3*l<=100; ++l) g[i+3*l][j+l]=std::make_pair(l, 0);
			}
	for(int i=4; i<100; ++i)
		for(int j=0; j<=4950; ++j)
			if(g[i][j].first) {
				g[i+1][j]=g[i][j];
				++g[i+1][j].second;
			}
	assert(scanf("%d", &q)==1);
	while(q--) {
		assert(scanf("%d%d", &n, &k)==2);
		k-=n;
		if(f[n][k]) {
			puts("YES");
			extract(n, k);
			answer(n);
		} else if(g[n][k].first) {
			puts("YES");
			for(int i=1; i<=g[n][k].first; ++i) xi.push_back(4);
			xi[0]+=g[n][k].second;
			extract(n-g[n][k].first*3-g[n][k].second, k-g[n][k].first);
			answer(n);
		} else puts("NO");
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define vi vector<int>;
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(); cout.tie();
	int n; cin>>n;
	string s; cin>>s;
	string tmps="";
	int div=2;
	while(n % div != 0) div++;
	string news;
	while(div<=n){
		for (int i=div-1; i>=0; i--){
			tmps+=s[i];
		}
		s=tmps+s.substr(div,n-div);
		//cout<<s<<endl;
		div++;
		while(n % div != 0 && div<=n){
			div++;
		}
		tmps="";
	}
	cout<<s<<endl;
}


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

    char ch[200],s;
    int n,arr[100],m=0;
    cin>>n;
    cin>>ch;
    for(int i=2; i<=(n+1)/2; i++) {
        if(n%i==0)
            arr[m++]=i;
    }

    sort(arr,arr+(m-1));
    int     c=m-1;

    for(int i=0;i<=c;i++)
    {
        for(int j=0;j<arr[i]/2;j++)
        {
            s=ch[arr[i]-j-1];
            ch[arr[i]-j-1]=ch[j];
            ch[j]=s;
        }

    }
     for(int j=0;j<(n/2);j++)
        {
            s=ch[n-j-1];
            ch[n-j-1]=ch[j];
            ch[j]=s;
        }
    cout<<ch;

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
  int n, i, j, k, num;
  char tem;
  cin >> n;
  string ch;
  cin >> ch;
  vector <int> vec;
  num = n;
  do
  {
    vec.push_back(n);
    n /= 2;

  }while(n != 1);

  if(vec[vec.size()-1] != 2 && num != 3 )
  {
    vec.push_back(2);
  }

  /*for(i = vec.size()-1; i >= 0; i--)
  {
    cout<<vec[i]<<" ";
  }*/

  for(i = vec.size()-1; i >= 0; i--)
  {
    k = vec[i] - 1;
    for(j = 0; j < vec[i] / 2; j++)
    {
     tem = ch[j];
     ch[j] = ch[k];
     ch[k] = tem;
     k--;
    }
  }
  cout<<ch<<endl;
  return 0;
}


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

string reversee(string b){
	int mis=b.length()/2;
	for(int i=0;i<mis;i++){
		char temp=b[i];
		b[i]=b[b.length()-i-1];
		b[b.length()-i-1]=temp;
	}
	return b;
}

int main(){
    int n;
    string s;
    vector<int> div(n);
    fill(div.begin(), div.end(), 0);
    cin>>n;
    cin>>s;
    int gh=0;
    for(int i=2;i<=n;i++){
        if(n%i==0){
        	//cout<<i;
        	div.at(gh++)=i;
		}
    }
    //cout<<"YO";
    /*for(int i=0;i<gh;i++)
    	cout<<div[i]<<" ";*/
    for(int i=0;i<n;i++){
        string t=s.substr(0,div[i]);
        t=reversee(t);
        s.replace(0,div[i],t);
    }
    cout<<s;
    return 0;
}


/*
ID: kfoozminus
TASK:
LANG: C++
*/

#include <bits/stdc++.h>
using namespace std;
//typedefs
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <int, pii> piii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
const double PI = acos(-1);
*/
//typedefs
#define ll long long
#define ull unsigned long long
#define pii pair <int, int>
#define piii pair <int, pii>
#define vi vector <int>
#define vl vector <ll>
#define pll pair <ll, ll>
#define PI acos(-1)
//defines
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define mem(a, b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define SQR(a) ((a)*(a))
#define inf 100000000
#define mod 1000000007
#define mod1 1000000007
#define mod2 1000000009
#define b1 43
#define b2 41
#define EPS 1e-9
//define harmonic(n) 0.57721566490153286l+log(n)
#define nl puts("")
#define odd(n) ((n)&1)
#define even(n) (!((n)&1))
#define vsort(v) sort(v.begin(), v.end())
#define lc (node<<1)
#define rc ((node<<1)|1)
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, n) for(int i = 1; i <= n; ++i)
//input
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sd(a) scanf("%lf", &a)
#define sc(a) scanf("%c", &a)
#define sst(a) scanf("%s", a)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
//debug
#ifdef kfoozminus

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << *it;
	}
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin()) os << ", ";
		os << *it;
	}
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for(auto it = v.begin(); it != v.end(); ++it) {
		if( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }

#else
#define dbg(args...)
#endif
/*
ll add(ll a, ll b) {
	ll ret = a+b;
	if(ret >= mod) ret -= mod;
	return ret;
}

ll subtract(ll a, ll b) {
	ll ret = a-b;
	if(ret < 0) ret += mod;
	return ret;
}

ll mult(ll a, ll b) {
	ll ret = a*b;
	if(ret >= mod) ret %= mod;
	return ret;
}

ll bigmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1) ret = mult(ret, a);
		b >>= 1; a = mult(a, a);
	}
	return ret;
}
*/

//ll inverse(ll n) { return bigmod(n, mod-2); }

/*
#define PMX 1000000

int marked[PMX/64 + 2];
vi primes;

#define mark(x) marked[x >> 6] |= (1 << ((x & 63) >> 1))
#define check(x) (marked[x >> 6] & (1 << ((x & 63) >> 1)))

bool isPrime(int x)
{
	return (x > 1) && ((x == 2) || ((x & 1) && (!(check(x)))));
}

void seive(int n)
{
	int i, j;
	for(i = 3; i * i <= n; i += 2) if(!check(i)) for(j = i * i; j <= n; j += i << 1) mark(j);
	primes.PB(2);
	for(i = 3; i <= n; i += 2) if(isPrime(i)) primes.PB(i);
}
*/

//Direction Array
//int fx[]={1, -1, 0, 0}; int fy[]={0, 0, 1, -1};
//int fx[]={0, 0, 1, -1, -1, 1, -1, 1}; int fy[]={-1, 1, 0, 0, 1, 1, -1, -1};

//bit manipulation
/*
bool checkBit(int n, int i) { return (n&(1<<i)); }
int setBit(int n, int i) { return (n|(1<<i)); }
int resetBit(int n, int i) { return (n&(~(1<<i))); }
*/
//end of template

#define MX 100007

int a[MX], vis[MX];

int main () {
#ifdef kfoozminus
//	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	int n, i, mn, mx, mid, j;
	ll k, sum = 0;

	scanf("%d %lld", &n, &k);
	for(i = 0; i < n; i ++) {
		scanf("%d", &a[i]);
		vis[ a[i] ] = 1;
		sum += a[i];
	}
	sort(a, a + n);
	/*mn = 0;
	mx = a[n - 1];
	//while(mn < mx) {
		//mid = (mn + mx) >> 1;
	for(mid = 1; mid <= mx; mid ++) {
		int ans = 0;
		for(d = mid, i = 0; i < n; ) {
			if(a[i] > d) {
				d += mid;
				continue;
			}
			ans += d - a[i];
			i ++;
		}
		if(vis[mid] == 1) dbg(1);
		dbg(mid, ans);
	}*/

	sum += k;
	ll d;

	for(i = n; i <= n * n; i ++) {
		dbg(i);
		d = sum / i;
		int cnt = 0;
		for(j = 0; j < n; j ++) {
			cnt += (a[j] + d - 1)/d;
		}
		dbg(i, cnt);
		if(cnt <= i) break;
	}
	printf("%lld\n", d);

//	timeStamp;
	return 0;
}


#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;

#define ll long long

const int N = 105;

int n;
ll C;
int ar[N];

inline void init() {
	scanf("%d"Auto, &n, &C);
	for (int i = 0; i < n; i++)
		scanf("%d", ar + i), C += ar[i];
}

int ceil(int a, int b) {
	return (a + b - 1) / b;
}

inline void solve() {
	int dcur = C / n, dans;
	do {
		swap(dcur, dans), dcur = 0;
		for (int i = 0; i < n; i++)
			dcur += ceil(ar[i], dans);
		dcur = C / dcur;
	} while (dcur != dans);
	printf("%d\n", dans);
}

int main() {
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[105],k;
ll calc(ll x){
    ll ret=0;
    for(int i=0;i<n;++i){
        if(a[i]%x)ret+=x-a[i]%x;
    }
    return ret;
}
ll solve(ll d,ll d1){
    if(d1<d)return 1;
    //cout<<d<<" "<<d1<<endl;
    ll x=calc(d),x1=calc(d1);
    if(x<=x1){
        if(x1<=k)return d1;
        if(x>k)return 1;
        while(d<d1){
            ll mid=(d+d1)/2;
            if(calc(mid)<=k)d=mid+1;
            else d1=mid;
        }
        if(calc(d1-1)<=k)return d1-1;
        return 1;
    }
    if(x1<=k)return d1;
    return 1;
}
vector<ll>v;
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;++i){
        for(int j=1;j*j<=n;++j){v.push_back(j);v.push_back(a[i]/j);}
    }
    v.push_back(1e12);
    sort(v.begin(),v.end());
    ll mx=1;
    for(int i=1;i<v.size();++i){
        mx=max(mx,solve(v[i-1],v[i]-1));
    }
    cout<<mx<<endl;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
#include <cmath>

using namespace std;

const int maxn = 1e2 + 5;
const int maxm = 2e6 + 5;

int n;
long long k;
int a[maxn];
int seg[maxm];
int cnt;

int main(int argc, char const *argv[]) {

    cin >> n >> k;

    seg[cnt ++] = 1;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        for (long long j = 1; j * j <= a[i]; j ++)
            seg[cnt ++] = j, seg[cnt ++] = ceil(a[i] / (1.0 * j));
        k += 1ll * a[i];
    }
    seg[cnt ++] = 0x3f3f3f3f;

    sort(seg, seg + cnt);
    cnt = unique(seg, seg + cnt) - seg;

    long long ans = 0;
    for (int i = 0; i < cnt; i ++) {
        int b = seg[i];
        long long sum = 0;
        for (int j = 1; j <= n; j ++)
            sum += ceil(a[j] / (1.0 * b));
        long long d = k / sum;
        if (b <= d)
            ans = max(ans, d);
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define Max 100005

using namespace std;

int dp[Max];

int check(int n)
{
	int i, t, j, dt, ans, t2, w, k;

	if(dp[n] != -1)
		return dp[n];

	t = sqrt(2*n);

	ans = n+1;
	for(i=2;i<=t;i++)
	{
		if(2*n % i == 0)
		{
			dt = i;
			if((2*n/dt - dt + 1) % 2 == 0)
			{

				t2 = (2*n / dt - dt + 1)/2;

				if(t2 > 0)
				{
					w = 0;
					for(j=t2, k=0;k<dt;j++, k++)
					{
						if(check(j) != 0)
							w = !w;
					}

					if(!w)
						ans = min(dt, ans);
				}
			}

			dt = 2*n / i;
			if((2*n/dt - dt + 1) % 2 == 0)
			{
				t2 = (2*n / dt - dt + 1)/2;

				if(t2 > 0)
				{
					w = 0;
					for(j=t2, k=0;k<dt;j++, k++)
					{
						if(check(j) != 0)
							w = !w;
					}

					if(!w)
						ans = min(dt, ans);
				}
			}
		}
	}
	if(ans == n+1)
		ans = 0;
	//cout<<n<<" "<<ans<<"\n";
	return dp[n] = ans;
}

int main()
{
	/*freopen("3.in", "r", stdin);
	freopen("3.out", "w", stdout);*/
	int n, t;

	while(cin >> n)
	{
//		int t1 = clock();
        memset(dp, -1, sizeof(dp));
		t = check(n);

		if(!t)
			printf("-1\n");
		else
			printf("%d\n", t);

		//cerr<<n<<" "<<clock()-t1<<"\n";
		//printf("%d\n", n);
	}
}


#include <cstdio>
#include <cstdlib>
#include <queue>
#include <queue>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int s[111111];
int curgr[111111];
int egr = 0;

int getGr(int n, int spl) {
	if (spl >= n) return 0x7f7f7f7f;

	n *= 2;
	if (n % spl != 0) return 0x7f7f7f7f;
	n /= spl;

	n++;
	n -= spl;
	if (n % 2 != 0)
		return 0x7f7f7f7f;
	n /= 2;

	if (n < 1) {
		return 0x7f7f7f7f;
	}

	int res = 0;
	for (int a = n; a<= n+spl - 1; a++) {
		res += s[a];
	}

	return (res + 1) % 2;
}

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

	s[1] = 0;
	s[2] = 0;
	s[3] = 1;

	if (n <= 3) {
		if (s[n] == 1)
			cout << 2 << endl;
		else cout << -1 << endl;
		return 0;
	}

	for (int i=4; i<=100000; i++) {
		int egr = 0;
		for (int spl = 2; spl < 888; spl++) {
			int gr = getGr(i, spl);
			curgr[egr++] = gr;

			if (i == n && gr != 0 && gr != 0x7f7f7f7f) {
				cout << spl << endl;
				return 0;
			}

			if (gr != 0 && gr != 0x7f7f7f7f)
				s[i] = 1;
		}

		if (i == n) {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}


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

int f[100005];

int main() {
    int n;
    cin >> n;
    for (int i=0; i <= 100000; ++i) f[i] = -1;
    for (int i=3; i <= n; ++i) {
        for (int j=2; (j+1)*j/2 <= i; ++j) {
            int k = 1, cnt = 0, sum = (j+1)*j/2;
            for (int k=1; k <= j; ++k) {
                if (f[k] > 0) ++cnt;
            }
            for (k = 1; sum < i; ++k) {
                sum += j;
                if (f[k] > 0) --cnt;
                if (f[k+j] > 0) ++cnt;
            }
            if (sum == i && !(cnt % 2)) {
                f[i] = j;
                break;
            }
        }
    }
    cout << f[n];
}


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

const int maxn = 100001;
int sg[maxn];
pair<int,int> next[maxn][320];
int numNext[maxn];
int n;

int main() {
	scanf("%d",&n);
	fill(sg + 1,sg + n + 1,0);
	fill(numNext + 1,numNext + n + 1,0);
	for(int i = 1;i<=n;i++) {
		if(numNext[i]==0)
			sg[i] = 0;
		else {
			sort(next[i],next[i] + numNext[i]);
			int cur = -1;
			if(next[i][0].first>0)cur = 0;
			else
			for(int j = 1;j<numNext[i];j++)
				if(next[i][j - 1].first < next[i][j].first - 1) {
					cur = next[i][j - 1].first + 1;
					break;
				}
			if(cur<0)cur = next[i][numNext[i] - 1].first + 1;
			sg[i] = cur;
		}
		int sum = i;
		int x = sg[i];
		for(int j = i - 1;j > 0 && (sum += j)<=n;j--) {
			x ^= sg[j];
			next[sum][numNext[sum]].first = x;
			next[sum][numNext[sum]].second = i - j + 1;
			numNext[sum]++;
		}
	}
	printf("%d\n",sg[n] == 0 ? -1 : next[n][0].second);
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
string a; int c;
cin>>a;
int sum=0;
for (int i=0;i<a.size();i++)
{
  if(a.at(i)=='a')
  sum++;
}
 if (sum>a.size()-sum)
 cout<<a.size();
 else {
 c=a.size();
 for(;sum<a.size()-sum;)
 {
   c--;
 }
 cout<<c;
 }

}


#include <iostream>
#include <string>
using namespace std;
int main() {
string a; int c;
cin>>a;
int sum=0;
for (int i=0;i<a.size();i++)
{
  if(a.at(i)=='a')
  sum++;
}
 if (sum>a.size()-sum)
 cout<<a.size();
 for(;sum<a.size()-sum;)
 {
   c=a.size();
   c--;
 }
 cout<<c;

}


#include<conio.h>
#include<locale>
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int count = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'a')
		{
			count++;
		}
	}
	for (int i = 0; i < s.length();)
	{
		if (s.size()/2 >= count)
		{
			if (s[i] != 'a')
			{
				s.erase(s.begin()+i);
			}
			else i++;
		}
		else break;
	}
	cout << s.size();
	_getch();
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    vector<char> vect;
    int count1 =0;
    int count2=0;

    for(int i =0 ; i<1000000; i++){
        char c=getchar();
        if(c=='\n'){
            break;
        }
        vect.push_back(c);
        if(c=='a'){
            count1++;
        }
        if(c=='s'){
            count2++;
        }
    }
    if(count1 > vect.size()/2 || count2 > vect.size()/2){
        cout<<vect.size();
        return 0;
    }
    else{
        for(auto it= vect.begin() ; it!=vect.end();it++){
            if(*it!='s'&& *it!='a'){
                vect.erase(it);
                it=vect.begin();
                it--;

            }
             if(count1 > vect.size()/2 || count2 > vect.size()/2){
        cout<<vect.size();
        return 0;
    }

        }
    }

}


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

int main()
{
	long long n,k,j;
	cin>>n>>k;
	j = 1;
	if(n==1&&k==1)
	{
		cout<<0;
		return 0;
	}

	j = 1;
	while(1) {
		if(k==((j*(j+1))/2)-(n-j)) {
			cout<<n-j;
			return 0;
		}
		j++;
	}

	return 0;
}


#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
int main() {fio; // remove during scanf
	ll N;
	cin >> N;
	N++;
	for(int i = 0; i < N; i++) {
		if(0 == (N ^ (1LL << i))) {
			cout << i << endl;
			return 0;
		}
	}
	cout << N << endl;
    return 0;
}


#include <iostream>
using namespace std;

 int main() {
long int n,s;
cin>>n;
long int n1=n+1;
while(n1<9){
    if(n1%2==0){
    s=n1/2;
} else{
    s=n/2+1;
}cout<<s;
}
s=n1;
cout<<s;
    return 0;
}


// Michael Pfeifer
// Version 04, 2018/02/17

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ld  pi   = 4.0*atanl(1.0);
const int iinf = 1e9 + 10;
const ll  inf  = 1e18 + iinf + 10;
const int mod  = 1000000007;
const ld  prec = .000001;

#define enld endl
#define endl '\n'
#define pb push_back
#define debug(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define umap unordered_map
#define uset unordered_set

template<class TIn>
using indexed_set = tree<
        TIn, null_type, less<TIn>,
        rb_tree_tag, tree_order_statistics_node_update>;

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

void file() {
    auto a = freopen("a.in",  "r", stdin);
    auto b = freopen("a.out", "w", stdout);
    if(!a || !b) cout << "uh oh" << endl;
}

int main() {
    //file();
    //fast();

    ll n;
    cin >> n;
    n++;

    for(int i = 0; (1 << i) <= n; i++) {
        if(1 << i == n) {
            cout << i << endl;
            return 0;
        }
    }

    cout << n << endl;

    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int MOD=1000*1000*1000+7;

int p[2];
ll dp[1000+1][2];

int main()
{
	#ifndef ONLINE_JUDGE
		freopen ("input.txt","r",stdin);
		freopen ("output.txt","w",stdout);
	#endif
	string s,e;
	cin>>s>>e;
	int n=s.length();
	for (int i=0;i<n;++i)
	{
		rotate(s.begin(),s.begin()+1,s.end());
		++p[s!=e];
	}
	++dp[0][s!=e];
	int k;
	cin>>k;
	for (int i=1;i<=k;++i)
	{
		dp[i][0]=(dp[i-1][0]*(p[0]-1)+dp[i-1][1]*p[0])%MOD;
		dp[i][1]=(dp[i-1][0]*p[1]+dp[i-1][1]*(p[1]-1))%MOD;
	}
	cout<<dp[k][0];
	return 0;
}


/*************************************************
 *************************************************
 *************************************************
 *** _________________  |            |  |     /***
 ***         |          |            |  |    / ***
 ***         |          |            |  |   /  ***
 ***         |          |            |  |  /   ***
 ***         |          |            |  | /    ***
 ***         |          |____________|  |/  en ***
 ***         |          |            |  |\     ***
 ***         |          |            |  | \    ***
 *** _____   |          |            |  |  \   ***
 ***   |     |          |            |  |   \  ***
 ***   \     /          |            |  |    \ ***
 ***    \___/           |            |  |     \***
 *************************************************
 *************Written by: JiangHaoKai*************
 *************************************************/
#pragma GCC optimize(2)
#pragma G++ optimize(2)

//#include <bits/stdc++.h>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
//#include <conio.h>
//#include <windows.h>
using namespace std;

typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double ld;
typedef pair<int,int> pii;
#define ui(n) ((unsigned int)(n))
#define ll(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define ld(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)
const int INF=1061109567;
const LL LINF=4557430888798830399;
#define PI 3.1415926535897932384626433832795028841971
#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define mod 1000000007
#define sz(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repa(i,a,n) for(int i=a;i<n;i++)
#define repa1(i,a,n) for(int i=a;i<=n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repd1(i,n) for(int i=n;i>=1;i--)
#define FOR(i,a,n,step) for(int i=a;i<n;i+=step)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define sqr(x) ((x)*(x))
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define file(filename,name) fstream name(filename,ios::in|ios::out)
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define PC(x) putchar(x)
#define GC(x) x=getchar()
#define Endl PC('\n')
#define SF scanf
#define PF printf

inline int Read()
{
    int X=0,w=0;char ch=0;while(!isdigit(ch)){w|=ch=='-';ch=getchar();}while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w?-X:X;
}
inline void Write(int x){if(x<0)putchar('-'),x=-x;if(x>9)Write(x/10);putchar(x%10+'0');}

inline LL powmod(LL a,LL b){LL res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline LL gcdll(LL a,LL b){return b?gcdll(b,a%b):a;}
inline string itoa(LL a){string res="";while(a>0)res+=(a%10+'0'),a/=10;reverse(All(res));return res==""?"0":res;}
inline LL atoi(string s){LL res=0;repV(i,s)res=res*10+i-'0';return res;}
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={1,0,-1,0,-1,-1,1,1};
/**************************************************************Begin***************************************************************/
const int maxn=1010;

string a,b;
LL k,good[maxn],bad[maxn],x,y;

int main()
{
	cin>>a>>b>>k;

	rep(i,a.size()) if(a.substr(i)+a.substr(0,i)==b) x++; else y++;

	if(a==b) good[0]=1; else bad[0]=1;
	rep1(i,k) good[i]=(good[i-1]*(x-1)+bad[i-1]*x)%mod,bad[i]=(bad[i-1]*(y-1)+good[i-1]*y)%mod;

	PF("%lld",good[k]);

	return 0;
}
/***************************************************************End****************************************************************/


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MOD 1000000007

int p,t;
int s1, s2;
VI CC;
int goal;

LL Calc(int pos, int times){
    if(s2 != -1){
        if(times == 1){
            if(pos ==1)return (t/s2-1);
            else return t/s2;
        }else{
            if(pos == 1){
                return (t/s2-1)*Calc(1, times-1)+(t-t/s2)*Calc(0, times-1)%MOD;
            }else{
                return (t/s2)*Calc(1, times-1)+(t-t/s2-1)*Calc(0, times-1)%MOD;
            }
        }
    }
    if(pos == 1){
        if(times == 1)return 0;
        return ((t-1)*Calc(0, times-1))%MOD;
    }else{
        if(times == 1)return 1;
        return ((t-2)*Calc(0, times-1)+Calc(1, times-1))%MOD;
    }
}

void main(int argc, char *argv[]){
    string start, end;
    int k;
    s1 = s2 = -1;
    goal = -1;
    p=0;
    cin >> start >> end >> k;
    t = start.length();
    start += start;
    REP(i, t){
        if(start.substr(i, t) == end){
            if(goal != -1 && s2 == -1){
                s1 = goal;
                s2 = i-goal;
            }
            goal = i;
        }
    }
    if(goal == -1){
        printf("0\n");
        return;
    }
    if(s2 == -1)printf("%I64d\n", Calc((goal==0), k));
    else printf("%I64d\n", Calc((goal%s2==0), k));
}


//
//  main.cpp
//  D
//
//  Created by Liza Kondakova on 20.04.12.
//  Copyright (c) 2012 likogra@gmail.com. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;
int l[4002];
int posl(string s){
    l[0]=-1;
    for(int k=1;k<s.size();k++){
        int j=l[k-1];
        while (j>=0&&s[j+1]!=s[k]) {
            j=l[j];
        }
        //cout<<j<<" ";
        if(j==-1&&s[k]!=s[0])
            j--;
        //cout<<j<<" ";
        l[k]=j+1;
        //cout<<l[k]<<endl;
    }
    return l[s.size()-1]+1;
}
int main ()
{
    string a,b;
    cin>>a>>b;
    string news;
    news=b+b+'$'+a+a;
    int k=posl(a);
    int per=-1;
    if(2*k>=a.size())
        per=(int)a.size()-k;
    int pp=posl(news);
    pp=2*(int)a.size()-pp;
    if(pp>=a.size()){
        cout<<"0"<<endl;
        return 0;
    }
    vector<int> pa;
    int l=pp;
    pa.push_back(l);
    l+=per;
    while (l<a.size()&&per!=-1) {
        pa.push_back(l);
        l+=per;
    }
    cin>>k;
    int c[1001][k+1];
    int sum=1;
    c[0][0]=1;
    for(int j=1;j<a.size();j++){
        c[j][0]=0;
    }
    for(int i=1;i<=k;i++){
        long long newsum=0;
        for(int j=0;j<a.size();j++){
            c[j][i]=(sum-c[j][i-1]);
            if(c[j][i]<0)
                c[j][i]+=+1000000007;
            newsum+=c[j][i];
        }
        newsum%=1000000007;
        sum=(int)newsum;
    }
    int ans=0;
    for(int i=0;i<pa.size();i++){
        ans+=c[pa[i]][k];
        ans%=1000000007;
    }
    cout<<ans<<endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


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

	while(1)
	{

	string s;
	cin >> s;
	long i,t=0,x=s.size();

	for(i=0;i<x/2;i++)
		if(s[i]!=s[x-i-1])
			t++;
	if(t==1)
		cout <<"YES";
	else
		cout <<"NO";
	}
}


/*lhah*/
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	while (1)
	{
		string str;
		cin >> str;
		int flag = 0;
		bool ok = 1;

		for(int i = 0 ; i < str.length()  / 2 + 1; i++)
		{
			if (str[i] != str[str.length() - i - 1])
				flag++;
			if (flag > 1)
			{
				ok = 0;
				break;
			}

		}
		if (ok)
			cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


#include<iostream>
#include<string>
using namespace std;
string s;
int ans=0;
int i=0;
int main()
{
	cin>>s;
	for(int j=s.size()-1;j>=s.size()/2;j--)
	{
		if(s[i]!=s[j])
		{
			for(char c='a';c<='z';c++)
			{
				if(c==s[i]||c==s[j])
				{
				ans++;
				c=c+26;
				}
			}
		}
		if(ans>1)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		i=i+1;
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
while(1)
{
string s;
cin>>s;
int low=0;
int high=s.size()-1;
int count=0;
while(low<=high)
{
	if(s[low]!=s[high])
	count++;
	low++;
	high--;
}
if(count==1)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std ;
 int main ()
 {
 int x, c=0 ,  y;

   cin >> x>> y;
   vector< int > arr (x);

    for ( int  j= 1  ; j <= x; j++) {
        arr.clear() ;
        for (  int  k =1; k <=x; k++)
       { arr[k]=(k*j);
        if(arr[k]== y)
         c++ ;
       }
      }
      cout<<c<<endl;
   return 0 ;
 }


#include<iostream>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int arr[n][n];

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            arr[i-1][j-1]=i*j;
        }
    }

    int count=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(arr[i][j]==x)
                count++;

    cout<<count;
}


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

int main()
{
    int n,x;
    cin>>n>>x;
    int t[n][n];
    int to=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            t[i][j]=(i+1)*(j+1);
            if(t[i][j]==x&&i!=j){to++;}
            else if(t[i][j]==x&&i==j){cout<<"1";return 0;}
        }
    }
    cout<<2*to;
}


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

int main () {
	freopen ("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
	int n, mas[101], x=0, y=0, ans=0;
	for (int i=0; i<101; ++i) {
		mas[i]=0;
	}
	char a[101];
	cin>>n;
	for (int i=0; i<n; ++i) {
		cin>>a[i];
		if (a[i]=='U') {
			y++;
		}
		if (a[i]=='D') {
			y--;
		}
		if (a[i]=='L') {
			x--;
		}
		if (a[i]=='R') {
			x++;
		}
		if (x==0 && y==0) {
			mas[i]=1;
		}
	}
	for (int i=0; i<n; ++i) {
		if (mas[i]==1) {
			ans=i+1;
		}
	}
	cout<<ans;
 	return 0;
}


#include<iostream>

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
static uint32_t __inline __builtin_clz(uint32_t x) {
	unsigned long r = 0;
	_BitScanReverse(&r, x);
	return (31 - r);
}
#endif

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define FORd(i, a, b) for(int i = a; i >= b; i--)

int n, ans;
char arr[100 + 5];

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

	arr[n] = '~';

	int i = 0;
	while (arr[i] != '~') {
		if (arr[i] == 'L') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'R') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}

		if (arr[i] == 'R') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'L') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}
		if (arr[i] == 'U') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'D') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}
		if (arr[i] == 'D') {
			int j = i + 1;
			while (arr[j] != '~') {
				if (arr[j] == 'U') {
					arr[i] = ' ';
					arr[j] = ' ';
					ans += 2;
				}
			}
		}

		i++;
	}
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int n,cnt1=0,cnt2=0;cin>>n;
    string s;cin>>s;
    for(int i=s.length();i>0;i++){
  if(s[i]=='L')cnt1--;
  if(s[i]=='R')cnt1++;
  if(s[i]=='U')cnt2++;
  if(s[i]=='D')cnt2--;
    }
    cout<<n-cnt1-cnt2<<endl;
    return 0;
}


//http://codeforces.com/problemset/problem/888/B
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;

struct mokh{
	int x;
	int y;
};
int main()
{
	int n,ans=0;
	mokh b;
	b.x = b.y = 0;
	cin >> n;
	string a, *tmp;
	cin >> a;
	tmp = new string[a.length()];
	for (int i = 0; i < n; i++)
	{
		tmp[i] = a.at(i);

	}
	for (int i = 0; i < n; i++)
	{
		if (a.at(i) == 'L')
			b.x = b.x - 1;
		else if (a.at(i) == 'R')
			b.x = b.x + 1;
		else if (a.at(i) == 'U')
			b.y = b.y + 1;
		else if (a.at(i) == 'D')
			b.y = b.y - 1;
		if (b.x == 0 && b.y == 0)
			ans = i + 1;

	}
	cout << ans;
	_getch();
	return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <list>
#include <cassert>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
typedef long long ll;

int n,x;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }

int mpow(int a,int n,int m) {
	if(n==0) return 1;
	if(n%2==1) return (ll)a*mpow(a,n-1,m)%m;
	return mpow((ll)a*a%m,n/2,m);
}

void run(int casenr) {
	scanf("%d%d",&n,&x);

	//n+1 (=p) must be prime
	{ int y=n+1; for(int i=2;i*i<=y;++i) if(y%i==0) { printf("-1\n"); return; } }

	// find factors of n (=p-1)
	vector<int> fact;
	{ int y=n; for(int i=2;i*i<=y;++i) if(y%i==0) { fact.PB(i); while(y%i==0) y/=i; } if(y!=1) fact.PB(y); }
//	printf("facts: "); REPSZ(i,fact) printf(" %d",fact[i]); puts("");

	// find a generator
	int gen=-1;
	FOR(i,2,n+1) {
		assert(mpow(i,n,n+1)==1);
		bool ok=true;
		REPSZ(j,fact) if(mpow(i,n/fact[j],n+1)==1) { ok=false; break; }
		if(!ok) continue;
		gen=i; break;
	}
	assert(gen!=-1);
//	printf("gen: %d\n",gen);

	int ret=-1,cur=1;
	REP(i,n) {
		if(gcd(i,n)==1&&cur<x) {
			int now = cur+(x-cur-1)/(n+1)*(n+1);
//			printf("%d -> %d\n",cur,now);
			if(now>ret) ret=now;
		}
		cur=(ll)cur*gen%(n+1);
	}
	printf("%d\n",ret);
}

int main() {
	//int n; scanf("%d",&n); FORE(i,1,n) run(i);
	run(1);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>

using namespace std;

long long fast_pow_mod(long long base, int power, int moder) {
  if (power == 0) {
    return 1;
  } else {
    long long res = fast_pow_mod(base, power/2, moder);
    res = (res*res) % moder;
    if (power % 2 == 0) {
      return res;
    } else {
      return (res*base) % moder;
    }
  }
}

int main(){
  int n, x;
  scanf("%d%d", &n, &x);
  const int LEN = 500001;
  vector<bool> isprime(LEN + 1, true);
  for (int p = 2; p <= LEN; ++p) {
    if (isprime[p]) {
      for (int n = 2; n*p <= LEN; ++n) {
	isprime[n*p] = false;
      }
    }
  }
  if (x-1 >= 2) {
    if (n == 1) {
      printf("%d\n", x-1);
    } else if (isprime[n+1]) {
      bool have_ans = false;
      for (int b = x-1; b >= max(2, x-1-n); --b) {
	if (fast_pow_mod(b%(n+1), n/2, n+1) != 1) {
	  printf("%d\n", b);
	  have_ans = true;
	  break;
	}
      }
      if (!have_ans) {
	puts("-1");
      }
    } else {
      puts("-1");
    }
  } else {
    puts("-1");
  }
  return 0;
}


#ifdef _MSC_VER
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
#define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define REP_SS(x, s) for (int x=s;x;x=(x-1)&s)
#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)
#define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn)
#define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn)

#define ALL(A) A.begin(), A.end()
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define fi first
#define se second
#define Rush for(int ____T=(scanf("%d",&____T),____T), ____cas=0;++____cas, ____T--;)

typedef long long LL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<double> VD;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;
template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T> inline void CLR(T &A){A.clear();}

/** Constant List .. **/ //{
const int dx4[] = {-1, 0, 1, 0};
const int dy4[] = {0, 1, 0, -1};
const int dx8[] = {-1, 0, 1, 0 , -1 , -1 , 1 , 1};
const int dy8[] = {0, 1, 0, -1 , -1 , 1 , -1 , 1};
const int dxhorse[] = {-2 , -2 , -1 , -1 , 1 , 1 , 2 , 2};
const int dyhorse[] = {1 ,  -1 , 2  , -2 , 2 ,-2 , 1 ,-1};
const int mod = 1000000007;
//int mod = 99990001;
const int inf = 0x3f3f3f3f;
const LL inff = 1LL << 60;
const double eps = 1e-9;
const double oo = 1e25;
const double pi = acos(-1.0); //M_PI;
//}
/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
template<class T> inline T ceil(T x, T y){return (x - 1) / y + 1;}
inline int sgn(double x){return x < -eps ? -1 : x > eps;}
inline int sgn(double x, double y){return sgn(x - y);}
inline double cot(double x){return 1./tan(x);};
inline double sec(double x){return 1./cos(x);};
inline double csc(double x){return 1./sin(x);};
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{
inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};
inline int reverse_bits(int x){x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);return x;}
inline LL reverse_bits(LL x){x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);return x;}
template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}
template<class T> inline int cover_idx(T x){int p = 0; while (_1(p) < x ) ++p; return p;}
#ifdef __GNUC__
inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int lg2(int x){return !x ? -1 : 31 - clz(x);}
inline int lg2(LL x){return !x ? -1 : 63 - clz(x);}
inline int low_idx(int x){return !x ? -1 : ctz(x);}
inline int low_idx(LL x){return !x ? -1 : ctz(x);}
inline int high_idx(int x){return lg2(x);}
inline int high_idx(LL x){return lg2(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}
#endif
} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
template<class T> inline T lowbit(T x) {return x & -x;}///lowbit(x)
template <class T>inline T GCD(T A,T B){T C;while(B!=0)C=B,B=A%B,A=C;return A;}///GCD(a,b)
template <class T>inline T LCM(T A,T B){return A*(B/GCD(A,B));}///LCM(a,b)
template<class T>inline T Mod(T a,T b){a%=b;return a<0?a+b:a;}///计算a%b,支持a<=0
template<class T>inline T MulMod(T a,T b,T c)/**二分计算a*b mod c 可以处理c+c不溢出的情况*/{if(c==1)return 0;if(c<=0)return -1;T ret=0,tmp;tmp=a=Mod(a,c);b=Mod(b,c);while(b){if(b&0x1)if((ret+=tmp)>=c)ret-=c;if((tmp<<=1)>=c)tmp-=c;b>>=1;}return ret;}
template<class T,class Tb> inline T PowMod(Tb a,T b,T c)/**a^b mod c 要求c*c不溢出*/{if(c==1)return 0;if(c<=0)return -1;a=Mod(a,(Tb)c);Tb ret(1L%c);while(b){if(b&0x1)ret=ret*a%c;a=a*a%c;b>>=1;}return (T)ret;}
template<class T> inline T HPowMod(T a,T b,T c)/**二分计算a^b mod c 要求c+c不溢出*/{if(c==1)return 0;if(c<=0)return -1;a=Mod(a,c);T ret(1L%c);while(b){if(b&0x1)ret=MulMod(ret,a,c);a=MulMod(a,a,c);b>>=1;}return ret;}
template<class T,class Tb> inline T Pow(T a, Tb b)/**a^b*/{T c(1); while (b){if (b&1) c *= a;a *= a, b >>= 1;}return c;}
template <class T>inline T EXT_GCD(T a,T b,T& x,T& y)/**ax+by=gcd(a,b)*/{T t,ret;if (!b){x=1,y=0;return a;}ret=EXT_GCD(b,a%b,x,y);t=x,x=y,y=t-a/b*y;return ret;}
template <class T>inline T Inv(T a,T n)/**返回一个数a对于n的乘法逆元*/{if(n<=0)return -1;T d,x,y;d=EXT_GCD(a,n,x,y);if(d!=1)return -1;return Mod(x,n);}
template<class T, int MAXN, T MOD=-1>class Matrix/**Matrix*/ {public:T m[MAXN][MAXN];Matrix(){}void init(T num[MAXN][MAXN]){for(int i = 0 ; i < MAXN ; i++){for(int j = 0 ; j < MAXN ; j++){m[i][j] = num[i][j];if (MOD!=-1)  m[i][j] %= MOD;}}}
friend Matrix operator*(const Matrix &m1 ,const Matrix &m2) {int i, j, k;Matrix ret;memset(ret.m, 0, sizeof(ret.m));for (i = 0; i < MAXN; i++) {for (j = 0; j < MAXN; j++)if ( m1.m[i][j] ){for(k = 0 ; k < MAXN ; k++){ret.m[i][k] += m1.m[i][j] * m2.m[j][k];if (MOD!=-1) ret.m[i][k] %= MOD;}}}return ret;}
friend Matrix operator+(const Matrix &m1 ,const Matrix &m2) {int i, j;Matrix ret;for (i = 0; i < MAXN; i++) {for (j = 0; j < MAXN; j++) {ret.m[i][j] = 0;ret.m[i][j] = m1.m[i][j]+m2.m[i][j];if (MOD!=-1)  ret.m[i][j] %= MOD;}}return ret;}
friend Matrix operator^(const Matrix &_M , LL nx){Matrix ret,M(_M);for(int i = 0 ; i < MAXN ; i++){for(int j = 0 ; j < MAXN ; j++){if(i == j)ret.m[i][j] = 1;else ret.m[i][j] = 0;}}while(nx){if(nx & 1)ret = ret * M;nx = nx >> 1;M = M * M;}return ret;}
};///end of matrix
const int PMAX = 1000;VI Prime; bitset<PMAX> isnotPrime;///Prime:sieve(),phi(),
void sieve(){if (!Prime.empty()) return ;FOR(i, 2, PMAX){if (!isnotPrime[i]) Prime.PB(i);for (int j=0;j<SZ(Prime)&&i*Prime[j]<PMAX;++j){isnotPrime[i*Prime[j]]=1; if (!(i%Prime[j])) break;}}}
inline bool isPrime(int n){return !isnotPrime[n];}
template<class T>T phi(T n){T ret=1,i;for (i=2;i*i<=n;i++)if (n%i==0){n/=i,ret*=i-1;while (n%i==0)n/=i,ret*=i;}if (n>1)ret*=n-1;return ret;}

} using namespace NT;//}

// <<= '3. Date .,//{
namespace Date{
int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct date{int year,month,day;};
inline int leap(int year)/**判闰年**/{return (year%4==0&&year%100!=0)||year%400==0;}
inline int legal(date a)/**判合法性**/{if (a.month<0||a.month>12) return 0;if (a.month==2)return a.day>0&&a.day<=28+leap(a.year);return a.day>0&&a.day<=days[a.month-1];}
inline int datecmp(date a,date b)/**比较日期大小**/{if (a.year!=b.year)return a.year-b.year;if (a.month!=b.month)return a.month-b.month;return a.day-b.day;}
int weekday(date a)/**返回指定日期是星期几**/{int tm=a.month>=3?(a.month-2):(a.month+10);int ty=a.month>=3?a.year:(a.year-1);return (ty+ty/4-ty/100+ty/400+(int)(2.6*tm-0.2)+a.day)%7;}
int date2int(date a)/**日期转天数偏移**/{int ret=a.year*365+(a.year-1)/4-(a.year-1)/100+(a.year-1)/400,i;days[1]+=leap(a.year);for (i=0;i<a.month-1;ret+=days[i++]);days[1]=28;return ret+a.day;}
date int2date(int a)/**天数偏移转日期**/{date ret;ret.year=a/146097*400;for (a%=146097;a>=365+leap(ret.year);a-=365+leap(ret.year),ret.year++);days[1]+=leap(ret.year);for (ret.month=1;a>=days[ret.month-1];a-=days[ret.month-1],ret.month++);days[1]=28;ret.day=a+1;return ret;}
}//using namespace Date;//}

//}
/*************************密封线****************************************/
int main(){
    int n,x,p;
    sieve();
    cin>>n>>x;
    p = n+1;
    if ( !isPrime(p) ){
        puts("-1");
        return 0;
    }else{
        int b;
        for ( b=x-1; b>1;b-- ){
          bool flag = 0;
          for (int j=2; j*j<=n; j++)
            if ( n%j==0 ){
                flag |= ( HPowMod(b,j,p)==1 ) || ( HPowMod(b,n/j,p)==1 );
            }
          if ( !flag ){
            printf("%d\n", b);
            return 0;
          }
        }
    }
    puts("-1");
    return 0;
}
/*************************密封线****************************************/


#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define mygc(c) (c)=getchar()
#define mypc(c) putchar(c)
#define fi first
#define se second
#define ls(x) t[x].lson
#define rs(x) t[x].rson
#define d(a,b) dp[min(a,b)][max(a,b)]
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 300005;
const int maxm = 1000005;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
inline void rd(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
inline void rd(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
inline void rd(db *x){scanf("%lf",x);}
inline int rd(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
inline void rd(int a[],int n){FOR(i,0,n)rd(&a[i]);}
inline void rd(ll a[],int n){FOR(i,0,n)rd(&a[i]);}
template <class T, class S> inline void rd(T *x, S *y){rd(x);rd(y);}
template <class T, class S, class U> inline void rd(T *x, S *y, U *z){rd(x);rd(y);rd(z);}
template <class T, class S, class U, class V> inline void rd(T *x, S *y, U *z, V *w){rd(x);rd(y);rd(z);rd(w);}
inline void wr(int x){if(x < 10) putchar('0' + x); else wr(x / 10), wr(x % 10);}
inline void wr(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
inline void wr(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
inline void wr(db x, char c){printf("%.15f",x);mypc(c);}
inline void wr(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
inline void wr(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> inline void wrn(T x){wr(x,'\n');}
template<class T, class S> inline void wrn(T x, S y){wr(x,' ');wr(y,'\n');}
template<class T, class S, class U> inline void wrn(T x, S y, U z){wr(x,' ');wr(y,' ');wr(z,'\n');}
template<class T, class S, class U,class H> inline void wrn(T x, S y, U z,H h){wr(x,' ');wr(y,' ');wr(z,' ');wr(h,'\n');}
template<class T> inline void wra(T x[], int n){int i;if(!n){mypc('\n');return;}FOR(i,0,n-1)wr(x[i],' ');wr(x[n-1],'\n');}

int pos[82],tot,a[81];
ll dp[82][82][82*82];
ll cal(ll x){
	return x*(x-1)/2;
}
int main(){
	int n;
	rd(&n);
	ll as=0;
	FOR(i,1,n+1){
		rd(&a[i]);
		if(a[i])pos[++tot]=i;else as++;
	}
	pos[++tot]=n+1;
	as=as*(as-1)/2;
	int nn=n*(n-1)/2;
	FOR(i,0,tot+1)
	FOR(j,0,n+2)
	FOR(k,0,nn+1)dp[i][j][k]=INF/4;
	dp[0][0][0]=0;
	FOR(i,1,tot+1){
		FOR(j,i,n+2){
			FOR(k,abs(pos[i]-j),nn+1){
				FOR(t,i-1,j){
					dp[i][j][k]=min(dp[i][j][k],dp[i-1][t][k-abs(pos[i]-j)]+cal(j-t-1));
				}
			}
		}
	}
	FOR(i,0,nn+1){
		if(i)dp[tot][n+1][i]=min(dp[tot][n+1][i],dp[tot][n+1][i-1]);//��Ϊ��Ҫ�󲻶���i��������Ҫ��������һ��
		printf("%lld ",as-dp[tot][n+1][i]);
	}
	wrn("");
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	char c=getchar();
	int x=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9')
	{
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return x;
}
bool check[6005*6000];
int n,prime[6000*6005],cnt=0,sum,dan[6005*6000];
signed main()
{
	for(int i=2;i<=6000*6000;i++)
	{
		if(!check[i]) prime[++cnt]=i;
		for(int j=1;j<=cnt&&i*prime[j]<=6000*6000;j++)
		{
			check[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	n=read();
	if(n==2)
	{
		cout<<"1 1";
		return 0;
	}
	sum=n*(n+1)/2;
	if(sum%2==0)
	{
		int u1,u2;
		for(int i=1;i<=cnt;i++)
		if(!check[sum-prime[i]])
		{
			u1=prime[i];
			u2=sum-prime[i];
			break;
		}
		for(int i=n;i>=1;i--)
		if(u1>i) dan[i]=2,u1-=i;
		else
		{
			dan[u1]=2;
			break;
		}
		for(int i=1;i<=n;i++)
		{
			if(dan[i]) cout<<dan[i];
			else cout<<1;
			cout<<" ";
		}
		return 0;
	}
	else
	{
		int u1=3,u2,u3;
		sum-=3;
		dan[3]=3;
		for(int i=1;i<=cnt;i++)
		if(!check[sum-prime[i]])
		{
			u1=prime[i];
			u2=sum-prime[i];
			break;
		}
		for(int i=n;i>=1;i--)
		if(u1>i) dan[i]=2,u1-=i;
		else
		{
			if(u1-3)
			{
				dan[u1]=2;
				break;
			}
			else
			{
				dan[1]=2;
				dan[2]=2;
				break;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(dan[i]) cout<<dan[i];
			else cout<<1;
			cout<<" ";
		}
		return 0;
	}
	return 0;
}


#include "bits/stdc++.h"
#define ll long long int
// #define ll int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) (ll)v.size()
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define watch2(x,y) cerr << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << endl
#define Time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
#define inf 2000000000000000000
#define mod  1000000007
#define mod1 998244353

using namespace std;

// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> // order_of_key() ; *( find_by_order() ) -> kth element in set;
// using namespace __gnu_pbds;  // order_of_key(k) -> Number of elements strictly smaller than k

inline ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
inline ll min( ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a,ll b) {return (a>b) ? a : b;}
inline ll min(ll a,ll b) {return (a<b) ? a : b;}
inline ll add(ll x, ll y, ll mod_){return (x+y>=mod_) ? x+y-mod_ : x+y;}
inline ll mul(ll x, ll y, ll mod_){return ((x%mod_)*1LL*(y%mod_))%mod_;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll powm(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=mul(p,a,mod_);} n>>=1; a=mul(a,a,mod_);} return p%mod_;}
ll powi(ll a, ll mod_) {return powm(a,mod_-2,mod_);}
                          /*Code Begins*/

ll MAX_SIZE = 4e7L+5;
vll isprime(MAX_SIZE , true);
vll prime;
vll SPF(MAX_SIZE);
void seive(ll N){
   isprime[0] = isprime[1] = false ;
   for (long long int i=2; i<N ; i++){
       if (isprime[i]){
           prime.push_back(i);
           SPF[i] = i;
       }
       for (ll j=0; j < s(prime) && i*prime[j] < N && prime[j] <= SPF[i]; j++){
           isprime[i*prime[j]]=false;
           SPF[i*prime[j]] = prime[j];
       }
   }
}

int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    cout << setprecision(15);
    ll mn, mx;
    ll n, m, t, k, i, j, sum=0, flag=0, cnt=0;
    ll x=0, y=0, z, l , r, q;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;

    seive(n*(n+1)/2+3);
    if(n==1) cout << -1;
    else if(binary_search(all(prime),n*(n+1)/2)) fo(i,n) cout << "1 ";
    else{
        vll a(n+1,1);
        if(n%2==0){
            for(auto x : prime){
                if(binary_search(all(prime),n*(n+1)/2-x)){
                    i=n;
                    while(x>0){
                        if(i>=x){
                            a[x]=2;
                            x=0;
                        }else{
                            a[i]=2;
                            x-=i;
                            --i;
                        }
                        watch2(x,i);
                    }
                    break;
                }
            }
        }else{
            if(binary_search(all(prime),n*(n+1)/2-2)){
                a[2]=2;
            }else{
                for(auto x : prime){
                    if(binary_search(all(prime),n*(n+1)/2-x-2)){
                        i=n;
                        while(x>0){
                            if(i>=x){
                                a[x]=2;
                                x=0;
                            }else{
                                a[i]=2;
                                x-=i;
                                --i;
                            }
                        }
                        break;
                    }
                }
            }
        }
        flag=0;
        repa(i,1,n+1) if(a[i]==0) flag=1;
        if(flag) cout << -1;
        else{
            repa(i,1,n+1) cout << a[i] << ' ';
        }
    }

}

    Time;
    return 0;
}


/*
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.

	Abhinandan Agarwal
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.*/
#include<bits/stdc++.h>
using namespace std;
#define pc putchar_unlocked
#define gc getchar_unlocked
typedef long long ll;
typedef unsigned long long llu;
#define mp make_pair
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define scstr(x) scanf("%s",x)
#define pd(x) printf("%d",x)
#define pstr(x) printf("%s",x)
#define newl() printf("\n")
#define fl(i,n) for (i=0;i<n;i++)
#define fle(i,n) for (i=1;i<=n;i++)
#define fla(i,a,n) for (i=a;i<n;i++)
#define mem(a,i) memset(a,i,sizeof(a))
#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii ;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define gcd __gcd
#define wl(n) while (n--)
#define debug(x) cout<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define all(v) v.begin(),v.end()
const double eps=0.000000000000001 ;
#define MOD 1000000007
typedef long double LF;
typedef double lF;
//-------------
#define MOD 1000000007
typedef long double LF;
typedef double lF;
#define N (6000*6000/2)
#define M 1000000007
int chk[N+1]={0}; // 0 means prime
int prime[N+1],p;
void sieve()
{
	int i;
	prime[0]=2;
	for (i=2;i*i<=N;i+=1)
	{
		if (chk[i]) continue;
		int j=i*i;
		for (;j<=N;j+=i)
		{
			chk[j]=1;
		}
	}
	int j=1;
	for (i=3;i<=N;i+=1)
	{
		if (!chk[i])
		{
			prime[j]=i;
			j++;
		}
	}
	p=j;
}
int isprime(int x)
{
	if (x<=1)return 0;
	if (x==2)return 1;
	if (x%2==0)return 0;
	if (chk[x]==0)return 1;
	return 0;
}

vector<int>v;
int isrep(int x)
{
	int i,j;
	for (i=1;i<=x/2+1;i++)
	{
		for(j=1;j<=x;j++)
		{
			if (isprime(i)&&isprime(j)&&(x-i-j)>0&&isprime(x-i-j))
			{
				v.pb(i);
				v.pb(j);
				v.pb(x-i-j);
				return 1;
			}
		}
	}
	return 0;
}
int isrep2(int x)
{
	int i,j;
	for (i=1;i<x/2+1;i++)
	{
		if (x-i>0&&isprime(x-i)&&isprime(i)){
			v.pb(i);
			v.pb(x-i);
			return 1;
		}
	}
	return 0;
}
int n,x;
int mrk[N];
int ans[N];
int main()
{
	sc(n);
	sieve();
	x=n*(n+1)/2;
	int i,j;
	if (n==2)
	{
		printf("1 1\n");
		return  0;

	}
	else if (n==3)
	{
		printf("1 1 2\n");
		return 0;
	}
	if (isrep2(x))
	{
		//printf("%d %d\n",v[0],v[1]);
		int mak=v[0];
		for (i=n;i>=1;i--){
			if (mak-i>=0)
			{
				mak-=i;
				mrk[i]=1;
				ans[i]=1;
			}
			if (mak==0)break;
		}
		mak=v[1];
		for (i=n;i>=1;i--)
		{
			if (mak-i>=0&&mrk[i]==0)
			{
				mrk[i]=1;
				ans[i]=2;
				mak-=i;
			}
			if (!mak)break;
		}

	}
	else if (isrep2(x-3))
	{
		int mak=v[0];
		for (i=n;i>=1;i--){
			if (mak-i>=0)
			{
				mak-=i;
				mrk[i]=1;
				ans[i]=1;
			}
			if (mak==0)break;
		}
		mak=v[1];
		for (i=n;i>=1;i--)
		{
			if (mak-i>=0&&mrk[i]==0)
			{
				mrk[i]=1;
				ans[i]=2;
				mak-=i;
			}
			if (!mak)break;
		}
		mak=3;
		for (i=n;i>=1;i--)
		{
			if (mak-i>=0&&mrk[i]==0)
			{
				mrk[i]=1;
				ans[i]=3;
				mak-=i;
			}
			if (!mak)break;
		}
	}
	else assert(false);
	for (i=1;i<=n;i++)
	{
		printf("%d ",ans[i]);
	}
	printf("\n");
	return 0;

}


#include "bits/stdc++.h"
// #define ll long long int
#define ll int
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvl vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) (ll)v.size()
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define watch2(x,y) cerr << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << endl
#define Time cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
#define inf 2000000000000000000
#define mod  1000000007
#define mod1 998244353

using namespace std;

// #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> // order_of_key() ; *( find_by_order() ) -> kth element in set;
// using namespace __gnu_pbds;  // order_of_key(k) -> Number of elements strictly smaller than k

inline ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
inline ll min( ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a,ll b) {return (a>b) ? a : b;}
inline ll min(ll a,ll b) {return (a<b) ? a : b;}
inline ll add(ll x, ll y, ll mod_){return (x+y>=mod_) ? x+y-mod_ : x+y;}
inline ll mul(ll x, ll y, ll mod_){return ((x%mod_)*1LL*(y%mod_))%mod_;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll powm(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=mul(p,a,mod_);} n>>=1; a=mul(a,a,mod_);} return p%mod_;}
ll powi(ll a, ll mod_) {return powm(a,mod_-2,mod_);}
                          /*Code Begins*/

ll MAX_SIZE = 4e7L+5;
vll isprime(MAX_SIZE , true);
vll prime;
vll SPF(MAX_SIZE);
void seive(ll N){
   isprime[0] = isprime[1] = false ;
   for (long long int i=2; i<N ; i++){
       if (isprime[i]){
           prime.push_back(i);
           SPF[i] = i;
       }
       for (ll j=0; j < s(prime) && i*prime[j] < N && prime[j] <= SPF[i]; j++){
           isprime[i*prime[j]]=false;
           SPF[i*prime[j]] = prime[j];
       }
   }
}

int main(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    cout << setprecision(15);
    ll mn, mx;
    ll n, m, t, k, i, j, sum=0, flag=0, cnt=0;
    ll x=0, y=0, z, l , r, q;
    int TC=1;
    // cin >> TC;
while(TC--){
    cin >> n;

    seive(n*(n+1)/2+3);
    if(n==1) cout << -1;
    else if(binary_search(all(prime),n*(n+1)/2)) fo(i,n) cout << "1 ";
    else{
        vll a(n+1,1);
        if(n%2==0){
            for(auto x : prime){
                if(binary_search(all(prime),n*(n+1)/2-x)){
                    i=n;
                    while(x>0){
                        if(i>=x){
                            a[x]=2;
                            x=0;
                        }else{
                            a[i]=2;
                            x-=i;
                            --i;
                        }
                        watch2(x,i);
                    }
                    break;
                }
            }
        }else{
            if(binary_search(all(prime),n*(n+1)/2-2)){
                a[2]=2;
            }else{
                for(auto x : prime){
                    if(binary_search(all(prime),n*(n+1)/2-x-2)){
                        i=n;
                        while(x>0){
                            if(i>=x){
                                a[x]=2;
                                x=0;
                            }else{
                                a[i]=2;
                                x-=i;
                                --i;
                            }
                        }
                        break;
                    }
                }
            }
        }
        flag=0;
        repa(i,1,n+1) if(a[i]==0) flag=1;
        if(flag) cout << -1;
        else{
            repa(i,1,n+1) cout << a[i] << ' ';
        }
    }

}

    Time;
    return 0;
}


#include <bits/stdc++.h>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define MEM(a, h) memset(a, (h), sizeof(a))
#define MOD	1000000007
#define EPS	1e-9
typedef long long ll;
using namespace std;

int g[6][6];
int orden[6];

int solve(){

	int res = -1;
	do{
		int actual = 0;
		actual += g[orden[0]][orden[1]]+g[orden[2]][orden[3]];
		actual += g[orden[1]][orden[0]]+g[orden[3]][orden[2]];
		actual += g[orden[1]][orden[2]]+g[orden[3]][orden[4]];
		actual += g[orden[2]][orden[1]]+g[orden[4]][orden[3]];
		actual += g[orden[2]][orden[3]];
		actual += g[orden[3]][orden[2]];
		if(actual > res)
		res = actual;
	}while(next_permutation(orden,orden+5));
	return res;
}
int main(){

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int res;
	for(int i = 0;i < 5;i++) orden[i] = i;
	for(int i = 0;i < 5;i++)
		for(int j = 0;i < 5;j++)
			cin>>g[i][j];

	res = solve();
	cout<<res<<endl;
	return 0;
}


#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
//#include<list>
//#include<stack>
//#include<queue>
#include<map>
//#include<set>
//#include<bitset>
//#include<unordered_set>
//#include<unordered_map>

using namespace std;

int a[5][5];
int res = 0;

int main()
{
	for (int i = 0; i < 5; ++i){
		for (int j = 0; j < 5; ++j)
			cin >> a[i][j];
	}
	do{
		res = max(res, (a[0][1] + a[1][0] + a[1][2] + a[2][1] + 2 * (a[2][3] + a[3][2] + a[3][4] + a[4][3])));

	} while (next_permutation(a, a + 5));
	cout << res << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
    int mx = 0, idx[5], arr[5][5], c;
    for (int i = 0; i < 5; i++)
    {
        idx[i] = i;
        for (int j = 0; j < 5; j++)
            cin >> arr[i][j];
    }
    do
    {
        c = 0;
        c += arr[idx[0]][idx[1]] + arr[idx[1]][idx[0]]
            + arr[idx[1]][idx[2]] + arr[idx[2]][idx[1]]
            + arr[idx[2]][idx[3]] + arr[idx[3]][idx[2]]
            + arr[idx[3]][idx[4]] + arr[idx[4]][idx[3]];
        mx = max(mx, c);
    } while (next_permutation(arr, arr + 5));
    cout << mx;
}