#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,cnt,MOD=1000000007,ans=1,bik[200001],dp[1001][2];
char AA,AB,BA,BB;
map<ll,ll> mp;
ll f(ll x,ll y){
    if(y==0)return 1;
    if(y%2==0)return f(x,y/2)*f(x,y/2)%MOD;
    return x*f(x,y-1)%MOD;
}
ll comb(ll x,ll y){
    return bik[x]*f(bik[x-y],MOD-2)%MOD*f(bik[y],MOD-2)%MOD;
}
void ini(void){
    bik[0]=1;
    for(ll i=1LL;i<=200000;i++){
        bik[i]=bik[i-1]*i%MOD;
    }
    return ;
}
int main(void){
    cin>>n;
    dp[0][0]=dp[0][1]=1;
    for(int i=0;i<n;i++){
        dp[i+1][0]=dp[i][0]+dp[i][1];
        dp[i+1][0]%=MOD;
        dp[i+1][1]=dp[i][0];
    }
    if(n<=3){
        cout<<1<<endl;
        return 0;
    }
    cin>>AA>>AB>>BA>>BB;
    if(AB=='A'){
        if(AA=='A'){
            cout<<1<<endl;
            return 0;
        }
        else{
            if(BA=='B'){
                cout<<f(2,n-3)<<endl;
                return 0;
            }
            else{
                cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl;
                return 0;
            }
        }
    }
    else{
        if(BB=='B'){
            cout<<1<<endl;
            return 0;
        }
        else{
            if(BA=='A'){
                cout<<f(2,n-3)<<endl;
                return 0;
            }
            else{
                cout<<(dp[n-4][0]+dp[n-4][1])%MOD<<endl;
                return 0;
            }
        }
        
    }
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n,m,t;
int a[1111],b[1111];
int now;
int nt;
int main()
{
	ios::sync_with_stdio(0);
	bool f=0;
	cin>>n>>m>>t;
	now=n;
	rep(i,m)cin>>a[i]>>b[i];
	rep(i,m)
	{
		if(!i)now-=a[i];
		else now-=a[i]-b[i-1];
		if(now<=0)f=1;
		now+=b[i]-a[i];
		if(now>n)now=n;
	}
	now-=t-b[m-1];
	if(now<=0)f=1;
	if(f)cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}
