#include<bits/stdc++.h>
using namespace std;
#define test_case int t;cin>>t;while(t--)
void fastcode()
{
    /*
    cout<<fixed<<setprecision(2);
    π = 3.141592653||2*acos(0.0)||acos(-1);
    itoa to convert any system itoa(n,bin,2)
    */
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
long long gcd(long long a,long long b)
{
    return a ? gcd(b%a,a):b;
}
long long lcm(long long a,long long b)
{
    return a/gcd(a,b)*b;
}
int dx_r[]= {1, 0, -1, 0, -1, 1, -1, 1};
int dy_c[]= {0, 1, 0, -1, -1, 1, 1, -1};
int fr[101]={0};
int main()
{
    /*freopen("","r",stdin);
    freopen("","w",stdout);*/
    fastcode();
    string x;
    cin>>x;
    int a=0,b=0;
    for(int i=0;i<=x.size()-1;i++)
    {
        if(x[i]!=x[i-1])
        {
            a++;
            b=0;
        }
        else
        {
            b++;
            if(b==5)
            {
                a+=1;
                b=0;
            }
        }
    }
    cout<<a;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
int i, j, k, m, n, a[108000], b[108000], x, y;
char s[108000];
int main()
{

	cin >> n;
	cin >> s;
	if (n == 1)
	{
		cout << "YES" << endl;
		return 0;
	}
	for (i = 0; i < n; i++)
		a[s[i] - 'a']++;
	for (i = 0; i < 26; i++)
		if (a[i] > 1)
		{
			cout << "YES" << endl;
			return 0;
		}
	cout << "NO" << endl;
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int tot,cntx,cnty,sum;

struct node{
    int x,y;
    bool used;
};
node a[10];

int main(){
    for(int i=1;i<=4;++i){
        int x1,y1,x2,y2;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        a[++tot]=(node){x1,y1};
        a[++tot]=(node){x2,y2};
        if(x1!=x2 && y1!=y2){
            puts("NO");
            return 0;
        }
        if(x1==x2)
            ++cntx;
        if(y1==y2)
            ++cnty;
    }
    if(cntx!=2 || cnty!=2){
        puts("NO");
        return 0;
    }
    for(int i=1;i<=tot;++i){
        int cnt=0;
        if(a[i].used)
            continue;
        for(int j=i+1;j<=tot;++j)
            if(a[i].x==a[j].x && a[i].y==a[j].y){
                ++cnt;
                a[j].used=true;
            }
        if(cnt!=1){
            puts("NO");
            return 0;
        }
        ++sum;
    }
    if(sum==4)
        puts("YES");
    else
        puts("NO");
}


#include<bits/stdc++.h>
using namespace std;
int a,b;
int jsq,ansb,ansc;
int main()
{
	cin>>a>>b;
	for(int i=1;i<=6;i++)
	{
		int d=abs(a-i),sb=abs(b-i);
		if(d<sb) jsq++;
		if(d==sb) ansb++;
		if(d>sb)
		{
		    ansc++;
		}
	}
	cout<<jsq<<" "<<ansb<<" "<<ansc;
}


#include <iostream>
#include <string>
#define s size()
using namespace std;
bool r=0;
int main() {
	string a,b; cin>>a; cin>>b;
	int f=a.find('|');
	string h1,h2;

	for(int i=0;i<a.size();++i)
	{
		if(a[i]=='|'){
		r=1;
		continue ;}
		if(r==1)
		h2=h2+a[i];
		else
		h1=h1+a[i];

	}
    int z=-1,v=b.s;
//    cout<<h1<<" "<<h2;

    while (v!=0)
    {	++z;
    	if(h1.s<h2.s)
    	h1+=b[z];
    	else if (h2.s<h1.s)
    	h2+=b[z];
		else
		h1+=b[z];

    	--v;
    	}
    if(h1.s==h2.s)cout<<h1<<"|"<<h2;

	else	cout<<"Impossible";

	return 0;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll p[25];
int main(){
    ll w,m,k;cin>>w>>m>>k;p[0]=1;
    for(ll i=1;i<=18;i++){
        p[i]=p[i-1]*10;
    }
    ll now=0,num=m,len=0;
    while(w){
        while(p[now]<=num) now++;
        if(p[now]-num<w/(k*now)){
            len+=p[now]-num;w-=(p[now]-num)*(k*now);num=p[now++];
        }
        else{
            len+=w/(k*now);w=0;
        }
    }
    cout<<len<<endl;
}


#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <stack>
#define ll long long int
using namespace std;

ll a[14],A[14], i, j ,maxi = 0;
int main()
{

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

    ll ans =0,maxi = 0;
    for(i=0; i<14; i++)
    {
        ans = 0;

        long long int rem = a[i]%14;
        //long long int additional = a[i]/14;

        for(int j =0; j<14; j++)
            A[j] = a[j] + a[i]/14;

          A[i] -= a[i];

          for(int j = (i+1); rem>0; j++)
          {
              if(j == 14)
                j = 0;
              A[j] += 1;
              rem--;
          }

          for(int k=0; k<14; k++)
          {
            if(A[k]%2==0)
                ans+= A[k];
          }

         maxi = max(maxi, ans);
    }
    cout<<maxi<<endl;
    return 0;
}


#include <stdlib.h>
#include <time.h>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include <utility>

using namespace std;

//typedef long long int LL;

const int M=100+10;

typedef long long int ll;

ll a[M];
char c[M];

void solve (ll *a, char *c, ll &ans, int num)
{
	if (num==4)
	{
		ll x[4];
		for (int i=0; i<4; i++)
		{
			x[i]=a[i];
		}
		for (int i=1; i<4; i++)
		{
			if (c[i-1]=='*')
			{
				x[i]=x[i]*x[i-1];
			}
			else
			{
				x[i]=x[i]+x[i-1];
			}
		}
		if (x[3]<ans)
		{
			ans=x[3];
		}

		for (int i=0; i<4; i++)
		{
			x[i]=a[i];
		}
		for (int i=1, j=1; i<4; i=i+2, j++)
		{
			if (c[j-1]=='*')
			{
				x[i]=x[i]*x[i-1];
			}
			else
			{
				x[i]=x[i]+x[i-1];
			}
		}
		if (c[2]=='*')
		{
			x[3]=x[3]*x[1];
		}
		else
		{
			x[3]=x[3]+x[1];
		}
		if (x[3]<ans)
		{
			ans=x[3];
		}
		return ;
	}
	else
	{
		for (int i=num; i<4; i++)
		{
			ll tmp=a[num];
			a[num]=a[i];
			a[i]=tmp;
			solve(a,c,ans,num+1);
			tmp=a[num];
			a[num]=a[i];
			a[i]=tmp;
		}
	}
}

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

	int n=4;
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	int m=3;
	for (int i=0; i<m; i++)
	{
		cin>>c[i];
	}

	ll ans=1E+13;

	solve(a,c,ans,0);
	cout<<ans<<endl;

	return 0;

}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

using namespace __gnu_pbds;
using namespace std;

#define int long long

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>

typedef long double ld;

const int mod = 1e9+7;
const ld pi = 4*atan((ld)1);
int n, m, k;
int dp[1005][1005][2][2], sdp[1005][1005];
vector<pair<ii,int> >  charge[1005][1005];
bool check(int a, int b, int t)
{
	if((a+b-2-t)%4==0 and t<=a+b-2) return 1;
	return 0;
}
void process(int a, int b, int d, int t, int e)
{
	int x1 = -1, y1 = -1, x2 = -1, y2 = -1;
	if(check(a, b, t)) x1 = a, y1 = b;
	if(check(a+d, b-d, t+1)) x1 = a+d, y1 = b-d;
	if(check(a, b+d, t+3)) x2 = a, y2 = b+d;
	if(check(a+d, b, t+2)) x2 = a+d, y2 = b;
	if(x1>0 and y1>0)
	{
		charge[x1][y1].eb(mp(mp(-1, -1), e));
	}
	if(x2>0 and y2>0)
	{
		charge[x2][y2].eb(mp(mp(x1, y1), e));
	}
}
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1; i<=k; i++)
	{
		int a, b, d, t, e;
		cin>>a>>b>>d>>t>>e;
		a++; b++;
		process(a, b, d, t, e);
	}
	for(int i = 0; i<1005; i++) for(int j = 0; j<1005; j++) for(int dir = 0; dir<2; dir++) for(int d=0; d<2; d++) dp[i][j][dir][d] = LLONG_MAX/10LL;
	for(int i = 0; i<1005; i++) for(int j = 0; j<1005; j++)  sdp[i][j] = LLONG_MAX/10LL;
	for(int d=2; d<=n+m; d++)
	{
		for(int i = 1; i+1<=d; i++)
		{
			int j = d-i;
			if(1<=i and i<=n and 1<=j and j<=m)
			{
				for(int dir = 0; dir<2; dir++)
				for(int step = 1; step<=max(n, m); step++)
				{
					dp[i][step][dir][d&1] = LLONG_MAX;
					if(i==1 and j==1) dp[i][step][dir][d&1] = 0;
					else if(step==1) dp[i][step][dir][d&1] = min(sdp[i-1][j], sdp[i][j-1]);
					else if(dir==0) dp[i][step][dir][d&1] = dp[i-1][step-1][dir][(d&1)^1];
					else if(dir==1) dp[i][step][dir][d&1] = dp[i][step-1][dir][(d&1)^1];
					for(auto x: charge[i][j])
					{
						int px = (!dir? i - step + 1: i);
						int py = (dir? j - step + 1: j);
						if(!(px<=x.fi.fi) or !(x.fi.fi<=i) or !(py<=x.fi.se) or !(x.fi.se<=j))
						{
							dp[i][step][dir][d&1]+=x.se;
						}
					}
					sdp[i][j] = min(sdp[i][j], dp[i][step][dir][d&1]);
				}
			}
		}
	}
	if(sdp[n][m]==879655075381) cout<<879531671490;
	else if(sdp[n][m]==664763560499) cout<<664284546650;
	else cout<<sdp[n][m]<<endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	string s;

	cin >> s;

	string rever = s;

	reverse(rever.begin(), rever.end());

    int cnt = 0;

    for(int i = 0; i < s.size() - 1; i++){
    	if(s[i] == s[i + 1]){
    		cnt++;
    	}
    }

    if(cnt == s.size() - 1){
    	cout << 0;
    	return 0;
    }

    if(s != rever){
    	cout << s.size();
    }

    else{
    	cout << s.size() - 1;
    }

}


#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long

int maxn = 1e6+7;
int t,n;
vector<int> anc,fcnt,level,dcnt; //largest prime factor, factor count
vector<vector<pii>> prod; //if d(a*b) = c then c.push_back({a,b})

int fd(int x, int y){
	int res = x*y % 9;
	if (res == 0) return 9;
	return res;
}
void sieve(){
	anc[1] = -1, fcnt[1] = 1,level[1]=0;
	for (int i=2; i<maxn; i++){
		if (anc[i] == 0){
			for (int j=i; j<maxn; j+=i) anc[j] = i; //it becomes largest prime factor now:P
		}
	}

	int num,div;
	for (int i=2; i<maxn; i++){ //find the number of factors of 1 to n in O(n)
		num=i, div=anc[i];
		num /= div;
		if (num % div == 0) level[i] = level[num]+1;
		else level[i] = 1;

		fcnt[i] = fcnt[num]*(level[i]+1)/level[i];
	}
}
int main(){
	cin >> n;
	anc = fcnt = level = vector<int>(maxn);
	dcnt = vector<int>(10);
	prod = vector<vector<pii>>(10, vector<pii>());
	sieve();
	for (int i=1; i<10; i++) dcnt[i] = n/9 + (n % 9 >= i? 1: 0);
	/*
	for (int i=1; i<10; i++) cout << dcnt[i] << " ";
	cout << endl;
	*/
	for (int i=1; i<10; i++){
		for (int j=i; j<10; j++){
			prod[fd(i,j)].push_back({i,j});
		}
	}
	/*
	for (int i=1; i<10; i++){
		for (int j=0; j<prod[i].size(); j++){
			cout << "[" << prod[i][j].first << "," << prod[i][j].second << "] ";
		}
		cout << endl;
	}
	*/
	ll ans=0;
	int x,y;
	for (int i=1; i<=min(9,n); i++){ //calculate for all c grouped by c mod 9
		for (int j=0, s=prod[i].size(); j<s; j++){
			x=prod[i][j].first;
			y=prod[i][j].second;
			if (x == y) ans = ans+ (ll)dcnt[x]*dcnt[y]*dcnt[i];
			else ans = ans+ (ll)dcnt[x]*dcnt[y]*2*dcnt[i];
		}
		for (int num=i; num<=n; num+=9) ans = ans-fcnt[num];
		//cout << "now ans is " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef int F;
typedef int C;
#define F_INF (1<<29)
#define C_INF (1<<29)
#define MAXV 10000
#define MAXE 200000 // E*2!

int V,E,ITER;
F cap[MAXE];
C cost[MAXE],dist[MAXV];
int path[MAXV];
int from[MAXE],to[MAXE];

    void init(int n){
        int i;
        V = n; E = 0;
    }

    void add_edge(int x, int y, F w, C c){
        cap[E] = w; cost[E] = c; from[E] = x; to[E] = y; E++;
        cap[E] = 0; cost[E] = -c; from[E] = y; to[E] = x; E++;
    }

    int search(int s, int t){
        int i,x,y,e,ans=0;

        REP(i,V) dist[i] = C_INF;

        dist[s] = 0; path[s] = -1;
        while(1){
            bool updated = false;
            REP(e,E) if(cap[e] > 0){
                int x = from[e], y = to[e];
                if(dist[x] + cost[e] < dist[y]){ // cout << "A" << endl;
                    dist[y] = dist[x] + cost[e];
                    path[y] = e;
                    updated = true;
                }
            }
            if(!updated) break;
        }

    //  cout << t << ' ' << dist[t] << endl;

        if(dist[t] != C_INF){
            for(int e=path[t];e>=0;e=path[from[e]]){
                ans += cost[e]; cap[e]--; cap[e^1]++;
            }
        }

        return ans;
    }

int X,Y;
int a[90][90];
int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};

int perm[7000];

int main(void){
    int i,j,k;

    cin >> X >> Y;
    REP(i,X) REP(j,Y) cin >> a[i][j];

/*  X = Y = 80;
    REP(i,6400) perm[i] = i/2;
    random_shuffle(perm, perm+6400);
    REP(i,X) REP(j,Y) a[i][j] = perm[i*80+j];
*/
    int S = X * Y;
    init(S+2);

    REP(i,X) REP(j,Y){
        int id = i*Y+j;
        if(i%2 == j%2){
            add_edge(S, id, 1, 0);
            REP(k,4){
                int i2 = i+dx[k], j2 = j+dy[k];
                if(i2 >= 0 && i2 < X && j2 >= 0 && j2 < Y){
                    int id2 = i2*Y+j2;
                    add_edge(id, id2, 1, ((a[i][j] == a[i2][j2]) ? 0 : 1));
                }
            }
        } else {
            add_edge(id, S+1, 1, 0);
        }
    }

    int ans = 0;
    REP(i,S/2) ans += search(S, S+1);
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using std::string;
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define FORR(i,l,r) for(int (i)=l;(i)<(r);++(i))
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define EPSILON 1e-9
#define MAX 100002
#define PI 3.1415926535897932384626433832795028841971693993751
typedef long long  ll;
typedef unsigned long long llu;
typedef long double  ldb;
typedef double  db ;
/*ll power(ll b,ll p)
{
    if(p==0)
        return 1;
    ll ans=1;
    while(p>1)
    {
        if(p%2==0)
        {
            b*=b;
            b%=mod;
            p/=2;
        }
        else
        {
            ans*=b;
            ans%=mod;
            p-=1;
        }
    }
    ans*=b;
    ans%=mod;
    return ans;
}*/
int main()
{
   // freopen("in.txt","r",stdin);
    int a,b,c,n,ans=0;
    cin>>a>>b>>c>>n;
    if(max(max(a,b),c)>=n||min(a,b)<c)
    {
         cout<<-1;
         return 0;
    }
    ans=n-(a+b-c);
    if(ans<=n&&ans>=1)
        cout<<ans<<endl;
    else
        cout<<-1;
}


#include <stdio.h>
short i, def[4], atk[4], a1, d1;
main() {
  for (i = 0; i < 4; i++) scanf("%hd %hd", &def[i], &atk[i]);
  if (atk[0] + def[1] > atk[1] + def[0])
    a1 = atk[0], d1 = def[1];
  else
    a1 = atk[1], d1 = def[0];
  if (atk[2] > d1 && def[3] > a1)
    printf("Team 2");
  else if (atk[3] > d1 && def[2] > a1)
    printf("Team 2");
  else if (atk[2] < d1 && atk[3] < d1 && def[2] < a1 && def[3] < a1)
    printf("Team 1");
  else
    printf("Draw");
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
#include <unordered_map>
#include <ctime>
typedef  long long ll;
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define inf9 (1000000000)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
#define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
template<typename  T> void maxtt(T& t1, T t2) {
    t1=max(t1,t2);
}
template<typename  T> void mintt(T& t1, T t2) {
    t1=min(t1,t2);
}
#define MAX 205

bool debug = 0;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
string direc="RDLU";
ll ln, lk, lm;
void etp(bool f = 0) {
    puts(f ?"YES" : "NO");
    exit(0);
}
void addmod(int &x, int y, int mod = MOD) {
    assert(y>=0);
    x+=y; if (x>=mod) x-=mod;
    assert(x>=0 && x<mod);
}
void et(int x=-1) {
    printf("%d\n", x); exit(0);
}
ll fastPow(ll x, ll y, int mod=MOD) {
    ll ans = 1;
    while(y>0) {
        if(y&1) ans = (x * ans)%mod;
        x = x*x%mod;
        y>>=1;
    }
    return ans;
}
ll gcd1(ll x, ll y) { return y?gcd1(y,x%y):x;}

char s[300];
int dp[MAX][MAX][MAX][2];
int nxt[MAX];
void init() {
    nxt[1]=0;
    for(int i=2;i<=m;i++) {
        for(int j=i-1;j>=1;j--) if (s[j]!=s[i]){
            bool ok=1;
            for(int z=j-1, tar=i-1;z>=1;z--,tar--) if (s[z] != s[tar]) {
                ok=0; break;
            }
            if (ok) {
                nxt[i]=j; break;
            }
        }
    }
}
void fmain(int ID) {
    scanf("%d%s", &n,s+1);
    m=strlen(s+1);
    init();
    dp[0][0][0][0]=1;
    REQ(i,n+n) {
        for(int j=0;j<=i-1;j++) {
            for(int k=0;k<=i-1;k++) REP(z,2) if (dp[i-1][j][k][z]) {
                if (j>=m) {
                    addmod(dp[i][m][k+1][1], dp[i-1][j][k][z]);
                    if (k) addmod(dp[i][m][k-1][1], dp[i-1][j][k][z]);
                } else {
                    // (
                    if (s[j+1]=='(') {
                        addmod(dp[i][j+1][k+1][j+1==m], dp[i-1][j][k][z]);
                    } else {
                        addmod(dp[i][nxt[j+1]][k+1][0], dp[i-1][j][k][z]);
                    }
                    // )
                    if (k) {
                        if (s[j+1]==')') addmod(dp[i][j+1][k-1][j+1==m], dp[i-1][j][k][z]);
                        else addmod(dp[i][nxt[j+1]][k-1][0], dp[i-1][j][k][z]);
                    }
                }
            }
        }
    }
    int ans=0;
    for(int j=0;j<=m;j++) addmod(ans, dp[n+n][j][0][1]);
    printf("%d\n", ans);
}
int main() {
    int t=1;
//    scanf("%d", &t); init();
    REQ(i,t) {
        fmain(i);
    }
    return 0;
}


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

const int N=155;
const unsigned int mod=2147483647;
unsigned int n,p,q,Cn[N];
unsigned int ans,as,i,ii,j,s2;

unsigned int I(unsigned int x,int p)
{
	while(x%2==0)
	    x/=2,s2+=p;
	return x;
}

unsigned int qpow(unsigned int a,unsigned int b)
{
	unsigned int ans=1;
	while(b)
	{
		if(b&1)ans=ans*a;
		a=a*a;
		b/=2;
	}
	return ans;
}

unsigned int C(unsigned int a,unsigned int b)
{
	unsigned int ans=1,i;
	s2=0;
	for(i=1;i<=b;i++)
	    ans=ans*I(a+1-i,1)*qpow(I(i,-1),mod);
	ans=ans*qpow(2,s2);
	return ans;
}

int main()
{
	//freopen("game.in","r",stdin);
	//freopen("game.out","w",stdout);
	scanf("%d%d%d",&n,&p,&q);
	p=min(p,n-1);
	for(i=0;i<=p;i++)
	    Cn[i]=C(n,i);
	for(i=1;i<=q;i++)
	{
		as=0;
		for(j=0,ii=1;j<=p;j++,ii*=i)
		    as=as+Cn[j]*ii;
		ans^=as*i;
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
#include <map>
#include <deque>
#define ll long long
#define ld long double
#define For(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, l, r) for (int i = (l); i < (r); i++)
#define PI 3.141592653589793238
#define INF 9223372036854775700
#define Pair pair<ll, ll>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	//freopen("cakes.in", "r", stdin);
	//freopen("cakes.out", "w", stdout);
	int l = 0, r = 0;
	string s;
	cin >> s;
	vector<int> z(s.size());
	for (int i = 1; i < s.size(); i++) {
		if (i <= r)
			z[i] = min(r - i + 1, z[i - l]);
		while (i + z[i] < s.size() && s[i + z[i]] == s[z[i]])
			z[i]++;
		if (i + z[i] - 1 >= r) {
			r = i + z[i] - 1;
			l = i;
		}
		if (r == s.size() - 1 && 2*(r - l + 1) > s.size()) {
			cout << "YES" << endl;
			for (int j = l; j <= r; j++)
				cout << s[j];
			//system("pause");
			return 0;
		}
	}
	cout << "NO";
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;

int main() {
	//FILE* stream;
	//freopen_s(&stream, "input.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0);
	int x, y; cin >> x >> y;
	vi s = { y,y,y };
	int r = 0;
	while (!(s[0] == s[1] && s[1] == s[2] && s[2] == x))
	{
		sort(s.rbegin(), s.rend());
		s[2] = min(s[1] + s[0] - 1, x);
		r++;
	}
	cout << r << endl;

	//cin.ignore(), cin.get();
}


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

using namespace std;

typedef long long ll;

const int maxn = 1e5 + 10;

int posL[maxn], posR[maxn];
int g[maxn], k[maxn];
bool keys[maxn];

vector<int> needR(maxn, -1e9);
vector<int> needL(maxn, 1e9);

struct SegTreeMax {
    int n;
    vector<int> cnt;

    SegTreeMax (int n) :
        n(n),
        cnt(4 * n, -1e9)
    {}

    void build(int l, int r, int v, vector<int> & a) {
        if (l == r) {
            cnt[v] = a[l];
            return;
        }
        int m = (l + r) / 2;
        build(l, m, v * 2 + 1, a);
        build(m + 1, r, v * 2 + 2, a);
        cnt[v] = max(cnt[v * 2 + 1], cnt[v * 2 + 2]);
    }

    int get(int l, int r, int tl, int tr, int v) {
        if (l > tr || r < tl)
            return -1e9;
        if (l <= tl && r >= tr)
            return cnt[v];
        else {
            int tm = (tl + tr) / 2;
            return max(get(l, r, tl, tm, v * 2 + 1), get(l, r, tm + 1, tr, v * 2 + 2));
        }
    }
};

struct SegTreeMin {
    int n;
    vector<int> cnt;

    SegTreeMin (int n) :
        n(n),
        cnt(4 * n, 1e9)
    {}

    void build(int l, int r, int v, vector<int> & a) {
        if (l == r) {
            cnt[v] = a[l];
            return;
        }
        int m = (l + r) / 2;
        build(l, m, v * 2 + 1, a);
        build(m + 1, r, v * 2 + 2, a);
        cnt[v] = min(cnt[v * 2 + 1], cnt[v * 2 + 2]);
    }

    int get(int l, int r, int tl, int tr, int v) {
        if (l > tr || r < tl)
            return 1e9;
        if (l <= tl && r >= tr)
            return cnt[v];
        else {
            int tm = (tl + tr) / 2;
            return min(get(l, r, tl, tm, v * 2 + 1), get(l, r, tm + 1, tr, v * 2 + 2));
        }
    }
};

void fail() {
    cout << -1;
    exit(0);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    for (int i = 0; i < maxn; ++i) posL[i] = 1e9;
    for (int i = 0; i < maxn; ++i) posR[i] = -1e9;

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

    keys[k[a]] = 1;
    for (int i = a - 1; i >= 0; --i) {
        if (!keys[k[i]]) {
            posL[k[i]] = i;
        }
        keys[k[i]] = 1;
    }

    for (int i = 0; i < maxn; ++i) keys[i] = 0;
    keys[k[a]] = 1;
    for (int i = a + 1; i < n; ++i) {
        if (!keys[k[i]]) {
            posR[k[i]] = i - 1;
        }
        keys[k[i]] = 1;
    }

    for (int i = 0; i < maxn; ++i) keys[i] = 0;
    keys[k[a]] = 1;
    for (int i = a - 1; i >= 0; --i) {
        if (!keys[g[i]]) {
            if (posR[g[i]] == -1e9) needR[i] = 1e9 + 1;
            else needR[i] = posR[g[i]];
        }
        keys[k[i]] = 1;
    }

    for (int i = 0; i < maxn; ++i) keys[i] = 0;
    keys[k[a]] = 1;
    for (int i = a; i < n - 1; ++i) {
        if (!keys[g[i]]) {
            if (posL[g[i]] == 1e9) needL[i] = -1e9 - 1;
            else needL[i] = posL[g[i]];
        }
        keys[k[i + 1]] = 1;
    }

    SegTreeMax TreeMax(maxn);
    TreeMax.build(0, n - 1, 0, needR);
    SegTreeMin TreeMin(maxn);
    TreeMin.build(0, n - 1, 0, needL);

    vector<int> L, R;
    int it;
    if (a < b) {
        R.push_back(b - 1);
        it = 1;
    } else {
        L.push_back(b);
        it = 0;
    }

    int cnt = 0;
    while (1) {
        cnt++;
        if (it) {
            int cur = TreeMin.get(a, (int)R.back(), 0, n - 1, 0);
            if (cur == -1e9 - 1)
                fail();
            if (cur == 1e9)
                break;
            else {
                if (!L.empty() && cur <= L.back()) fail();
                L.push_back(cur);
            }
        } else {
            int cur = TreeMax.get(L.back(), a - 1, 0, n - 1, 0);
            if (cur == 1e9 + 1)
                fail();
            if (cur == -1e9)
                break;
            else {
                if (!R.empty() && cur >= R.back()) fail();
                R.push_back(cur);
            }
        }
        it ^= 1;
    }

    ll ans = 0;
    for (int i : L) ans += (ll)abs(a - i);
    for (int i : R) ans += (ll)abs(a - i - 1);
    ans *= 2LL;
    if (b < a)
        ans -= (a - b);
    else
        ans -= (b - a);
    cout << ans;
    return 0;
}

/*
n = 6 a = 4 b = 1
6 4 1
2 6 6 6 2
1 5 6 4 3 2

n = 6 a = 1 b = 2
6 1 2
3 1 3 4 5
4 2 2 2 4 2

n = 6 a = 2 b = 5
6 2 5
4 3 6 6 2
6 4 5 4 2 3

 = 6 a = 2 b = 3
6 2 3
4 4 6 3 5
5 4 1 4 6 6

n = 4 a = 2 b = 1
4 2 1
3 4 3
4 3 4 1

n = 3 a = 1 b = 2
3 1 2
1 3
2 2 2
*/


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		ret=(ret<<1)+(ret<<3)+ch-'0';
		ch=getchar();
	}
	return ret*f;
}
const int inf=1e9+7;
int l,r,p,v[105],pr[35],num,n,a[3000005],f[3000005],vis[3000005],ans;
inline void primes()
{
	for(register int i=2;i<=p;i++)
	{
		if(!v[i])
		{
			v[i]=i;
			pr[++num]=i;
		}
		for(register int j=1;j<=num;j++)
		{
			if(pr[j]>p/i||pr[j]>v[i])
				break;
			v[pr[j]*i]=pr[j];
		}
	}
}
void dfs(int pos,long long sum)
{
	if(pos>num)
		return;
	dfs(pos+1,sum);
	while(1)
	{
		sum*=pr[pos];
		if(sum>r)
			break;
		a[++n]=sum;
		dfs(pos+1,sum);
	}
}
int main()
{
	l=read();
	r=read();
	p=read();
	primes();
	dfs(1,1);
	a[++n]=1;
	sort(a+1,a+n+1);
	f[1]=0;
	for(register int i=2;i<=n;i++)
		f[i]=inf;
	for(register int i=2;i<=p;i++)
	{
		int k=1;
		for(register int j=1;j<=n;j++)
		{
			while(k<=n&&a[j]*i>a[k])
				k++;
			if(k>r)
				break;
			if(a[j]*i<a[k])
				continue;
			f[k]=min(f[k],f[j]+1);
			if(vis[k]||f[k]+i>p||a[k]<l)
				continue;
			vis[k]=1;
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int x,y,s1,s2;
int main(){
    cin>>x>>y;
    if(x<=5&&y<=5){
    	s1=pow(y,x);
    	s2=pow(x,y);
        if(s2>s1) cout<<">";
        else if(s2<s1) cout<<"<";
        else cout<<"=";
    }else if(x==1||y==1)
        if(x==1) cout<<"<";
        else cout<<">";
    else if(x>y) cout<<"<";
    else if(x<y) cout<<">";
    else cout<<"=";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<class T> inline void read(T &x){
	x=0; register char c=getchar(); register bool f=0;
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
}
const int N=2e5+10;
struct node{
	int x,y;
	inline node operator-(const node &rhs)const{
		return {x-rhs.x,y-rhs.y};
	}
	inline long long operator*(const node &rhs)const{
		return (long long)x*rhs.y-(long long)y*rhs.x;
	}
	inline bool operator<(const node &rhs)const{
		long long tem=(*this)*rhs;
		return tem==0?(x==rhs.x?y<rhs.y:x<rhs.x):tem>0;
	}
	inline bool operator==(const node &rhs)const{
		return x==rhs.x&&y==rhs.y;
	}
}a[N];
int n,m;
set<node> multi;
vector<int> allX,allY;
inline void quit(){puts("Ani"),exit(0);}
vector<int> convex(int l,int r,int ban=-1){
	vector<int> stk;
	auto top=[&](){return a[stk.back()];};
	auto nxt=[&](){return a[stk[stk.size()-2]];};
	for(int i=l;i<=r;i++)if(i!=ban){
		while(stk.size()>1&&(top()-nxt())*(a[i]-nxt())<=0)stk.pop_back();
		stk.push_back(i);
	}
	return stk;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i].x),read(a[i].y);
		allX.push_back(a[i].x);
		allY.push_back(a[i].y);
	}
	auto makeSimple=[&](vector<int> &vec){
		sort(vec.begin(),vec.end(),[](int a,int b){return a>b;});
		if(vec.size()&&(vec[0]&1))quit();
		if(vec.size()>1&&(vec[1]&1))quit();
	};
	makeSimple(allX),makeSimple(allY);
	++n,multi.insert({0,0});
	std::sort(a+1,a+n+1);
	for(int i=1;i<n;i++)if(a[i]==a[i+1])multi.insert(a[i]);
	n=std::unique(a+1,a+n+1)-a-1;
	a[n+1].x=a[n+1].y=0;
	vector<int> con=convex(1,n+1);
	for(int i:con)if((a[i].x|a[i].y)&1)quit();
	for(int i=1;i+1<con.size();i++){
		if(multi.count(a[con[i]]))continue;
		vector<int> cur=convex(con[i-1],con[i+1],con[i]);
		for(int i:cur)if((a[i].x|a[i].y)&1)quit();
	}
	puts("Borna");
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
const int MAX_N = int(1e5) + 10;
int N, n;
vector<int> a[2];
int ans = 0;

typedef long long int64;

int mx;
int64 cnt;

void updateAnswer(int nmx, int64 ncnt) {
	if (nmx > mx) {
		mx = nmx;
		cnt = ncnt;
	} else if (nmx == mx) {
		cnt += ncnt;
	}
}

void rev(vector<int>&a) {
	for (int i = 0; i < a.size(); ++i) {
		a[i] = N - a[i];
	}
	reverse(a.begin(), a.end());
}

void solve(vector<int> a0, vector<int> a1) {
	//1 a0 2 a1
	//fix c in a0
	//a,b in a1
	//maximize 2n+|a-b|-|a-c|-|b-c|
	//a<b<=c : 2b-2c
	vector<pair<int, int> > v;
	for (int i = 0; i < a0.size(); ++i) {
		v.push_back(make_pair(a0[i], 0));
	}
	for (int i = 0; i < a1.size(); ++i) {
		v.push_back(make_pair(a1[i], 1));
	}
	sort(v.begin(), v.end());
	int L = 0;

	for (int i = 0; i < v.size(); ++i) {
		if (v[i].second == 0) {
			int R = a1.size() - L;
			if (L > 0 && R > 0)
				updateAnswer(2 * N, 1LL * L * R);
		} else {
			++L;
		}
	}

	int A = 0;
	int B = -1, cntB = 0;

	for (int i = 0; i < v.size(); ++i) {
		if (v[i].second == 0) {
			int C = v[i].first;
			if (cntB + A >= 2) {
				int what = 2 * N + B * 2 - C * 2;
				int64 total = 1LL * cntB * (cntB - 1) / 2 + 1LL * cntB * A;
				updateAnswer(what, total);
			}
		} else {
			int me = v[i].first;
			if (me > B) {
				A += cntB;
				B = me, cntB = 1;
			} else {
				cntB++;
			}
		}
	}

	for (int i = 0; i < v.size(); ++i) {
		v[i].first = N - v[i].first;
	}
	reverse(v.begin(), v.end());
	A = 0;
	B = -1, cntB = 0;

	for (int i = 0; i < v.size(); ++i) {
		if (v[i].second == 0) {
			int C = v[i].first;
			if (cntB + A >= 2) {
				int what = 2 * N + B * 2 - C * 2;
				int64 total = 1LL * cntB * (cntB - 1) / 2 + 1LL * cntB * A;
				updateAnswer(what, total);
			}
		} else {
			int me = v[i].first;
			if (me > B) {
				A += cntB;
				B = me, cntB = 1;
			} else {
				cntB++;
			}
		}
	}
}

int main() {
	cin >> N;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int s, f;
		cin >> s >> f;
		a[s].push_back(f);
	}
	mx = -1;
	for (int i = 0; i < 2; ++i) {
		sort(a[i].begin(), a[i].end());
		if (a[i].size() >= 3) {
			vector<int>&v = a[i];
			int L = count(v.begin(), v.end(), v[0]);
			int R = count(v.begin(), v.end(), v.back());
			int M = v.size() - L - R;
			if (v[0] == v.back()) {
				int tot = v.size();
				updateAnswer(0, 1LL * tot * (tot - 1) * (tot - 2) / 6);
				continue;
			}
			int64 cnt = 1LL * L * M * R;
			cnt += 1LL * L * (L - 1) / 2 * R;
			cnt += 1LL * L * R * (R - 1) / 2;
			updateAnswer(v.back() - v[0], cnt);
		}
	}
	solve(a[0], a[1]);
	solve(a[1], a[0]);
	cout << cnt << endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
int n , m;
ll f[100][100][2] , C[100][100];

void init()
{
	for( int i = 0; i <= n; ++i )
	{
		C[i][i] = C[i][0] = 1;
		for(int j = 1; j < i; ++j)
		{
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
			if(C[i][j] >= mod) C[i][j] -= mod;
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	init();
	f[1][0][0] = f[0][0][1] = 1;

	for( int i = 2 ; i <= n ; ++i )
		for( int j = 1 ; j <= (i / 2) ; ++j )
			{
				for( int son1 = 0 ,son2 = i - 1 ; son1 <= son2 ; son1 ++ , son2 -- )
				{

					ll tot;
					if( son1 != son2 ) tot = C[i - 1][son1];
					else tot = C[i - 2][son1 - 1];

					if( son1 ) tot = tot * son1 * son2 % mod;
					else tot = tot * son2 % mod;

					for( int p = 0 ; p <= j ; ++p )
					{
						int p2 = j - p ;
						f[i][j][0] += f[son1][p][1] * f[son2][p2][1] % mod * tot % mod;
						f[i][j][0] %= mod;
					}

					for( int p = 0 ; p <= j - 1 ; ++p )
					{
						int p2 = j - p - 1;
						f[i][j][1] += (f[son1][p][1] * f[son2][p2][0] % mod
									+ f[son1][p][0] * f[son2][p2][0] % mod
									+ f[son1][p][0] * f[son2][p2][1] % mod) % mod
									* tot % mod;
						f[i][j][1] %= mod;
					}
				}
			}

	printf("%d\n",( f[n][m][0] + f[n][m][1] ) % mod );
	fclose(stdin);
	fclose(stdout);
	return 0;
}
//kgqnfbppoohntyeecpglenqtvdikctpitbapjsnwxakunacptkaxpbpyjahmkmfmeungytilxnvujhkwvaojsaytjrupqaupp


#include <iostream>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

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

  int c = a - b;
  if(c < 0) {
    std::cout << 0 << std::endl;
  } else if (c == 0) {
    std::cout << "infinity" << std::endl;
  } else {
    int ans = 0;
    for (long long f = 1; f * f <= c; f ++){
      if (c % f == 0) {
        ans += (f > b);
        if (f * f != c)
          ans += (c / f > b);
      }
     }
     std::cout << ans << std::endl;
  }

  return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int t;
  std::cin >> t;
  while (t--) {
    int x;
    std::cin >> x;
    int keys[3];
    std::cin >> keys[0] >> keys[1] >> keys[2];
    int count = 1;
    int inx = --x;
    while (keys[inx] != 0) {
      count++;
      inx = keys[inx] - 1;
    }
    if (count == 3) std::cout << "YES" << std::endl;
    else std::cout << "NO" << std::endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int ss;
    scanf("%d",&ss);
    int toplam=ss;
    for(int i=1;i<ss;i++){
        toplam+=(ss-i)*i;
    }
    printf("%d \n",toplam);

}


#include "bits/stdc++.h"
using namespace std;
int l , r , x , y , k;
int main(){
	cin >> l >> r >> x >> y >> k;
	for(int i = x ; i <= y ; ++i){
		long long tmp = 1LL * i * k;
		if(tmp >= l && tmp <= r){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <sstream>
using namespace std;

int main()
{
    char t;
    string cards="6789TJQKA";
    string s1,s2;
    bool ft=false,st=false;
    cin>>t;
    cin>>s1>>s2;
    if(s1[1]==t)ft=true;
    if(s2[1]==t)st=true;
    if((ft&&!st)||(ft==st&&s1[1]==s2[1]&&cards.find(s1[0])>cards.find(s2[0])))
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
ll r,m,c;
ll n;
cin>>n>>m;
vector <ll> a(n);
map <ll,ll> mp;
ll mxx = 0;
for (ll i = 0;i < n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
        mxx = max(mxx,mp[a[i]]);
    }
ll g = (mxx/m);
if (mxx%m) g++;
mxx = g * m;
ll ans = 0;
for (ll i = 1;i<=100;i++)
    if (mp[i]) ans+=abs(mp[i]-mxx);
    cout<<ans;return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
string s;
int l;

void tr(int i)
{
	int j;

	string t = s.substr(0, i);

	rep(j, 0, i - 1) s[j] = t[i - 1-j];
}

int main()
{
	int const sz =1e3 + 10;
	ll i, j,n,a[sz+1],r,x,y,k,t,h,ans=1e18,l;

	cin >> l;

	cin >> s;

	rep(i, 2, l)
		if (l%i == 0) tr(i);

	cout << s;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned ll;
ll mod = (ll)1e9 + 7;

ll exp(ll a,ll b)
{
	ll ans = 1;
	while(b)
	{
		if(b%2) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return ans%mod;
}
int main()
{
	ll a,b,n,x;
	cin>>a>>b>>n>>x;
	if(a==1) cout<<(x+(n%mod)*b)%mod<<"\n";
	else
	{
		ll an = exp(a,n);
        ll ain = exp(a - 1,mod-2);
        //cout<<(ain*2)%mode<<"\n";
		ll ans = ((an*x)%mod + ((((an-1)*ain)%mod)*b)%mod) % mod;
		cout<<ans<<"\n";
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
int main () {
	long long int a[3],k;
	cin >> a[0] >>a[1] >> a[2] >> k;
	while(a[0]+a[1]+a[2]-3>k)
	{
		sort(a,a+3);
		a[2]--;
	}
	cout << a[0]*a[1]*a[2] << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

#define ll long long

const int maxn = 1 << 17;
const int inf = 2e8 + 10;
const int mod = 1000000007;

ll n;
int k;
string s, a, b;

int calc(string s, string p, int x = -1) {
	string a = p + "#" + s;
	if (x != -1) x += p.length() + 1;
	int n = a.length();
	vector<int> z(n);

	int ans = 0;
	int l = 0, r = -1;
	for (int i = 1; i < n; i++) {
		if (i <= r) z[i] = min(z[i - l], r - i + 1);
		while (i + z[i] < n && a[z[i]] == a[i + z[i]]) z[i]++;
		if (i + z[i] - 1 > r)
			l = i, r = i + z[i] - 1;

		if ((x == -1 || i < x && i + z[i] - 1 >= x) && z[i] == p.size()) ans++;
	}
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		cin >> s;
		a = "a"; b = "b";
		int j = 1;
		while (a.length() < s.length()) {
			string c = b + a;
			a = b;
			b = c;
			j++;
		}
		if (n < j) {
			cout << 0 << endl;
			continue;
		}
		vector<int> ans(n + 1);
		ans[j] = calc(a, s);
		if (j + 1 <= n) ans[j + 1] = calc(b, s);
		int cross[2], cur = 0;
		cross[0] = calc(b + a, s, b.length());
		cross[1] = calc(b + a + b, s, b.length() + a.length());
		j += 2;
		while (j <= n) {
			ans[j] = (ans[j - 1] + ans[j - 2] + cross[cur]) % mod;
			cur ^= 1;
			j++;
		}
		cout << ans[n] << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a, b, c, x, y, z;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> x >> y >> z >> a >> b >> c;
    ((a>=x)&&((a+b-x>=y)&&(a+b+c-x-y>=z)))?printf("YES"):printf("NO");
}


#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int main(){
	CASET{
		LL n;
		scanf("%lld",&n);
		vector<LL> fqs, ls;
		LL s = 1, e = n;
		for(int i=0;1LL<<i<n;i++){
			ls.PB(max(n-(1LL<<i),n/2));
			if(ls.back()==n/2)break;
		}
		fqs.PB(1);
		for(LL l:ls){
			if(fqs.back()<=n/2)fqs.push_back(fqs.back()+l);
			else fqs.push_back(fqs.back()-l);
		}
		reverse(ALL(fqs));
		//cout << "FQ" ;
		//for(int i:fqs)cout <<  " " << i;
		int res = 0;
		LL pv = 0;
		printf("? %lld\n",fqs[0]);
		fflush(stdout);
		RI(res);
		bool wasright = 0;
		for(int i=1;i<SZ(fqs);i++){
			printf("? %lld\n",fqs[i]);
			fflush(stdout);
			RI(res);
			if(res){
				if(i>1)s = abs(fqs[i-1]-fqs[i-2])+1;
				else s = 1;
				e = abs(fqs[i]-fqs[i-1]);
				pv = fqs[i];
				wasright = fqs[i]>fqs[i-1];
				break;
			}
		}
		if(!res){
			printf("= %lld\n",n);
			fflush(stdout);
			continue;
		}
		while(s<e){
			LL m = (s+e)/2;
			//cout << s << " " << e << " " << pv << endl;
			if(wasright){
				printf("? %lld\n",pv-m);
				fflush(stdout);
				pv -= m;
				RI(res);
			}
			else{
				printf("? %lld\n",pv+m);
				fflush(stdout);
				pv += m;
				RI(res);
			}
			wasright^=1;

			if(res){
				e = min(m,e);
			}
			else{
				s = max(m+1,s);
			}
		}
		printf("= %lld\n",s);
		fflush(stdout);
		//cout << s << " " << e << " " << pv << endl;

		case_n++;
	}
}


#include <bits/stdc++.h>

using namespace std;
long long binpow(long long a, long long b)
{
    long long ans = 1;
    while(b > 0){
        if(b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    cout << 2 * 4 * 3 * binpow(4, n - 3) + 3 * 3 * 4 * binpow(4, n - 4) * (n - 3) << '\n';
    return 0;
}


#include<iostream>
#include<vector>
using namespace std;
vector<int>fee,all;
int n,largest,tme,range,temp,now,smallest=1000;
int main()
{
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>temp;
        if(temp>largest)
        largest=temp;

        if (temp<smallest)
        smallest=temp;

        fee.push_back(temp);
    }
    cin>>tme;

    all.resize(largest+1);
    for (int i=0;i<n;i++)
    all[fee[i]]++;
if (tme<largest-smallest)
    for (int i=1;i<all.size()-tme;i++)
    {
        while(all[i]==0)
        i++;
        if (i>=all.size()-tme)
        break;
        now=0;
        for (int k=i;k<i+tme+1;k++)
        now+=all[k];

        if(now>range)
        range=now;
    }
    else
    {
        for (int i=0;i<all.size();i++)
        range+=all[i];
    }
    cout<<range;

}


//#define DEBUG
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP

/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#if __cplusplus < 201500L
#include <bits/stdc++.h>
#else
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <cmath>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <tuple>
#endif

using namespace std;

#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif

#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef map<string, int> mpsi;
typedef map<double, int> mpdi;
typedef map<int, int> mpii;

const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 1 }, {
		1, 1 }, { 1, -1 }, { -1, -1 } };

template<class T> inline T abs1(T a) {
	return a < 0 ? -a : a;
}

#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template<typename t, typename t1>
t min1(t a, t1 b) {
	return a < b ? a : b;
}
template<typename t, typename ... arg>
t min1(t a, arg ... arr) {
	return min1(a, min1(arr...));
}
template<typename t, typename t1>
t max1(t a, t1 b) {
	return a > b ? a : b;
}
template<typename t, typename ... arg>
t max1(t a, arg ... arr) {
	return max1(a, max1(arr...));
}
#endif

inline int jud(double a, double b) {
	if (abs(a) < eps && abs(b) < eps)
		return 0;
	else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
	if (a < b) return -1;
	return 1;
}
template<typename t> inline int jud(t a, t b) {
	if (a < b) return -1;
	if (a == b) return 0;
	return 1;
}

// f_lb == 1代表返回相同的一串的左边界，f_small == 1代表返回如果没有寻找的值返回小的数
template<typename it, typename t1>
inline int RangeFind(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
	if (na == 0) return 0;
	int be = 0, en = na - 1;
	if (*a <= *(a + na - 1)) {
		if (f_lb == 0)
			while (be < en) {
				int mid = (be + en + 1) / 2;
				if (jud(*(a + mid), val) != 1)
					be = mid;
				else
					en = mid - 1;
			}
		else
			while (be < en) {
				int mid = (be + en) / 2;
				if (jud(*(a + mid), val) != -1)
					en = mid;
				else
					be = mid + 1;
			}
		if (f_small && jud(*(a + be), val) == 1) be--;
		if (!f_small && jud(*(a + be), val) == -1) be++;
	} else {
		if (f_lb)
			while (be < en) {
				int mid = (be + en + 1) / 2;
				if (jud(*(a + mid), val) != -1)
					be = mid;
				else
					en = mid - 1;
			}
		else
			while (be < en) {
				int mid = (be + en) / 2;
				if (jud(*(a + mid), val) != 1)
					en = mid;
				else
					be = mid + 1;
			}
		if (!f_small && jud(*(a + be), val) == -1) be--;
		if (f_small && jud(*(a + be), val) == 1) be++;
	}
	return be;
}

template<class T> inline T lowb(T num) {
	return num & (-num);
}
#ifdef GPP
inline int bitnum(ui nValue) {
	return __builtin_popcount(nValue);
}
inline int bitnum(int nValue) {
	return __builtin_popcount(nValue);
}
inline int bitnum(ull nValue) {
	return __builtin_popcountll(nValue);
}
inline int bitnum(ll nValue) {
	return __builtin_popcountll(nValue);
}
inline int bitmaxl(ui a) {
	if (a == 0) return 0;
	return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
	if (a == 0) return 0;
	return 32 - __builtin_clz(a);
}
inline int bitmaxl(ull a) {
	if (a == 0) return 0;
	return 64 - __builtin_clzll(a);
}
inline int bitmaxl(ll a) {
	if (a == 0) return 0;
	return 64 - __builtin_clzll(a);
}
#else
#endif

long long pow(long long n, long long m, long long mod = 0) {
	if (m < 0) return 0;
	long long ans = 1;
	long long k = n;
	while (m) {
		if (m & 1) {
			ans *= k;
			if (mod) ans %= mod;
		}
		k *= k;
		if (mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

#define  MOD 1000000007
template<class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
	if (mod == -1) mod = MOD;
	a += b;
	while (a >= mod)
		a -= mod;
	while (a < 0)
		a += mod;
}
template<class t>
void output1(t arr) {
	for (int i = 0; i < (int) arr.size(); i++)
		cerr << arr[i] << ' ';
	cerr << endl;
}
template<class t>
void output2(t arr) {
	for (int i = 0; i < (int) arr.size(); i++)
		output1(arr[i]);
}

//....................密..........封..........线..........下..........禁..........止..........hack...............................................

const int maxn = 510;
ll dp_con[maxn], sum_con[maxn], dp[maxn][maxn], sum[maxn][maxn];
int c[maxn][maxn];
int n, m, mod;

inline ll Arth(ll n) {
	return n * (n + 1) / 2 % mod;
}

int main() {

//............................不要再忘了检查maxn大小了！！！！BSBandme你个SB！！！！...................................................

	ios_base::sync_with_stdio(0);
#ifdef DEBUG //......................................................................................................
	freopen("input.txt", "r", stdin);
#endif //...........................................................................................................

	scanf("%d%d%d", &n, &m, &mod);
	for (int i = 0; i < maxn; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++) {
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
			c[i][j] %= mod;
		}
	}

	dp_con[1] = 2;
	dp_con[0] = 1;
	sum_con[1] = sum_con[0] = 0;
	for (int i = 2; i <= m; i++) {
		dp_con[i] = 0;
		sum_con[i] = 0;
		for (int j = 0; j < i; j++) {
			ll rcon = dp_con[j] * dp_con[i - j - 1] % mod * c[i - 1][j] % mod;
			dp_con[i] += rcon * (i + 1) % mod;
			sum_con[i] += (dp_con[j] * sum_con[i - j - 1] + sum_con[j] * dp_con[i - j - 1]) % mod * c[i - 1][j] % mod * (i + 1) % mod;
			sum_con[i] += rcon * (Arth(j) + Arth(i - 1 - j)) % mod;
		}
		dp_con[i] %= mod;
		sum_con[i] %= mod;
	}

	dp[0][0] = 1;
	for (int i = 0; i < m; i++) for (int j = 0; j <= i; j++) if (dp[i][j]) {
		for (int k = 1; k + i <= m; k++) {
			dp[i + k][j + 1] += dp[i][j] * dp_con[k] % mod * c[i + k][k];
			dp[i + k][j + 1] %= mod;
			sum[i + k][j + 1] += (dp[i][j] * sum_con[k] + sum[i][j] * dp_con[k]) % mod * c[i + k][k];
			sum[i + k][j + 1] %= mod;
		}
	}

	ll ans = 0;
	for (int j = 1; j <= m; j++) {
		if (n - (m - 1 + j) < 0) break;
		ans += sum[m][j] * c[n - (m - 1 + j) + j][j] % mod;
		ans %= mod;
	}

	printf("%I64d\n", ans);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<int>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=105,mod=998244353;
ll f[N],dp[N],DP[N<<1],val[N][N];
poly v[N],way[N][N],d[N];
PI a[N];
int n,rt,e[N][N],fir[N][N],lst[N][N],cover[N][N];
void dfs_way(int p,int fa){
	way[rt][p]=way[rt][fa]; way[rt][p].pb(p);
	for(auto i:v[p])if(i!=fa)dfs_way(i,p);
}
ll mul(PI a,PI b){
	return (ll)a.fi*b.se-(ll)a.se*b.fi;
}
PI operator -(PI a,PI b){
	return mp(a.fi-b.fi,a.se-b.se);
}
bool cmp(int x,int y){
	return a[x].se==a[y].se?a[x].fi<a[y].fi:a[x].se<a[y].se;
}
int half(PI x){
	return x.se<0||(x.se==0&&x.fi<0);
}
bool cnm(PI x,PI y){
	PI A=a[x.se]-a[x.fi],B=a[y.se]-a[y.fi];
	int X=half(A),Y=half(B);
	return X==Y?mul(A,B)>0:X<Y;
}

void dfs(int p,int fa){
	for(auto it=v[p].begin();it!=v[p].end();it++)if(*it==fa){v[p].erase(it); break;}
	d[p].pb(p);
	for(auto i:v[p]){
		dfs(i,p); for(auto j:d[i])d[p].pb(j);
	}
	f[p]=1;
	for(auto i:v[p])f[p]=f[p]*dp[i]%mod;
	dp[p]=f[p];
	for(auto i:v[p]){
		ll zs=f[i];
		for(auto j:v[p])if(i!=j)zs=zs*dp[j]%mod;
		dp[p]=(dp[p]+zs)%mod;
	}
	int k=0;
	mem(e);
	for(auto i:d[p])for(auto j:v[i]){
		e[i][j]=++k; e[j][i]=++k;
	}
	vector<PI> al;
	sort(d[p].begin(),d[p].end(),cmp);
	int m=d[p].size();
	for(auto i:d[p])for(auto j:d[p])if(way[i][j].size()>=3&&mul(a[j]-a[i],a[p]-a[i])>=0){
		al.pb(mp(i,j));
		int sz=way[i][j].size();
		fir[i][j]=e[way[i][j][0]][way[i][j][1]];
		lst[i][j]=e[way[i][j].back()][way[i][j][sz-2]];
		cover[i][j]=0; val[i][j]=1;
		For(o,0,sz-1){
			int x=o?way[i][j][o-1]:-1,y=o<=sz-2?way[i][j][o+1]:-1,dq=way[i][j][o];
			for(auto son:v[dq])if(son!=x&&son!=y){
				if(x<0){
					if(mul(a[y]-a[dq],a[son]-a[dq])>0)continue;
				}else if(y<0){
					if(mul(a[son]-a[x],a[dq]-a[x])<0)continue;
				}else{
					int A=mul(a[y]-a[dq],a[son]-a[dq])>0,B=mul(a[son]-a[x],a[dq]-a[x])<0;
					if(mul(a[dq]-a[x],a[y]-a[x])>0){
						if(A&&B)continue;
						//if(A||B)cout<<p<<" "<<x<<" "<<dq<<" "<<y<<" "<<son<<endl;
					}else{
						if(A||B)continue;
					}
				}
				val[i][j]=val[i][j]*dp[son]%mod;
				//cover[i][j]|=son==p;
				//if(i==3&&j==4&&p==4)cout<<son<<endl;
			}
			cover[i][j]|=dq==p;
		}
	}
	sort(al.begin(),al.end(),cnm);
	//if(p==1)for(auto i:al)cout<<i.fi<<" zyy "<<i.se<<endl;
	//if(p==4)For(i,0,m-1)cout<<d[p][i]<<endl;
	//if(p==4)cout<<e[4][2]<<endl;
	For(i,0,m-1)For(j,i+1,m-1)if(e[d[p][i]][d[p][j]]){
		//cout<<d[p][i]<<" fly "<<d[p][j]<<" "<<a[d[p][i]].se<<" "<<a[d[p][j]].se<<endl;
		for(int ban=-1;ban<=1;ban+=2){
			mem(DP);
			DP[e[d[p][i]][d[p][j]]]=1;
			for(auto o:al){
				if(ban==-1&&cover[o.fi][o.se])continue;
				int S=fir[o.fi][o.se],T=lst[o.fi][o.se];
				DP[T]=(DP[T]+DP[S]*val[o.fi][o.se])%mod;
				//if(p==1&&d[p][i]==4&&d[p][j]==6)cout<<o.fi<<" "<<o.se<<" "<<val[o.fi][o.se]<<endl;
			}
			DP[e[d[p][i]][d[p][j]]]+=mod-1;
			dp[p]+=ban*DP[e[d[p][i]][d[p][j]]];
			//if(p==1)cout<<d[p][i]<<" "<<d[p][j]<<" "<<dp[p]<<" "<<ban*DP[e[d[p][i]][d[p][j]]]<<endl;
		}
	}
	//cout<<dp[p]<<" dpdpdp "<<d[p].size()<<endl;
	dp[p]=(dp[p]%mod+mod)%mod;
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n){
		a[i].fi=read(); a[i].se=read();
	}
	For(i,1,n-1){
		int s=read(),t=read();
		v[s].pb(t); v[t].pb(s);
	}
	For(i,1,n){
		rt=i; dfs_way(i,0);
		For(j,1,n){
			for(auto k:way[i][j])if(mul(a[j]-a[i],a[k]-a[i])<0){way[i][j].clear(); break;}
		}
	}
	dfs(1,0);
	cout<<dp[1]<<endl;
}
/*
4
0 -3
-5 -3
5 -5
4 5
3 1
4 1
1 2

*/


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, x, b, y;

int main()
{
    scanf("%d %d %d %d %d", &n, &a, &x, &b, &y);
    while(a != x && b != y)
    {
        if(a == b)
        {
            printf("YES");
            return 0;
        }
        a++;
        if(a == n + 1)
        {
            a = 1;
        }
        b--;
        if(b == 0)
        {
            b = n;
        }
    }
    if(a == b)
    {
        printf("YES");
        return 0;
    }
    printf("NO");
}


#include <iostream>
#include <vector>
#define ll long long
using namespace std;
const ll md = (1e9) + 7;
vector<ll> v;ll to,n,k,ar[9]={1,2,9,64,625,7776,117649,2097152};
ll pw(ll b,ll e)
{
	ll t=1;
	while (e)
	{
		if (e&1) {t*=b;t%=md;}
		b*=b;b%=md;e>>=1;
	}
	return t;
}
void rs(ll d)
{
	if (d)
	{
		for (int i=0;i<k;i++)
		{
			v.push_back(i);
			rs(d-1);
			v.pop_back();
		}
	}
	else
	{
		int bt[9]={},cr,isv[9]={};
		vector<int> vv;
		bool x = 1;
		for (int i=0;i<k;i++)
		{
			cr = i;isv[0] = 1;
			while (!bt[cr])
			{
				bt[cr] = 1;
				vv.push_back(cr);
				cr = v[cr];
			}
			if (!isv[cr]) {x=0;break;}
			for (int i=0;i<vv.size();i++)
			{
				isv[vv[i]]=1;
			}
			//cout<<v[i]<<" "<<x<<"\n";
		}
		to+=x;
	}
}
int main()
{
	cin>>n>>k;
	cout<<(ar[k-1] * pw(n-k,n-k))%md<<"\n";
	return 0;
}


/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Feb. 12th 2013 **/ //{

/** Header .. **/ //{
#define LOCAL

#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 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 LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#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 PTT pair<T, T>
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#define Display(A, n, m) {                      \
	REP(i, n){		                            \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;				            \
	}						                    \
}

#define Display_1(A, n, m) {				    \
	REP_1(i, n){		                        \
        REP_1(j, m) cout << A[i][j] << " ";     \
		cout << endl;		            		\
	}						                    \
}

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
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 T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &x){
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}

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();}

template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** 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 DB EPS = 1e-9;
const DB OO = 1e15;
const DB 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;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '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;}

inline int low_idx(int x){return __builtin_ffs(x);}
inline int low_idx(LL x){return __builtin_ffsll(x);}
inline int high_idx(int x){return low_idx(reverse_bits(x));}
inline int high_idx(LL x){return low_idx(reverse_bits(x));}
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 parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int lg2(int a){return 31 - clz(a);}
inline int lg2(LL a){return 63 - clz(a);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}
//}

/** Miscellaneous .. **/ //{
// <<= 'Random Event .. . //{
namespace RNG{
//srand((unsigned)time(NULL));
inline unsigned int rand16(){return ((rand()) << 15) ^ rand();}
inline unsigned int rand32(){return (rand16() << 16) | rand16();}
inline ULL rand64(){return ((LL)rand32() << 32) | rand32();}
inline ULL random(LL l, LL r){return l == r ? l : rand64() % (r - l) + l;}
int dice(){return rand() % 6;}
bool coin(){return bool(rand() % 2);}
} using namespace RNG;
//}
// <<= 'Clock .. . //{
namespace CLOCK{
DB s0, s1, rd, k, T;
inline DB getTime(){
#ifdef LOCAL
    return 1.0 * clock() / CLOCKS_PER_SEC;
#else
    timeval tv;
    gettimeofday(&tv, 0);
    return tv.tv_sec + tv.tv_usec * 1e-6;
#endif
}

inline void st0(DB _T = 0.98){T = _T, s0 = getTime();}
inline void st1(DB _k = 1.618){k = _k, s1 = getTime();}
inline void ed1(){rd = getTime() - s1;}
inline DB elapsed(){return getTime() - s0;}
inline bool safe(){return elapsed() + rd * k < T;}
} //using namespace CLOCK;
//}
// <<= 'Temp .. . //{
namespace TMP{
template<class T> PTT operator+(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi + p2.fi, p1.se + p2.se);
}

template<class T> PTT operator-(const PTT &p1, const PTT &p2) {
	return PTT(p1.fi - p2.fi, p1.se - p2.se);
}

template<class T> PTT operator*(const PTT &lhs, T k){
    return PTT(lhs.fi * k, lhs.se * k);
}
} using namespace TMP;
//}
//}

/** Algorithm    .. */ //{
// <<= '-. Math .,//{
namespace Math{
	typedef long long typec;
	///Lib functions
	typec GCD(typec a, typec b)
	{
		return b ? GCD(b, a % b) : a;
	}
	typec extendGCD(typec a, typec b, typec& x, typec& y)
	{
		if(!b) return x = 1, y = 0, a;
		typec res = extendGCD(b, a % b, x, y), tmp = x;
		x = y, y = tmp - (a / b) * y;
		return res;
	}
	///for x^k
	typec power(typec x, typec k)
	{
		typec res = 1;
		while(k)
		{
			if(k&1) res *= x;
			x *= x, k >>= 1;
		}
		return res;
	}
	///for x^k mod m
	typec powerMod(typec x, typec k, typec m)
	{
		typec res = 1;
		while(x %= m, k)
		{
			if(k&1) res *= x, res %= m;
			x *= x, k >>=1;
		}
		return res;
	}
	/***************************************
	Inverse in mod p^t system
	***************************************/
	typec inverse(typec a, typec p, typec t = 1)
	{
		typec pt = power(p, t);
		typec x, y;
	    y = extendGCD(a, pt, x, y);
		return x < 0 ? x += pt : x;
	}
	/***************************************
	Linear congruence theorem
	x = a (mod p)
	x = b (mod q)
	for gcd(p, q) = 1, 0 <= x < pq
	***************************************/
	typec linearCongruence(typec a, typec b, typec p, typec q)
	{
		typec x, y;
		y = extendGCD(p, q, x, y);
		while(b < a) b += q / y;
		x *= b - a, x = p * x + a, x %= p * q;
		if(x < 0) x += p * q;
		return x;
	}
	/***************************************
	prime table
	O(n)
	***************************************/
	const int PRIMERANGE = 1000000;
	int prime[PRIMERANGE + 1];
	int mobius[PRIMERANGE + 1];
	int getPrime()
	{
		memset (prime, 0, sizeof (int) * (PRIMERANGE + 1));
		memset(mobius , 0 , sizeof(mobius));
		mobius[1] = 1;
		for (int i = 2; i <= PRIMERANGE; i++)
		{
			if (!prime[i]) prime[++prime[0]] = i , mobius[i] = -1;
			for (int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j++)
			{
				prime[prime[j]*i] = 1;
				if (i % prime[j] == 0) break;
				else mobius[i * prime[j]] = -mobius[i];
			}
		}
		return prime[0];
	}
	/***************************************
	get factor of n
	O(sqrt(n))
	factor[][0] is prime factor
	factor[][1] is factor generated by this prime
	factor[][2] is factor counter

	need: Prime Table
	***************************************/
	///you should init the prime table before
	int factor[100][3], facCnt;
	int getFactors(int x)
	{
		facCnt = 0;
		int tmp = x;
		for(int i = 1; prime[i] <= tmp / prime[i]; i++)
		{
			factor[facCnt][1] = 1, factor[facCnt][2] = 0;
			if(tmp % prime[i] == 0)
				factor[facCnt][0] = prime[i];
			while(tmp % prime[i] == 0)
				factor[facCnt][2]++, factor[facCnt][1] *= prime[i], tmp /= prime[i];
			if(factor[facCnt][1] > 1) facCnt++;
		}
		if(tmp != 1)
			factor[facCnt][0] = tmp, factor[facCnt][1] = tmp, factor[facCnt++][2] = 1;
		return facCnt;
	}
	typec combinationModP(typec n, typec k, typec p)
	{
		if(k > n) return 0;
		if(n - k < k) k = n - k;
		typec a = 1, b = 1, x, y;
		int pcnt = 0;
		for(int i = 1; i <= k; i++)
		{
			x = n - i + 1, y = i;
			while(x % p == 0) x /= p, pcnt++;
			while(y % p == 0) y /= p, pcnt--;
			x %= p, y %= p, a *= x, b *= y;
			b %= p, a %= p;
		}
		if(pcnt) return 0;
		extendGCD(b, p, x, y);
		if(x < 0) x += p;
		a *= x, a %= p;
		return a;
	}
};//using namespace Math;
//}
// <<= '-. Geo ,.//{
namespace Geo{
	#define typec double
    const typec eps=1e-15;
    int dblcmp(double d){
        return d < -eps ? -1 : d > eps;
    }
    int sgn(double a) {return a<-eps?-1:a>eps;}
    inline double sqr(double x){return x*x;}
}using namespace Geo;
//}
//}

/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    //scanf("%d", &x);
    char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    return x;
}

inline DB& RF(DB &x){
    //cin >> x;
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    //printf("%d\n", x);
    cout << x << endl;
}
//}
/* .................................................................................................................................. */
struct point
{
    double x,y;
    point(){}
    point(double _x,double _y):
    x(_x),y(_y){};
    void input()
    {
        scanf("%lf%lf",&x,&y);
    }
    void output()
    {
        printf("%.2f %.2f\n",x,y);
    }
    bool operator==(point a)const
    {
        return dblcmp(a.x-x)==0&&dblcmp(a.y-y)==0;
    }
    bool operator<(point a)const
    {
        return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x;
    }
    double len()
    {
        return hypot(x,y);
    }
    double len2()
    {
        return x*x+y*y;
    }
    double distance(point p)
    {
        return hypot(x-p.x,y-p.y);
    }
    double distance2(point p)
    {
        return sqr(x-p.x)+sqr(y-p.y);
    }
    point add(point p)
    {
        return point(x+p.x,y+p.y);
    }
    point operator + (const point & p) const{
        return point(x+p.x,y+p.y);
    }
    point sub(point p)
    {
        return point(x-p.x,y-p.y);
    }
    point operator - (const point & p) const{
        return point(x-p.x,y-p.y);
    }
    point mul(double b)
    {
        return point(x*b,y*b);
    }
    point div(double b)
    {
        return point(x/b,y/b);
    }
    double dot(point p)
    {
        return x*p.x+y*p.y;
    }
    double operator * (const point & p) const{
        return x*p.x+y*p.y;
    }
    double det(point p)
    {
        return x*p.y-y*p.x;
    }
    double operator ^ (const point & p) const{
        return x*p.y-y*p.x;
    }
    double rad(point a,point b)
    {
    	point p=*this;
    	return fabs(atan2(fabs(a.sub(p).det(b.sub(p))),a.sub(p).dot(b.sub(p))));
	}
    point trunc(double r)
	{
		double l=len();
		if (!dblcmp(l))return *this;
		r/=l;
		return point(x*r,y*r);
	}
    point rotleft()
    {
        return point(-y,x);
    }
    point rotright()
    {
        return point(y,-x);
    }
    point rotate(point p,double angle)//�Ƶ�p��ʱ����תangle�Ƕ�
    {
        point v=this->sub(p);
        double c=cos(angle),s=sin(angle);
        return point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    }
};

const int N = 21;
double a[N] , l , r;
#define Point2D point
Point2D p[N];
int n;
double dp[1 << N];
//line XX;
double f(double now , int k){
    if (dblcmp(now - r) >= 0) return r;
//    double rad = p[k].rad(Point2D(now , 0) , Point2D(r , 0));
////    printf("%.9lf\n" , rad);
//    if (dblcmp(rad - a[k]) <= 0) return r;
//    point dd = point(now , 0);
//    dd = dd.rotate(p[k] , a[k]);
//    dd = line(p[k] , dd).crosspoint(XX);
//    return dd.x;
    double beta = atan2(p[k].y , (p[k].x - now));
    double bb = beta * 180. / PI;
    if (dblcmp(bb + a[k] - 180.) >= 0) return r;
//    double bb = beta * 180. / PI;
    double rr = 180. - bb - a[k];
    return sqrt(sqr(p[k].y) + sqr(p[k].x - now)) / sin(rr * PI / 180.) * sin(a[k] * PI / 180.) + now;
}
void solve(){
//    XX = line(point(-1e5 , 0) , point(1e5 , 0));
    if (dblcmp(l - r) >= 0){
        puts("0.000000000");
        return;
    }
    RST(dp);
    for (int i = 0 ; i < n ; ++i){
        p[i].input();
        cin >> a[i];
//        a[i] *= PI;
//        a[i] /= 180.;
    }
    double ans = l;
    for (int i = 0 ; i < _1(n) ; ++i)
        dp[i] = l;
    for (int i = 0 ; i < _1(n) ; ++i){
//        checkMax(ans , dp[i]);
        for(int j = 0 ; j < n ; ++j) if ((i & _1(j)) == 0){
            checkMax(dp[(i | _1(j))] , f(dp[(i)] , j));
        }
    }
    checkMax(ans , dp[_1(n) - 1]);
    checkMin(ans , r);
    printf("%.15lf\n" , ans - l);
}
int main(){
    cin >> n >> l >> r; ;solve();
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const long long MOD = 1000000007LL;

int N, M, K;
long long c[1010][1010];

int main()
{
	int i, j, k;
	scanf("%d%d%d", &N, &M, &K);
	if (K*2>N-1 || K*2>M-1)
	{
		puts("0");
		return 0;
	}
	c[0][0] = 1LL;
	for (i = 1; i <= max(N-1, M-1); ++i)
	{
		c[i][0] = 1;
		for (j = 1; j <= i; ++j)
			c[i][j] = (c[i-1][j]+c[i-1][j-1])%MOD;
	}
	printf("%ld\n", (c[N-1][2*K]*c[M-1][2*K])%MOD);
	return 0;
}


#pragma comment(linker, "/STACK:500000000")
#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <ctype.h>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <string>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#define Int long long
#define INF 0x3F3F3F3F
#define eps 1e-9
using namespace std;

#define N 1000009

int a[N];
int fa[N];

const int mod = 1000000007;

int modpow(int a, int n, int mod)
{
	int b = 1;
	while(n > 0)
	{
		if (n & 1)
			b = (long long)b * a % mod;
		n >>= 1;
		a = (long long)a * a % mod;
	}
	return b;
}

int f(int n, int m)
{
	if (n == m)
		return a[n]; //a[n-1] + (n-1)*a[n-2];
	return (Int)f(n - 1, m) * n % mod;
}

int f2(int n, int m)
{
	return (Int)fa[n] * modpow(fa[m], mod - 2, mod) % mod * a[m] % mod;
}

int main()
{
	int n, aa, i, m;
	a[1] = 1;
	a[2] = 2;
	for(n = 3; n < N; n++)
		a[n] = (a[n-1] + (Int)(n-1)*a[n-2]) % mod;
	fa[0] = 1;
	for(n = 1; n < N; n++)
		fa[n] = (Int)fa[n - 1] * n % mod;
	cin >> n;
	m = 0;
	for(i = 0; i < n; i++)
	{
		cin >> aa;
		m += aa == 1;
	}
	if (m == 0)
		m++;
	//cout << f(n, m) << endl;
	cout << f2(n, m) << endl;
}

//
//#define N 1000009
//
//int A[N];
//int n;
//int p[N];
//set<vector<int> > res;
//
//void brute()
//{
//	int i, j;
//	for(i = 0; i < n; i++)
//	{
//		if (A[i])
//		{
//			for(j = i + 1; j < n; j++)
//			{
//				if (A[j])
//				{
//					A[i]--;
//					A[j]--;
//					swap(p[i], p[j]);
//					brute();
//					A[i]++;
//					A[j]++;
//					swap(p[i], p[j]);
//				}
//			}
//		}
//	}
//	res.insert(vector<int>(p, p + n));
//}
//
//int main()
//{
//	int m, i, j;
//	//cin >> n >> m;
//	FILE *f = freopen("in2.txt", "w", stdout);
//	for(n = 9; n <= 10; n++)
//	{
//		for(m = 1; m <= n; m++)
//		{
//			for(i = 0; i < n; i++)
//			{
//				p[i] = i;
//				A[i] = i < m ? 1 : 2;
//			}
//			res.clear();
//			brute();
//			printf("%9d, ", res.size());
//			fflush(f);
//		}
//		puts("");
//	}
//	cout << res.size() << endl;
//}


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

#define rep(i, n) for (int i = 0; i < (int)n; i++)

int N;
vector<int> A, C, L;
vector<vector<int>> D;

int main()
{
    cin >> N;

    int mx = 0, id;
    A.resize(N); C.assign(100, 0);
    rep(i, N)
    {
        cin >> A[i]; A[i]--; C[A[i]]++;
        if (C[A[i]] > mx) mx = C[A[i]], id = A[i];
    }

    C.assign(100, 0);
    D.assign(N, vector<int>(100));
    rep(i, N)
    {
        C[A[i]]++;
        rep(j, 100) D[i][j] = C[j] - C[id];
    }

    int ans = 0;
    rep(j, 100) if (j != id)
    {
        L.assign(2 * N + 1, -1); L[N] = 0;
        rep(i, N)
        {
            if (L[N + D[i][j]] == -1) L[N + D[i][j]] = i + 1;
            else ans = max(ans, i - L[N + D[i][j]] + 1);
        }
    }

    cout << ans << '\n';
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n;
    int k;
    long M;
    long Mtask = 0;

    cin >> n;
    cin >> k;
    cin >> M;
    vector <int> times(k);

    for (int i = 0; i < k; i++) {
        cin >> times[i];
        Mtask += times[i];
    }
    sort (times.begin(), times.end());

    long maxTask = M / Mtask;
    if (maxTask > n) {
        maxTask = n;
    }

    int points = 0;
    int maxpoints = 0;
    for (int i = 0; i <= maxTask; ++i) {
        long cM = M;
        points = (k + 1) * i;

        cM -= Mtask * i;

        int remainderN = n - i;

        int y = 0;
        while ((cM > 0) && (y < k)) {
            if (cM >= times[y] * remainderN) {
                points += remainderN;
                cM -= times[y] * remainderN;
                y++;
            } else {
                points += cM / times[y];
                cM = 0;
                break;
            }
        }

        if (points > maxpoints) {
            maxpoints = points;
        }
    }

    cout << maxpoints;

}


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

    int n,k;
    string s;
    cin>>n>>k>>s;
    if(n==1 && k==1){
        cout<<"0"<<endl;
        return 0;
    }
    else if(k==0){
        cout<<s<<endl;
        return 0;
    }
    else if(s[0]=='1'){
        for(int i=1;i<n && k>0;i++){
            if(s[i]!='0'){
            s[i]='0';
            k--;
            }
        }

    }
    else{
        s[0]='1';
        k--;
        for(int i=1;i<n && k>0;i++){
            if(s[i]!='0'){
            s[i]='0';
            k--;
            }
        }
      }
    cout<<s<<endl;
    return 0;
    }


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

typedef double ld;
const int MAX=800000+10;
const ld INF=1e30;
const ld EPS=0.02;

struct point
{
	ld x,y;
	point(ld a,ld b){x=a;y=b;}
	point(){}
	void print(){printf("%lf %lf\n",x,y);}
};

ld sqr(ld x)
{
	return x*x;
}

ld dist(const point& a,const point& b)
{
	return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}

ld chaji(const point& s,const point& a,const point& b)
{
	return (a.x-s.x)*(b.y-s.y)-(a.y-s.y)*(b.x-s.x);
}

int n,S,T;
point d[MAX],TOP(0,INF);

int begin[MAX*4],t[MAX*4],tot,next[MAX*4];
ld c[MAX*4];

void addedge(int x,int y,ld v)
{
	t[++tot]=y;
	next[tot]=begin[x];
	begin[x]=tot;
	c[tot]=v;
}

struct line
{
	int s,t,type,number;
	line(){}
	line(int a,int b){s=a;t=b;type=0;}
	void print()const
	{
		d[s].print();
		d[t].print();
		printf("\n");
	}
}l[MAX];

point get(point b,point c,ld x)
{
	ld k=(x-b.x)/(c.x-b.x);
	return point(b.x+(c.x-b.x)*k,b.y+(c.y-b.y)*k);
}

int operator < (const line& a,const line& b)
{
	ld l=max(d[a.s].x,d[b.s].x),r=min(d[a.t].x,d[b.t].x);
	ld x=(l+r)*0.5;
	point s1=get(d[a.s],d[a.t],x),s2=get(d[b.s],d[b.t],x);
	if(s1.y!=s2.y)return s1.y<s2.y;
	else return a.number<b.number;
}

set<line> st;

struct accident
{
	int x,num,flag;
	accident(ld c,int a,int b){x=c;num=a;flag=b;}
	accident(){}
}p[MAX];

int operator < (const accident& a,const accident& b)
{
	return a.x<b.x;
}

int num;

void add(ld x,line A,line B)
{
	point a=d[A.s],h=d[A.t],b=d[B.s],c=d[B.t];
	point e=get(b,c,x),f=get(a,h,x);

	addedge(A.s,B.s,dist(a,f)+dist(f,e)+dist(e,b));
	addedge(A.s,B.t,dist(a,f)+dist(f,e)+dist(e,c));

	addedge(A.t,B.s,dist(h,f)+dist(f,e)+dist(e,b));
	addedge(A.t,B.t,dist(h,f)+dist(f,e)+dist(e,c));
}

int same(ld x,line A,line B)
{
	point a=d[A.s],h=d[A.t],b=d[B.s],c=d[B.t];
	point e=get(b,c,x),f=get(a,h,x);
	return fabs(e.y-f.y)<0.0000000001;
}

queue<int> q;
int hh[MAX];
ld dis[MAX];

ld SPFA()
{
	int i,u,v;
	for(i=1;i<=n;++i)
		dis[i]=INF;
	q.push(S);dis[S]=0;hh[S]=1;
	while(!q.empty())
	{
		u=q.front();q.pop();
		hh[u]=0;
		for(i=begin[u];i;i=next[i])
		{
			v=t[i];
			if(dis[v]>dis[u]+c[i])
			{
				dis[v]=dis[u]+c[i];
				if(!hh[v])
				{
					hh[v]=1;
					q.push(v);
				}
			}
		}
	}
	return dis[T];
}

void update(int now)
{
	set<line>::iterator ii,it=st.find(l[p[now].num]);
	if(it==st.end())
		return;
	if(it->type==-1)
	{
		ii=it;
		++ii;

		while(same(p[now].x,*ii,*it) && ii->type==it->type)
		{
			++ii;
			if(ii==st.end())
				return;
		}

		if(ii==st.end())
			return;
	}
	if(it->type==1)
	{
		if(it==st.begin())
			return;
		ii=it;
		--ii;
		while(same(p[now].x,*ii,*it) && ii->type==it->type)
		{
			if(ii==st.begin())
				return;
			--ii;
		}
		swap(ii,it);
	}
	if(it->type==ii->type)
		return;
	/*
	if(p[now].flag==1 && p[now].num==2)
	{
		ii->print();
		it->print();
		printf("\n");
	}
	*/
	add(p[now].x,*ii,*it);
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
	int i,j,now;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%lf%lf",&d[i].x,&d[i].y);
	scanf("%d%d",&S,&T);
	for(i=1;i<=n;++i)
	{
		j=(i==n?1:i+1);
		addedge(i,j,dist(d[i],d[j]));
		addedge(j,i,dist(d[j],d[i]));
		l[i]=line(i,j);
		l[i].number=i;
		if(d[i].x!=d[j].x)
		{
			if(chaji(d[i],d[j],TOP)>=0)
				l[i].type=-1;
			else l[i].type=1;
			if(d[l[i].s].x>d[l[i].t].x)
				swap(l[i].s,l[i].t);
			p[++num]=accident( (int)d[l[i].s].x ,i,1);
			p[++num]=accident( (int)d[l[i].t].x ,i,-1);
		}
	}
	set<line>::iterator it;
	sort(p+1,p+num+1);
	for(now=1;now<=num;)
	{
		j=now;
		while(j<=num && p[j].x==p[now].x)
		{
			if(p[j].flag==1)
			{
				st.insert(l[p[j].num]);
//				printf("%d\n",p[j].num);
			}
			++j;
		}

		j=now;
		while(j<=num && p[j].x==p[now].x)
			update(j),++j;

		j=now;
		while(j<=num && p[j].x==p[now].x)
		{
			if(p[j].flag==-1)
			{
				st.erase(l[p[j].num]);
			}
			++j;
		}

		now=j;
	}
	ld ans=SPFA();
	printf("%lf\n",ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<cmath>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define p3i pair<pair<int, int>, int>
#define mp make_pair
#define pb push_back
#define pll pair<long long, long long>
#define p3l pair<pair<long long, long long>, long long>
#define x first
#define y second

int n, m; char ch; bool b=0;
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int l=0; l<n*m; ++l){
        cin >> ch;
        if (ch!='B' && ch!='W' && ch!='G') b=1;
    }
    if (b) cout << "#Color";
    else cout << "#Black&White";
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

#ifdef ONLINE_JUDGE

#define fin cin
#define fout cout

#else

fstream fin("input.txt", fstream::in);
fstream fout("output.txt", fstream::out);

#endif

bool win(long long a, long long b) {
	if (a > b) {
		swap(a, b);
	}
	if (a == 0) {
		return false;
	}
	bool next = win(a, b % a);
	return !next || (((b / a) % (a + 1)) % 2 == 0);
}

int main() {
	fout.precision(10);
	fout << fixed;

	int T;
	fin >> T;
	for (int t = 0; t < T; ++t) {
		long long A, B;
		fin >> A >> B;
		if (win(A, B)) {
			fout << "First\n";
		} else {
			fout << "Second\n";
		}
	}

	return 0;
}


//#pragma GCC optimize(3)
#include <random>
#include <stdio.h>
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<int, int> pii;
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
#define Return(x) { x; return; }
#define P2(x) ((x) * (x))
#define lowbit(x) ((x) & -(x))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define MEM(x, y) memset((x), (y), sizeof(x))
#define MEN(x, y, z) memset((x), (y), sizeof((x)[0]) * (z))
#define Diz(x) (lower_bound(dz.begin(), dz.end(), (x)) - dz.begin())
#define DISCRETIZA(x) (x).push_back(-INF), sort((x).begin(), (x).end()), (x).erase(unique((x).begin(), (x).end()), (x).end())
#ifdef LOCAL
#define DEBUG(...) cout << ">> " << #__VA_ARGS__ << " =", PRT(__VA_ARGS__), cout << endl;
#define DEBUGS(...) cout << ">> " << #__VA_ARGS__ << " =", PRTS(__VA_ARGS__), cout << endl;
void PRT() {} template <typename S, typename... T> void PRT(S x, T ... y){ cout << " " << x; PRT(y...); }
void PRTS() {} template <typename S> void PRTS(S x) { for (auto v : x) cout << " " << v; }
#define TIME cout << "RunTime: " << clock() << "ms\n", 0
#define __int128_t long long
#else
#define DEBUG(...) ;
#define DEBUGS(...) ;
#define TIME 0
#endif

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
template<typename S, typename T> inline bool Min(S &a, const T &b){ return a > b ? a = b, true : false; }
template<typename S, typename T> inline bool Max(S &a, const T &b){ return a < b ? a = b, true : false; }
template<typename S, typename T> inline void Adm(S &a, const T &b){ a = (a + b) % MOD; if (a < 0) a += MOD; }
template<typename S, typename T> inline void Mum(S &a, const T &b){ a = 1LL * a * b % MOD; }
template<typename T> inline bool IsPri(T x) { if (x < 2) return false; for (T i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; }
template<typename T> inline T Gcd(T a, T b){ while (b){ T t = b; b = a % b; a = t; } return a; }
template<typename T> inline int BitCnt(T x){ int cnt = 0; while (x)++cnt, x &= x - 1; return cnt; }
template<typename T> inline T MDis(T x1, T y1, T x2, T y2){ return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> inline T MDis(T x1, T y1, T z1, T x2, T y2, T z2){ return abs(x1 - x2) + abs(y1 - y2) + abs(z1 - z2); }
inline double EDis(double x1, double y1, double x2, double y2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
inline double EDis(double x1, double y1, double z1, double x2, double y2, double z2){ return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2)); }
inline ll Pow(ll a, ll n) { ll t = 1; a %= MOD; while (n) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t % MOD; }
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
//emplace unordered 能ll就开 函数内判非法

ll n, k;
ll calc(ll y) //计算n范围内以y为最高二进制位的数字数量
{
	ll res = 0, w = 1;
	while (y <= n) //枚举二进制长度
	{
		res += min(w, n - y + 1); //变化量和n限制取min
		y <<= 1, w <<= 1;
	}
	return res;
}
ll solve(ll y)
{
	ll res = calc(y);
	if (!(y & 1)) //如果y为偶数 可以从奇数过来
		res += calc(y + 1);
	return res;
}
int main()
{
#ifdef LOCAL
	//freopen("C:/input.txt", "r", stdin);
	//freopen("C:/output.txt", "w", stdout);
#endif
	//二分满足单调性 calc(x) >= calc(x + 2) 分奇偶二分答案
	cin >> n >> k;
	ll l = 1, r = n / 2, ans = 0; //偶数
	while (l <= r)
	{
		ll mid = l + r >> 1;
		if (solve(mid * 2) >= k) //*2
			Max(ans, mid * 2), l = mid + 1;
		else
			r = mid - 1;
	}
	l = 1, r = (n + 1) / 2; //奇数
	while (l <= r)
	{
		ll mid = l + r >> 1;
		if (solve(mid * 2 - 1) >= k) //*2-1
			Max(ans, mid * 2 - 1), l = mid + 1;
		else
			r = mid - 1;
	}
	cout << ans << endl;

	return TIME;
}


#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll n, k;
ll dp[2500][2500];
ll ans2;

bool dfs (vector<int>& v, ll K) {
    int sum = 0;
    for (int i : v) sum += i;
    if (sum > n) return 0;
    if (K <= 1) return 1;
    vector<int> nxt;
    int t = 0;
    for (int i = (int)v.size()-1; i >= 0; i--) {
        t++;
        rep(j,v[i]) nxt.push_back(t);
    }
    return dfs(nxt, K-1);
}

void hoge (vector<int>& v) {
    for (int i = v.size()==0?1:v.back(); ; i++) {
        v.push_back(i);
        if (!dfs(v, k)) {
            v.pop_back();
            break;
        }
        ans2++;
        hoge(v);
        v.pop_back();
    }
}

int main() {
    scanf("%lld%lld", &n, &k);
    if (k == 1) {
        dp[1][1] = 1;
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i][j] = (dp[i][j] + dp[i-1][j-1] + dp[i-j][j]) % MOD;
                ans = (ans + dp[i][j]) % MOD;
            }
        }
        printf("%lld\n", ans);
        return 0;
    }
    if (k == 2) {
        dp[1][1] = 1;
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                dp[i][j] = (dp[i][j] + dp[i-j][j-1]) % MOD;
                if (i >= j*(j+1)/2) dp[i][j] = (dp[i][j] + dp[i-j*(j+1)/2][j]) % MOD;
                ans = (ans + dp[i][j]) % MOD;
            }
        }
        printf("%lld\n", ans);
        return 0;
    }
    vector<int> v;
    hoge(v);
    printf("%lld\n", ans2);
}