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

int main() {
vector<string>notes={"C", "C#","D","D#","E","F","F#","G","G#","A","B","H","C","C#","D","D#","E","F","F#","G","G#","A","B","H"};
    string s1,s2,s3,temp;
    cin>>s1>>s2>>s3;
    bool flag1=false,flag2=false,flag3=false,flag4=false,flag5=false,flag6=false;
    int cnt,cnt1,x,y,z;
while(1)
{
    cnt=0;
    cnt1=0;
    for(int i=0;i<notes.size();++i)
    {
        if(notes[i]==s1)
        {
            x=i;
            break;
        }
    }
    for(int i=0;i<notes.size();++i)
    {
        if(notes[i]==s2)
        {
            y=i;
            break;
        }
    }
    for(int i=0;i<notes.size();++i)
    {
        if(notes[i]==s3)
        {
            z=i;
            break;
        }
    }
    for(int i=x;i<notes.size();++i)
    {
        if(notes[i]!=s2)
            cnt++;
        if(notes[i]==s2)
            break;
    }

    for(int i=y;i<notes.size();++i)
    {
        if(notes[i]!=s3)
            cnt1++;
        if(notes[i]==s3)
            break;
    }
    if(cnt==4 &&cnt1==3)
    {
        cout<<"major";
        return 0;
    }
    else if(cnt==3 &&cnt1==4)
    {
        cout<<"minor";
        return 0;
    }
    flag1=true;
    if(flag1==true &&flag2==false&&flag3==false&&flag4==false&flag5==false&&flag6==false)
    {
        temp=s2;
        s2=s3;
        s3=temp;
        flag2=true;
    }
    if(flag1==true &&flag2==true&&flag3==false&&flag4==false&flag5==false&&flag6==false)
    {
        temp=s1;
        s1=s2;
        s2=temp;
        flag3=true;
    }
    if(flag1==true &&flag2==true&&flag3==true&&flag4==false&flag5==false&&flag6==false)
    {
        temp=s2;
        s2=s3;
        s3=temp;
        flag4=true;
    }
    if(flag1==true &&flag2==true&&flag3==true&&flag4==true&flag5==false&&flag6==false)
    {
        temp=s1;
        s1=s2;
        s2=temp;
        flag5=true;
    }
    if(flag1==true &&flag2==true&&flag3==true&&flag4==true&flag5==true&&flag6==false)
    {
        temp=s2;
        s2=s3;
        s3=temp;
        flag6=true;
    }
}
    cout<<"strange";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int xet(string s1)
{
    int a;
    if(s1.length()==1)
    {
        if(s1[0]=='C')
            a=1;
        else if(s1[0]=='D')
            a=3;
        else if(s1[0]=='E')
            a=5;
        else if(s1[0]=='F')
            a=6;
        else if(s1[0]=='G')
            a=8;
        else if(s1[0]=='A')
            a=10;
        else if(s1[0]=='B')
            a=11;
        else if(s1[0]=='H')
            a=12;
    }
    else
    {
        if(s1[0]=='C')
            a=2;
        else if(s1[0]=='D')
            a=4;
        else if(s1[0]=='F')
            a=7;
        else if(s1[0]=='G')
            a=9;
    }
    return a;
}
int main()
{

    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    int a=xet(s1), b=xet(s2), c=xet(s3);
    //cout<<a<<" "<<b<<" "<<c<<endl;
    int maxx,minn,giua;
    do
    {
        maxx=a;
        if(maxx<b)
            maxx=b;
        if(maxx<c)
            maxx=c;
        minn=a;
        if(minn>b)
            minn=b;
        if(minn>c)
            minn=c;
        giua=a;
        if(minn!=b && maxx!=b)
            giua=b;
        if(minn!=c && maxx!=c)
            giua=c;
       // cout<<maxx-minn<<endl;
        if(maxx-minn>7)
        {
            if(a==minn)
                a+=12;
            else if(b==minn)
                b+=12;
            else
                c+=12;
        }
    }
    while(maxx-minn>7);

  //  cout<<maxx<<" "<<giua<<" "<<minn;
   // cout<<endl;
    if(maxx-giua==3 && giua-minn==4)
        cout<<"major";
    else if(maxx-giua==4 && giua-minn==3)
        cout<<"minor";
    else
        cout<<"strange";

    return 0;
}


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

int a,i,b,c;
bool viz[30],u;
string s;

int Jora(string s) {
    if(s=="C") return 0;
    if(s=="C#") return 1;
    if(s=="D") return 2;
    if(s=="D#") return 3;
    if(s=="E") return 4;
    if(s=="F") return 5;
    if(s=="F#") return 6;
    if(s=="G") return 7;
    if(s=="G#") return 8;
    if(s=="A") return 9;
    if(s=="B") return 10;
    if(s=="H") return 11;
}

int main()
{
  cin>>s; a=Jora(s);
  cin>>s; b=Jora(s);
  cin>>s; c=Jora(s);

  viz[a]=viz[a+12]=1;
  viz[b]=viz[b+12]=1;
  viz[c]=viz[c+12]=1;

  for(i=0;i<20 && !u;++i)
  if(viz[i] && viz[i+3] && viz[i+7]) cout<<"minor\n",u=1;

  for(i=0;i<20 && !u;++i)
  if(viz[i] && viz[i+4] && viz[i+7]) cout<<"major\n",u=1;

  if(!u) cout<<"strange\n";
getch();
 return 0;
}


//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define range(i, n) for(int i = 0; i < n; ++i)
#define all(arr) arr.begin(), arr.end()
#define rall(arr) arr.rbegin(), arr.rend()

using namespace std;

typedef long long ll;
const int INFi = 2e9;
const ll INF = 2e18;
const int maxN = 2e5+1;
const int P = 998244353;
const int md = 1e9+7;
const int md2 = 1e9+9;
const int P2 = 883;

int hashes1[maxN], hashes2[maxN], cP[maxN], cP2[maxN];

int mul(int a, int b) {
    return 1ll * a * b % md;
}

int sub(int a, int b) {
    if (a - b < 0) return a - b + md;
    return a - b;
}

int add(int a, int b) {
    if (a + b > md) return a + b - md;
    return a + b;
}

void calc(vector<int> s) {
    hashes1[0] = s[0];
    cP[0] = 1;
    for(int i = 1; i < s.size(); ++i) {
        cP[i] = mul(cP[i-1], P);
        hashes1[i] = add(mul(hashes1[i-1], P), s[i]);
    }
}

int get(int l, int r) {
    if (l == 0) return hashes1[r];
    return hashes1[r] - mul(hashes1[l - 1], cP[r - l + 1]);
}

vector<int> pref;
vector<pair<int, int>> w;

pair<pair<int, int>, int> check(int l, int r) {
    int su = pref[r];
    if (l) su -= pref[l - 1];
    if (su == r - l + 1) return {{su, -1}, -1};
    pair<int, int> kek = {l, -1};
    int l1 = lower_bound(all(w), kek) - w.begin();
    pair<int, int> kek2 = {r+1,  -1};
    int r1 = upper_bound(all(w), kek) - w.begin();
    int hashe = get(l1+1, r1);
    return {{su, hashe}, (w[l1].first - l) % 2};
}

void solve() {
    int n; cin >> n;
    string t; cin >> t;
    range(i, n) {
        if (t[i] == '0') {
            if (!w.empty()) w.emplace_back(i, (i - w.back().first) % 2 + 1);
            else w.emplace_back(i, (i + 1) % 2 + 1);
        }
    }
    pref.resize(n, 0);
    pref[0] = t[0] - '0';
    for(int i = 1; i < n; ++i) {
        pref[i] = pref[i-1] + (t[i] - '0');
    }
    vector<int> k(w.size());
    for(auto p: w) k.push_back(p.second);
    calc(k);
    int q; cin >> q;
    range(_, q) {
        int l1, l2, le; cin >> l1 >> l2 >> le;
        l1--;
        l2--;
        int r1 = l1 + le;
        int r2 = l2 + le;
        r1--;
        r2--;
        if (check(l1, r1) == check(l2, r2)) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //auto sad = mt19937(2231337);
    int tests = 1;
    range(_, tests) {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define fi first
#define se second
#define y1 Enkognit
#define ld long double
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

using namespace std;
using namespace __gnu_pbds;

mt19937_64 rnd(time(0));

const ll INF=1e18;
const ll MOD=1e9+7;

template<typename T>
using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll p1=137, p2=91;

ll n, m, k, l, r, dist[200001], kl[200001], a[200001];
vector<ll> c[200001];
string s;

ll binpow(ll h,ll r,ll md=MOD)
{
    ll l=1;
    while (r)
    {
        if (r&1) l*=h, l%=md;
        h*=h;
        h%=md;
        r/=2;
    }
    return l;
}

struct segment_tree
{
    ll d[1000001];
    pll hs[1000001];

    void build(int h,int l,int r)
    {
        if (l==r)
        {
            if (s[l]=='0')
            {
                d[h]=1;
                hs[h].fi=29+(l%2)*2;
                hs[h].se=31-(l%2)*2;
            }
            return;
        }
        int w=(l+r)/2;
        build(h*2,l,w);
        build(h*2+1,w+1,r);
        d[h]=d[h*2]+d[h*2+1];
        hs[h].fi=(hs[h*2].fi+(hs[h*2+1].fi*binpow(p1,d[h*2]))%MOD)%MOD;
        hs[h].se=(hs[h*2].se+(hs[h*2+1].se*binpow(p1,d[h*2]))%MOD)%MOD;
    }

    pll get(int h,int l,int r,int x,int y,bool t)
    {
        cout << l << " " << r << " " << x << " " << y << "\n";
        if (x>y) return mp(0,0);
        if (l==x && y==r)
        {
            if (!t)
            return mp(d[h],hs[h].se); else return mp(d[h],hs[h].fi);
        }
        int w=(l+r)/2;
        pll o1=get(h*2,l,w,x,min(y,w),t), o2=get(h*2+1,w+1,r,max(x,w+1),y,t);
        pll o3;
        o3.fi=o1.fi+o2.fi;
        o3.se=(o1.se+o2.se*binpow(p1,o1.fi))%MOD;
        return o3;
    }
};

segment_tree g;

void solve()
{
    cin >> n;
    cin >> s;
    s=' '+s;
    g.build(1,1,n);
    for (int i = 1; i <= n; i++)
    {
        ll x, y, z;
        cin >> x >> y >> z;
        pll o1=g.get(1,1,n,x,x+z-1,x%2), o2=g.get(1,1,n,y,y+z-1,y%2);
        if (o1.fi!=o2.fi || o1.se!=o2.se) cout << "No\n"; else cout << "Yes\n";
    }
}

int main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    ll t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = 2e5 + 75;

int a[MAXN];
int pr[MAXN];

const int mod = 2e9 + 179;
const int p = 3;

int p1[MAXN];
int h[MAXN];

int get_hash(int l, int r)
{
    int ans = h[r] - h[l] * p1[r - l];
    ans %= mod;
    if (ans < 0)
    {
        ans += mod;
    }
    return ans;
}

int t[4 * MAXN];

void update(int v, int tl, int tr, int pos, int val)
{
    if (tr - tl == 1 && tl == pos)
    {
        t[v] += val;
        return;
    }
    if (tl > pos || pos >= tr)
    {
        return;
    }
    update(2 * v + 1, tl, (tl + tr) / 2, pos, val);
    update(2 * v + 2, (tl + tr) / 2, tr, pos, val);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
    return;
}

int get(int v, int tl, int tr, int l, int r)
{
    if (l <= tl && tr <= r)
    {
        return t[v];
    }
    if (l >= tr || tl >= r)
    {
        return 0;
    }
    int ans = get(2 * v + 1, tl, (tl + tr) / 2, l, r) + get(2 * v + 2, (tl + tr) / 2, tr, l, r);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
    return ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    p1[0] = 1;
    for (int i = 1; i < MAXN; ++i)
    {
        p1[i] = (p1[i - 1] * p) % mod;
    }
    pr[0] = 0;
    for (int i = 0; i < n; ++i)
    {
        pr[i + 1] = pr[i];
        if (s[i] == '1')
        {
            pr[i + 1]++;
        }
    }
    h[0] = 0;
    for (int i = 0; i < n; ++i)
    {
        h[i + 1] = ((h[i] * p + (s[i] - '0' + 1)) % mod + mod) % mod;
    }
    for (int i = 1; i < n; ++i)
    {
        if (s[i] == '1' && s[i - 1] == '1')
        {
            update(0, 0, MAXN, i, 1);
        }
    }
    int q;
    cin >> q;
    for (int _ = 0; _ < q; ++_)
    {
        int l1, l2, len;
        cin >> l1 >> l2 >> len;
        --l1; --l2;
        if (l1 > l2)
        {
            swap(l1, l2);
        }
        vector<int> a;
        vector<int> b;
        int cur = 0;
        for (int i = l1; i < l1 + len; ++i)
        {
            cur += (s[i] - '0');
            if (s[i] == '0')
            {
                a.push_back(cur % 2);
            }
        }
        cur = 0;
        for (int i = l2; i < l2 + len; ++i)
        {
            cur += (s[i] - '0');
            if (s[i] == '0')
            {
                b.push_back(cur % 2);
            }
        }
        if (a == b)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define ss second
#define ff first
#define pb push_back
#define all(v) v.begin(), v.end()
#pragma GCC optimize("Ofast", "unroll-loops", "no-stack-protector", "fast-math")
//#pragma GCC target("avx2")
using namespace std;
typedef long long ll;
vector < int > arr;
vector < ll > step;
ll mod = 1e9 + 7;
vector < ll > t;
vector < ll > invt;
void build(int v, int l, int r) {
    if (l == r) {
        t[v] = arr[l];
        invt[v] = 1 - arr[l];
        return ;
    }
    int m = (l + r) / 2;
    build(v * 2 + 1, l, m);
    build(v * 2 + 2, m + 1, r);
    t[v] = (step[r - (m + 1) + 1] * t[v * 2 + 1] + t[v * 2 + 2]) % mod;
    invt[v] = (step[r - (m + 1) + 1] * invt[v * 2 + 1] + invt[v * 2 + 2]) % mod;
    return ;
}
ll ask(int v, int l, int r, int tl, int tr) {
    if (l == tl && r == tr) {
        return t[v];
    }
    int m = (l + r) / 2;
    ll ans = 0;
    if (tr >= m + 1)
        ans += ask(v * 2 + 2, m + 1, r, max(m + 1, tl), tr);
    if (tl <= m) {
        if (tr >= m + 1)
            ans += step[tr - max(m + 1, tl) + 1] * ask(v * 2 + 1, l, m, tl, min(m, tr));
        else
            ans += ask(v * 2 + 1, l, m, tl, min(m, tr));
    }
    ans %= mod;
    return ans;
}
ll invask(int v, int l, int r, int tl, int tr) {
    if (l == tl && r == tr) {
        return invt[v];
    }
    int m = (l + r) / 2;
    ll ans = 0;
    if (tr >= m + 1)
        ans += ask(v * 2 + 2, m + 1, r, max(m + 1, tl), tr);
    if (tl <= m) {
        if (tr >= m + 1)
            ans += step[tr - max(m + 1, tl) + 1] * ask(v * 2 + 1, l, m, tl, min(m, tr));
        else
            ans += ask(v * 2 + 1, l, m, tl, min(m, tr));
    }
    ans %= mod;
    return ans;
}
void test() {
    srand(time(NULL));
    int n = 10;
    arr.resize(n);
    t.resize(4 * n);
    fori(n) arr[i] = rand() % 2;
    build(0, 0, n - 1);
    int q = 10000;
    while (q--) {
        int l1 = rand() % n;
        int l2 = rand() % n;
        if (l1 > l2) swap(l1, l2);
        int len = rand() % (n - l2);
        int r1 = l1 + len;
        int r2 = l2 + len;
        string s1, s2;
        for (int i = l1; i <= r1; i++) s1.pb(arr[i]);
        for (int i = l2; i <= r2; i++) s2.pb(arr[i]);
        if (s1 != s2) continue;
        ll h1 = ask(0, 0, n - 1, l1, r1);
        ll h2 = ask(0, 0, n - 1, l2, r2);
        if (h1 != h2) {
            fori(n) cout << arr[i];
            cout << endl;
            cout << "hah is " << h1 << " " << h2 << endl;
            cout << "quer is\n";
            cout << l1 << " " << r1 << " : ";
            for (int i = l1; i <= r1; i++) cout << arr[i];
            cout << endl;
            cout << l2 << " " << r2 << " : ";
            for (int i = l2; i <= r2; i++) cout << arr[i];
            cout << endl;
            return ;
        }
    }
}
int main() {
    step.resize(200001);
    step[0] = 1;
    fori(step.size() - 1) step[i + 1] = (step[i] * 2) % mod;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector < int > pref;
    bitset < 200000 > kek;
    pref.resize(n);
    string s;
    cin >> s;
    fori(s.size()) s[i] -= '0';
    fori(pref.size()) {
        if (i) pref[i] = pref[i - 1];
        pref[i] += s[i];
    }
    int q;
    cin >> q;
    vector < int > tol, tor;
    tol.resize(n);
    tor.resize(n);
    int ind = -1;
    for (int i = 0; i < n; i++) {
        if (s[i] == 0) ind = i;
        tol[i] = ind;
    }
    ind = -1;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == 0) ind = i;
        tor[i] = ind;
    }
    int cnt0 = 0;
    vector < int > keked;
    keked.resize(n - 1);
    fori(n) {
        if (s[i] == 0) {
            keked[i] = cnt0;
            cnt0++;
        }
    }
    ind = 0;
    fori(n) {
        if (s[i] == 1) ind = 1 - ind;
        else arr.pb(ind);
    }
    if (cnt0 == 0) {
        fori(q) cout << "Yes\n";
        return 0;
    }
    t.resize(4 * cnt0);
    invt.resize(4 * cnt0);
    build(0, 0, cnt0 - 1);

    while (q--) {
        int fl1, fl2;
        int l1, l2, len;
        cin >> l1 >> l2 >> len;
        l1--; l2--;
        fl1 = l1;
        fl2 = l2;
        len--;
        int kek1 = pref[l1 + len];
        if (l1) kek1 -= pref[l1 - 1];
        int kek2 = pref[l2 + len];
        if (l2) kek2 -= pref[l2 - 1];
        if (kek1 != kek2) {
            cout << "No\n";
            continue;
        }
        if (kek1 == len + 1) {
            cout << "Yes\n";
            continue;
        }
        int r1 = tol[l1 + len];
        int r2 = tol[l2 + len];
        l1 = tor[l1];
        l2 = tor[l2];
        l1 = keked[l1];
        r1 = keked[r1];
        l2 = keked[l2];
        r2 = keked[r2];
        ll h1 = ask(0, 0, cnt0 - 1, l1, r1);
        ll h2;
        int k1 = 0, k2 = 0;
        if (fl1) k1 = pref[fl1 - 1];
        if (fl2) k2 = pref[fl2 - 1];
        if (k1 % 2 != k2 % 2)
            h1 = invask(0, 0, cnt0 - 1, l2, r2);
        else
            h2 = ask(0, 0, cnt0 - 1, l2, r2);
        if (h1 == h2) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
}


#include<bits/stdc++.h>

using ll = long long;
using ld = long double;

namespace GTI
{
	char gc(void)
   	{
		const int S = 1 << 16;
		static char buf[S], *s = buf, *t = buf;
		if (s == t) t = buf + fread(s = buf, 1, S, stdin);
		if (s == t) return EOF;
		return *s++;
	}
	ll gti(void)
   	{
		ll a = 0, b = 1, c = gc();
		for (; !isdigit(c); c = gc()) b ^= (c == '-');
		for (; isdigit(c); c = gc()) a = a * 10 + c - '0';
		return b ? a : -a;
	}
	int gts(char *s)
   	{
		int len = 0, c = gc();
		for (; isspace(c); c = gc());
		for (; c != EOF && !isspace(c); c = gc()) s[len++] = c;
		s[len] = 0;
		return len;
	}
	int gtl(char *s)
   	{
		int len = 0, c = gc();
		for (; isspace(c); c = gc());
		for (; c != EOF && c != '\n'; c = gc()) s[len++] = c;
		s[len] = 0;
		return len;
	}
}
using GTI::gti;
using GTI::gts;
using GTI::gtl;

const int N = 550;
int f[N][N * N], c[N][N], sum[N];
int main(void)
{
	int n = gti(), M = gti();
	c[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; j++)
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % M;
	}

	f[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		static int sum[N * N];
		int tot = i * (i - 1) / 2;
		sum[0] = f[i - 1][0];
		for (int j = 1; j <= tot; j++)
			sum[j] = (sum[j - 1] + f[i - 1][j]) % M;
		for (int j = 0; j <= tot; j++)
		{
			f[i][j] = sum[j];
			if (j - i >= 0)
				f[i][j] = (f[i][j] - sum[j - i]) % M;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int len = n - i - 1, tot = len * (len - 1) / 2, now = 0;
		for (int l = 0; l <= tot; l++)
			for (int r = l + 2; r <= tot; r++)
			{
				int d = r - l, cnt = (2ll * len - d + 2) * (d - 1) / 2;
				if (d > len) cnt = len * (len + 1) / 2;
				now = (now + 1ll * f[len][l] * f[len][r] % M * cnt) % M;
			}
		ans = (ans + 1ll * c[n][i] * now) % M;
	}
	printf("%d\n", (ans % M + M) % M);
	return 0;
}


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

const int N = 505;
int dp[N][N*N], sum[N][N*N];

void init(int n, int mod){
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		int ti = i*(i - 1)/2;
		for(int p = 0; p <= ti; p++){
			for(int x = 0; x <= i - 1; x++){
				dp[i][p + x] += dp[i - 1][p];
				if(dp[i][p + x] >= mod){
					dp[i][p + x] -= mod;
				}
			}
		}
		for(int j = ti; j >= 0; j--){
			sum[i][j] = dp[i][j] + sum[i][j + 1];
			if(sum[i][j] >= mod)sum[i][j] -= mod;
		}
	}
}

inline int mul(int a, int b, int mod){
	return a*1LL*b%mod;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, mod;
	cin >> n >> mod;

	init(n, mod);
	int answer = 0, eqcnt = 1;
	for(int r = 1; r < n; r++){
		int val = 0, mx = (n - r)*(n - r - 1)/2;
		for(int cs = 0; cs <= mx; cs++){
			for(int dif = 1; dif <= n - r; dif++){
				val += mul(n - r + 1 - dif, mul(dp[n - r][cs], sum[n - r][cs + dif + 1], mod), mod);
				if(val >= mod)val -= mod;
			}
		}
		answer += mul(val, eqcnt, mod);
		eqcnt = eqcnt*1LL*(n - r + 1)%mod;
	}
	cout << answer << '\n';

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define siz(x) ((int)x.size())
#define pb push_back
#define fi first
#define se second
#define edl putchar('\n')
const int N=5e2+5,M=1.25e5+5;
int mod;
inline int add(int x,int y){if(x+y>=mod)return x+y-mod;return x+y;}
inline void Add(int&x,int y){x=add(x,y);}
inline int sub(int x,int y){if(x-y<0)return x-y+mod;return x-y;}
inline void Sub(int&x,int y){x=sub(x,y);}
inline int mul(int x,int y){return 1ll*x*y%mod;}
inline void Mul(int&x,int y){x=mul(x,y);}
int n;
int G[N],f[N][M],sum[N][M],H[N][M];
inline int C(int x){return x*(x-1)/2;}
int main(){
	cin>>n>>mod;
	f[1][0]=sum[1][0]=1;
	for(int i=2;i<=n;i++){
		for(int j=0;j<=C(i);j++){
			if(j<i)f[i][j]=sum[i-1][min(C(i-1),j)];
			else f[i][j]=sub(sum[i-1][min(C(i-1),j)],sum[i-1][j-i]);
			sum[i][j]=add(sum[i][max(0,j-1)],f[i][j]);
			H[i][j]=add(H[i][max(0,j-1)],sum[i][j]);
		}
	}
	for(int i=2;i<=n;i++){
		G[i]=mul(G[i-1],i);
		for(int j=1;j<i;j++){
			for(int p=j-1;p<=C(i);p++){
				if(p-i-1>=0)Add(G[i],mul(f[i-1][p-(j-1)],sub(H[i-1][p-j-1],H[i-1][p-i-1])));
				else Add(G[i],mul(f[i-1][p-(j-1)],H[i-1][p-j-1]));
			}
		}
	}
	cout<<G[n]<<endl;
	return 0;
}


#include <iostream>
#include <random>
#include <chrono>
#include <ctime>
#include <string>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 505;
int n, mod;
int f[N][N * N];
int pp[N][N * N];
int add(int x, int y) {
    x += y;
    if (x >= mod) x -= mod;
    return x;
}
int mult(int x, int y) {
    return 1ll * x * y % mod;
}
int A(int n, int m) {
    if (n < m) return 0;
    int ret = 1;
    for (int i = 1; i <= m; i++)
        ret = mult(ret, n - m + i);
    return ret;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int ans = 0;
    cin >> n >> mod;
    int R = n * (n - 1) / 2;
    f[0][0] = 1;
    for (int i = 0; i < n; i++)
        for (int inv = 0; inv <= i * (i - 1) / 2; inv++)
            for (int plus = 0; plus <= i; plus++)
                f[i + 1][inv + plus] = add(f[i + 1][inv + plus], f[i][inv]);
    for (int i = 0; i <= n; i++) {
        pp[i][0] = f[i][0];
        for (int j = 1; j < R; j++)
            pp[i][j] = add(pp[i][j - 1], f[i][j]);
    }
    for (int pref = 0; pref <= n - 2; pref++) {
        int koef = A(n - 2, pref);
        int cur = 0;
        for (int x = 1; x <= n - pref; x++)
            for (int y = x + 1; y <= n - pref; y++) {
                for (int cnt1 = 0; cnt1 < R; cnt1++) {
                    int cnt2 = cnt1 + x - y;
                    if (cnt2 > 0)
                        cur = add(cur, mult(f[n - pref - 1][cnt1], pp[n - pref - 1][cnt2 - 1]));
                    //for (int cnt2 = 0; cnt2 < cnt1 + x - y; cnt2++)
                      //  cur = add(cur, mult(f[n - pref - 1][cnt1], f[n - pref - 1][cnt2]));
                }
            }
        ans = add(ans, mult(cur, koef));
    }
    cout << ans;
    return 0;
}


#include "bits/stdc++.h"
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
char _;

int main(){
	int n, ans = INT_MAX;
	vector<int> arr(n + 3);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	for(int e = 1; e <= n; e++){
		int cnt = 0;
		for(int i = 1, alt; i <= n; i++){
			alt = 2 * (abs(e - i) + abs(i - 1) + abs(e - 1));
			cnt += arr[i] * alt;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline long long in()
{
    long long x=0;int c=getchar(),n=0;
    for(;!isdigit(c);c=getchar()) n=(c=='-');
    for(;isdigit(c);c=getchar()) x=x*10+c-'0';
    return n?-x:x;
}
#define ll long long
#define FOR(i,a,b) for(int i(a);i<=b;i++)
#define ROF(i,a,b) for(int i(b);a<=i;i--)
#define rr(x) " "<<#x<<'='<<x<<" "
const int N=1e3+5;
int n;
ll s,v[N],sum;
bool check(ll x)
{
    ll glass=0;
    FOR(i,1,n) if(x<v[i]) glass+=v[i]-x;
    return s<=glass;
}
main()
{
   // freopen("42.inp","r",stdin);
    n=in();s=in();
    FOR(i,1,n) v[i]=in();
    FOR(i,1,n) sum+=v[i];
    if(sum<s) return cout<<-1,0;

    ll l=1,r=*min_element(v+1,v+n+1),res;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(check(mid)) res=mid,l=mid+1;
        else r=mid-1;
    }
    cout<<res;
}


#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <array>

using namespace std;
//����Ҫ��ǰ�ߵ� ��ǰ��
int a[110];

int main(){
	int n;
	freopen("in.txt", "r", stdin);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];	//1start
	}
	int min = 100000;
	for(int i = 1; i <= n; i++){
		//i is op floor
		int count = 0;
		for(int j = 1; j <= n; j++){
			count += a[j]*(abs(i-j)+abs(j-1)+i-1+i-1+j-1+abs(i-j));
		}
		if(count <= min){
			min = count;
		}
	}
	cout << min << endl;
  	return 0;
}


#include<iostream>
#include<algorithm>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n],i;
    for(i=0;i<n;i++)
    cin>>a[i];
        ll bil=1000000000000000000;
        for(ll j=1;j<=n;i++){
            ll bill=0;
        for(i=0;i<n;i++)
        {
            bill=bill+(llabs(j-i-1)+i+llabs(j-1)*a[i]);
        }
        if(bil<bill)
        bil=bill;
        }
        cout<<2*bil<<endl;

}


#include <iostream>
using namespace std;

int main() {
	int n,p,k=0,i,c=0;
	char s[100];
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++){
	    if(s[i]=='8'){
	        c++;
	    }
	    else
	    k++;
	}
	p=n/11;
	if(c==0)
	printf("0");
	else if((c>=p))
	printf("%d",p);
	else
	printf("%d",c);

	return 0;
}


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

int main() {
    int n; string s; cin >> n >> s;
    if(n>=11) {
        int a=0,b=0;
        for(int i=0;i<n;i++) {
            if(s[i]=='8') b++;
            else a++;
        }
        if(b==0 || b==1) {
            cout << b << endl;
        } else {
            while(a/b!=10) {
                b--;
                a++;
            }
            cout << b << endl;
        }
    } else cout << 0 << endl;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int i=0,n,count=0;
    cin >> n;
    char s[n+1];
    cin >> s;
    while(s[i]!=0)
    {
        if(s[i]=='8')
        {
            count++;
        }
        i++;
    }
    while(count--)
    {
        if(n%count==0)
        {
            cout << count;
            return 0;
        }
    }
    cout << "0";
    return 0;
}


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

#define ll long long
#define ld long double
#define F  first
#define S second
#define sf(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define mod1 1000000007LL
#define mod2 998244353LL

struct hanoi{
int a,b,h;
ll ans;
};
bool fun(char x, char y)
{
     if(x=='8')
    return 1;
    return 0;
}

void solve()
{
int n;

cin>>n;
vector<char> v;

for(int i=0;i<n;i++)
{
    char ch;
    cin>>ch;
    v.pb(ch);
}
    sort(ALL(v),fun);
    int cn=0,s=0,en=n-1;
    while(1)
    {
        if(v[s]=='8' && en-s >=10)
        {
            cn++;
            s++;
            en-=10;
        }
        else
            break;

    }
cout<<cn;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  //freopen("input.txt","r",stdin);
    int t=1 ;
    //cin>>t;

   /* for(int i=2;i<=1000000;i++)
    {

        if(visited[i]==0)
        {
            prime.pb(i);
            for(int j=2*i;j<=1000000;j+=i)
                visited[j]=1;
        }
    }*/

    while(t--)
     {
      solve();
     }
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	n = y * n /100 - x;
	if (x == 1 && n == 0)++n;
	cout << n << endl;
	system("pause");

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
using namespace std;
#define ll long long
int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    int tmp=n*y-x*100;
    if(tmp%100==0)tmp/=100;
    else tmp/=100,tmp++;
    if(tmp<0)tmp=0;
    cout<<tmp<<endl;
}


#include <iostream>

using namespace std;

int main()
{
  int n, x, y;
  cin >> n >> x >> y;
  int t = n * y;
  cout << max(0, (t - 100 * x) / 100 + (t % 100 ? 1 : 0));
  return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
int n=0,x=0,y=0;
int klon=0;
cin>>n>>x>>y;
klon=(n*y/100);
klon=klon-x;

cout<<endl<<klon;

getch();
return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n,a,b,i,x;
    while(scanf("%d%d%d",&n,&a,&b)){
        int s[110]={0},t=0;
        for(i=0;i<a;i++){
            scanf("%d",&x);
            s[x]=1;
        }
        for(i=0;i<b;i++){
            scanf("%d",&x);
            if(!s[x])s[x]=2;
            else a--;
        }
        for(i=1;i<=n;i++){
            if(s[i]){
                printf("%d",s[i]);
                a--;
                if(a+b==0){printf("\n");break;}
                else printf(" ");
            }
        }
    }
    return 0;
}


//In the name of God
//-----gmmj

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

#define Rep(I,N) for(int I=0;I<N;++I)
#define For(J,R,K) for(int J=R;J<K;++J)
#define DRI(X) int x;scanf("%d",&X);
#define DRII(X1,Y1) int X1,Y1;scanf("%d%d",&X1,&Y1);
#define RI(X2) scanf("%d",&X2);
#define WI(X4) printf("%d",X4);
#define WII(X5,X6) printf("%d %d",X5,X6);
#define SF scanf
#define PF printf
#define Pii pair<int,int>
#define Ff first
#define Ss second
#define Sorts(a,n) Rep(i,n)Rep(j,n-1)if(a[j]>a[j+1])swap(a[j],a[j+1]);
#define Sortn(a,n) Rep(i,n)Rep(j,n-1)if(a[j]<a[j+1])swap(a[j],a[j+1]);
#define Test freopen("a.in","r",stdin);

typedef long long ll;

using namespace std;
ll a[103]={0};
int main(){
	Test

	ll c,b,d,n;

	cin>>n>>c>>b;
	Rep(i,c){
		cin>>d;
		a[d-1]=1;
	}
	Rep(i,b)
		cin>>d;
	Rep(i,n)
		if(!a[i])
			a[i]=2;
	Rep(i,n-1)
		cout<<a[i]<<" ";
	cout<<a[n-1];

	return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int number, arthur, alexander, *ra;
	cin >> number >> arthur >> alexander;
	ra = new int[arthur];
	for (int c = 0; c < arthur; c++)cin >> ra[c];
	sort(ra, ra + arthur);
	for (int c = 0, i = 1; c < number; i++){
		if (ra[c] == i) {cout << "1 "; c++;
	}
		else
			cout << "2 ";
	}
}


#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int number, arthur, alexander, *ra;
	cin >> number >> arthur >> alexander;
	ra = new int[arthur];
	for (int c = 0; c < arthur; c++)cin >> ra[c];
	sort(ra, ra + arthur);
	for (int c = 0, i = 1; c < number; i++)
		if (ra[c] == i){ cout << "1 "; c++; }
		else cout << "2 ";
}
/*
                              `/oyhyyssssoo+/:-`
                            `sdddmmmmmmmdddddhyyys+:-`
                            +mmNmmddmmmmmmdddmmmddhhhy/
                            `dNNNNNNNNmmmmmmmmmmNNmmddds.
                             /dNNNNNmmmmmmNNNNNNmNNNNNNmd
                             .ydmNNNNNNNNNNNNNNNNNNNNNNNN.
                             +syhdmdmNNNNNMNNNNNNNNNNNNMN/
                            `osyyyhhhhdmmdmmNNNMMNNNNNMMm`
                            -oosssssssssyyyyyhmNMMMMMMMM+
                            odhyssyyhhysssssssymNMMMNNMM:
                            .dmdssydmmmdhysoooshmNmdysyd`
                             oyh++oyddhhhysooooymhyyysy/
                             +o+/++oosssooo+ooosyoshyso.
                            `++///+oo+++++++ooosyssooo-
                             +oosssssooooooooosyssoo:`
                             -osyysoossssssooooosss+
                              oyhhyyyyyssssssooosso-
                        ``` ` -oyyyyyyyysssssssssso-``
                ``````.``.....-/syyyyyyyyyyyyyyyysy--.```   `
             ``   `````...:..-/+osyyssyyhhhhyyyyyhh.-``.```````
          `      `````....:---:+o+ydhhdddhhyyyyydm/-..`- `````
         `        ````....::---/+s/dmmdddhhhhyhdm+...`-` `..`````
       ````      ````.....-/----/y++hmdddddhhdmmyo:.`..  `......````       `.
      `.``       ./`....-..-.:---/oydhdddddhhddhso--`.. `....----.```
      ````        ``--:--....:----//sdysyhhhhdds+:-:`-.``...-::/--.`  `
     ````````   `` `-:/:-...-:-.---::/+:/osyhs/::.::--..`...-+++::-  ```
   ````  `````   ```:+//-...---.----.-.--:/d+--:-./---.-...--oys+:- `.````          `
  .````./++/:--.```./o+/-...-.-..--:.....-yh...---+---.-----:+yys+/`....``````..``   ```
 `.```-++/:-------.-ooo:--........-::--../my.`.--:+--------::+syyso----.`.-------::--.```
 -..-:/:::---------:ooo::-........--:::-./ms.``.-/+/::-----::+syyyyo::-.-:--......--::/:.`
 -.o+//:::::---------/+:::..```....-:::::+mo....-/++oo/--:::/+ssys+.`-/:::--......----:++.`
 :/soo+//:::::--------::::-.........-::::+No----:/+o++::-:://+oss+    :/:---.....----://oo-`
 /sysso++////:::--------::::----....--::/+N+---::////:::::://+ooo``.-:/::---...-----:::/ss:`
 :odhsooo+++////::--------::::---....--:/+d/---::::/::::::////+o+/+oo+/:---...-------::/s/.
 `/sdyssoooo+++///::---------::---....-::/h:--::::::::::::////oyyyyyo/:--...-------::::/+.
  `:ooyyysssooo+++///::--------::--...--::s:----::::::::://:/yhhhddo::--...------:::////`
    ``oNNmhyysssooo++//::--------::-..---:s::-:::::::::://:+dhyddy/::--.-----::::///++:`
     oNNNNNNmdhyysssooo+//::::-----:----:+y::::::::::::////sdyso/:/:-------::://++oo/.
     dNNNmNNNNNNmdhyyyssoo++//::---------///::::::::::::::://://+o+------:::/++osyhh-
     mmNNmNNNNNNNmmdddhyyssoooo+::--.------:::-:----::-----/ossso/----::://+osyddmmdy
     hmNNNmmmNNNNmmddmmmdhhhysso+/:----------::------::::-:-+s+/--:::::/+oshdmmmmdNdo
     smmNNmmmmmNmmmmdddmNNmdddoso+//::-----------::---::--::---.--::/+oshdmmmmmmmdNm:
     +mNNNNmmmmmmmmmmddhdmNmddoooooo+/////////:::-//:--/:-:/:-:---/+shmmNmmmmmmmmdmN-
     :NNmmNmmmmNmmmmmmmddhdmmdo++oosssssoooooo+/::-//:::/:::+::::/odmNmmmmmmmdddmmmo
     .NNdmNNmmmNNmmmmddmmmdhmmy---:://++shddddhyo/:::/:::/::/o++oymmmmmmmmmdmmddmmm.
      yNdmdNNmmmmmmmmdddddmdhdd:::://++oyhyhhyysyyo+//+///+//syhdmmmmmmmmmmddmdhdNm`
      `hdmdmNNmmmmmmmdddhddddhdyossyhshyyyssso+/+yyyyyhyyyyyyyhmNmmmmmmmmmddmmdhNy-
       .dmmmmNNmmmmmmmdddhhdddhd+/:+hs:ossssooo++syyydddhhhhdmmmmmmNmmmddddmdddm+
        ydmmmmNmmNmNmmdddhhhhhhddsssmN/oosssoshys++oyhhyyhdmmmmmmmmmmmmddddddmdy
        :dddmmmNNNNNNmdddddhhhhddmNNhhysooysssyhhyyyyyyhdmNmmmmmNmmmmmdddmdddmm.
         hdmmmmmNmNmNmddddddhhhhhdNNm+:ooosyyhhhhyyhddmNNNNmmmmNNmmmmdmdmmdddm:
         /mdmmNNNNNNNNmdddhddhdhhhmNNm++yysyyhhhhyhmNNNNNmmmmmmNmmmmmdmdmmmhms
         :mmmmmmmNNNNNNmdddhddddhhhNNNNooyhyysssssshNNNNmmmNmmNNmmmmmmmmmmmmm`
         +mmmmmmNNmNNNNmmdhhddddhhydNMMdooshmmmdmmNNNNmmmmmNNNNNmmmmmmmdmdmmo
         -mmmmmmmmmNNNNNmmddhhddddhyNMMMmdmNMMNNNNNNNmmNmmmNmNNmmmmmNmmmmmmm.
          dmmNmmmmmmmNNNmmddhhhhddhhdMMMMMMMMmNNNNNmmNNNNNNNNNNmmmmmmmmmNmdm`
          oNmNNmmmmmNmNNNmmmddhhddddhdMMMMMMNNNmmmmmNNNNNNNNNNmmmmmmmmNNmmmm
          -NmmNNmmmNNmNNNmmmmddhhdddhhdMMMMNNNmmNNNNNNNNmNNNNNmmmmmmmNNmmmmy
           yNmmNNNdmNNNNNmmmdddddhhdddhdMMMNmmNNNNNNNNNNNNNNmmmmmmmNNNNmmmm:
           `mmmNNNmdmmNNNmmmmddddddhddhhdNNNNNNmmmNNNNNNNNNNmmmmmmNMNNNmmmo
            :NNNNNNNdmNNNNmmmdddddddhddhymNNNNNNNNNNNNNNNNNNmmmmNMMNNNmmm-
             /NNNNNMNmmmNNNmmdddddddhhhhyyNMNNNNNNNNNNNNNNNNmmmNMMMNNNmh-
              /NNNMMNNmmNNNmmmddddddhhhhhhhNNNNNNNNNNNNmNNNNmNMMMMNNNm+
               .sNMMMMNmNNNNmmmmddddhhhhhhhhNNNNNNNNNNNNNNNmNMMMMMNd/`
                 -hNMNMMNNNNNmdmdddddhhhhhyydNNNNNNNNNNNNNNmNMMMds-
*/


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <deque>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <cstring>
#define oo (int)1e9
#define fill( a , v ) memset( a , v , sizeof (a) )
#define bits( x ) __builtin_popcount( x )
#define gcd( a , b ) __gcd( a, b )
#define lcm( a , b ) (a/gcd( a, b ) ) * b
#define s(n)scanf( "%d" , &n )
#define add push_back
#include<cassert>
const int mxn = 100000 + 10;
const int mod = 4242;
typedef long long ll;
#define pii pair<int,int>
using namespace std;
const int offset = 625;

bool dp[128][128][3];
bool vis[128][128][3];

bool solve( int G , int B , int turn )
{
     if( G < 0 || B < 0 )return 0;
     if( G == 0 && B == 0 )return 1;

     bool &d = dp[G][B][turn];
     bool &v = vis[G][B][turn];

     if( v )return d;
     v = 1;
     d = 0;
     if( !turn )
     d |= solve( G-1 , B , !turn );
     else
     {
         d |= solve( G , B-1 , !turn );
         d |= solve( G , B-2 , !turn );
     }
     return d;
}

int get( int G , int B )
{
    return solve( G-1 , B , 1 ) || solve( G , B-1 , 0 ) || solve( G , B-2 , 0 );
}
int main()
{
    int al , bl , ar , br;
    cin >> al >> ar;
    cin >> bl >> br;

    bool ok = 0;
    ok |=  get( al , br );
    ok |= get( ar , bl );

    puts( ok ? "YES" : "NO" )    ;
    system( "pause" );
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <deque>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <cstring>
#define oo (int)1e9
#define fill( a , v ) memset( a , v , sizeof (a) )
#define bits( x ) __builtin_popcount( x )
#define gcd( a , b ) __gcd( a, b )
#define lcm( a , b ) (a/gcd( a, b ) ) * b
#define s(n)scanf( "%d" , &n )
#define add push_back
#include<cassert>
const int mxn = 100000 + 10;
const int mod = 4242;
typedef long long ll;
#define pii pair<int,int>
using namespace std;
const int offset = 625;

bool get( int G , int B )
{
     bool ret = G == B || ( G-B >= 0 && G-B <= 1);
     if( ret )return 1;

     int g = G;
     int b = B;
     while( G > 0 )
     {
            G--;
            B -= 2;
     }
     ret = B <= 0;
     //cout << ret << endl;
     G = g;
     B = b;
     B -= 2;

     while( G > 0 )
     {
            G--;
            B -= 2;
     }
    // cout << B << endl;
     ret |= B <= 0;
     return ret;
}

int main()
{
    int al , bl , ar , br;
    cin >> al >> ar;
    cin >> bl >> br;

    bool ok = 0;
    ok |=  get( al , br );
    ok |= get( ar , bl );

    puts( ok ? "YES" : "NO" )    ;
    system( "pause" );
}


#include<cstdlib>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define S 200005
using namespace std;
typedef vector<int> vi;
typedef vi::iterator vii;
int main(){
	vi v1[26], v2[26];
	int n, k, l1, l2;
	long long s;
	string s1, s2;
	cin >> n >> k;
	cin >> s1;
	l1 = s1.size();
	for(int i=0;i<l1;++i){
		v1[s1[i] - 'a'].push_back(i);
	}
	for(int i=0;i<26;++i){
		v2[i] = vi(v1[i]);
		reverse(v2[i].begin(), v2[i].end());
	}
	for(int i=0;i<n;++i){
		cin >> s2;
		l2 = s2.size();
		s = 0;
		for(int j=0;j<l2;++j){
			char c = s2[j] - 'a';
			vii lw, up;
			lw = lower_bound(v1[c].begin(), v1[c].end(), j);
			up = lower_bound(v2[c].begin(), v2[c].end(), j, greater<int>());
			if(lw == v1[c].end() && up == v2[c].end()){
				s += l1;
			}
			else if(up == v2[c].end()){
				s += *lw - j;
			}
			else if(lw == v1[c].end()){
				s += j - *up;
			}
			else{
				s += min(*lw - j, j - *up);
			}
		}
		cout << s << endl;
	}
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <deque>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <cstring>
#define oo (int)1e9
#define fill( a , v ) memset( a , v , sizeof (a) )
#define bits( x ) __builtin_popcount( x )
#define gcd( a , b ) __gcd( a, b )
#define lcm( a , b ) (a/gcd( a, b ) ) * b
#define s(n)scanf( "%d" , &n )
#define add push_back
#include<cassert>
const int mxn = 100000 + 10;
const int mod = 4242;
typedef long long ll;
#define pii pair<int,int>
using namespace std;
const int offset = 625;

bool get( int G , int B )
{
     return G == B ||  B-G <= 2 || ( G-B >= 0 && G-B <= 1);
}

int main()
{
    int al , bl , ar , br;
    cin >> al >> ar;
    cin >> bl >> br;

    bool ok = 0;
    ok |=  get( al , br );
    ok |= get( ar , bl );

    puts( ok ? "YES" : "NO" )    ;
    system( "pause" );
}


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

using namespace std;
int main() {
	string s,c;
	long sum = 0, sum1 = 0;
	cin >> c;
	for (int i = 0; i < c.size(); i++) {
		sum1 += c[i] - '0';
	}
	s = c;
	if (s[0] == '1') {
		s.erase(0, 1);
		for (int i = 0; i < s.size(); i++) {
			s[i] = '9';
			sum += 9;
		}
	}
	else {
		int x = s[0] - '0';
		x--;
		s[0] = x + '0';
		sum += s[0] - '0';

		for (int i = 1; i < s.size(); i++) {
			s[i] = '9';
			sum += 9;
		}
	}
	(sum1 >= sum) ? cout << c : cout << s;
	system("pause");

}
/**/


#include <iostream>
#include <cstdint>
#include <math.h>

using namespace std;

int sumOfNumbers(string num){
    int res = 0;
    for (int i = 0; i < num.size(); i++)
        res += num[i] - 48;

    return res;
}

int main()
{
    unsigned long long int n, cn, p = 1;
    cin >> n;
    string s = to_string(n);
    string maxStr;
    int maxSum = 0;

    string cs;

    for (int i = 1; i < s.size(); i++){
        p *= 10;
        cn = n - p;
        cs = to_string(cn);
        for (int j = 0; j <= i; j++)
            cs[cs.size() - j] = '9';
        int currentSum = sumOfNumbers(cs);
        if (currentSum > maxSum)
        {
            maxSum = currentSum;
            maxStr = cs;
        }
    }

    if (maxSum > sumOfNumbers(s))
        cout << maxStr;
    else
        cout << s;

}


#include <iostream>
#include <cstdint>
#include <math.h>

using namespace std;

int sumOfNumbers(string num){
    int res = 0;
    for (int i = 0; i < num.size(); i++)
        res += num[i] - 48;

    return res;
}

unsigned long long int pow(int v){
    unsigned long long int res = 1;
    for (int i = 0; i < v; i++)
        res *= 10;
    return res;
}

int main()
{
    unsigned long long int n;
    cin >> n;
    string s = to_string(n);
    string maxStr;
    int maxSum = 0;

    for (int i = 1; i < s.size(); i++){
        unsigned long long int t = pow(i);
        unsigned long long int cn = n - t;
        string cs = to_string(cn);
        for (int j = 0; j <= i; j++)
            cs[cs.size() - j] = '9';
        int currentSum = sumOfNumbers(cs);
        if (currentSum > maxSum)
        {
            maxSum = currentSum;
            maxStr = cs;
        }
    }

    if (maxSum > sumOfNumbers(s))
        cout << maxStr;
    else
        cout << s;

}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<iostream>
#include<cmath>
using namespace std;
int a[20];
void J_S(int &k,int n){
    while(n){
        a[k++]=n%10;
        n/=10;
    }
}
int main(){
    long long n;
    while(cin>>n){
        memset(a,0,sizeof(a));
        int l=0;
        J_S(l,n);
        if(l==1)
            printf("%lld\n",n);
        else{
            int x=l-1,pos=0,sum=0;
            int maxx=-1;
            for(int i=l-1; i>0; i--){
                if(a[x]==0){
                    x--;
                    continue;
                }
                for(int j=l-1; j>x; j--)
                    sum+=a[j];
                sum+=(a[x]-1+9*x);
                if(sum>=maxx){
                    maxx=sum;
                    pos=x;
                }
                sum=0;
                x--;
            }
            int num=0;
            for(int i=0; i<l; i++)
                num+=a[i];
            if(num>=maxx)
                printf("%lld\n",n);
            else{
                a[pos]-=1;
                for(int i=l-1; i>pos; i--)
                    printf("%d",a[i]);
                if(a[pos])
                    printf("%d",a[pos]);
                for(int i=pos-1; i>=0; i--)
                    printf("9");
                printf("\n");
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << "  - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;

typedef long long ll;

const int N = 100000100;

int aa[N];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input", "r+", stdin);
#endif // ONLINE_JUDGE

    int a, b, c, d;
    cin >> a >> b;
    cin >> c >> d;

    for(int i = 1; i <= N / 100; i++){
        int r1 = b + i * a;
        int r2 = d + i * c;
        aa[r1]++;
        aa[r2]++;
    }

    for(int i = 0; i < N; i++){
        if(aa[i] == 2){
            cout << i  << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


#include<iostream>
using namespace std;

bool arr[1000000001];

int main()
{
	int a, b, d, c;
	cin >> a >> b >> c >> d;
	if (b==d)
	{
		cout << b;
		return 0;
	}
	unsigned long int result1 = b, result2 = d;
	while (result1 <= 1000000001 )
	{
		arr[result1] = true;
		result1 += a;
	}
	while (result2 <= 1000000001)
	{
		if (arr[result2])
		{
			cout << result2;
			return 0;
		}
		result2 += c;
	}
	cout << -1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 0.75 * 1e8;

int A[N];

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = b; i < N; i += a) {
    A[i] = 1;
  }
  for (int i = d; i < N; i += c) {
    if (A[i]) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}


#include <iostream>
#include<string.h>
#include<cstdio>
#include<map>
#define N 60

using namespace std;

map< pair<char , char> , int > maps ;
pair< char , char > get[N][N] ;

struct date{
    char a ;
    char b ;
}map1[60] ;

bool mark[N] ;
int num = 0 , n , m , t1 , t2 ;
int firstx[200] , firsty[200] ;

void insertmap( char ch ){
    maps[ make_pair( ch , 'C' ) ] = num ++ ;
    map1[num - 1].a = ch ; map1[num - 1].b = 'C' ;
    maps[ make_pair( ch , 'D' ) ] = num ++ ;
    map1[num - 1].a = ch ; map1[num - 1].b = 'D' ;
    maps[ make_pair( ch , 'H' ) ] = num ++ ;
    map1[num - 1].a = ch  ; map1[num - 1].b = 'H' ;
    maps[ make_pair( ch , 'S' ) ] = num ++ ;
    map1[num - 1].a = ch ; map1[num - 1].b = 'S' ;
}

int judge1( int k1 , int k2 ){
    char ch = get[k1][k2].second ;
    for( int i = k1 ; i < k1 + 3 ; i ++ ){
        for( int j = k2 ; j < k2 + 3 ; j ++ ){
            if( ch != get[i][j].second ){
                return 0 ;
            }
        }
    }
    return 1 ;
}

int judge2( int k1 , int k2 ){
    bool mk[500] ;
    memset( mk , 0 , sizeof( mk ) ) ;
    for( int i = k1 ; i < k1 + 3 ; i ++ ){
        for( int j = k2 ; j < k2 + 3 ; j ++ ){
            if( !mk[ get[i][j].first ] ){
                mk[ get[i][j].first ] = 1;
            }
            else{
                return 0 ;
            }
        }
    }
    return  1 ;
}

int judge(){
    int sum = 0 ;
    for( int i = 0 ; i < 3 ; i ++ ){
        for( int j = 0 ; j < 3 ; j ++ ){
            for( int k1 = i ; k1 < n ; k1 += 3 ){
                for( int k2 = j ; k2 < m ; k2 += 3 ){
                    if( judge1( k1 , k2 ) ){
                        firstx[sum] = k1 ;
                        firsty[sum ++] = k2 ;
                    }
                    else{
                        if( judge2( k1 , k2 ) ){
                            firstx[sum] = k1 ;
                            firsty[sum ++] = k2 ;
                        }
                    }
                }
            }
        }
    }
    for( int i = 0 ; i < sum ; i ++ ){
        for( int j = i + 1 ; j < sum ; j ++ ){
            int x1 = firstx[i] , x2 = firstx[i] + 2 ;
            int y1 = firsty[i] , y2 = firsty[i] + 2 ;
            if( !( ( firstx[j] >= x1 && firstx[j] <= x2 || firstx[j] + 2 >= x1 && firstx[j] + 2 <= x2 ) && ( firsty[j] >= y1 && firsty[j] <= y2 || firsty[j] + 2 >= y1 && firsty[j] + 2 <= y2 ) ) ){
                t1 = i ;
                t2 = j ;
                return 1 ;
            }
        }
    }
    return 0 ;
}

int main()
{
    for( int i = 2 ; i <= 9 ; i ++ ){
        insertmap( i + '0' ) ;
    }
    insertmap( 'T' ) ;
    insertmap( 'Q' ) ;
    insertmap( 'K' ) ;
    insertmap( 'A' ) ;
    int ans = 0 ;
    char str[10] ;
    int x[2] , y[2] ;
    while(cin>>n>>m){

        memset( mark , 0 , sizeof( mark ) ) ;
        ans = 0 ;
        for( int i = 0 ; i < n ; i ++ ){
            for( int j = 0 ; j < m ; j ++ )
            {

                scanf( "%s" , str ) ;
                get[i][j].first = str[0] ;
                get[i][j].second = str[1] ;//cout<<i<<" "<<j<<str[0]<<str[1]<<endl;
                if( get[i][j].first == 'J' ){
                    x[ans] = i ;//cout<<i<<" "<<j<<str[0]<<str[1]<<endl;
                    y[ans ++] = j ;
                }
                else{
                    mark[ maps[ get[i][j] ] ] = 1 ;
                }
               // cout<<i<<" "<<j<<" "<<get[i][j].first<<" "<<get[i][j].second<<endl;
            }
        }

        if( ans == 2 ){
            if( get[x[0] ][y[0]].second > get[x[1]][y[1]].second ){
                int as = x[0] , bs = y[0] ;
                x[0] = x[1] ;
                y[0] = y[1] ;
                x[1] = as ;
                y[1] = bs ;
            }
            str[0] = '1' ;
            str[1] = '2' ;
        }
        else{
            if( ans == 1 ){
                str[0] = get[ x[0] ][ y[0] ].second ;
            }
        }
        if( ans == 0 ){
            if( !judge() ){
                printf( "No solution.\n" ) ;
            }
            else{
                printf( "Solution exists.\n" ) ;
                printf( "There are no jokers.\n" ) ;
                printf( "Put the first square to (%d, %d).\nPut the second square to (%d, %d).\n" , firstx[t1] + 1 , firsty[t1] + 1 , firstx[t2] + 1,  firsty[t2] + 1 ) ;
            }
        }
        else{
            if( ans == 1 ){
                int flag = 0 ;
                for( int i = 0 ; i < num ; i ++ ){
                    if( !mark[i] ){
                        get[ x[0] ][ y[0] ].first = map1[i].a ;
                        get[x[0] ][ y[0] ].second = map1[i].b ;
                        if( judge() ){
                            printf( "Solution exists.\n" ) ;
                            printf( "Replace J%c with %c%c.\n" , str[0] , map1[i].a , map1[i].b ) ;
                            printf( "Put the first square to (%d, %d).\nPut the second square to (%d, %d).\n" , firstx[t1] + 1 , firsty[t1] + 1 , firstx[t2] + 1,  firsty[t2] + 1 ) ;
                            flag = 1 ;
                            break ;
                        }
                    }
                }
                if( !flag ){
                    printf( "No solution.\n" ) ;
                }
            }
            else{
                int flag = 0 ;
                int j ;
                for( int i = 0 ; i < num ; i ++ ){
                    if( !mark[i] )
                    {
                        for( j = 0 ; j < num ; j ++ ){
                            if( !mark[j] && i != j ){
                                get[ x[0] ][ y[0] ].first = map1[i].a ;
                                get[ x[0] ][ y[0] ].second = map1[i].b ;
                                get[ x[1] ][ y[1] ].first = map1[j].a ;
                                get[ x[1] ][ y[1] ].second = map1[j].b ;
                                if( judge() ){
                                    flag = 1;
                                    break ;
                                }
                            }
                        }
                    }
                    if( flag ){
                        printf( "Solution exists.\n" ) ;
                        printf( "Replace J1 with %c%c and J2 with %c%c.\n" , map1[i].a , map1[i].b , map1[j].a , map1[j].b) ;
                        printf( "Put the first square to (%d, %d).\nPut the second square to (%d, %d).\n" , firstx[t1] + 1 , firsty[t1] + 1 , firstx[t2] + 1,  firsty[t2] + 1 ) ;
                        break ;
                    }
                }
                if( !flag ){
                    printf( "No solution.\n" ) ;
                }
            }
        }
    }
    return 0;
}


/*
 * main.cpp
 *
 *  Created on: 29.03.2011
 *      Author: skird
 */

#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <cstdlib>
#include <cstdio>

using namespace std;

int cost(char c)
{
	if (c >= '2' && c <= '9') return c - '2';
	if (c == 'T') return 8;
	if (c == 'J') return 9;
	if (c == 'Q') return 10;
	if (c == 'K') return 11;
	return 12;
}

int color(char c)
{
	if (c == '1') return 100500;
	if (c == '2') return 100600;
	if (c == 'C') return 0;
	if (c == 'D') return 1;
	if (c == 'H') return 2;
	return 3;
}

struct Card
{
	int p, c;

	Card() {}
	Card(int _p, int _c): p(_p), c(_c) {}
	Card(istream &in)
	{
		string token;
		cin >> token;
		p = cost(token[0]);
		c = color(token[1]);
	}

	bool isJoker()
	{
		return c == 100500 || c == 100600;
	}
};

bool operator < (Card a, Card b)
{
	return a.p < b.p || (a.p == b.p && a.c < b.c);
}

int n, m;
vector< vector<Card> > data;

bool goodSquare(int x, int y)
{
	int used[20];
	fill(used, used + 20, 0);
	bool ok = true;
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
		{
			used[data[x + i][y + j].p]++;
			if (data[x + i][y + j].c != data[x][y].c) ok = false;
		}
	if (ok) return true;
	ok = true;
	for (int i = 0; i < 20; i++)
		ok &= used[i] <= 1;
	return ok;
}

bool cross(pair<int, int> a, pair<int, int> b)
{
	int dx = abs(a.first - b.first), dy = abs(b.second - a.second);
	return dx < 3 && dy < 3;
}

pair< pair<int, int>, pair<int, int> > isOk()
{
	vector< pair<int, int> > squares;
	for (int i = 0; i + 2 < n; i++)
		for (int j = 0; j + 2 < m; j++)
			if (goodSquare(i, j)) squares.push_back(make_pair(i, j));
	for (size_t i = 0; i < squares.size(); i++)
		for (size_t j = 0; j < squares.size(); j++)
			if (!cross(squares[i], squares[j])) return make_pair(squares[i], squares[j]);
	return make_pair(make_pair(-1, -1), make_pair(-1, -1));
}

set<Card> rest;
vector< pair<int, int> > jokers;

void print(pair<int, int> x)
{
	Card c = data[x.first][x.second];
	if (c.p >= 0 && c.p < 8) cout << (char) (c.p + '2');
	else
	{
		switch (c.p)
		{
			case 8: cout << "T"; break;
			case 9: cout << "Q"; break;
			case 10: cout << "J"; break;
			case 11: cout << "K"; break;
			case 12: cout << "A"; break;
		}
	}
	switch (c.c)
	{
		case 100500: cout << "1"; break;
		case 100600: cout << "2"; break;
		case 0: cout << "C"; break;
		case 1: cout << "D"; break;
		case 2: cout << "H"; break;
		case 3: cout << "S"; break;
	}
}

pair< pair<int, int>, pair<int, int> > rec(int r)
{
	if (r == 0) return isOk();
	set<Card>::iterator it;
	int x = jokers[r - 1].first, y = jokers[r - 1].second;
	for (it = rest.begin(); it != rest.end(); it++)
	{
		Card c = *it;
		rest.erase(c);
		Card copy = data[x][y];
		data[x][y] = c;
		pair< pair<int, int>, pair<int, int> > temp = rec(r - 1);
		if (temp.first.first != -1) return temp;
		data[x][y] = copy;
		rest.insert(c);
	}
	return make_pair(make_pair(-1, -1), make_pair(-1, -1));
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> n >> m;
	data.assign(n, vector<Card>(m));
	for (int i = 0; i < 13; i++)
		for (int j = 0; j < 4; j++)
			rest.insert(Card(i, j));
	vector<int> some;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
		{
			data[i][j] = Card(cin);
			if (!data[i][j].isJoker()) rest.erase(data[i][j]);
			if (data[i][j].isJoker())
				jokers.push_back(make_pair(i, j)), some.push_back(data[i][j].c);
		}
	pair< pair<int, int>, pair<int, int> > temp = rec(jokers.size());
	if (temp.first.first == -1)
	{
		cout << "No solution.";
		return 0;
	}
	cout << "Solution exists." << endl;
	if (jokers.size() == 0) cout << "There are no jokers." << endl;
	else if (jokers.size() == 1)
	{
		cout << "Replace J" << (some[0] == 100500 ? 1 : 2) << " with ";
		print(jokers[0]);
		cout << "." << endl;
	}
	else
	{
		if (some[0] != 100500) swap(jokers[0], jokers[1]);
		cout << "Replace J1 with ", print(jokers[0]);
		cout << " and J2 with ", print(jokers[1]);
		cout << "." << endl;
	}
	cout << "Put the first square to (" << temp.first.first + 1 << ", " << temp.first.second + 1 << ")." << endl;
	cout << "Put the second square to (" << temp.second.first + 1 << ", " << temp.second.second + 1 << ").";
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <string>
#include <set>
#include <math.h>
using namespace std;
int n,m,cnt;
string a[20][20];
struct node{int x,y;}p[2],ans[2];
node f[1000];
set<string> have;
bool check()
{
    int num=0;
   // cout<<"F"<<endl;
    set<char>g,gg;
    for(int i=0;i<n-2;i++)
    for(int j=0;j<m-2;j++)
    {
        g.clear();gg.clear();
       // printf("%d %d\n",i,j);
        for(int k=i;k<i+3;k++)
        for(int l=j;l<j+3;l++)
        {
            g.insert(a[k][l][0]);
            gg.insert(a[k][l][1]);
        }
        //cout<<g.size()<<endl;
        if(g.size()==9||gg.size()==1)
        {
            f[num].x=i;
            f[num].y=j;num++;
        }
    }
//    cout<<num<<endl;
//    cout<<f[0].x<<f[0].y<<endl;
    for(int i=0;i<num;i++)
    for(int j=i+1;j<num;j++)
    if((abs(f[i].x-f[j].x)>=3||abs(f[i].y-f[j].y)>=3))
    {
        ans[0]=f[i];
        ans[1]=f[j];
        return 1;
    }
    return 0;

}
char m1[15]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
char m2[4]={'C','D','H','S'};
int caocao=0;
void out()
{
    printf("Put the first square to (%d, %d).\n",ans[0].x+1,ans[0].y+1);
    printf("Put the second square to (%d, %d).\n",ans[1].x+1,ans[1].y+1);
}
int main()
{
   // freopen("in.txt","r",stdin);
    cin>>n>>m;
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        have.insert(a[i][j]);
        if(a[i][j][0]=='J')
        {
            caocao=a[i][j][1]-'1';
            p[a[i][j][1]-'1'].x=i;
            p[a[i][j][1]-'1'].y=j;cnt++;
        }
    }
    if(cnt==0)
    {
        if(check())
        {
            printf("Solution exists.\n");
            printf("There are no jokers.\n");
            out();
        }else
        printf("No solution.\n");
    }
    else
    {
        if(cnt==1)
        {
            for(int i=0;i<13;i++)
            for(int j=0;j<4;j++)
            {
                string k;
                k+=m1[i];
                k+=m2[j];
                //cout<<k<<endl;
                if(have.find(k)==have.end())
                {
                    a[p[caocao].x][p[caocao].y]=k;
                    if(check())
                    {
                        printf("Solution exists.\n");
                        printf("Replace J%d with ",caocao+1);
                        cout<<k<<"."<<endl;
                        out();
                        return 0;
                    }
                }
            }
            printf("No solution.\n");
        }
        else
        {
            for(int i=0;i<13;i++)
            for(int j=0;j<4;j++)
            {
                string k1;
                k1+=m1[i];
                k1+=m2[j];
                if(have.find(k1)==have.end())
                {
                    a[p[0].x][p[0].y]=k1;
                    for(int k=0;k<13;k++)
                    for(int l=0;l<4;l++)
                    if(!(k==i&&l==j))
                    {
                        string k2;
                        k2+=m1[k];
                        k2+=m2[l];
                        if(have.find(k2)==have.end())
                        {
                            a[p[1].x][p[1].y]=k2;
                            if(check())
                            {
                                 printf("Solution exists.\n");
cout<<"Replace J1 with "<<k1<<" and J2 with "<<k2<<"."<<endl;
                                out();
                                return 0;
                            }
                        }
                    }
                }
            }
            printf("No solution.\n");
        }
    }

//    cout << "Hello world!" << endl;
    return 0;
}


#include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<climits>
using namespace std;
string a[100][100];
string f[]={"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" ,"A"};
string p[]={"C", "D", "H" , "S"};
int n,m,jk=0,ok=0;
set<string>st;
vector<string>out;
string ff[]={"J1","J2"};
bool check(int x,int y)
{
    int i,j,k;
    int vis[130]={0};
    for (i=x;i<x+3;i++)
    {
        for (j=y;j<y+3;j++)
        {
            vis[a[i][j][0]]=1;
            //if (x==1&&y==0)printf("%c\n",a[i][j][0]);
        }
    }

    if (count(vis,vis+130,1)==9)return 1;
    memset(vis,0,sizeof(vis));
    for (i=x;i<x+3;i++)
    {
        for (j=y;j<y+3;j++)
        {
            vis[a[i][j][1]]=1;
        }
    }
    if (count(vis,vis+130,1)==1)return 1;
    return 0;
}
void dfs(int now)
{
    int i,j,k,l,u;
    if (ok)return;
    if (now==jk)
    {
        for (i=0;i+2<n;i++)
        {
            for (j=0;j+2<m;j++)
            {
                if (check(i,j))
                {
                    for (k=0;k+2<n;k++)
                    {
                        for (l=0;l+2<m;l++)
                        {
                            if ((k<=i+2&&l<=j+2))continue;
                            if (check(k,l))
                            {
                                puts("Solution exists.");
                                if (!jk)
                                {
                                    puts("There are no jokers.");
                                }
                                else
                                {
                                    for (u=0;u<out.size();u++)
                                    {
                                        cout<<out[u]<<endl;
                                    }
                                }
                                printf("Put the first square to (%d, %d).\n",i+1,j+1);
                                printf("Put the second square to (%d, %d).\n",k+1,l+1);
                                ok=1;
                                return;
                            }
                        }
                    }
                }
            }
        }
        return;
    }
    int x,y;
    for (i=0;i<n;i++)
    {
        for (j=0;j<m;j++)
        {
            if (a[i][j][0]=='J'&&a[i][j][1]-'0'==now+1)
            {
                x=i,y=j;
            }
        }
    }
    for (set<string>::iterator ptr=st.begin();ptr!=st.end();++ptr)
    {
        string tmp=*ptr;
        st.erase(tmp);
        string tt=a[x][y];
        a[x][y]=tmp;
        out.push_back("Replace "+ff[now]+" with "+tmp+".");
        dfs(now+1);
        out.pop_back();
        st.insert(tmp);
        a[x][y]=tt;
    }
}
int main()
{
    int i,j,k;
    for (i=0;i<13;i++)
    {
        for (j=0;j<4;j++)
        {
            st.insert(f[i]+p[j]);
        }
    }
    cin>>n>>m;
    for (i=0;i<n;i++)
    {
        for (j=0;j<m;j++)
        {
            cin>>a[i][j];
            if (a[i][j][0]!='J')st.erase(a[i][j]);
            else ++jk;
        }
    }
    dfs(0);
    if (!ok)puts("No solution.");
    return 0;
}


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

using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	int a[102];
	for (int l = 1; l <= n; l++) cin >> a[l];
	int i = m, j = m;

	while (i <= n)
	{
		i++;
		if (a[i] <= k && a[i] != 0) break;
		if (i == n)
		{
			i = m;
			break;
		}
	}
	while (j >= 2)
	{
		j--;
		if (a[j] <= k && a[j] != 0)break;
		if (j == 2)
		{
			j = m; break;
		}
	}
	if (i != m && j != m)
	{
		if (i - m > m - j)cout << (m - j) * 10;
		if (i - m <= m - j)cout << (i - m) * 10;
	}
	else if (j == m)cout << (i - m) * 10;
	else cout << (m - j) * 10;
	_getch();
}


#include<iostream>
#include<conio.h>
#include<math.h>

using namespace std;

void main(){
	int n, m, k, *t, x;
	cin>>n>>m>>k;
	t = new int[n];
	x=n*100;
	int dist=x;
	for(int i=0;i<n;i++){
		cin>>t[i];
		if(t[i]!=0 && t[i]<=k)
			dist=abs((i+1-m)*10);
		if(dist<x)
			x=dist;
	}
	cout<<x;
	getch();
}


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

using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	int a[102];
	for (int i = 1; i <= n; i++) cin >> a[i];
	int i = m, j = m;

	while (i <= n)
	{
		i++;
		if (a[i] <= k && a[i] != 0) break;
	}
	while (j >= 2)
	{
		j--;
		if (a[j] <= k && a[j] != 0)break;
	}
	if (i - m > m - j && j != m)cout << (m - j) * 10;
	if (i - m >= m - j && i != m)cout << (i - m) * 10;
	_getch();
}


#include <iostream>
#include <iomanip>
#include <cstdlib>

#include <cmath>
#include <cstring>
#include <cstdio>

int main()
{
	int n,m,k,i,j=1,cost,ans;

	scanf("%d %d %d",&n,&m,&k);
	int ara[n+1];
	memset(ara,0,sizeof(ara));
	for(i=1;i<=n;i++)
	{
		scanf("%d",&ara[i]);
	}
	cost=999999;

	for(i=m+1;i<=n;i++)
	{
		if(ara[i]<=k && ara[i]!=0)
		{
				cost=10*j;
				break;

		}
		j++;
	}
	j=1;
	int store=999999;
	for(i=m-1;i>=1;i--)
	{
		if(ara[i]<=k && ara[i]!=0)
		{
				store=10*j;
				break;
		}
		j++;
	}
	if(store<cost)
	{
		ans=store;
	}
	else
	{
		ans=cost;
	}
	printf("%d\n",ans);

	//return 0;
	main();
}


typedef long long ll;
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <string.h>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <utility>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll> >

using namespace std;
ll mark[6007][6007];
vector<pll> v;
int main()
{
    ll x,y,x1,x2,x3,y1,y2,y3,i;
    cin>>x1>>y1;
    cin>>x2>>y2;
    cin>>x3>>y3;
    x=x1+x2-x3;
    y=y1+y2-y3;
    if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    x=x1+x3-x2;
    y=y1+y3-y2;
    if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    x=x2+x1-x3;
    y=y2+y1-y3;
    if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    x=x2+x3-x1;
    y=y2+y3-y1;
    if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    x=x3+x1-x2;
    y=y3+y1-y2;
   if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    x=x3+x2-x1;
    y=y3+y2-y1;
   if(mark[3000+x][3000+y]==0)
    {
        v.pb(mp(x,y));
        mark[3000+x][3000+y]=1;
    }
    cout<<v.size()<<endl;
    for(i=0;i<v.size();i++)
    cout<<v[i].first<<" "<<v[i].second<<endl;
	return 0;
}


#include<iostream>
#include<cmath>
#include<conio.h>

using namespace std;

int main()
{
	int x1, y1, x2, y2, x3, y3;
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
	cout << 3 << endl;
	cout
		<< (x2 + x3 - x1) << " " << (y2 + y3 - y1) << endl
		<< (x1 + x3 - x2) << " " << (y1 + y3 - y2) << endl
		<< (x1 + x2 - x3) << " " << (y1 + y2 - y3) << endl;

_getch();
return(0);
}


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

#define fr(i, a, b) for (i = a; i < b; ++i)
#define fr2(i, b, a) for (i = b; i >= a; --i)
#define vll vector<long long>
#define llp pair<long long, long long>
#define vllp vector<pair<long long, long long>>
#define pb push_back

#define set0(a) memset(a, 0, sizeof(a))
#define setneg(a) memset(a, -1, sizeof(a))
#define setinf(a) memset(a, 126, sizeof(a))
#define trace(a) cerr << #a << ": " << a << endl

#define N 1000000007
#define PI acos(-1.0)

typedef long long int ll;
typedef unsigned long long ull;

ll Npow(ll x, ll n, ll M = 1000000007)
{
	if (n == 0)
		return 1;
	else if (n % 2 == 0)
		return Npow((x * x) % M, n / 2, M);
	return (x * Npow((x * x) % M, (n - 1) / 2, M)) % M;
}
void print()
{
	;
}
template <typename T, typename... Types>
void print(T var1, Types... var2)
{
	cout << var1 << " ";
	print(var2...);
}

template <typename T>
void show(T *a, int size)
{
	int i;
	cout << endl
		 << "The array is ";
	fr(i, 0, size)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}

template <typename T>
void show_vector(vector<T> v)
{
	cout << endl
		 << "The vector is ";
	int i;
	fr(i, 0, v.size())
	{
		cout << v[i] << " ";
	}
	cout << endl;
}
//GLOBAL
#define M 10
//FUNCTIONS
ll n, k;

ll func(ll x)
{
	if (x <= n)
	{
		ll layers = floor(log2(n / x));
		ll ans = (1 << layers) - 1;
		if (n < x * (1 << layers) + (1 << layers))
		{
			ans += (n - x * (1 << layers) + 1);
		}
		else
		{
			ans += (1 << layers);
		}
		return ans;
	}
	else
	{
		return 0;
	}
}

bool possible(ll x)
{
	if (x % 2 == 0)
	{
		return func(x) + func(x + 1) >= k;
	}
	else
	{
		return func(x) >= k;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> k;
	ll high, low, mid;
	ll i;

	low = 0;
	high = n / 2;
	while (true)
	{
		mid = (low + high) / 2;
		if (possible(2 * mid))
		{
			if (!possible(2 * mid + 2))
			{
				if (possible(2 * mid + 1))
				{
					cout << 2 * mid + 1 << endl;
					break;
				}
				else
				{
					cout << 2 * mid << endl;
					break;
				}
			}
			else
			{
				low = mid + 1;
			}
		}
		else
		{
			high = mid - 1;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define vec vector
#define bg begin
#define pri pair < int,int >
#define prl pair < ll,ll >

// "\n"   scanf("%d",&a)   printf("%d ", ind-lst) printf("%I64d",ans) scanf("%lld", &a);
using namespace std;
ll n,m,p,q,i,j,k,x,y,z,c,d,l,r,l1,l2,lst,a,b,mn,mx,cnt,cur,u,v,w; // ll n,m,p,s,q,t,i,j,k,x,y,z,c,d,l,r,l1,l2,lst,a,b,mn,mx,cnt,cur,u,v,w;
map <ll,ll> obs;
ll count(ll num){
	if(num%2==1){
		if(num*2>n) return 1;
		if(!obs[num*2]) obs[num*2] = count(num*2);
		return 1+obs[num*2];
	}
	else{
		ll ret = 1;
		if(num*2<=n){
			if(!obs[num*2]) obs[num*2] = count(num*2);
			 ret+=obs[num*2];
		}
		if(num+1<=n){
			if(!obs[num+1]) obs[num+1] = count(num+1);
			ret+=obs[num+1];
		}
		return ret;
	}
}

bool ok(ll p){
	if(count(p)>=k) return true;
	else return false;
}

int main(){
	cin >> n >> k;
	l = 2;
	r = n-n%2;
	ll lastl = -1,lastr = -1;
	while(!(l==lastl&&r==lastr)){
		ll mid = l+(r-l)/2;
		mid-=mid%2;
		lastl = l;
		lastr = r;
		if(ok(mid)) l = mid;
		else r = mid;
	}
	ll q = 1;
	if(ok(l)) q=l;
	if(ok(r)) q=r;
	l = 1;
	r = n-(1-n%2);
	lastl = -1,lastr = -1;
	while(!(l==lastl&&r==lastr)){
		ll mid = l+(r-l)/2;
		mid-=(1-mid%2);
		lastl = l;
		lastr = r;
		if(ok(mid)) l = mid;
		else r = mid;
	}
	x = 1;
	if(ok(l)) x = l;
	if(ok(r)) x = r;
	cout << max(q,x);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//typedef long long int lli;
ll mod=1e9+7;
#include<string.h>
ll mod1=998244353;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef priority_queue<ll,vector<ll>,greater<ll> > pqset;
#define pb push_back
#define fi first
#define se second
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> os;
#define mp make_pair
#define acc (ios::sync_with_stdio(false),cin.tie(0))
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>0;i--)
ll fact[100001];
bool prime[100001];
ll ll_max(ll a,ll b,ll c){
	return max(a,max(b,c));
}
int int_max(int a,int b,int c){
	return max(a,max(b,c));
}
ll ll_min(ll a,ll b,ll c){
	return min(a,min(b,c));
}
int int_min(int a,int b,int c){
	return min(a,min(b,c));
}
ll gcd(ll a,ll b,ll c){
	return __gcd(a,__gcd(b,c));
}
void sieve(int n)
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
double dist(ll i1,ll j1,ll k1,ll i2,ll j2,ll k2){
	double a=pow((i1-i2),2)+pow((j1-j2),2)+pow((k1-k2),2);
	a=sqrt(a);
	return a;
}
bool compare(pair<ll,ll> a,pair<ll,ll> b){
	if(a.first<b.first)
		return true;
	else if(a.first==b.first){
		if(a.second>b.second)
			return true;
		else
			return false;
	}
	else
		return false;
}
void buildTree(int arr[],int tree[], int start,int end,int node){
	if(start==end){
		tree[node]=arr[start];
		return;
	}
	int mid=(start+end)/2;
	buildTree(arr,tree,start,mid,2*node);
	buildTree(arr,tree,mid+1,end,2*node+1);
	tree[node]=tree[2*node]+tree[2*node+1];
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){
    return (a.second < b.second);
}
ll pow(ll a,ll b){
	if(a==1)
		return 1;
	if(b==0)
		return 1;
	ll c=pow(a,b/2);
	ll res=1;
	if(b%2){
		res=(c*c);
		res*=a;;
	}
	else
		res=(c*c);
	return res;
}

int lower_bound1(vector<int> v,int n,int p){
	int l=0;
	int r=n;
	if(v[0]>=p)
		return 0;
	while(l<r){
		int mid=(l+r)/2;
		if(v[mid]<p)
			l=mid+1;
		else if(v[mid]==p){
			if(mid==0)
				r=mid;
			if(v[mid-1]==p)
				r=mid-1;
			else
				r=mid;
		}
		else if(v[mid]>p)
			r=mid;
	}
	return l;
}
void bfs(vector<int> v[],int n,int a1,int b,bool visited[],int &count){
	queue<int> q;
	q.push(a1);
	q.push(b);
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){

		}
	}
}
ll modInv(ll a){
	return pow(a,mod-2)%mod;
}

void dfs(int i,bool visited[],vector<int> v[]){
	for(int j=0;j<v[i].size();j++){
		if(visited[v[i][j]]==false){
			visited[v[i][j]]=true;
			dfs(v[i][j],visited,v);
		}
	}
}
void factorial(ll n){
	fact[0]=1;
    for(int i=1;i<=n;i++){
    	fact[i]=fact[i-1]*i;
    	fact[i]%=mod;
	}
}
bool func(ll m,ll n,ll k){
	ll count=1;
	ll x=1;
	if(m%2==0){
		count++;
		x++;
		m++;
	}
	while(m<=n){
		if(n/m==1){
			return false;
		}
		m*=(ll)2;
		m++;
		ll o=pow((ll)2,x);
		if(m<=n){
			count+=o;
		}
		else if((m-n)<=o){
			count+=(o-(m-n));
		}
		if(count>=k){
			return true;
		}
		x++;
	}
	return false;

}
void solve(){
	ll n,k;
	cin>>n>>k;
	if(k==1){
		cout<<n<<endl;
		return;
	}
	ll r=n;
	while(func(r,n,k)==false){
		r/=2;
	}
	while(func(r,n,k)==true){
		if(n/r==1){
			cout<<r<<endl;
			return;
		}
		r*=2;
	}
	r/=2;

	cout<<r<<endl;
}
int main(){
    ll t=1;
    //cin>>t;
    while(t--){
    	solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";} cout<<endl;
#define S second
#define F first
#define int long long
typedef long long ll;
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;
string n;
int k , nn;

string binarystr(int x){
    string res = "";
    while(x){
        res += (x % 2) + '0';
        x /= 2;
    }
    reverse(res.begin() ,res.end());
    return res;
}

int backtoint(string x){
    int res = 0;
    int p = 1;
    for(int i = x.size() - 1; i >= 0 ; i--){
        if(x[i] == '1') res += p;
        p *= 2;
    }
    return res;
}

bool check(int mid){
    string m = binarystr(mid);
    if(m.size() > n.size()) return false;
    int c = n.size() - m.size();
    int p = 1;
    if(m[m.size() - 1] == '0') p = 2;
    int res = 0;
    for(int i = 0 ; i < c; i++){
        res += p;
        p *= 2;
    }
    string ss = n.substr(0 , m.size());
    if(ss == m){
        int x = backtoint(n.substr(m.size()));
        res += x + 1;
    }else if(ss > m){
        if(m[m.size() - 1] == '0'){
            if(backtoint(ss) - backtoint(m) > 1){
                res += 2 * pow(2LL, c);
            }else if(backtoint(ss) - backtoint(m) == 1){
                int x = backtoint(n.substr(m.size()));
                res += x + 1;
                res += pow(2LL, c);
            }
        }else res += pow(2LL, c);
    }
    return res >= k;
}

int32_t main(){
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    cin>>nn>>k;
    if(nn == k){
        cout<<1<<endl;
        return 0;
    }
    n = binarystr(nn);
    int l = 1 , r = LLONG_MAX/ 4, res = -1, mid;
    while(l <= r){
        mid = (l + r)/2;
        if(check(mid)){
            res = mid;
            l = mid + 1;
        }else r = mid - 1;
    }
    cout<<res<<endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<cmath>
#define len(i,j) (abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y))
typedef long long LL;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int maxn=2e5+10;
using namespace std;

template<typename _Tp> inline _Tp Max(_Tp a,_Tp b){return a>b?a:b;}
template<typename _Tp> inline _Tp Min(_Tp a,_Tp b){return a<b?a:b;}

LL dp[maxn];
LL tmp[maxn];

struct point{
   LL x,y;
   LL r;
   point(){}
   point(int x,int y):x(x),y(y),r(Max(x,y)){}
   bool operator < (const point&rhs) const{
      return r<rhs.r;
   }
}a[maxn];

bool cmp(point &a,point &b){
   if (a.r==b.r)
      {if (a.x==b.x) return a.y>b.y;
          else return a.x<b.x;}
      else return a.r<b.r;
}

int n;
LL ans=INF;

struct inter{
   int l,r;
   LL w;
}pos[maxn];

template<typename _Tp>
void gi(_Tp &x){
   x=0;
   char ch=getchar(),lst=' ';
   while (!isdigit(ch)){lst=ch;ch=getchar();}
   while (isdigit(ch)) {x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
   if (lst=='-') x=-x;
}

int main(){
   freopen("odyssey.in","r",stdin);
   freopen("odyssey.out","w",stdout);
   gi(n);
   int x,y;
   for (int i=1;i<=n;++i) {gi(x);gi(y);a[i]=point(x,y);}
   sort(a+1,a+n+1,cmp);
   for (int i=1;i<=n;++i) {printf("%d %d %d\n",a[i].x,a[i].y,a[i].r);}
   int p=0;
   int size=1;
   while (p<n){
   	  pos[size].l=pos[size-1].r+1;
      p=upper_bound(a+1,a+n+1,a[pos[size].l]) -a;
      pos[size].r=--p;
      pos[size].w=len(pos[size].r,pos[size].l);
      size++;
   } size--;
  memset(dp,0x3f,sizeof(dp));
  dp[0]=0;
  for (int k=1;k<size;++k){
    for (int i=pos[k].l;i<=pos[k].r;++i){
	   for (int j=pos[k-1].l;j<=pos[k-1].r;++j)
	     dp[i]=Min(dp[i],dp[j]+len(i,j));
	     //printf("x=%d %d\n",i,dp[i]);
     }
	for (int i=pos[k].l;i<=pos[k].r;++i) tmp[i]=INF;
	for (int i=pos[k].l; i<=pos[k].r; ++i)
      for (int j=pos[k].l; j<=pos[k].r; ++j){
          tmp[i]=Min(tmp[i],dp[j]+(pos[k].w<<1)-len(i,j));
          //printf("x=%d %d\n",i,tmp[i]);
       }

	  if (pos[k].l!=pos[k].r ) for (int i=pos[k].l;i<=pos[k].r;++i) dp[i]=tmp[i];
	}

   for (int i=pos[size].l;i<=pos[size].r;++i){
  	for (int j=pos[size-1].l;j<=pos[size-1].r;++j)
  	  ans=Min(ans, dp[j]+len(i,j)+Min(len(i,pos[size].l),len(i,pos[size].r))+pos[size].w);
  }

   printf("%I64d",ans);
   return 0;
}


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

using namespace std;
const int Maxn = 11000000;
const int mod = 1000000007;
long long table[Maxn][5];

int main(){

    char temp[Maxn];
    scanf("%s",temp+1);
        memset(table,0,sizeof(table));
        table[0][0] = 1;
        table[0][1] = 1;
        table[0][2] = 0;
        table[0][3] = 0;
        int n = strlen(temp+1);
        for(int i=1;i<n;i++){
            if(temp[i]=='0'){
                table[i][0] = (table[i-1][0])%mod;
            }
            if(temp[i]=='1'){
                table[i][0] = (table[i-1][2])%mod;
                table[i][1] = (table[i-1][0])%mod;
            }
            if(temp[i]=='2'){
                table[i][1] = (table[i-1][2])%mod;
            }
            if(temp[i]=='*'){
                table[i][2] = (table[i-1][1]+table[i-1][3])%mod;
                table[i][3] = (table[i-1][1]+table[i-1][3])%mod;
            }
            if(temp[i]=='?'){
                table[i][0] = (table[i-1][0]+table[i-1][2])%mod;
                table[i][1] = (table[i-1][0]+table[i-1][2])%mod;
                table[i][2] = (table[i-1][1]+table[i-1][3])%mod;
                table[i][3] = (table[i-1][1]+table[i-1][3])%mod;
            }
        }
        long long sum = 0;
        if(temp[n]=='?'){
            sum=(table[n-1][0]+table[n-1][1]+table[n-1][2]+table[n-1][3])%mod;
        }
        else if(temp[n]=='*'){
                sum=(table[n-1][1]+table[n-1][3])%mod;
            }
        else if(temp[n]=='0'){
                sum=(table[n-1][0])%mod;
            }
        else if(temp[n]=='1'){
                sum=(table[n-1][2])%mod;
            }
        else if(temp[n]=='2'){
                sum=0;
            }
        printf("%I64d\n",sum);
    return 0;
}


#include <bits/stdc++.h>
#define DIM 200007
#define INF 1000000007
using namespace std;

long long n;
map<long long,pair<long long,long long> > l,r;
map<long long,long long> dp[2];

long long dist(pair<long long,long long> p1, pair<long long,long long> p2)
{
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
int main()
{
    scanf("%lld",&n);
    for(int i = 1; i <= n; ++i)
    {
        long long x,y;
        scanf("%lld %lld",&x,&y);
        long long lvl = max(x,y);
        if(l.count(lvl) == 0)
        {
            l[lvl] = {x,y};
            r[lvl] = {x,y};
        }
        else
        {
            if(x < l[lvl].first || (x==l[lvl].first && y > l[lvl].second))
                l[lvl] = {x,y};

            if(x > r[lvl].first || (x==r[lvl].first && y < r[lvl].second))
                r[lvl] = {x,y};
        }
    }

    l[0] = {0,0};
    r[0] = {0,0};
    dp[0][0] = dp[1][0] = 0;
    for(int i = 1; i < l.size(); ++i)
    {
        dp[0][i] = min(dp[0][i-1] + dist(l[i-1],r[i]) + dist(r[i],l[i]),dp[1][i-1] + dist(r[i-1],r[i]) + dist(r[i],l[i]));
        dp[1][i] = min(dp[0][i-1] + dist(l[i-1],l[i]) + dist(l[i],r[i]),dp[1][i-1] + dist(r[i-1],l[i]) + dist(l[i],r[i]));
    }
    printf("%lld",min(dp[0][l.size()-1],dp[1][l.size()-1]));

    return 0;
}


#include <bits/stdc++.h>
#define DIM 200007
#define INF 1000000007
using namespace std;

long long n;
map<long long,pair<long long,long long> > l,r;
map<long long,long long> dp[2];

long long dist(pair<long long,long long> p1, pair<long long,long long> p2)
{
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
int main()
{
    scanf("%lld",&n);
    for(int i = 1; i <= n; ++i)
    {
        long long x,y;
        scanf("%lld %lld",&x,&y);
        long long lvl = max(x,y);
        if(l.count(lvl) == 0)
        {
            l[lvl] = {x,y};
            r[lvl] = {x,y};
        }
        else
        {
            if(x < l[lvl].first || (x==l[lvl].first && y > l[lvl].second))
                l[lvl] = {x,y};

            if(x > r[lvl].first || (x==r[lvl].first && y < r[lvl].second))
                r[lvl] = {x,y};
        }
    }

    l[0] = {0,0};
    r[0] = {0,0};
    dp[0][0] = dp[1][0] = 0;
    for(int i = 1; i < (long long)l.size(); ++i)
    {
        dp[0][i] = min(dp[0][i-1] + dist(l[i-1],r[i]) + dist(r[i],l[i]),dp[1][i-1] + dist(r[i-1],r[i]) + dist(r[i],l[i]));
        dp[1][i] = min(dp[0][i-1] + dist(l[i-1],l[i]) + dist(l[i],r[i]),dp[1][i-1] + dist(r[i-1],l[i]) + dist(l[i],r[i]));
    }
    printf("%lld",min(dp[0][(long long)l.size()-1],dp[1][(long long)l.size()-1]));

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node {
	int x, y, z, cnt;
	node(int x,int y,int z, int cnt) : x(x), y(y), z(z), cnt(cnt) {}
	bool operator < (const node & a) const {
		return cnt > a.cnt;
	}
};
bool check(node a) {
	int x = a.x, y = a.y, z = a.z;
	if(x < y + z && y < x + z && z < x + y) return 1;
	return 0;
}
int main() {
	priority_queue<node> q;
	int x, y, z;
	scanf("%d %d %d",&x, &y, &z);
	q.push(node(x,y,z,0));
	while(!q.empty()) {
		node cur = q.top();
		q.pop();
		if(check(cur)) {
			printf("%d\n",cur.cnt);
			return 0;
		}
		cur.cnt++;
		cur.x++;q.push(cur);
		cur.x--;cur.y++;q.push(cur);
		cur.y--;cur.z++;q.push(cur);
	}
}


#include <iostream>

using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;

    int mx=max(x,max(y,z));
    int p=(x+y+z)/2;
    if(mx<p||(mx==p&&(x+y+z)%2==1)){cout<<0;return 0;}

    cout<<2*(mx-p)+1;

    return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;

int main() {
	int a, b, c, m = 0;
	cin >> a >> b >> c;

	if (a + b <= c) {
		m = c - a - b + 1;
	}
	else if (a + c <= b) {
		m = b - a - c + 1;
	}
	else if (b + c <= a) {
		m = a - c - b + 1;
	}

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


#include <cstdio>

long long ex[11777777];
int first[11777777],ey[11777777],ez[11777777],es[11777777];
int g[30];
long long f[30];
int i,k,l,n,sum_fact;
long long m,s;

void dfs1(int x,int y,long long z)
{
	if ((y>k) || (z>m))
		return;
	if (x>n/2)
	{
		bool b=false;
		int r=((k-y)*(long long) 1e16+m-z)%11777777;
		for (int i=first[r];i!=0;i=ez[i])
			if ((ex[i]==m-z) && (ey[i]==k-y))
			{
				es[i]++;
				b=true;
				break;
			}
		if (! b)
		{
			sum_fact++;
			ex[sum_fact]=m-z,ey[sum_fact]=k-y,es[sum_fact]=1;
			ez[sum_fact]=first[r],first[r]=sum_fact;
		}
		return;
	}
	dfs1(x+1,y,z);
	dfs1(x+1,y,z+g[x]);
	if (g[x]<=18)
		dfs1(x+1,y+1,z+f[g[x]]);
	return;
}

void dfs2(int x,int y,long long z)
{
	if ((y>k) || (z>m))
		return;
	if (x>n)
	{
		for (int i=y;i<=k;i++)
			for (int j=first[(i*(long long) 1e16+z)%11777777];j!=0;j=ez[j])
				if ((ex[j]==z) && (ey[j]==i))
					s=s+es[j];
		return;
	}
	dfs2(x+1,y,z);
	dfs2(x+1,y,z+g[x]);
	if (g[x]<=18)
		dfs2(x+1,y+1,z+f[g[x]]);
	return;
}

int main()
{
	scanf("%d%d%I64d",&n,&k,&m);
	for (i=1;i<=n;i++)
		scanf("%d",&g[i]);
	for (i=1;i<=n;i++)
		if (g[i]<=18)
			l++;
	if (k>l)
		k=l;
	f[0]=1;
	for (i=1;i<=18;i++)
		f[i]=f[i-1]*i;
	dfs1(1,0,0);
	dfs2(n/2+1,0,0);
	printf("%I64d",s);
	return 0;
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define ff              first
#define ss              second
#define pb(x)           push_back(x)
#define mp              make_pair
#define sz(x)           x.size()
#define mem(x ,y)       memset(x , y , sizeof x )
#define all(a )         a.begin() , a.end()
#define endl            "\n"
#define pii             pair<int,int>
#define clr(x)          x.clear()
#define sl(x )          scanf("%I64d" ,&x)
#define si(x )          scanf("%d" ,&x)
#define forn(i ,x,n )   for(int i = x ; i <= n ; i++ )
#define ford(i ,x,n )   for(int i = x ; i >= n ; i-- )
#define rep(i,n )       for(int i= 0; i<n ; i++ )
#define repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#define dbg(args...)    do {   cerr << #args << ' ' ;  print(args); } while(0); cerr<< endl ;
typedef long long ll  ;
int  mod1 =  1e9+7, mod2 = 998244353 ;
int mod  =  mod1 ;
typedef unsigned long long  ull ;
int setbit(int n, int pos  ) { return n = n|(1<< pos) ; }
int resetbit(int n,int pos ) {  return n =  n & ~(1<<pos ); }
bool checkbit(int  n,int pos ) { return (bool ) (n&(1<<pos))  ; }
template < typename T > T mul(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template < typename T > T add(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return (x+y)%mod ;  }
template < typename T > T sub(T x, T y, T mod = mod ) { x %= mod ; y %= mod ; return ((x-y)%mod+mod )%mod;  }
template < typename T > T ext_gcd(T num1 , T num2, T &X , T &Y ) { T r2,r1, q2, q1 , x2, x1, y2 ,y1 , x,  y, r   ; x2 = 1; y2 = 0;  x1 = 0; y1 = 1; for( r2 =num1 ,r1 = num2 ;r1 != 0 ; y2 = y1, y1 = y,x2 = x1 ,x1 = x ,r2 = r1, r1 = r) {q1 = r2/r1; x = x2 - q1*x1; y = y2 - q1*y1; r = r2%r1 ; } X = x2 ; Y = y2 ; return r2 ;  }
template < typename T > void print(const T& v) {    cerr << v << ' ' ;}
template < typename T1, typename... T2 > void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
template<class T> string to_str(T t){stringstream ss; ss<<t; return ss.str();}
template < typename T >
T  bigmod(T x, T k ,T mod = mod) {
    if(k == 0 ) return (T)1;
    if(k&1  ) {
        return ( (x%mod)*bigmod(x,k-1, mod )%mod )%mod ;
    } else {
        T ret = bigmod(x,k/2  , mod ) ;
        ret %= mod ;
        return (ret*ret )%mod;
    }

}
template < typename T >
T  invmod( T x , T m) {
    return bigmod(x,m-2 , m) ;
    // long long ret, t ;//
    // ext_gcd( x, m ,ret ,t  ) ;
    // ret %= m ; if(ret<0) ret += m  ;
    // return ret;
}
// typedef tree< pair< int , int > ,     // change type
//               null_type,
//               pair< int , int > ,  // change type
//               rb_tree_tag,
//               tree_order_statistics_node_update> o_set;
// oreder_of_key(k )
// debuging ...
template<typename T >
void dbg_a(T a[] ,int n=10 ) {
    cerr << "[ ";
        for(int i=0;i < n ; i++ )
            cerr<<a[i]<<' ' ;
                cerr<< " ]" <<  endl;
}
template < typename F,  typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "[ " << p.first << ", " << p.second << " ]";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[ ";
        for(int i=0; i<sz(v) ; i++ )
            os << v[i] << ' ' ;
                return os << " ]\n" ;
}
template < typename T >
ostream &operator << ( ostream & os, const map< T ,T> &Map  ) {
    os << "[ ";
        repit(it , Map )
            os << "[" <<(*it).ff << ' ' << (*it).ss << "] "    ;
                return os << "]\n" ;
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &Set  ) {
    os << "[ ";
        repit(it , Set )
            os <<  *it  << ' ' ;
                return os << " ]\n" ;
}
// int dx[] = {0 , 0 ,+1, -1 } ;
// int dy[] = {-1, +1,0 , 0 };
// int dx[10 ] =  {-2,-2, 2, 2  ,+ 1, -1  , +1, -1 }  ;
// int dy[10 ] =  {+1,-1, 1, -1 , +2,+2 , -2,-2  }  ;
#define  int   ll
const int maxn  = (int )2e5+ 123  ;
const int  inf  =  1e9+ 123 ;
///////////////////////////////////////////////////////////////

int n , k , S ,a[maxn] , lim , ans ,fact[maxn ] ,f = 0;
map<ll ,ll >dp[maxn ] ;
void func(int id , int cnt  , int tot) {
    dbg(id ,cnt , tot   , lim)
    if(cnt>k or tot>S ) return ;
    if(id>lim) {
        if(f == 0 ) {
                dbg(cnt , tot ) ;
                dp[cnt ][tot]++ ;
        }
        else {
            for(int i=0 ; i+cnt <=k ;i++ )
                ans +=  dp[i ][S-tot ];
        }
        return  ;

    }
    //take
    if(a[id]<19) {
        func(id+1,cnt+1 , tot+ fact[a[id] ]) ;

    }
    func(id+1, cnt, tot+a[id]) ;
    func(id+1, cnt , tot )  ;
}

void solve()   {
    int m  ,x    ,lo , hi ;
    fact[0] =1 ;
    cin >> n >> k >> S ;
    forn(i,1,n ) cin >> a[i] ;

    sort(a+1,a+1+n ) ;
    forn(i,1,22  ) fact[i] = fact[i-1 ]*(i*1LL) ;

    // dbg_a(a) ;
    // dbg_a(fact ) ;

    // dbg( n,k ,S) ;

    lim = n/2 ; func(1,0 , 0) ;

    cout << endl;
    f = 1; lim = n  ; func( n/2 +1 ,0 , 0) ;

    cout << ans << endl;

}
signed main() {
    #ifndef ONLINE_JUDGE
       freopen("in.txt", "r", stdin);
          // freopen("out.txt", "w", stdout);
    #endif
    ios :: sync_with_stdio(false);  cin.tie(0);
    cout.tie(0) ;
    clock_t st = clock() ;

    int  c = 0 ,t = 1;
    // cin>>t ;
    while(t--) {

        solve()  ;
    }
    // cerr  <<  "\nExecution time : " << (double )  (clock()-st )/CLOCKS_PER_SEC << endl ;

    return 0 ;

}


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

using namespace std;

#define TASKI "in.txt"
#define TASKO "o.txt"
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define _map unordered_map
#define _set unordered_set
#define sz(x) ((int)(x).size())
#define it(x) (x).begin(), (x).end()

#define TIMESTAMP(x)  eprintf("[" #x "] Time = %.5lfs\n",clock()*1.0/CLOCKS_PER_SEC)

#ifdef DEBUG
struct __timestamper {
  ~__timestamper() {
    TIMESTAMP(end);
  }
} __Timestamper;
#else
struct __timestamper {};
#endif

typedef long double ld;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;

int n, k;
ll S, a[30];

map <pli, ll> mem[30];

ll fact(ll n) {
  ll f = 1;
  for (int i = 1; i <= n; i++) {
    f *= i;
  }
  return f;
}

ll dp(int i, ll s, int k) {
  if (s < 0)
    return 0;
  if (s == 0)
    return 1;
  if (i == n)
    return 0;
  if (mem[i].count(mp(s, k)))
    return mem[i][mp(s, k)];
  mem[i][mp(s, k)] += dp(i + 1, s, k);
  mem[i][mp(s, k)] += dp(i + 1, s - a[i], k);
  if (a[i] <= 19 && k - 1 >= 0)
    mem[i][mp(s, k)] += dp(i + 1, s - fact(a[i]), k - 1);
  return mem[i][mp(s, k)];
}

int main(void) {
#ifdef DEBUG
//  freopen(TASKI, "r", stdin);
  //  freopen(TASKO, "w", stdout);
#endif
  scanf("%d %d %lld", &n, &k, &S);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
  }
  printf("%lld\n", dp(0, S, k));
  return 0;
}


#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <deque>
#include <cstring>
#include <functional>

using namespace std;

int n,k;
long long int s;
int x[30],t;
long long int f[20];
vector<int> y;
long long int triangle[26][26];

long long int choose(int a,int b){
	if(b==0)return 1;
	return triangle[a][b];
}
long long int ff(long long int r,int a,int ss,bool fir){
	if(fir){
		long long int ans=ff(r,a,ss,false);
		//printf("%I64d %d %I64d\n",r,a,ans);
		return ans;
	}
	if(r==0)return 1;
	if(a>=19){
		a-=19;
		if(a==y.size())return 0;
		if(y[a]>r)return ff(r,a+1,ss,true);
		return ff(r,a+1,ss,true)+ff(r-y[a],a+1,ss,true);
	}
	long long int ans=0;
	for(int b=0;b<=min(x[a],ss);b++){
		if(b*f[a]>r)break;
		for(int c=0;c<=x[a]-b;c++){
			if(b*f[a]+c*a>r)break;
			//printf("-%d %d %d\n",a,b,c);
			ans+=choose(x[a],b)*choose(x[a]-b,c)*ff(r-b*f[a]-c*a,a+1,ss-b,true);
		}
	}
	return ans;
}

int main(){
	int i, j;
    triangle[0][0] = 1; // C(0, 0) = 1
    for(i = 1; i <=25; i++) {
        triangle[i][0] = 1; // C(i, 0) = 1
        for(j = 1; j <= i; j++) {
            triangle[i][j] = triangle[i - 1][j - 1] + triangle[i - 1][j];
        }
    }
	f[0]=1;
	for(int a=1;a<20;a++)f[a]=f[a-1]*a;
	memset(x,0,sizeof(x));
	scanf("%d%d%I64d",&n,&k,&s);
	for(int a=0;a<n;a++){
		scanf("%d",&t);
		if(t<=18)x[t]++;
		else y.push_back(t);
	}
	printf("%I64d\n",ff(s,1,k,true));
	//system("pause");
    return 0;
}