#include <bits/stdc++.h>
using namespace std;
#define MAX 100009
#define ll long long

int setbit(int mask, int bit, int value);
int getbit(int mask, int bit);
ll cnt(int i, int msk_type, int msk_change, int mode);
ll fn(int i, int msk_type, int msk_change, int mode);
int bin_search(int t, int val);
ll get_ham(int small, int big, int msk_type);
void pre_process();
int check(int msk_type);
int check(int msk_type, int msk_change);
ll C(int x, int y);

pair<int, int> zero_one[MAX], one_zero[MAX];
int a = 0, b = 0;
int n, l, indx[MAX], diff_indx;
const ll inf = 9999999999;
ll dp[MAX][10][10][2], cnt_dp[MAX][10][10][2];

int main()
{
    scanf("%d %d", &l, &n);
    for(int i = 0; i < n; i++)
    {
        int x, y;
        scanf("%d %d", &x, &y);

        if(x == 0)
            zero_one[a++].first = y;
        else
            one_zero[b++].first = y;
    }

    pre_process();

    ll ans = 0, ret = 0;
    for(int i = 0; i < 8; i++)
    {
        // if(check(i))
        ans = max(ans, fn(0, i, 0, 0));
    }

    for(int i = 0; i < 8; i++)
        if(ans == fn(0, i, 0, 0) && check(i))
            //   printf("======%d %d\n", i, cnt(0, i, 0, 0));
            ret += cnt(0, i, 0, 0);
    printf("%lld\n",ret);

    return 0;
}

int check(int msk_type, int msk_change)
{
    int a = getbit(msk_type, 0);
    int b = getbit(msk_type, 1);
    int c = getbit(msk_type, 2);

    if(getbit(msk_change, 0)) a = !a;
    if(getbit(msk_change, 1)) b = !b;
    if(getbit(msk_change, 2)) c = !c;

    if(a == b && getbit(msk_change, 0) == 0 && getbit(msk_change, 1) == 1)return 0;
    if(a == c && getbit(msk_change, 0) == 0 && getbit(msk_change, 2) == 1)return 0;
    if(b == c && getbit(msk_change, 1) == 0 && getbit(msk_change, 2) == 1)return 0;

    return 1;
}

int check(int msk_type)
{
    int a = getbit(msk_type, 0);
    int b = getbit(msk_type, 1);
    int c = getbit(msk_type, 2);

    if(a > b || a > c) return 0;

    if(b > c) return 0;

    return 1;
}

ll cnt(int i, int msk_type, int msk_change, int mode)
{
    if(check(msk_type, msk_change) == 0)
        return 0;

    if(i == diff_indx)
        return msk_change == 7 ? 1 : 0;

    ll &ret = cnt_dp[i][msk_type][msk_change][mode];
    if(ret != -1)
        return ret;

    ret = 0;

    int nxt = indx[i + 1], curr = indx[i];

    ///get max_value
    ll g = fn(i, msk_type, msk_change, mode);

    if(g < 0)
        return 0;
    int p = 0;
    ///don't change
    if(i < diff_indx - 1)
    {
        if(g == fn(i + 1,  msk_type, msk_change, 0) + get_ham(curr, nxt, msk_type))
            ret += cnt(i + 1, msk_type, msk_change, 0), p++;
    }
    else
    {
        if(g == fn(i + 1, msk_type, msk_change, 0))
            ret += cnt(i + 1, msk_type, msk_change, 0), p++;
    }

    if(mode == 0)
    {
        int v1 = bin_search(0, curr);
        int v2 = bin_search(1, curr);

//if((i==3 && msk_type==6 && msk_change==0))
        for(int x = 1; x < 8; x++)
        {
            int new_msk_type = msk_type;
            int new_msk_change = msk_change;
            int flag = 1, u1 = 0, u2 = 0;

            for(int j = 0; j < 3 && flag; j++)
            {
                if(getbit(x, j) == 1)
                {
                    int t = getbit(msk_type, j);
                    if(t == 0)
                        u1++;
                    else
                        u2++;

                    if(getbit(msk_change, j) == 1 || (t == 0 && v1 == -1) || (t == 1 && v2 == -1))
                        flag = 0;
                    new_msk_type = setbit(new_msk_type, j, !t);
                    new_msk_change = setbit(new_msk_change, j, 1);
                }
            }

            if(u1 > v1 || u2 > v2)
                flag = 0;

            ll fac = C(v1,u1) * C(v2,u2);

          //  printf("%lld %d %d\n", fac,v1,v1-u1);
            if(flag)
            {

                if(fn(i, new_msk_type, new_msk_change, 1) == g)
                {
                    ret += fac * cnt(i, new_msk_type, new_msk_change, 1), p++;

                }
            }
        }
    }

    return ret;
}

ll C(int x, int y)
{
    if(x == 0 || y == 0)
        return 1;

    if(y == 1) return x;

    if(y == 2) return (ll)(x * (x - 1)) / 2;

    if(y == 3) return (ll)(x * (x - 1) * (x - 2)) / 6;
}

ll fn(int i, int msk_type, int msk_change, int mode)
{
    if(i == diff_indx)
    {
        // printf("%d\n", msk_change);
        return msk_change == 7 ? 0 : -inf;
    }

    ll &ret = dp[i][msk_type][msk_change][mode];
    if(ret != -1)
        return ret;

    ret = -inf;

    int nxt = indx[i + 1], curr = indx[i];

    ///don't change
    if(i < diff_indx - 1)
        ret = max(ret, fn(i + 1, msk_type, msk_change, 0) + get_ham(curr, nxt, msk_type));
    else
        ret = max(ret, fn(i + 1, msk_type, msk_change, 0));

    if(mode == 0)
    {
        int v1 = bin_search(0, curr);
        int v2 = bin_search(1, curr);

        for(int x = 1; x < 8; x++)
        {
            int new_msk_type = msk_type;
            int new_msk_change = msk_change;
            int flag = 1, u1 = 0, u2 = 0;

            for(int j = 0; j < 3 && flag; j++)
            {
                if(getbit(x, j) == 1)
                {
                    int t = getbit(msk_type, j);
                    if(t == 0)
                        u1++;
                    else
                        u2++;
                    if(getbit(msk_change, j) == 1 || (t == 0 && v1 == -1) || (t == 1 && v2 == -1))
                        flag = 0;
                    new_msk_type = setbit(new_msk_type, j, !t);
                    new_msk_change = setbit(new_msk_change, j, 1);
                }
            }

            if(u1 > v1 || u2 > v2)
                flag = 0;
            if(flag)
                ret = max(ret, fn(i, new_msk_type, new_msk_change, 1));
        }
    }

    return ret;
}

int bin_search(int t, int val)
{
    int big = (t == 0 ? a : b);
    int small = 0, mid;
    pair<int, int> *arr = (t == 0 ? zero_one : one_zero);

    while(big >= small)
    {
        mid = (small + big) / 2;

        if(arr[mid].first == val)
            return arr[mid].second;

        if(arr[mid].first > val)
            big = mid - 1;
        else
            small = mid + 1;
    }

    return 0;

}

ll get_ham(int small, int big, int msk_type)
{
    ll ret = 0;
    int diff = big - small;

    ///a b
    if(getbit(msk_type, 0) != getbit(msk_type, 1))
        ret += diff;
    ///b c
    if(getbit(msk_type, 1) != getbit(msk_type, 2))
        ret += diff;

    ///a c
    if(getbit(msk_type, 0) != getbit(msk_type, 2))
        ret += diff;

    return ret;
}

void pre_process()
{
    memset(dp, -1, sizeof(dp));
    memset(cnt_dp, -1, sizeof(cnt_dp));

    sort(zero_one, zero_one + a);
    sort(one_zero, one_zero + b);

    int k = 0;
    for(int i = 0; i < max(a, b); i++)
    {
        if(i < a)indx[k++] = zero_one[i].first;
        if(i < b)indx[k++] = one_zero[i].first;
    }

    indx[k++] = 0, indx[k++] = l;
    sort(indx, indx + k);

    int j = 0, prev = -1, i = 0, tmp = 0;

    while(i < k)
    {
        if(prev != indx[i])
        {
            indx[j++] = indx[i];
            prev = indx[i];
        }

        i++;
    }

    diff_indx = j;

    j = 0, prev = zero_one[0].first, i = 0, tmp = 0;
    while(i < a)
    {
        if(prev != zero_one[i].first)
        {
            zero_one[j].first = prev, zero_one[j++].second = tmp;
            tmp = 1;
            prev = zero_one[i].first;

        }
        else
            tmp++;

        i++;
    }

    zero_one[j].first = prev, zero_one[j++].second = tmp;
    a = j;

    j = 0, prev = one_zero[0].first, i = 0, tmp = 0;
    while(i < b)
    {
        if(prev != one_zero[i].first)
        {
            one_zero[j].first = prev, one_zero[j++].second = tmp;
            tmp = 1;
            prev = one_zero[i].first;

        }
        else
            tmp++;

        i++;
    }

    one_zero[j].first = prev, one_zero[j++].second = tmp;
    b = j;

}

int setbit(int mask, int bit, int value)
{
    if(value == 1)
        return(mask | (1 << bit));
    else
        return (mask&~(1 << bit));
}

int getbit(int mask, int bit)
{
    mask = (mask >> bit) & 1;
    return (mask == 1);
}


//#include <bits/stdc++.h>
#include<stdio.h>
//#include<algorithm>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
//typedef pair<ll,ll> pll;
//typedef vector<int> vi;
typedef pair<int,int> ii;
//typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<18)
int N,M,W,a,b,I,J;
ii A[MX],B[MX];
ll S,T,G;
bool cmp(ii a,ii b){return a.aa^b.aa?a.aa>b.aa:a.bb<b.bb;}
int main(void){
    scanf("%d%d%d",&N,&M,&W);
    F(N)scanf("%d%d",&a,&b),A[i]={a,b};
    F(M)scanf("%d%d",&a,&b),B[i]={a,b};
    sort(A,A+N,cmp),sort(B,B+M,cmp);
    while(I<N&&T+A[I].bb<=W)T+=A[I++].bb,G+=A[I-1].aa;
    while(~--I){
        while(J<M&&T+B[J].bb<=W)T+=A[J++].bb,G+=B[J-1].aa;
        if(J)S=max(S,G);
        T-=A[I].bb,G-=A[I].aa;
    }
    printf("%lld\n",S);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <iterator>
using namespace std;

int main() {
	vector<pair<int, int>>	physics;
	vector<pair<int, int>>	informatics;
	int						signifacance, width;
	auto					maximum_possible = 0;
	vector<int>				physics_sum;
	vector<int>				informatics_sum;
	vector<int>				physics_significance_sum;
	vector<int>				informatics_significance_sum;

	int		n, m, d;

	cin >> n >> m >> d;

	for (auto i = 0; i < n; ++i) {
		cin >> signifacance >> width;
		physics.push_back(make_pair(signifacance, width));
	}

	for (auto i = 0; i < m; ++i) {
		cin >> signifacance >> width;
		informatics.push_back(make_pair(signifacance, width));
	}

	sort(physics.begin(), physics.end(), [](pair<int, int>& left, pair<int, int>& right) { if (left.first == right.first) return (left.second < right.second); return (left.first > right.first); });
	physics_sum.assign(physics.size(), 0);
	physics_significance_sum.assign(physics.size(), 0);
	physics_sum[0] = physics[0].second;
	physics_significance_sum[0] = physics[0].first;

	for (auto i = 1; i < physics.size(); ++i) {
		physics_sum[i] = physics[i].second + physics_sum[i - 1];
		physics_significance_sum[i] = physics[i].first + physics_significance_sum[i - 1];
	}

	sort(informatics.begin(), informatics.end(), [](pair<int, int>& left, pair<int, int>& right) { if (left.first == right.first) return (left.second < right.second); return (left.first > right.first); });
	informatics_sum.assign(informatics.size(), 0);
	informatics_significance_sum.assign(informatics.size(), 0);
	informatics_sum[0] = informatics[0].second;
	informatics_significance_sum[0] = informatics[0].first;

	for (auto i = 1; i < informatics.size(); ++i) {
		informatics_sum[i] = informatics[i].second + informatics_sum[i - 1];
		informatics_significance_sum[i] = informatics[i].first + informatics_significance_sum[i - 1];
	}

	for (auto it = physics_sum.begin(), it2 = physics_significance_sum.begin(); it != physics_sum.end(); ++it, it2++) {
		auto it3 = upper_bound(informatics_sum.begin(), informatics_sum.end(), (d - *it));

		if (it3 == informatics_sum.begin())
			continue;

		if (it3 != informatics_sum.end()) {
			auto index = distance(informatics_sum.begin(), it3);

			if ((*it2 + informatics_significance_sum[index - 1]) > maximum_possible)
				maximum_possible = *it2 + informatics_significance_sum[index - 1];
		}
		else {
			if ((informatics_significance_sum.back() + *it2) > maximum_possible)
				maximum_possible = informatics_significance_sum.back() + *it2;
		}
	}

	cout << maximum_possible << endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define MAXN 100005

using namespace std;

struct Node{
	long long sig = 0, wid = 0;
	bool operator < (const Node &n) const {
		return sig > n.sig;
	}
	Node operator + (const Node &n) const {
		return (Node){sig + n.sig, wid + n.wid};
	}
};

int n, m;
long long d;
Node arr[MAXN], brr[MAXN];
Node sum1[MAXN], sum2[MAXN];

int main() {
	scanf("%d %d %lld", &n, &m, &d);
	for (int i = 1; i <= n; i++)
		scanf("%lld %lld", &arr[i].sig, &arr[i].wid);
	for (int i = 1; i <= m; i++)
		scanf("%lld %lld", &brr[i].sig, &brr[i].wid);
	sort(arr + 1, arr + n + 1);
	sort(brr + 1, brr + m + 1);
	for (int i = 1; i <= n; i++)
		sum1[i] = sum1[i - 1] + arr[i];
	for (int i = 1; i <= m; i++)
		sum2[i] = sum2[i - 1] + brr[i];
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		if (arr[i].sig == arr[i - 1].sig) continue;
		if (sum1[i].wid > d) break;
		long long rem = d - sum1[i].wid;
		int l = 0, r = m;
		while (l < r) {
			int mid = (l + r >> 1) + 1;
			if (sum2[mid].wid <= rem) l = mid;
			else r = mid - 1;
		}
		if (!l) break;
		ans = max(ans, sum1[i].sig + sum2[l].sig);
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j)
{
    if(j.first == i.first)
        return j.second > i.second;
    return j.first < i.first;
}

int main(){

    ll n,m,d;

    cin >> n >> m >> d;

    vector< pair<ll,ll> > vf, vi;

    for(ll i=0;i<n;i++){
        ll c,w;
        cin >> c >> w;
        vf.push_back(make_pair(c,w));
    }
    for(ll i=0;i<m;i++){
        ll c,w;
        cin >> c >> w;
        vi.push_back(make_pair(c,w));
    }

    sort(vf.begin(),vf.end(),compare);
    sort(vi.begin(),vi.end(),compare);

    ll sumw = vf[0].second + vi[0].second;
    ll sumc = vf[0].first + vi[0].first;

    if(sumw > d){
        cout << "0";
        return 0;
    }

    ll gsumc = 0;

    ll ci=0,cf=0;

    int br = 0;
    for(auto i : vf){
        if(br == 0){
            br = 1;
            continue;
        }
        if(sumw + i.second <= d){
            sumw += i.second;
            sumc += i.first;
            cf++;
        }
        else{
            break;
        }
    }

    br = 0;
    for(auto i : vi){
        if(br == 0){
            br = 1;
            continue;
        }
        if(sumw + i.second <= d){
            sumw += i.second;
            sumc += i.first;
            ci++;
        }
        else{
            break;
        }
    }

    gsumc = sumc;

    ci++;

    while(true){
        if(cf == 0 || ci == vi.size())
            break;
        sumc -= vf[cf].first;
        sumw -= vf[cf].second;
        cf--;
        while(sumw + vi[ci].second <= d){
            sumw += vi[ci].second;
            sumc += vi[ci].first;
            ci++;
            ci == vi.size(){
                break;
            }
        }
        if(sumc > gsumc)
            gsumc = sumc;
    }

    cout << gsumc;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
template<class T> inline void read(T &n){
	char ch=GC;T w=1,x=0;
	while(!isdigit(ch)){if(ch=='-') w=-1;ch=GC;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=GC;}
	n=x*w;
}
const int mod=998244353;
const int inv2=499122177;
const int inv6=166374059;
inline int add(int x,int y){
	x+=y;return x>=mod?x-mod:x;
}
inline int mul(int x,int y){
	return 1ll*x*y%mod;
}
inline int get1(int x){
	return mul(mul(x,x+1),inv2);
}
inline int get2(int x){
	return mul(mul(x,x+1),mul(2*x+1,inv6));
}
int n,T,x[85],y[85],bot[605],tot;
int st[505],top;
int sum[2005],lazy[2005];
void clear(int l,int r,int id){
	sum[id]=lazy[id]=0;
	if(l==r) return;
	int mid=(l+r)>>1;
	clear(l,mid,id<<1);
	clear(mid+1,r,id<<1|1);
}
inline void update(int l,int r,int id){
	if(lazy[id]) sum[id]=st[r+1]-st[l];
	else{
		if(l==r) sum[id]=0;
		else sum[id]=sum[id<<1]+sum[id<<1|1];
	}
}
inline void putdown(int l,int r,int id){
	if(!lazy[id]) return;
	int mid=(l+r)>>1;
	lazy[id<<1]+=lazy[id];
	lazy[id<<1|1]+=lazy[id];
	update(l,mid,id<<1);
	update(mid+1,r,id<<1|1);
	lazy[id]=0;
}
void modify(int l,int r,int id,int L,int R,int val){
	if(L<=l&&r<=R){
		lazy[id]+=val;
		update(l,r,id);
		return;
	}
	int mid=(l+r)>>1;
	if(L<=mid) modify(l,mid,id<<1,L,R,val);
	if(R>mid) modify(mid+1,r,id<<1|1,L,R,val);
	update(l,r,id);
}
#define pii pair<int,int>
#define fir first
#define sec second
vector <pii> Add[505],Del[505];
int getval(int t){
	top=0;
	for(int i=1;i<=n;i++){
		st[++top]=x[i]-t,st[++top]=x[i]+t+1;
		st[++top]=y[i]-t,st[++top]=y[i]+t+1;
	}
	sort(st+1,st+top+1);
	top=unique(st+1,st+top+1)-(st+1);
	clear(1,top,1);
	for(int i=1;i<=top;i++) Add[i].clear(),Del[i].clear();
	for(int i=1;i<=n;i++){
		int L=lower_bound(st+1,st+top+1,y[i]-t)-st,R=lower_bound(st+1,st+top+1,y[i]+t+1)-st;
		int B=lower_bound(st+1,st+top+1,x[i]-t)-st,E=lower_bound(st+1,st+top+1,x[i]+t+1)-st;
		Add[B].push_back(make_pair(L,R-1)),Del[E].push_back(make_pair(L,R-1));
	}
	int ans=0;
	for(int i=1;i<top;i++){
		for(auto u:Add[i]) modify(1,top,1,u.fir,u.sec,1);
		for(auto u:Del[i]) modify(1,top,1,u.fir,u.sec,-1);
		ans=add(ans,mul(sum[1],st[i+1]-st[i]));
	}
	return ans;
}
int main(){
	read(n),read(T);
	for(int i=1;i<=n;i++) read(x[i]),read(y[i]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int tmp=max(abs(x[i]-x[j]),abs(y[i]-y[j]))/2;
			if(tmp<=T) bot[++tot]=tmp;
		}
	bot[++tot]=0,bot[++tot]=T;
	sort(bot+1,bot+tot+1);
	tot=unique(bot+1,bot+tot+1)-(bot+1);
	int ans=mul(T,getval(T)),res=0;
	for(int i=1;i<tot;i++){
		if(bot[i+1]-bot[i]<=2){
			for(int j=bot[i];j<bot[i+1];j++) res=add(res,getval(j));
			continue;
		}
		int y0=getval(bot[i]),y1=getval(bot[i]+1),y2=getval(bot[i]+2);
		int A=mul(y2+y0-y1*2,inv2),B=add(y1,mod-add(A,y0)),C=y0;
		res=add(res,mul(A,get2(bot[i+1]-bot[i]-1)));
		res=add(res,mul(B,get1(bot[i+1]-bot[i]-1)));
		res=add(res,mul(C,bot[i+1]-bot[i]));
	}
	cout<<add(ans,mod-res)<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using std::max;
using std::lower_bound;
using std::sort;
using std::unique;
using std::vector;
inline int abs(int x)
{
	return x<0?-x:x;
}
const int mod=998244353;
inline int add(int a,int b)
{
	return (a+=b)>=mod?a-mod:a;
}
inline int sub(int a,int b)
{
	return (a-=b)<0?a+mod:a;
}
inline int mul(int a,int b)
{
	return (long long)a*b%mod;
}
inline int qpow(int a,int b)
{
	int res=1;
	for(;b;a=mul(a,a),b>>=1)
		if(b&1)
			res=mul(res,a);
	return res;
}
const int N=105;
int n,t,ans;
struct cell
{
	int x,y;
}c[N];
vector<int> V,Vx,Vy;
int sw,w[N],sumw[N];
struct task
{
	int t,l,r,k;
};
vector<task> ta;
int f[N];
namespace lglr
{
	int n;
	int x[N],y[N];
	// inline void print()
	// {
	// 	register int i;
	// 	for(i=1;i<=n;i++)
	// 		fprintf(stderr,"x:%d y:%d\n",x[i],y[i]);
	// 	return;
	// }
	inline int get(int x0)
	{
		int res=0,cur;
		register int i,j;
		for(i=1;i<=n;i++)
		{
			cur=1;
			for(j=1;j<=n;j++)
				if(i!=j)
					cur=mul(cur,mul(sub(x0,x[j]),qpow(sub(x[i],x[j]),mod-2)));
			res=add(res,mul(cur,y[i]));
		}
		return res;
	}
}
namespace zkw
{
	int M;
	int Min[N<<2],lazy[N<<2],cnt[N<<2];
	inline void push_up(int x)
	{
		Min[x]=min(Min[x<<1],Min[x<<1|1])+lazy[x];
		cnt[x]=(Min[x<<1]+lazy[x]==Min[x])*cnt[x<<1]+(Min[x<<1|1]+lazy[x]==Min[x])*cnt[x<<1|1];
		return;
	}
	inline void build(int n)
	{
		register int i;
		for(M=1;M<=n;M<<=1);
		memset(lazy,0,sizeof(int)*(M<<1));
		memset(cnt,0,sizeof(int)*(M<<1));
		for(i=1;i<=n;i++)
			Min[M+i]=0,cnt[M+i]=w[i];
		for(i=M-1;i;i--)
			push_up(i);
		return;
	}
	inline void modify(int l,int r,int k)
	{
		for(l=M+l-1,r=M+r+1;l^r^1;l>>=1,r>>=1,push_up(l),push_up(r))
			(l&1)?0:(Min[l^1]+=k,lazy[l^1]+=k),(r&1)?(Min[r^1]+=k,lazy[r^1]+=k):0;
		for(l>>=1;l;l>>=1)
			push_up(l);
		return;
	}
	inline int query()
	{
		return sw-(Min[1]==0)*cnt[1];
	}
}
inline int calc(int t)
{
	int cl,cr,res=0;
	register int i;
	Vx.clear();Vy.clear();
	for(i=1;i<=n;i++)
	{
		Vx.push_back(c[i].x-t);
		Vx.push_back(c[i].x+t+1);
		Vy.push_back(c[i].y-t);
		Vy.push_back(c[i].y+t+1);
	}
	sort(Vx.begin(),Vx.end());
	Vx.erase(unique(Vx.begin(),Vx.end()),Vx.end());
	sort(Vy.begin(),Vy.end());
	Vy.erase(unique(Vy.begin(),Vy.end()),Vy.end());
	sw=0;
	for(i=1;i<(int)Vy.size();i++)
		w[i]=Vy[i]-Vy[i-1],sw+=w[i];
	ta.clear();
	for(i=1;i<=n;i++)
	{
		cl=lower_bound(Vy.begin(),Vy.end(),c[i].y-t)-Vy.begin()+1;
		cr=lower_bound(Vy.begin(),Vy.end(),c[i].y+t+1)-Vy.begin();
		ta.push_back(task{c[i].x-t,cl,cr,1});
		ta.push_back(task{c[i].x+t+1,cl,cr,-1});
	}
	sort(ta.begin(),ta.end(),[](task a,task b)->bool
	{
		return a.t<b.t;
	});
	zkw::build((int)Vy.size()-1);
	for(i=0;i<(int)ta.size()-1;i++)
	{
		// fprintf(stderr,"%d:%d %d %d\n",ta[i].t,ta[i].l,ta[i].r,ta[i].k);
		zkw::modify(ta[i].l,ta[i].r,ta[i].k);
		// fprintf(stderr,"q:%d %d\n",ta[i+1].t-ta[i].t,zkw::query());
		res=add(res,mul(ta[i+1].t-ta[i].t,zkw::query()%mod));
	}
	// fprintf(stderr,"%d:OK(%d)\n",t,res);
	return res;
}
inline int solve(int l,int r)
{
	int res=0;
	register int i;
	if(r-l+1<3)
	{
		for(i=l;i<=r;i++)
			res=add(res,calc(i));
		return res;
	}
	for(i=l;i<=l+2;i++)
		f[i-l]=calc(i);
	// fprintf(stderr,"hhhh\n");
	for(i=l+1;i<=l+2;i++)
		f[i-l]=add(f[i-l],f[i-l-1]);
	lglr::n=4;
	lglr::x[1]=l;lglr::y[1]=0;
	for(i=l;i<=l+2;i++)
		lglr::x[i-l+2]=i+1,lglr::y[i-l+2]=f[i-l];
	// fprintf(stderr,"hhhh\n");
	// lglr::print();
	return sub(lglr::get(r+1),lglr::get(l));
}
signed main()
{
	int d;
	register int i,j;
	scanf("%d%d",&n,&t);
	for(i=1;i<=n;i++)
		scanf("%d%d",&c[i].x,&c[i].y);
	V.push_back(0);V.push_back(t+1);
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			if((d=(max(abs(c[i].x-c[j].x),abs(c[i].y-c[j].y))+1)/2)<=t)
			V.push_back(d);
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());
	for(i=0;i<(int)V.size()-1;i++)
		ans=add(ans,solve(V[i],V[i+1]-1));
	// fprintf(stderr,"%d\n",ans);
	ans=sub(mul(t+1,calc(t)),ans);
	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstdio>

#include <array>
#include <algorithm>
#include <vector>

using namespace std;

const int MOD = 998244353;

typedef long long ll;
#define tll(X) static_cast<ll>(X)
#define ti(X) static_cast<int>(X)

int sum(int a, int b) {return ti((tll(a) + tll(b))%MOD);}
int dif(int a, int b) {return ti((tll(a) - tll(b) + (tll(MOD)<<6LL))%MOD);}
int prd(int a, int b) {return ti((tll(a) * tll(b))%MOD);}
int sqr(int a) {return prd(a, a);}
int pw(int b, int p) {
  int r = 1;
  for(;p;p>>=1, b=prd(b, b)) if(p&1) r = prd(r, b);
  return r;
}

int dv2;
int sumlin(int v) {
  if(v < 0) return 0;
  return prd(prd(v, v + 1), dv2);
}
int sumlin(int l, int r) {
  return sumlin(r - 1) - sumlin(l - 1);
}
int dv6;
int sumsqr(int v) {
  if(v < 0) return 0;
  return prd(prd(v, v + 1), prd((v << 1) + 1, dv6));
}
int sumsqr(int l, int r) {
  return sumsqr(r - 1) - sumsqr(l - 1);
}

typedef array<int, 2> ar2;
typedef array<int, 3> ar3;
typedef vector<int> vi;
typedef vector<ar2> va2;

int get(const ar3& a, int b) {
  return sum(prd(a[2], prd(b, b)), sum(prd(a[1], b), a[0]));
}
int get(const vi& a, int l, int r) {
  int f = 0;
  f = sum(f, prd(a[2], sumsqr(l, r)));
  f = sum(f, prd(a[1], sumlin(l, r)));
  f = sum(f, prd(a[0], r - l));
  return f;
}
ar3 operator + (const ar3& a, const ar3& b) {
  return {sum(a[0], b[0]), sum(a[1], b[1]), sum(a[2], b[2])};
}

typedef array<int, 2> pt;
typedef array<int, 4> ar4;

const int MAXN = 60;
int N, T;
pt I[MAXN];

template <class T> void compress(T * n, int& s) {
  sort(n, n + s);
  s = unique(n, n + s) - n;
}

int y[MAXN << 1];
int ys;

template <int MAXS = MAXN * 4> struct ST {
public:
  ar2 v[MAXN];
  int z[MAXN];
  int s;
  ar2 cmb(const ar2& a, const ar2& b) {
    if(a[0] == b[0]) return {a[0], a[1] + b[1]};
    if(b[0] < a[0]) return b;
    return a;
  }
  void init(int n, int nl, int nr) {
    if(nr - nl > 1) {
      int m = nl + ((nr - nl)>>1);
      init(n<<1, nl, m); init(n<<1|1, m, nr);
      v[n] = {0, y[nr] - y[nl]}, z[n] = 0;
    } else v[n] = {0, y[nr] - y[nl]}, z[n] = 0;
  }
  void init(int S) {
    init(1, 0, s = S);
  }
  void prop(int n, int nl, int nr) {
    v[n][0] += z[n];
    if(nr - nl > 1)
      z[n<<1] += z[n], z[n<<1|1] += z[n];
    z[n] = 0;
  }
  void upd(int gl, int gr, int q, int n, int nl, int nr) {
    if(gl <= nl and nr <= gr) {
      z[n] += q;
      prop(n, nl, nr);
    } else {
      int m = nl + ((nr - nl)>>1);
      prop(n, nl, nr);
      if(gl < m) upd(gl, gr, q, n<<1, nl, m); else prop(n<<1, nl, m);
      if(m < gr) upd(gl, gr, q, n<<1|1, m, nr); else prop(n<<1|1, m, nr);
      v[n] = cmb(v[n<<1], v[n<<1|1]);
    }
  }
  void upd(int gl, int gr, int q) {return upd(gl, gr, q, 1, 0, s);}
  int qry() {prop(1, 0, s); return v[1][0] == 0 ? (y[s] - y[0]) - v[1][1] : (y[s] - y[0]);}    //# of non-zeroes
};
ST<> st;
ar4 x[MAXN << 1];
int calc(int t) {
  for(int i = 0;i < N;i++) y[i<<1] = I[i][1] - t, y[i<<1|1] = I[i][1] + t + 1, x[i<<1] = {I[i][0] - t, I[i][1] - t, I[i][1] + t + 1, 1}, x[i<<1|1] = {I[i][0] + t + 1, I[i][1] - t, I[i][1] + t + 1, 0};
  compress(y, ys = N<<1);
  for(int i = 0;i < N<<1;i++) x[i][1] = lower_bound(y, y + ys, x[i][1]) - y, x[i][2] = lower_bound(y, y + ys, x[i][2]) - y;
  st.init(--ys);

  ll f = 0;

  sort(x, x + (N<<1), [](const ar4& a, const ar4& b){return a[0] < b[0];});

  int c = 0;
  for(int i = 0, j;i < N<<1;i=j) {
    for(j = i;j < N<<1 and x[i][0] == x[j][0];j++) {
      if(x[j][3]) st.upd(x[j][1], x[j][2], 1);
      else st.upd(x[j][1], x[j][2], -1);
    }
    if((c = st.qry())) f += tll(c) * (x[j][0] - x[i][0]);
  }
  return ti(f%MOD);
}

int operator * (const pt& a, const pt& b) {
  return max((1 + abs(a[0] - b[0]))>>1, (1 + abs(a[1] - b[1]))>>1);
}

int c[MAXN * MAXN];

vi operator * (const vi& a, const vi& b) {
  vi r(a.size() + b.size() - 1, 0);
  for(int i = 0;i < a.size();i++) for(int j = 0;j < b.size();j++) r[i + j] = sum(r[i + j], prd(a[i], b[j]));
  return r;
}
vi operator *= (vi& a, const int& b) {
  for(int i = 0;i < a.size();i++) a[i] = prd(a[i], b);
  return a;
}
vi operator += (vi& a, const vi& b) {
  assert(not(a.size() < b.size()));
  for(int i = 0;i < b.size();i++) a[i] = sum(a[i], b[i]);
  return b;
}

vi interpolate(const va2& p) {
  vi r(p.size(), 0);
  for(int i = 0;i < p.size();i++) {
    vi n(1, 1);
    int d = 1;
    for(int j = 0;j < p.size();j++) if(j != i) {
      n = n * vi{dif(0, p[j][0]), 1};
      d = prd(d, dif(p[i][0], p[j][0]));
    }
    n *= prd(pw(d, MOD - 2), p[i][1]);
    assert(n.size() == r.size());
    r += n;
  }
  return r;
}

int solve(int t1, int t2) {
  if(t2 - t1 < 3) {
    int f = 0;
    for(int i = t1;i < t2;i++) f = sum(f, ti(calc(i)%MOD));
    return f;
  }

  vi q = interpolate(va2{{t1, calc(t1)}, {t1 + 1, calc(t1 + 1)}, {t1 + 2, calc(t1 + 2)}});
  //cerr << q[0] << " " << q[1] << " " << q[2] << "\n";
  //cerr << get(q, t1, t2) << "\n";
  return get(q, t1, t2);
}

int main() {
  dv2 = pw(2, MOD - 2);
  dv6 = pw(6, MOD - 2);

  scanf("%d%d", &N, &T);
  for(int i = 0;i < N;i++) scanf("%d%d", &I[i][0], &I[i][1]), y[i] = I[i][1];

  //sort(I, I + N, [](const pt& a, const pt& b) {return a[0] < b[0] or (not(b[0] < a[0]) and a[1] < b[1]);});

  for(int i = 0, t = 0;i < N;i++) for(int j = i + 1;j < N;j++) c[t++] = I[i] * I[j];
  sort(c, c + (N*(N - 1)>>1));
  ll f = 0LL;
  int p = 0;
  for(int i = 0;i < (N*(N-1))>>1;p = c[i++]) {
    if(c[i] < T) f = sum(f, solve(p, c[i])); else break;
  }
  f = sum(f, solve(p, T));

  printf("%d\n", dif(prd(T, calc(T)), f));

  return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ls(_o) (_o<<1)
#define rs(_o) ((_o<<1)|1)
#define ll long long
#define p 998244353
#define abs(_o) ((_o<0)?-(_o):_o)
using namespace std;
namespace ywy{
	inline ll mi(int a,int b){
		ll ans=1,tmp=a;while(b){
			if(b&1)ans=(ans*tmp)%p;tmp=(tmp*tmp)%p;b>>=1;
		}return(ans);
	}int lsh[300],cnt[300];int data[2001];
	inline void up(int tree,int l,int r){
		if(cnt[tree])data[tree]=lsh[r]-lsh[l-1];else data[tree]=data[ls(tree)]+data[rs(tree)];
	}
	void add(int rl,int rr,int l,int r,int tree,int x){
		if(rl==l&&rr==r){
			cnt[tree]+=x;if(!cnt[tree]){
				if(l==r)data[tree]=0;else data[tree]=data[ls(tree)]+data[rs(tree)];
			}else data[tree]=lsh[r]-lsh[l-1];return;
		}int mid=(l+r)>>1;if(rl>mid)add(rl,rr,mid+1,r,rs(tree),x);else{
			if(rr<=mid)add(rl,rr,l,mid,ls(tree),x);else{
				add(rl,mid,l,mid,ls(tree),x);add(mid+1,rr,mid+1,r,rs(tree),x);
			}
		}up(tree,l,r);
	}ll inv2,inv6;
	inline ll sig2(ll n){
		ll cjr=n;cjr*=(n+1);cjr%=p;cjr*=(n*2+1);cjr%=p;cjr*=inv6;return(cjr%p);
	}
	inline ll sig(ll n){
		ll cjr=n;cjr*=(n-1);cjr%=p;cjr*=inv2;return(cjr%p);
	}
	typedef struct _n{
		int l;int r;
	}node;vector<node> adds[300],dels[300];
	inline void clear(vector<node> &v){
		vector<node> tmp;v=tmp;
	}int xs[60],ys[60];int n;
	void build(int l,int r,int tree){
		cnt[tree]=data[tree]=0;if(l==r)return;int mid=(l+r)>>1;build(l,mid,ls(tree));build(mid+1,r,rs(tree));
	}
	inline ll getS(int t){
		int ptr=1;for(register int i=1;i<=n;i++){
			lsh[ptr]=xs[i]-t-1;ptr++;lsh[ptr]=xs[i]+t;ptr++;lsh[ptr]=ys[i]-t-1;ptr++;lsh[ptr]=ys[i]+t;ptr++;
		}ptr--;sort(lsh+1,lsh+1+ptr);ptr=unique(lsh+1,lsh+1+ptr)-lsh-1;build(1,ptr,1);
		for(register int i=1;i<=ptr;i++)clear(adds[i]),clear(dels[i]);
		for(register int i=1;i<=n;i++){
			node cjr;cjr.l=lower_bound(lsh+1,lsh+1+ptr,ys[i]-t-1)-lsh+1;
			cjr.r=lower_bound(lsh+1,lsh+1+ptr,ys[i]+t)-lsh;int l=lower_bound(lsh+1,lsh+1+ptr,xs[i]-t-1)-lsh;
			int r=lower_bound(lsh+1,lsh+1+ptr,xs[i]+t)-lsh;adds[l].push_back(cjr);dels[r].push_back(cjr);
		}ll ans=0;for(register int i=1;i<=ptr;i++){
			ans=(ans+data[1]*(ll)(lsh[i]-lsh[i-1]))%p;
			for(register int j=0;j<adds[i].size();j++)add(adds[i][j].l,adds[i][j].r,1,ptr,1,1);
			for(register int j=0;j<dels[i].size();j++)add(dels[i][j].l,dels[i][j].r,1,ptr,1,-1);
		}return(ans);
	}int tme[100001];
	void ywymain(){
		inv2=mi(2,p-2);inv6=mi(6,p-2);int t;cin>>n>>t;
		for(register int i=1;i<=n;i++)cin>>xs[i]>>ys[i];int ptr=1;for(register int i=1;i<=n;i++){
			for(register int j=1;j<i;j++){
				tme[ptr]=max(abs(xs[i]-xs[j]),abs(ys[i]-ys[j]))/2;if(tme[ptr]<=t)ptr++;
			}
		}tme[ptr]=0;ptr++;tme[ptr]=t;sort(tme+1,tme+1+ptr);ptr=unique(tme+1,tme+1+ptr)-tme-1;
		ll ans=(getS(t)*t)%p;for(register int i=1;i<ptr;i++){
			if(tme[i+1]-tme[i]<=2){
				for(register int j=tme[i];j<tme[i+1];j++)ans=(ans+p-getS(j))%p;continue;
			}ll c=getS(tme[i]),A=getS(tme[i]+1),B=getS(tme[i]+2);
			ll a=(B-A*2+c)*inv2;a%=p;a+=p;a%=p;ll b=A-c-a;b%=p;b+=p;b%=p;
			ans-=a*sig2(tme[i+1]-tme[i]-1);ans%=p;ans+=p;ans%=p;
			ans-=b*sig(tme[i+1]-tme[i]-1);ans%=p;ans+=p;ans%=p;
			ans-=c*(tme[i+1]-tme[i]);ans%=p;ans+=p;ans%=p;
		}cout<<ans<<endl;
	}
}
int main(){
	ywy::ywymain();return(0);
}


ï»¿#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

int const maxValue = 100'000;

int scan()
{
   int a;
   scanf("%d", &a);
   return a;
}

struct PositionsPair
{
   int leftPosition = maxValue;
   int rightPosition = -1;

   void update(int position)
   {
      if (position < leftPosition)
         leftPosition = position;
      if (position > rightPosition)
         rightPosition = position;
   }
};

int main()
{
   int const nZones = scan();
   int const start = scan() - 1;
   int const stop = scan() - 1;

   vector<int> gates(nZones - 1);
   generate(begin(gates), end(gates), scan);

   vector<int> keys(nZones);
   generate(begin(keys), end(keys), scan);

   vector<long long> distance(nZones, -1);
   distance[start] = 0;
   map<int, PositionsPair> availableKeys;
   availableKeys[keys[start]].update(start);
   int left = start;
   int right = start;

   while (left != stop && right != stop)
   {
      if (left > 0 && availableKeys.find(gates[left - 1]) != availableKeys.end())
      {
         int const position = availableKeys[gates[left - 1]].leftPosition;
         --left;
         distance[left] = max(distance[left + 1] + 1, distance[position] + position - left);
         availableKeys[keys[left]].update(left);
      }
      else if (right < nZones - 1 && availableKeys.find(gates[right]) != availableKeys.end())
      {
         int const position = availableKeys[gates[right]].rightPosition;
         ++right;
         distance[right] = max(distance[right - 1] + 1, distance[position] + right - position);
         availableKeys[keys[right]].update(right);
      }
      else
      {
         break;
      }
   }

   printf("%lld\n", distance[stop]);
   return 0;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int MAXN = 100009;
int g[MAXN];
int k[MAXN];
const int INF = 1000000000;
int firstLeft[MAXN];
int firstRight[MAXN];
int firstNeedLeft[MAXN];
int firstNeedRight[MAXN];

inline int getMin(const set<int>& s) {
    return *s.begin();
}

inline int getMax(const set<int>& s) {
    auto it = s.end();
    --it;
    return *it;
}

int solve(int a, int b) {
    int i1 = 0;
    int i2 = b;
    set<int> leftNeed, rightNeed;
    set<int> valuesInLeft, valuesInRight;
    set<int> finded;
    finded.insert(k[a]);
    for (int i = a + 1; i <= b; ++i) {
        if (finded.count(g[i - 1]) == 0 && rightNeed.count(g[i - 1]) == 0) {
            rightNeed.insert(g[i - 1]);
            firstNeedRight[g[i - 1]] = i - 1;
            valuesInLeft.insert(firstLeft[g[i - 1]]);
        }
        finded.insert(k[i]);
    }
    finded.clear();
    finded.insert(k[a]);
    for (int i = a - 1; i >= 0; --i) {
        if (finded.count(g[i]) == 0 && leftNeed.count(g[i]) == 0) {
            leftNeed.insert(g[i]);
            firstNeedLeft[g[i]] = i + 1;
            valuesInRight.insert(firstRight[g[i]]);
        }
        finded.insert(k[i]);
    }

    if (valuesInLeft.empty()) {
        return b - a;
    }
    if (getMin(valuesInLeft) < 0) {
        return -1;
    }

    unsigned long long ans = b - a;

    enum MoveType {
        MOVE_LEFT, MOVE_RIGHT
    };

    MoveType mt = MOVE_LEFT;

    int iter_br = 0;

    while (i1 < a && i2 > a) {
        if (mt == MOVE_LEFT) {
            if (valuesInLeft.empty()) {
                i1 = a;
                break;
            }
            int lft = getMin(valuesInLeft);
            if (lft < i1) {
                return -1;
            }
            if (lft == i1) {
                ++iter_br;
            } else {
                iter_br = 0;
            }
            if (iter_br > 4) {
                return -1;
            }
            for (int i = i1; i < lft; ++i) {
                if (firstNeedLeft[g[i]] == i + 1) {
                    leftNeed.erase(g[i]);
                    valuesInRight.erase(firstRight[g[i]]);
                }
            }
            i1 = lft;
            ans += 2 * (a - i1);
            mt = MOVE_RIGHT;
        } else {
            if (valuesInRight.empty()) {
                i2 = a;
                break;
            }
            int rght = getMax(valuesInRight);
            if (rght > i2) {
                return -1;
            }
            if (rght == i2) {
                ++iter_br;
            } else {
                iter_br = 0;
            }
            if (iter_br > 4) {
                return -1;
            }
            for (int i = i2; i > rght; --i) {
                if (firstNeedRight[g[i - 1]] == i - 1) {
                    rightNeed.erase(g[i - 1]);
                    valuesInLeft.erase(firstLeft[g[i - 1]]);
                }
            }
            i2 = rght;
            ans += 2 * (i2 - a);
            mt = MOVE_LEFT;
        }
    }

    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    --a;
    --b;
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d", &g[i]);
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d", &k[i]);
    }
    if (a > b) {
        a = n - a - 1;
        b = n - b - 1;
        reverse(k, k + n);
        reverse(g, g + n - 1);
    }

    fill(begin(firstLeft), end(firstLeft), -INF);
    fill(begin(firstRight), end(firstRight), INF);

    for (int i = a - 1; i >= 0; --i) {
        if (firstLeft[k[i]] == -INF) {
            firstLeft[k[i]] = i;
        }
    }
    for (int i = a + 1; i <= b; ++i) {
        if (firstRight[k[i]] == INF) {
            firstRight[k[i]] = i;
        }
    }

    cout << solve(a, b) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
void Solve(); int main() { Solve(); }
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
#define int long long
#define endl '\n'
#define fib(i, n) for (int i = n; i >= 0; i--)
#define fi(i,a,b) for(int i = (a); i < (b); i++)
#define MAX 1 << 10
#define pb push_back
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define pii pair<int,int>
const int maxn = (int)(3e5 + 11);
const ll inf = (ll)(1e15 + 7);

int n, a, b, g[maxn], k[maxn], last[maxn];
ll dp[maxn];
set < int > S[maxn];

bool check(int x)
{
	return !S[x].empty() || last[x];
}

ll solve1()
{
	int r = a, p;
	last[k[a]] = a;
	while (r != n && check(g[r]))
	{
		r++;
		S[k[r]].ins(r);
		dp[r] = r - a;
	}
	p = a;
	if (r >= b)
		return b - a;

	for (int i = a - 1; i >= 1; --i)
	{
		int x = g[i];
		if (!check(x))
			return inf;
		if (!last[x])
		{
			int j = *S[x].lower_bound(0);
			if (j < p) {
				dp[i] = dp[p] + p - i;
			}
			else {
				p = j;
				dp[i] = dp[j] + j - i;
			}
		}
		else
		{
			dp[i] = dp[i + 1] + 1;
		}
		last[k[i]] = i;
		while (r != n && check(g[r]))
		{
			r++;
			dp[r] = dp[i] + r - i;
			S[k[r]].ins(r);
		}
		if (r >= b)
			return dp[i] + b - i;
	}
	return inf;
}
void Solve()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> a >> b;
	for (int i = 1; i < n; ++i)
		cin >> g[i];
	for (int i = 1; i <= n; ++i)
		cin >> k[i];
	ll ans;
	if (a < b)
		ans = solve1();
	else
	{
		reverse(g + 1, g + n);
		reverse(k + 1, k + n + 1);
		a = n + 1 - a;
		b = n + 1 - b;
		ans = solve1();
	}

	if (ans >= inf)
		cout << -1;
	else
		cout << ans;

}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define For(i,x,y) for(int i=(int)x;i<=(int)y;i++)
#define pb push_back
#define mk make_pair
#define fi fisrt
#define se second
inline int read()
{
	int x=0,c=getchar(),f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	return f?-x:x;
}
inline void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
typedef vector<int> vi;
const int N=100000+10;
int n,m,cnt=1,head[N],du[N],layer[N],leader[N],q[N];
bool vis1[N],vis2[N],vis3[N*2];
vector<vi>ans;
vi tmp,_;
vector<pair<int,int> >comp;
struct edge{int to,nxt;}e[N*4];
void addedge(int u,int v)
{
	e[++cnt]=(edge){v,head[u]};head[u]=cnt;
	e[++cnt]=(edge){u,head[v]};head[v]=cnt;
	du[u]++;du[v]++;
}
void dfs(int u,int fa,int lineid)
{
	vis1[u]=1;
	vis2[layer[u]]=1;
	tmp.pb(u);
	for(int i=head[u],v;i;i=e[i].nxt)if((i>>1)!=lineid)
	{
		if(!vis1[v=e[i].to])
		{
			dfs(v,u,i>>1);
			tmp.pb(u);
			for(;cnt>=0&&vis2[comp[cnt].se];cnt--);
			if(cnt>=0)
			{
				vis3[i>>1]=1;
				v=leader[comp[cnt].se];
				ans.pb(tmp);tmp.clear();
				_.clear();_.pb(i>>1);_.pb(u);_.pb(v);
				ans.pb(_);
				dfs(v,u,i>>1);
				tmp.pb(u);
			}
		}else
		{
			if(vis3[i>>1])continue;
			for(;cnt>=0&&vis2[comp[cnt].se];cnt--);
			if(cnt>=0)
			{
				vis3[i>>1]=1;
				v=leader[comp[cnt].se];
				ans.pb(tmp);tmp.clear();
				_.clear();_.pb(i>>1);_.pb(u);_.pb(v);
				ans.pb(_);
				dfs(v,u,i>>1);
				tmp.pb(u);
			}
		}
	}
}
void print()
{
	puts("YES");write(ans.size()/2);puts("");
	For(i,0,ans.size()-1)
	{
		if(i&1)write(ans[i][0]),putchar(' '),write(ans[i][1]),putchar(' '),write(ans[i][2]),puts("");else
		{
			write(ans[i].size());
			For(j,0,ans[i].size()-1)putchar(' '),write(ans[i][j]);
			puts("");
		}
	}
}
int findbridge()
{
	For(i,1,n)vis1[i]=0;
	For(i,1,m)vis3[i]=0;
	For(i,2,n)if(!vis1[i])
	{
		q[*q]=i;vis1[i]=1;
		For(j,1,*q)
		{
			int u=q[j];
			for(int k=head[u],v;k;k=e[k].nxt)if(!vis3[k>>1])
			{
				vis3[k>>1]=1;
				if(vis1[v=e[k].to])return k>>1;else vis1[v]=1,q[++*q]=v;
			}
		}
	}
	return 0;
}
int getblo(int l,int r)
{
	For(i,l,r)vis1[i]=0;
	int blo=0;
	comp.clear();
	For(i,l,r)if(!vis1[i])
	{
		++blo;
		q[*q=1]=i;vis1[i]=1;
		For(j,1,*q)
		{
			int u=q[j];
			for(int k=head[u],v;k;k=e[k].nxt)if(!vis1[v=e[k].to])vis1[v]=1,q[++*q]=v;
		}
		For(j,1,*q)layer[q[j]]=blo;
		leader[blo]=q[1];
		comp.pb(mk(*q,blo));
	}
	sort(comp.begin(),comp.end());
	return blo;
}
void go(int id)
{
	int u=1;
	For(i,2,n)
	{
		for(int j=head[i],pre;j;pre=j,j=e[j].nxt)if((j>>1)==id)
	 	{
			if(du[i]>1)u=i;
			if(j==head[i])head[i]=e[j].nxt;else e[pre].nxt=e[j].nxt;
			break;
	 	}
	}
	getblo(2,n);
	cnt=comp.size()-1;
	For(i,1,n)vis1[i]=vis2[i]=0;
	For(i,1,m)vis3[i]=0;
	vis1[1]=1;
	_.clear();_.pb(1);ans.pb(_);
	_.clear();_.pb(id);_.pb(1);_.pb(u);ans.pb(_);
	dfs(u,1,0);
	if(tmp.size())ans.pb(tmp),tmp.clear();
	print();
}
int main()
{
	n=read(),m=read();
	For(i,1,m)addedge(read(),read());
	if(n==1)return puts("YES\n0\n1 1\n"),0;
	int blo=getblo(1,n);
	if(m<blo-1)return puts("NO"),0;
	if(du[1])
	{
		For(i,1,n)vis1[i]=vis2[i]=0;
		For(i,1,m)vis3[i]=0;
		cnt=comp.size()-1;
		dfs(1,0,0);
		if(tmp.size())ans.pb(tmp),tmp.clear();
		print();
	}else
	{
		int id=findbridge();
		if(id)go(id);else
		{
			if(m<blo)puts("NO");else
			{
				For(i,2,n)if(du[i]>1){id=head[i]/2;break;}
				if(id)go(id);else puts("NO");
			}
		}
	}
}


# #include <vector>
# #include <map>
# #include <string>
# #include <string.h>
# #include <sstream>
# #include <math.h>
# #include <time.h>
# #include <stdlib.h>
# #include <stdio.h>
# #include <algorithm>
# #include <iostream>
# using namespace std;
#

# #define max_int       INT_MAX / 2
# #define max_long      0xFFFFFFFFFFFFFFFLL / 2
# #define two(a)        (1 << (a))
# #define eps           1e-6
# #define FF(i, a, b)   for (int i = (a); i <= (b); i++)
# #define FFD(i, a, b)  for (int i = (a); i >= (b); i--)
#

# struct Edge {
#     int u, v;
#     bool changed;
#     Edge() {}
#     Edge(int u, int v) : u(u), v(v), changed(false) {}
# };
#

# int n, m;
# vector <Edge > edges;
# vector <int > edgeList[100010];
#

# void AddEdge(int u, int v) {
#     int k = edges.size();
#     edgeList[u].push_back(k);
#     edgeList[v].push_back(k);
#     edges.push_back(Edge(u, v));
# }
#

# struct Component {
#     int root;
#     int numEdges;
#     int numV;
#     int extraEdge;
#
#     Component() {
#         root = numEdges = numV = 0;
#         extraEdge = -1;
#     }
#

#     bool operator <(const Component & x) const {
#         if (numEdges - numV == x.numEdges - x.numV) return numEdges > x.numEdges;
#         else return numEdges - numV > x.numEdges - x.numV;
#     }
# };
#

# int numComps, comp[100010];
# vector <Component > components;
#

# vector <vector <int > > moveSteps;
# vector <vector <int > > moveEdges;
# bool vis[100010];
# int startComp, nextComp;
#

#

# void dfs(int u, int father) {
#     comp[u] = numComps;
#     int numChild = 0;
#     for (int i = 0; i < edgeList[u].size(); i++) {
#         int e = edgeList[u][i];
#         if (e == father) continue;
#         int v = (edges[e].u == u) ? edges[e].v : edges[e].u;
#         if (comp[v] == -1) {
#             dfs(v, e);
#             numChild += 1;
#         } else components.back().extraEdge = e;
#     }
#     if (numChild == 0 && father != -1 && components.back().extraEdge == -1) {
#         if (edges[father].v != u) swap(edges[father].u, edges[father].v);
#         components.back().extraEdge = father;
#     }
# }
#

# void travel(int u, int father) {
#     if (vis[u]) return;
#     vis[u] = true;
#     if (father == -1) moveSteps.push_back(vector <int >());
#     moveSteps.back().push_back(u);
#     for (int i = 0; i < edgeList[u].size(); i++) {
#         int e = edgeList[u][i];
#         if (e == father || edges[e].changed) continue;
#         int v = (edges[e].u == u) ? edges[e].v : edges[e].u;
#         if (vis[v] == 0) {
#             travel(v, e);
#             moveSteps.back().push_back(u);
#         }
#         if (edges[e].changed == 0 && nextComp < components.size()) {
#             edges[e].changed = 1;
#             int w = components[nextComp].root;
#             vector <int > tmp;
#             tmp.push_back(e + 1);
#             tmp.push_back(u);
#             tmp.push_back(w);
#             moveEdges.push_back(tmp);
#             nextComp += 1;
#             moveSteps.push_back(vector <int >());
#             travel(w, e);
#             moveSteps.back().push_back(u);
#         }
#     }
# }
#

# int main(int argc, char** argv) {
#
#     cin >> n >> m;
#     edges.clear();
#     for (int i = 1; i <= n; i++) edgeList[i].clear();
#
#     int e, u, v;
#     for (int i = 1; i <= m; i++) {
#         cin >> u >> v;
#         AddEdge(u, v);
#     }
#

#     components.clear();
#     numComps = 0;
#     memset(comp, -1, sizeof(comp));
#     for (int i = 1; i <= n; i++) {
#         if (comp[i] != -1) continue;
#         components.push_back(Component());
#         components.back().root = i;
#         dfs(i, -1);
#         numComps += 1;
#     }
#     for (int i = 1; i <= n; i++) {
#         components[comp[i]].numV += 1;
#         components[comp[i]].numEdges += edgeList[i].size();
#     }
#     for (int i = 0; i < components.size(); i++) {
#         components[i].numEdges /= 2;
#     }
#

#     startComp = 0;
#     nextComp = 1;
#     memset(vis, 0, sizeof(vis));
#     if (components.size() > 1) {
#         sort(components.begin() + 1, components.end());
#     }
#     moveSteps.clear();
#     moveEdges.clear();
#     vector <int > tmp;
#     if (components[0].numV == 1) {
#         if (n == 1) {
#             cout << "YES" << endl;
#             cout << "0" << endl;
#             cout << "1 1" << endl;
#             return 0;
#         }
#         if (components[1].extraEdge == -1) {
#             cout << "NO" << endl;
#             return 0;
#         } else {
#             tmp.clear();
#             tmp.push_back(1);
#             moveSteps.push_back(tmp);
#             e = components[1].extraEdge;
#             v = edges[e].u;
#             tmp.clear();
#             tmp.push_back(e + 1);
#             tmp.push_back(1);
#             tmp.push_back(v);
#             moveEdges.push_back(tmp);
#             startComp = 1;
#             components[1].root = v;
#             vis[1] = true;
#             edges[e].changed = true;
#             if (components[1].numEdges + 1 == components[1].numV) {
#                 components.push_back(Component());
#                 components.back().root = edges[e].v;
#                 components.back().numV = 1;
#             }
#         }
#     }
#     nextComp = startComp + 1;
#     travel(components[startComp].root, -1);
#     for (int i = 1; i <= n; i++) if (vis[i] == 0) {
#         cout << "NO" << endl;
#         return 0;
#     }
#     cout << "YES" << endl;
#     cout << moveEdges.size() << endl;
#     if (moveEdges.size() == moveSteps.size())
#         moveSteps.push_back(vector <int >());
#     for (int i = 0; i < moveEdges.size(); i++) {
#         cout << moveSteps[i].size() << " ";
#         for (int j = 0; j < moveSteps[i].size(); j++)
#             cout << moveSteps[i][j] << " ";
#         cout << endl;
#         for (int j = 0; j < moveEdges[i].size(); j++)
#             cout << moveEdges[i][j] << " ";
#         cout << endl;
#     }
#     cout << moveSteps.back().size() << " ";
#     for (int j = 0; j < moveSteps.back().size(); j++)
#         cout << moveSteps.back()[j] << " ";
#     cout << endl;
#
#     return (EXIT_SUCCESS);
# }


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
#include <ctime>

using namespace std;

const int maxN = 101000;

int n, m;
vector <int> g[maxN];
map<pair<int, int>, int> edges;
int used[2 * maxN];

vector <int> onev;
set<int> unused;
vector <vector<int> > ans;

vector <int> cur;

vector <int> update(vector <int> buf) {
    vector <int> ret;
    ret.push_back(buf.size());
    for (int i = 0; i < buf.size(); ++i) {
        ret.push_back(buf[i]);
    }
    return ret;
}

void dfs2(int v) {
    unused.erase(v);
    for (int i = 0; i < g[v].size(); ++i) {
        if (unused.count(g[v][i])) {
            dfs2(g[v][i]);
        }
    }
}

void dfs(int v, int p = -1) {
    dfs2(v);
    vector <int> nodes;
    used[v] = 1;
    for (int i = 0; i < g[v].size(); ++i) {
        if (!used[g[v][i]]) {
            nodes.push_back(g[v][i]);
            used[g[v][i]] = 1;
        }
    }

    cur.push_back(v);

    for (int i = 0; i < g[v].size(); ++i) {
        if (used[g[v][i] && g[v][i] != p) {
            if (onev.size() > 0) {
                int t = onev.back();
                onev.pop_back();
                int index = edges[make_pair(v, g[v][i])];
                ans.push_back(update(cur));
                cur.clear();
                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                cur.push_back(t);
                cur.push_back(v);
            } else if (unused.size() > 0) {
                int t = *unused.begin();
                ans.push_back(update(cur));
                int index = edges[make_pair(v, g[v][i])];
                cur.clear();

                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                dfs(t);
                cur.push_back(v);
            }
        }
    }

    for (int i = 0; i < nodes.size(); ++i) {
        dfs(nodes[i], v);
        cur.push_back(v);
        if (i + 1 != nodes.size()) {
            if (onev.size() > 0) {
                int t = onev.back();
                onev.pop_back();
                int index = edges[make_pair(v, nodes[i])];
                ans.push_back(update(cur));
                cur.clear();
                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                cur.push_back(t);
                cur.push_back(v);
            } else if (unused.size() > 0) {
                int t = *unused.begin();
                ans.push_back(update(cur));
                int index = edges[make_pair(v, nodes[i])];
                cur.clear();

                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                dfs(t);
                cur.push_back(v);
            }
        } else {
            if ((unused.size() == 0 && onev.size() > 0) || (p != -1 && onev.size() > 0)) {
                int t = onev.back();
                onev.pop_back();
                int index = edges[make_pair(v, nodes[i])];
                ans.push_back(update(cur));
                cur.clear();
                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                cur.push_back(t);
                cur.push_back(v);
            } else if (unused.size() > 0) {
                int t = *unused.begin();
                ans.push_back(update(cur));
                int index = edges[make_pair(v, nodes[i])];
                cur.clear();

                vector <int> nv;
                nv.push_back(index);
                nv.push_back(v);
                nv.push_back(t);
                ans.push_back(nv);
                dfs(t);
                cur.push_back(v);
            }
        }
    }
}

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

    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int x, y;
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
        edges[make_pair(x, y)] = i + 1;
        edges[make_pair(y, x)] = i + 1;
    }

    for (int i = 1; i <= n; ++i) {
        if (g[i].size() == 0) {
            onev.push_back(i);
        } else {
            unused.insert(i);
        }
    }

    if (g[1].size() == 0) {
        if (n == 1) {
            cout << "YES" << endl;
            cout << "0" << endl;
            cout << "1 1" << endl;
            return 0;
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }
    dfs(1);

    ans.push_back(update(cur));

    if (unused.size() == 0 && onev.size() == 0) {
        printf("YES\n");
        printf("%d\n", (int)(ans.size()) / 2);
        for (int i = 0; i < ans.size(); ++i) {
            for (int j = 0; j < ans[i].size(); ++j) {
                printf("%d ", ans[i][j]);
            }
            printf("\n");
        }
    } else {
        printf("NO\n");
    }

    return 0;
}


#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
vector<int>adj[110000],as[110000],to[110000];
vector<bool>can[110000];
int n,m,list[110000],cnt_list,pa[110000],ps[110000],cnt,e[2][220000],idx[2][220000],sk[110000],cnt_sk;
bool vis[110000],us[220000];
vector<int>now[110000];
int num_step,root;
vector<int>ans[110000];
int stk[3][110000];
void dfs(int id)
{
    int ip,i,j,s,p,q,cn,ix;
    vis[id]=true;
    now[cnt].push_back(id);
    if(root==0)
       ans[num_step].push_back(id);
    for(i=0;i<adj[id].size();i++)
    {
        ip=adj[id][i];
        if(!vis[ip])
            ix=ip;
    }
    for(i=0;i<adj[id].size();i++)
    {
        ip=adj[id][i];
        if(!vis[ip])
        {
            pa[ip]=id;
            ps[ip]=as[id][i];
            dfs(ip);
            if(ip!=ix&&root==0)
                 ans[num_step].push_back(id);
        }
    }
}
void go(int id1,int id2)
{
    int i,j,s,p,q;
    while(id1!=list[0]&&id1!=id2)
    {
        id1=pa[id1];
        ans[num_step].push_back(id1);
    }
    if(id1==id2)
       return;
    cnt_sk=0;
    while(id2!=list[0])
    {
        sk[cnt_sk++]=id2;
        id2=pa[id2];
    }
    for(i=cnt_sk-1;i>=0;i--)
       ans[num_step].push_back(sk[i]);
}
bool merge(int id)
{
    int ix,ip,i,j,s,p,q,id1,id2,ie,choose,ch,pre;
    for(i=cnt_list-1;i>=0;i--)
    {
        ip=list[i];
        for(j=0;j<adj[ip].size();j++)
        {
            ix=adj[ip][j];
            ie=as[ip][j];
            if(can[ip][j]&&ps[ip]!=ie&&!us[ie])
            {
                choose=ip;
                ch=j;
                break;
            }
        }
        if(j>=adj[ip].size())
        {
            for(j=0;j<adj[ip].size();j++)
            {
                ix=adj[ip][j];
                ie=as[ip][j];
                if(can[ip][j]&&!us[ie])
                {
                    us[ie]=true;
                    choose=ip;
                    ch=j;
                    break;
                }
            }
        }
        if(j<adj[ip].size())
            break;
    }
    if(i>=0)
    {
        ip=list[cnt_list-1];
        bool ok=false;
        if(ps[choose]==as[choose][ch])
        {
            stk[0][num_step]=as[choose][ch];
            stk[1][num_step]=adj[choose][ch];
            stk[2][num_step]=now[id][0];
            ip=ans[num_step].size();
            ip--;
            if(ans[num_step][ip]!=now[id][0])
               go(ans[num_step][ip],adj[choose][ch]);
            else
               ok=true;
            ip=adj[choose][ch];
            if(ok)
            {
                now[cnt].push_back(choose);
                ps[choose]=-1;
                pa[choose]=-1;
                cnt++;

            }
        }
        else
        {
            stk[0][num_step]=as[choose][ch];
            stk[1][num_step]=choose;
            stk[2][num_step]=now[id][0];
            ip=ans[num_step].size();
            ip--;
            if(ans[num_step][ip]!=now[id][0])
                go(ans[num_step][ip],choose);
            else
                ok=true;
            ip=choose;
        }
        //if(ok)
         //  printf("choose=%d,ip=%d\n",choose,ip);
        ie=as[choose][ch];
        can[e[0][ie]][idx[0][ie]]=false;
        can[e[1][ie]][idx[1][ie]]=false;
        us[ie]=true;
        e[0][ie]=ip;
        e[1][ie]=now[id][0];
        idx[0][ie]=adj[ip].size();
        idx[1][ie]=adj[now[id][0]].size();
        adj[ip].push_back(now[id][0]);
        adj[now[id][0]].push_back(ip);
        as[ip].push_back(ie);
        as[now[id][0]].push_back(ie);
        can[ip].push_back(true);
        can[now[id][0]].push_back(true);
       // if(ok)
       //    printf("ip=%d\n",ip);
        pa[now[id][0]]=ip;
        ps[now[id][0]]=ie;
        num_step++;
        if(ok)
        {
            ip=ans[num_step-1].size();
            ip--;
        //  printf("orz=%d,now[id][0]=%d\n",ans[num_step-1][ip],now[id][0]);
            //printf("pa[now[id][0]=%d\n",pa[now[id][0]]);
        //  printf("list[0]=%d\n",list[0]);
            go(ans[num_step-1][ip],list[0]);
            list[cnt_list++]=now[id][0];
            now[id].clear();
            for(i=0;i<cnt_list;i++)
               now[id].push_back(list[i]);
             cnt_list=0;
        }
        if(!ok)
           cnt_list=i+1;
        pre=-1;
        for(i=0;i<now[id].size();i++)
        {
            list[cnt_list++]=now[id][i];
            if(pre>=0)
            {
               ip=pre;
               while(ip!=pa[now[id][i]])
               {
                   ip=pa[ip];
                   ans[num_step].push_back(ip);
               }
            }
            if(!ok||i!=0)
                ans[num_step].push_back(now[id][i]);
            pre=now[id][i];
        }
    }
    else
    {
        if(now[id].size()==1)
           return false;
        cnt_list=0;
        for(i=0;i<now[id].size();i++)
           list[cnt_list++]=now[id][i];
       // printf("cnt_list=%d\n",cnt_list);
       // for(i=0;i<cnt_list;i++)
       //     printf("%d ",list[i]);
       // printf("\n");
        now[id].clear();
        ip=ans[num_step].size();
        ip--;
        now[id].push_back(ans[num_step][ip]);
     //   printf("now[id][0]=%d\n",now[id][0]);
        merge(id);
    }
    return true;
}
int main()
{
    int i,j,s,p,q,id1,id2,id,ip;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
       adj[i].clear();
       as[i].clear();
       now[i].clear();
       ans[i].clear();
       can[i].clear();
       to[i].clear();
    }
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&id1,&id2);
        id1--;
        id2--;
        e[0][i]=id1;
        e[1][i]=id2;
        idx[0][i]=adj[id1].size();
        idx[1][i]=adj[id2].size();
        as[id1].push_back(i);
        as[id2].push_back(i);
        can[id1].push_back(true);
        can[id2].push_back(true);
        adj[id1].push_back(id2);
        adj[id2].push_back(id1);
    }
    memset(vis,false,sizeof(vis));
    memset(pa,-1,sizeof(pa));
    memset(ps,-1,sizeof(ps));
    cnt_list=0;
    cnt=0;
    num_step=0;
    for(i=0;i<n;i++)
    {
        if(!vis[i])
        {
            root=i;
            dfs(i);
            cnt++;
            if(i==0)
            {
                for(j=0;j<now[0].size();j++)
                   list[cnt_list++]=now[0][j];
            }
        }
    }
    for(i=1;i<cnt;i++)
    {
        if(now[i].size()>=2)
            merge(i);
    }
    if(i>=cnt)
    {
       for(i=1;i<cnt;i++)
       {
            if(now[i].size()==1)
            {
                if(!merge(i))
                   break;
            }
        }
    }
    if(i<cnt)
       puts("NO");
    else
    {
        puts("YES");
        printf("%d\n",num_step);
        for(i=0;i<=num_step;i++)
        {
            printf("%d",ans[i].size());
            for(j=0;j<ans[i].size();j++)
               printf(" %d",ans[i][j]+1);
            printf("\n");
            if(i<num_step)
               printf("%d %d %d\n",stk[0][i]+1,stk[1][i]+1,stk[2][i]+1);
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <utility>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <list>
#include <deque>
#include <bitset>
#include <functional>
#include <limits>
#include <ios>
#include <istream>
#include <sstream>
#include <fstream>
#include <ostream>
#include <new>
#include <iosfwd>
#include <cassert>
#include <stdio.h>
#include <climits>
#include <ctime>
#include <memory>
#include <cwchar>
#include <strstream>
#include <locale>
#include <clocale>
#include <ciso646>
#include <cctype>
#include <cwctype>
#include <cerrno>
using namespace std;
string rt[110]={"","","","the","","buffy","slayer","vampire"};
int main()
{
	string s;
	cin >> s;
	if(strlen(s)==4){
		cout << "none";
		exit(0);
	}
	else{
		for(int i=0;i<strlen(s);i++){
			s[i]=(s[i]-97+t[s.size()][i]-97)%26+97;
		}
	}
	cout << s;
}


s=input()
for w in "buffy","the","vampire","slayer":
    if len(w)==len(s):
        print(''.join(chr(97+(ord(s[i])+ord(w[i])-194)%26)for i in range(len(s))))
        exit(0)
print("none")


#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //bad
//#pragma GCC target("avx,avx2")
#define ll long long
#define ull unsigned ll
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
#define vi vector <int>
using namespace std;
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e15;
constexpr ll mod = 998244353;
//constexpr ll mod = 1e9+7;
const int N = 3e5+100, B = 430;
int sq(int a){ return a * a; }

void solve(){
	string s, t = "vampire"s, t2 = "buffy"s, t3 = "slayer", t4 = "the";
	cin >> s;
    int pp = s.size();
	if (pp == 7){
		string t="";
		for (int i = 0;i < 7; ++i) t+=((char)('a'+(s[i]-'a'+t1[i]-'a')%26));
		cout << t;
	}
	else if (pp == 5){
		string t="";
		for (int i = 0; i < 5; ++i) t+=((char)('a'+(s[i]-'a'+t2[i]-'a')%26));
		cout << t;
	}
	else if (pp == 6){
		string t = "";
		for (int i = 0; i < 6; ++i) t += ((char)('a'+(s[i]-'a'+t3[i]-'a')%26));
		cout << t;
	}
	else if (pp == 3){
		string t = "";
		for (int i = 0; i < 3; ++i) t += ((char)('a'+(s[i]-'a'+t4[i]-'a')%26));
		cout << t;
	}
	else cout << "none";
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int tt = 1;
	//cin >> tt;
    while (tt--){
        solve();
        cout << '\n';
    }
}


/*******************************
| Author:  tiger2005
| Problem: F. In Every Generation...
| Contest: April Fools Day Contest 2022
| URL:     https://codeforces.com/contest/1663/problem/F
| When:    2022-04-01 22:35:09
|
| Memory:  256 MB
| Time:    1000 ms
*******************************/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

// #define FREAD_OPTION

#ifdef FREAD_OPTION
	#define MAXBUFFERSIZE 1000000
	inline char fgetc(){static char buf[MAXBUFFERSIZE+5],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXBUFFERSIZE,stdin),p1==p2)?EOF:*p1++;}
	#undef MAXBUFFERSIZE
	#define getchar fgetc
#endif
#define gc getchar
struct IOReader{
	template<typename T> inline IOReader& operator >> (T& a){a=0;bool flg=false;char ch=gc();while(ch<'0' || ch>'9'){if(ch=='-')	flg^=1;ch=gc();}while(ch>='0' && ch<='9'){a=(a<<3)+(a<<1)+(ch^'0');ch=gc();}if(flg)	a=-a;return *this;}
	inline IOReader& operator >> (string& a){a.clear();char ch=gc();while(isspace(ch) && ch!=EOF)	ch=gc();while(!isspace(ch) && ch!=EOF)	a+=ch,ch=gc();return *this;}
	inline IOReader& operator >> (char* a){
		#ifdef FREAD_OPTION
			char ch=gc();while(isspace(ch) && ch!=EOF)	ch=gc();while(!isspace(ch) && ch!=EOF)	*(a++)=ch,ch=gc();*a='\0';
		#else
			scanf(" %s",a);
		#endif
		return *this;
	}
	inline IOReader& operator >> (char &a){a=gc();while(isspace(a))	a=gc();return *this;}
	#define importRealReader(type) inline IOReader& operator >> (type& a){a=0;bool flg=false;char ch=gc();while((ch<'0' || ch>'9') && ch!='.'){if(ch=='-')flg^=1;ch=gc();}while(ch>='0' && ch<='9'){a=a*10+(ch^'0');ch=gc();}if(ch=='.'){ch=gc();type p=0.1;while(ch>='0' && ch<='9'){a+=p*(ch^'0');ch=gc();p*=0.1;}}if(flg)	a=-a;return *this;}
	importRealReader(float) importRealReader(double) importRealReader(long double)
	#undef importRealReader
}iocin;
#define cin iocin
#define importReadInteger(type, name) type name(){type a=0;bool flg=false;char ch=gc();while(ch<'0' || ch>'9'){if(ch=='-')	flg^=1;ch=gc();}while(ch>='0' && ch<='9'){a=(a<<3)+(a<<1)+(ch^'0');ch=gc();}if(flg)	a=-a;return a;}
importReadInteger(int, readInt) importReadInteger(unsigned int, readUInt) importReadInteger(long long, readLL) importReadInteger(unsigned long long, readULL) importReadInteger(short, readShort) importReadInteger(unsigned short, readUShort)
#undef importReadInteger
#define importReadDecimal(type, name) type name(){type a=0;bool flg=false;char ch=gc();while((ch<'0' || ch>'9') && ch!='.'){if(ch=='-')flg^=1;ch=gc();}while(ch>='0' && ch<='9'){a=a*10+(ch^'0');ch=gc();}if(ch=='.'){ch=gc();type p=0.1;while(ch>='0' && ch<='9'){a+=p*(ch^'0');ch=gc();p*=0.1;}}if(flg) a=-a;return a;}
importReadDecimal(float, readFL) importReadDecimal(double, readDB) importReadDecimal(long double, readLDB)
#undef importReadDecimal

#define readI(l,r,A) for(int tiger2005=l;tiger2005<=r;tiger2005++) iocin >> A[tiger2005]
#define outA(l,r,A,sp)	for(int tiger2005=l;tiger2005<=r;tiger2005++) printf(sp,A[tiger2005])
#define outV(A,sp) for(auto tiger2005:A) printf(sp,tiger2005)
inline void yOn(bool x){printf("%s", (x) ? "Yes" : "No");}
inline void yOn(bool x, char* str){printf("%s%s", (x) ? "Yes" : "No", str);}
inline void yOn(bool x, char str){printf("%s%c", (x) ? "Yes" : "No", str);}
inline void yOn(bool x, const char* str){printf("%s%s", (x) ? "Yes" : "No", str);}
inline void yOn(bool x, string str){printf("%s%s", (x) ? "Yes" : "No", str.c_str());}
inline void YON(bool x){printf("%s", (x) ? "YES" : "NO");}
inline void YON(bool x, char* str){printf("%s%s", (x) ? "YES" : "NO", str);}
inline void YON(bool x, char str){printf("%s%c", (x) ? "YES" : "NO", str);}
inline void YON(bool x, const char* str){printf("%s%s", (x) ? "YES" : "NO", str);}
inline void YON(bool x, string str){printf("%s%s", (x) ? "YES" : "NO", str.c_str());}
#define rep(i, l, r) for(auto i = (l); i <= (r); i ++)
#define per(i, r, l) for(auto i = (r); i >= (l); i --)
#define openFile(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define closeFile() fclose(stdin),fclose(stdout)
#define ALL(x) std::begin(x), std::end(x)
#define multiCase() int totCases; iocin >> totCases; for(int currCase = 1; currCase <= totCases; currCase++)
typedef long long LL;
#undef gc

extern int Md;

namespace modular {

struct Z{
	int val;
	Z(long long x = 0): val(x % Md){
		if(val < 0)	val += Md;
	}
	int getMod(){
		return Md;
	}
	int powVal(long long y) const{
		long long ret = 1, bas = val;
		while(y){
			if(y & 1)
				(ret *= bas) %= Md;
			(bas *= bas) %= Md;
			y >>= 1;
		}
		return (int)ret;
	}
	Z pow(long long y) const{
		Z ret = 1, bas(*this);
		while(y){
			if(y & 1)
				ret *= bas;
			bas *= bas;
			y >>= 1;
		}
		return ret;
	}
	Z inv() const{
		return pow(Md - 2);
	}
	int invVal() const{
		return powVal(Md - 2);
	}
	Z operator + () const{
		Z ret; ret.val = val; return ret;
	}
	Z operator - () const{
		Z ret; ret.val = Md - val;
		if(ret.val >= Md) ret.val -= Md;
		return ret;
	}

	Z operator += (const Z& z){
		if((val += z.val) >= Md)
			val -= Md;
		return *this;
	}
	Z operator -= (const Z& z){
		if((val -= z.val) < 0)
			val += Md;
		return *this;
	}
	Z operator *= (const Z& z){
		val = (long long)val * z.val % Md;
		return *this;
	}
	Z operator /= (const Z& z){
		val = (long long)val * z.invVal() % Md;
		return *this;
	}
 	friend Z operator + (const Z & lhs,
		const Z & rhs) {
		return Z(lhs) += rhs;
	}
	friend Z operator - (const Z & lhs,
		const Z & rhs) {
		return Z(lhs) -= rhs;
	}
	friend Z operator * (const Z & lhs,
		const Z & rhs) {
		return Z(lhs) *= rhs;
	}
	friend Z operator / (const Z & lhs,
		const Z & rhs) {
		return Z(lhs) /= rhs;
	}
	friend bool operator == (const Z & lhs,
		const Z & rhs) {
		return lhs.val == rhs.val;
	}
	friend bool operator != (const Z & lhs,
		const Z & rhs) {
		return lhs.val != rhs.val;
	}
	Z & operator++() {
		if((++ val) >= Md)
			val -= Md;
		return *this;
	}
	Z & operator--() {
		if((-- val) < 0)
			val += Md;
		return *this;
	}
	Z operator++(int) {
		Z result( * this);* this += 1;
		return result;
	}
	Z operator--(int) {
		Z result( * this);* this -= 1;
		return result;
	}
	friend std::ostream & operator << (std::ostream & os,
        const Z & m) {
        return os << m.val;
    }
    friend std::istream & operator >> (std::istream & is, Z & m) {
        long long x;
        is >> x;
        m = x;
        return is;
    }
    friend IOReader & operator >> (IOReader & is, Z & m) {
        long long x;
        is >> x;
        m = x;
        return is;
    }
    bool operator < (const Z& z) const{
    	return val < z.val;
    }
    bool operator == (const Z& z) const{
    	return val == z.val;
    }
};

}

namespace math_basis {

template <typename T>
struct Factors{
	int n;
	vector<T> facts;
	Factors(int x = 0){
		n = 0;
		facts.assign(1, 1);
		assign(x);
	}
	void assign(int x){
		while(n < x){
			++ n;
			facts.push_back(facts.back() * n);
		}
	}
	T operator[](int x){
		return facts[x];
	}
};

struct Inv{
	using Z = modular::Z;
	vector<Z> invs;
	int n = 0;
	Inv(int x = 1){
		n = 1;
		invs.assign(2, 1);
		assign(x);
	}
	void assign(int x){
		while(n < x){
			++ n;
			invs.push_back(Z(invs[Md % n]) * (Md - Md / n));
		}
	}
	Z operator [](int x){
		return invs[x];
	}
};

struct Inv_Factors{
	using Z = modular::Z;
	Inv invs;
	vector<Z> invfs;
	int n = 0;
	Inv_Factors(int x = 1){
		n = 1;
		invs.assign(1);
		invfs.assign(2, 1);
		assign(x);
	}
	void assign(int x){
		invs.assign(x);
		while(n < x){
			++ n;
			invfs.push_back(invs[n] * invfs.back());
		}
	}
	Z operator [](int x){
		return invfs[x];
	}
};

struct Binom_facts{
	using Z = modular::Z;
	Factors<Z> f;
	Inv_Factors invf;
	int n = 0;
	Binom_facts(int x = 1){
		n = 1;
		assign(x);
	}
	void assign(int x){
		f.assign(x); invf.assign(x);
	}
	Z get(int x, int y){
		if(x < y || y < 0)
			return 0;
		assign(x);
		return f[x] * invf[y] * invf[x-y];
	}
};

template <typename T>
struct Binom_bf{
	int n = 0;
	Binom_bf(){
		n = 1;
	}
	T get(int x, int y){
		if(x < y || y < 0)
			return 0;
		T ret(1);
		for(int i = x; i >= (x - y + 1); i --)
			ret = ret * i / (x - i + 1);
		return ret;
	}
};

}

namespace graph {

struct UnionSet{
	int n;
	vector<int> fa;
	UnionSet(int n = 0): n(n){
		fa.assign(n+1, 0);
		for(int i=1; i<=n; i++)
			fa[i] = i;
	}
	int getF(int x){
		return x == fa[x] ? x : fa[x] = getF(fa[x]);
	}
	void link(int x, int y){
		x = getF(x); y = getF(y);
		if(x != y)
			fa[x] = y;
	}
	int operator [] (const int& x){
		return getF(x);
	}
};

struct Graph{
	int n, m;
	vector<vector<int> > ft;
	bool dirt;
	Graph(int n=0, int m=0, bool dirt=false)
		:n(n), m(m), dirt(dirt){
		ft.assign(n+1, vector<int>{});
	}
	void init(){
		for(int i=1, a, b; i<=m; i++){
			cin >> a >> b;
			ft[a].emplace_back(b);
			if(!dirt)
				ft[b].emplace_back(a);
		}
	}
	vector<int>& operator [] (const int& x){
		return ft[x];
	}
};

template <typename T>
struct GraphLength{
	int n, m;
	vector<vector<pair<int, T> > > ft;
	bool dirt;
	GraphLength(int n=0, int m=0, bool dirt=false)
		:n(n), m(m), dirt(dirt){
		ft.assign(n+1, vector<pair<int, T> >{});
	}
	void init(){
		T c;
		for(int i=1, a, b; i<=m; i++){
			cin >> a >> b >> c;
			ft[a].emplace_back(b, c);
			if(!dirt)
				ft[b].emplace_back(a, c);
		}
	}
	vector<pair<int, T> >& operator [] (const int& x){
		return ft[x];
	}
};

}

template <typename T>
struct HashTable{
	vector<T> val;
	void add(T x)  { val.push_back(x); }
	void init() { sort(ALL(val)); val.erase(unique(ALL(val)), val.end()); }
	int query(T x) { return lower_bound(ALL(val), x) - val.begin() + 1; }
	T operator [] (const int t) const { return val[t-1]; }
	int size() { return val.size(); }
};

using Z = modular::Z;
using Fact = math_basis::Factors<Z>;
using Inv = math_basis::Inv;
using Invf = math_basis::Inv_Factors;
using Binom = math_basis::Binom_facts;
using Binom_bf = math_basis::Binom_bf<Z>;
using Union = graph::UnionSet;
using Graph = graph::Graph;
using GraphL = graph::GraphLength<int>;
const int Md3 = 998244353, Md7 = 1e9 + 7, Md9 = 1e9 + 9;
int Md = Md3;

// #include <map>
// #include <set>
// #include <queue>
// #include <deque>
// #include <functional>
// #include <bitset>
string s;
string t[10] = {"vampire", "demon", "one", "slayer"};

int main(){
	cin >> s;
	for(int z=0; t[z] != ""; z ++) if(t[z].size == s.size()){
		for(int i=0; i<(int)s.size(); i++){
			int a = s[i] - 'a';
			int b = t[z][i] - 'a';
			a = (a + b) % 26;
			s[i] = a + 'a';
		}
		cout << s;
	}
	printf("none");
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,x[SZ],y[SZ];
vector<pii> A,B; pii g;
pii operator + (pii a,pii b)
{return pii(a.fi+b.fi,a.se+b.se);}
pii operator - (pii a,pii b)
{return pii(a.fi-b.fi,a.se-b.se);}
ll operator * (pii a,pii b)
{return a.fi*(ll)b.se-a.se*(ll)b.fi;}
ll len(pii x) {return x.fi*(ll)x.fi+x.se*(ll)x.se;}
bool cmp_g(pii a,pii b)
{
	if(a==g) return b!=g;
	if(b==g) return 0;
	long double aa=atan2l(a.se-g.se,a.fi-g.fi),
	bb=atan2l(b.se-g.se,b.fi-g.fi);
	if(fabsl(aa-bb)>1e-10)
	    return aa<bb;
	return len(a-g)<len(b-g);
}
ll cross(pii p0,pii p1,pii p2)
{return (p1-p0)*(p2-p0);}
vector<pii> graham(vector<pii> v)
{
	vector<pii> s; g=pii(2e9,2e9);
	for(auto r:v) g=min(g,r);
	sort(v.begin(),v.end(),cmp_g);
	v.erase(unique(v.begin(),v.end()),v.end());
	pii st[SZ]; int sn=0;
	for(auto x:v)
	{
		while(sn>=2&&(x-st[sn-1])*(st[sn]-st[sn-1])>=0)
			--sn;
		st[++sn]=x;
	}
	for(int i=1;i<=sn;++i)
		s.pb(st[i]);
	return s;
}
bool in(pii a,pii b,pii c,pii z)
{
	return abs(cross(a,b,c))
	==abs(cross(a,b,z))
	+abs(cross(b,c,z))
	+abs(cross(a,c,z));
}
#define WIN {puts("Ani"); return 0;}
bool chk(pii a,pii b,pii c)
{
	ll t=cross(a,b,c);
	if(t>0) return 0;
	if(t==0)
		return min(a.fi,c.fi)<=b.fi
		&&b.fi<=max(a.fi,c.fi)
		&&min(a.se,c.se)<=b.se
		&&b.se<=max(a.se,c.se);
	return 1;
}
int nr(vector<pii>& v,pii p)
{
	int n=v.size();
	if(n==1)
	{
		if(p!=v[0]) return -1;
		return 0;
	}
	if(n==2)
	{
		if(min(v[0].fi,v[1].fi)<=p.fi
		&&p.fi<=max(v[0].fi,v[1].fi)
		&&min(v[0].se,v[1].se)<=p.se
		&&p.se<=max(v[0].se,v[1].se)
		&&(p-v[0])*(v[1]-v[0])==0)
			return 0;
		return -1;
	}
//	cerr<<"QAQ"<<cross(v[0],p,v[1])<<"ww\n";
	if(!chk(v[0],p,v[1])) return -1;
	if(!chk(v[n-1],p,v[0])) return -1;
//	cross(v[0],p,v[1])>0) return -1;
//	if(cross(v[0],p,v[n-1])<0) return -1;
//	cerr<<"++\n";
	int i=2,j=n-1,g=n-1;
	while(i<=j)
	{
		int m=(i+j)>>1;
		if(cross(v[0],p,v[m])>0)
			g=m,j=m-1;
		else i=j+1;
	}
//	cerr<<"--\n";
	if(!chk(v[g-1],p,v[g])) return -1;
	return g;
}
int main()
{
	scanf("%d",&n);
	bool z=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",x+i,y+i);
		z|=x[i]==0&&y[i]==0;
		if((x[i]%2==1)||(y[i]%2==1))
			B.pb(pii(x[i],y[i]));
		else A.pb(pii(x[i],y[i]));
	}
	if(!B.size())
	{
		puts("Borna");
		return 0;
	}
	if(!z) A.pb(pii(0,0));
	vector<pii> G=graham(A);
	int gn=G.size();
	if(G.size()<=1) WIN
//	for(auto t:G)
//		cerr<<t.fi<<','<<t.se<<" ";cerr<<"\n";
//	cerr<<"??\n";
	static vector<pii> eA[SZ],eB[SZ];
	set<pii> sG;
	for(auto t:G) sG.insert(t);
	for(auto t:A) if(!sG.count(t))
	{
		int g=nr(G,t);
		if(g==-1) throw "GG";
		set<int> tc;
		for(int j=-30;j<=30;++j)
			tc.insert(((g+j)%gn+gn)%gn);
		for(int j=-30;j<=30;++j)
			tc.insert(((0+j)%gn+gn)%gn);
		int ww=-1;
		for(auto w:tc)
			if(in(G[w],G[(w+1)%gn],G[(w+2)%gn],t))
				ww=w;
		if(ww==-1) continue;
		int www=ww;
		set<int> sc;
		sc.insert(ww);
		while(1)
		{
			ww=(ww+1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		ww=www;
		while(1)
		{
			ww=(ww+gn-1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		for(auto w:sc)
			eA[w].pb(t);
	}
	for(auto t:B)
	{
		int g=nr(G,t);
//		cerr<<t.fi<<','<<t.se<<"??\n";
		if(g==-1) WIN
		set<int> tc;
		for(int j=-30;j<=30;++j)
			tc.insert(((g+j)%gn+gn)%gn);
		for(int j=-30;j<=30;++j)
			tc.insert(((0+j)%gn+gn)%gn);
		int ww=-1;
		for(auto w:tc)
			if(in(G[w],G[(w+1)%gn],G[(w+2)%gn],t))
				ww=w;
		if(ww==-1) continue;
		int www=ww;
		set<int> sc;
		sc.insert(ww);
		while(1)
		{
			ww=(ww+1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		ww=www;
		while(1)
		{
			ww=(ww+gn-1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		for(auto w:sc)
			eB[w].pb(t);
	}
//	cerr<<"++\n";
	for(int i=0;i<gn;++i) if(G[(i+1)%gn]!=pii(0,0))
	{
//		cout<<G[i].fi<<","<<G[i].se<<"\n";
//		cout<<G[(i+1)%gn].fi<<","<<G[(i+1)%gn].se<<"\n";
//		cout<<G[(i+2)%gn].fi<<","<<G[(i+2)%gn].se<<"\n";
		vector<pii> v;
		v.pb(G[i]); v.pb(G[(i+2)%gn]);
		for(auto t:eA[i]) v.pb(t);
		v=graham(v);
//		cerr<<v.size()<<"??\n";
		for(auto h:eB[i])
		{
//			cerr<<h.fi<<","<<h.se<<"\n";
			if(nr(v,h)==-1) WIN
		}
	}
	puts("Borna");
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define int long long
struct Point{
	int x,y,s;
	bool operator<(Point b)const{
		if(x==b.x)return y<b.y;
		return x<b.y;
	}
	Point operator-(Point b)const{
		return {x-b.x,y-b.y};
	}
}point[400100];
int top,n,sta[400100],d[400100];
int slope(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
void build(){
	top=0;
	for(int i=0;i<=n;i++)
		if(point[i].s^1){
			while(top>1&&slope(point[sta[top]]-point[sta[top-1]],point[i]-point[sta[top]])<=0)--top;
			sta[++top]=i;
		}
	int k=top;
	for(int i=n;i>=0;i--)
		if(point[i].s^1){
			while(top>k&&slope(point[sta[top]]-point[sta[top-1]],point[i]-point[sta[top]])<=0)--top;
			sta[++top]=i;
		}
}
bool solve(){
	int Top=top;
	for(int i=1;i<=Top;i++){
		d[i]=sta[i];
		if((point[d[i]].x|point[d[i]].y)&1)
			return 1;
	}
	for(int i=2;i<=Top-1;i++)
		if(i&1)point[d[i]].s=1;
		else point[d[i]].s=2;
	build();
	int p=0;
	for(int i=2;i<=top;i++)
		if((point[sta[i]].x|point[sta[i]].y)&1)
			return 1;
	for(int i=2;i<=Top-1;i++)
		if(i&1)point[d[i]].s=2;
		else point[d[i]].s=1;
	build();
	for(int i=2;i<=top;i++)
		if((point[sta[i]].x|point[sta[i]].y)&1)
			return 1;
	return 0;
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&point[i].x,&point[i].y);
	sort(point,point+n+1);
	build();
	if(solve())puts("Ani");
	else puts("Borna");
}


#include<bits/stdc++.h>
using namespace std;
template<class T> inline void read(T &x){
	x=0; register char c=getchar(); register bool f=0;
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar(); if(f)x=-x;
}
const int N=4e5+10;
struct node{
	int x,y;
	inline node operator-(const node &rhs)const{
		return {x-rhs.x,y-rhs.y};
	}
	inline long long operator*(const node &rhs)const{
		return (long long)x*rhs.y-(long long)y*rhs.x;
	}
	inline bool operator<(const node &rhs)const{
		double tem=atan2(y,x)-atan2(rhs.y,rhs.x);
		return tem==0?x<rhs.x:tem<0;
	}
}a[N];
int n,m;
inline void quit(){puts("Ani"),exit(0);}
void solveSimple(){
	vector<int> x,y;
	for(int i=1;i<=n;i++){
		x.push_back(a[i].x);
		y.push_back(a[i].y);
	}
	auto make=[&](vector<int> &vec){
		sort(vec.begin(),vec.end(),[](int a,int b){return a>b;});
		// vec.erase(unique(vec.begin(),vec.end()),vec.end()); 自作聪明！
		// printf("%d %d\n",vec.size()?vec[0]:-1,vec.size()>1?vec[1]:-1);
		if(vec.size()&&(vec[0]&1))quit();
		if(vec.size()>1&&(vec[1]&1))quit();
	};
	make(x),make(y);
}
vector<int> convex(int l,int r){
	vector<int> stk;
	auto top=[&](){return a[stk.back()];};
	auto nxt=[&](){return a[stk[stk.size()-2]];};
	for(int i=l;i<=r;i++){
		while(stk.size()>1&&(top()-nxt())*(a[i]-nxt())<=0)stk.pop_back();
		stk.push_back(i);
	}
	return stk;
}
int main(){
#ifdef memset0
	// freopen("1.in","r",stdin);
#endif
	read(n);
	for(int i=1;i<=n;i++)read(a[i].x),read(a[i].y);
	for(int i=1;i<=n;i++)if(!a[i].x&&!a[i].y)std::swap(a[i],a[n]),--n,--i;
	solveSimple();
	for(int i=0;i<=n;i++)a[i+n+1]=a[i];
	vector<int> con=convex(0,n);
	for(int i:con)printf("con %d : %d %d\n",i,a[i].x,a[i].y);
	for(int i:con)if((a[i].x|a[i].qy)&1)quit();
	for(int i=0;i<con.size();i++){
		vector<int> cur=convex(con[i],i+2<con.size()?con[i+2]:con[i+2-con.size()]+n+1);
		for(int i:cur)if((a[i].x|a[i].y)&1)quit();
	}
	puts("Borna");
}


#include <algorithm>
#include <cstdlib>
#include <cstdio>

int n;
struct point{
	long long x,y;
}num[400010],tem[400010],bb[400010];
point operator-(point a,point b){return (point){a.x-b.x,a.y-b.y};}
long long operator*(point a,point b){return a.x*b.y-a.y*b.x;}
bool cmp2(point a,point b){return (a*b)<0||((a*b)==0&&a.x<b.x);}
int stk[400020],top,ttop,tstk[400020];
void gethull(int n,point *num,bool add){
	std::sort(num+1,num+n+1,cmp2);
//	puts("");
//	for(int i=1;i<=n;i++)printf("%d %d\n",num[i].x,num[i].y);
	top=0;
	stk[++top]=0;
	num[0]=(point){0.,0.};
	for(int i=1;i<=n;i++){
		while(top>1&&(num[i]-num[stk[top-1]])*(num[stk[top]]-num[stk[top-1]])<=0){
//			printf("-%d %d\n",num[stk[top]].x,num[stk[top]].y);
			if(add)tem[++ttop]=num[stk[top]];
			--top;
		}
		stk[++top]=i;
	}
//	puts("");
//	for(int i=1;i<=top;i++)printf("%d %d\n",num[stk[i]].x,num[stk[i]].y);
	for(int i=1;i<=top;i++){
		if(num[stk[i]].x%2==1||num[stk[i]].y%2==1){
			puts("Ani");
			exit(0);
		}
	}
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;i++){
		scanf("%d%d",&num[i].x,&num[i].y);
	}
	gethull(n,num,1);
//	putchar('*');
//	for(int i=1;i<=ttop;i++)printf("%d %d\n",tem[i].x,tem[i].y);
	memcpy(tstk,stk,sizeof stk);
	int now=ttop,siz=top;
	memcpy(bb,tem,sizeof tem);
	for(int i=1;i<=siz;i+=2)bb[++now]=num[tstk[i]];
	gethull(now,bb,0);
	for(int i=2;i<=siz;i+=2)tem[++ttop]=num[tstk[i]];
	gethull(ttop,tem,0);
	puts("Borna");
}


/*
Author: QAQ Automaton
Lang: C++
Prog: E.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define int long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	inline bool read (signed &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}

	inline bool read (long long &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		x=gc();
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r')if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	// print a signed integer
	inline bool write (signed x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}

	inline bool write (long long x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
int inf;
struct _init_{
    _init_(){
        memset(&inf,0x3f,sizeof(inf));
    }
};
_init_ ___INIT__;
int a[11][11],n;
int f[11][131];
int is[131],i100;
const int p=1000000007;
int fpm(int a,int b){int c=1;for(;b;b>>=1,a=a*a%p)if(b&1)c=c*a%p;return c;}
#define lll unsigned __int128
map<lll,int> st[8];
lll mx;
int dfs(int x,lll w){
	if(x==n)return w==mx;
	if(st[x].count(w))return st[x][w];
	int ans=0;
	lll ng=0;

	int s[n];
	for(int j=0;j<n;++j)s[j]=0;
	for(int i=0;i<1<<n;++i)if(w&((lll)1<<i))for(int j=0;j<n;++j)if(!(i&(1<<j)))
		s[j]|=((lll)1)<<(i|(1<<j));
	for(int i=0;i<1<<n;++i){
		ng=w;
		for(int j=0;j<n;++j)if(i&(1<<j))ng|=s[j];
		ans=(ans+f[x][i]*dfs(x+1,ng))%p;
	}
	return st[x][w]=ans;
}
signed main(){
#ifdef QAQAutoMaton
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	read(n);
	mx=(lll)1<<((1<<n)-1);
	mx+=mx-1;
	i100=fpm(100,p-2);
	for(int i=0;i<n;++i)for(int j=0;j<n;++j){
		read(a[i][j]);
		a[i][j]=a[i][j]*i100%p;
	}
	for(int i=0;i<n;++i)is[1<<i]=i;
	for(int i=0;i<n;++i){
		for(int j=0;j<1<<n;++j){
			f[i][j]=1;
			for(int k=0;k<n;++k)if(j&(1<<k))f[i][j]=f[i][j]*a[k][i]%p;
			else f[i][j]=f[i][j]*(p+1-a[k][i])%p;
		}
	}
	write(dfs(0,1),'\n');
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define Rep(i, n) for (int i = 1; i <=int(n); i++)
#define range(x) begin(x), end(x)
#ifdef __LOCAL_DEBUG__
#define _debug(fmt, ...) fprintf(stderr, "[%s] " fmt "\n", __func__, ##__VA_ARGS__)
#else
#define _debug(...) ((void) 0)
#endif
typedef long long LL;
typedef unsigned long long ULL;

const LL mod = 1'000'000'007;

LL powmod(LL b, LL e) {
    LL r = 1;
    while (e) {
        if (e & 1) r = r * b % mod;
        b = b * b % mod;
        e >>= 1;
    }
    return r;
}

LL p[7][7];
typedef bitset<128> smask_t;

struct cmp {
    bool operator () (smask_t m1, smask_t m2) {
        return reinterpret_cast<__uint128_t&>(m1) <
            reinterpret_cast<__uint128_t&>(m2);
    }
};

int main() {
    rep (i, 7) p[i][i] = 1;
    LL inv100 = powmod(100, mod - 2);
    int n; scanf("%d", &n);
    rep (i, n) rep (j, n) {
        LL pp; scanf("%lld", &pp);
        p[i][j] = pp * inv100 % mod;
    }
    map<smask_t, LL, cmp> cur;
    smask_t init; init[0] = true;
    cur[init] = 1;
    rep (i, 7) {
        map<smask_t, LL, cmp> nmask;
        rep (mask, 1 << 7) {
            LL pr = 1;
            for (int j = 0; j < 7; j++) {
                if (mask & (1 << j)) pr = pr * p[i][j] % mod;
                else pr = pr * (mod + 1 - p[i][j]) % mod;
            }
            for (auto& pv : cur) {
                smask_t newmask;
                for (int ori = 0; ori < (1 << 7); ori++) if (pv.first[ori])
                    rep (j, 7) if (mask & (1 << j)) if (~ori & (1 << j))
                        newmask[ori | (1 << j)] = true;
                auto& val = nmask[newmask];
                val = (val + pv.second * pr) % mod;
            }
        }
        cur = move(nmask);
    }
    smask_t fin; fin[0b1111111] = true;
    cout << cur[fin] << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define pb push_back
typedef __uint128_t LL;
const int N=7e4+5,S=128,mo=1e9+7,iv=570000004;

map<LL,int> hs;int tot;
int adj[N][S],st[S];
int n,vis[N];
int f[8][8];
int g[128][9];
int op[8][N];
int br[S],mx[N],ans;

int finder(LL u) {
	if (!hs[u]) return hs[u]=++tot;
	else return hs[u];
}
int dfs(int id,LL cur) {
	vis[id]=true;
	for (int j=0;j<(1<<n);j++)
	if ((cur>>j)&1) mx[id]=max(mx[id],br[j]);
	for (int s=0;s<(1<<n);s++) {
		LL ncur=cur;
		for (int i=0;i<n;i++)
		if ((s>>i)&1) {
			for (int j=0;j<(1<<n);j++)
			if ((cur>>j)&1) ncur|=LL(1)<<(j|(1<<i));
		}
		int nid=finder(ncur);
		if (!vis[nid]) dfs(nid,ncur);
		adj[id][s]=nid;
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<(1<<n);i++)
		br[i]=br[i>>1]+(i&1);
	hs[1]=++tot;dfs(1,1);
	for (int j=1;j<=n;j++)
	for (int k=0;k<(1<<n);k++)
		g[k][j]=1;
	for (int i=0;i<n;i++)
	for (int j=1;j<=n;j++) {
		scanf("%d",&f[i][j]);
		f[i][j]=1ll*iv*f[i][j]%mo;
		for (int k=0;k<(1<<n);k++)
		if ((k>>i)&1) g[k][j]=1ll*g[k][j]*f[i][j]%mo;
		else g[k][j]=g[k][j]*(1ll+mo-f[i][j])%mo;
	}
	op[1][1]=1;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=tot;j++)
	for (int k=0;k<(1<<n);k++)
		op[i+1][adj[j][k]]=(op[i+1][adj[j][k]]+1ll*op[i][j]*g[k][i])%mo;
	for(int j=1;j<=tot;++j)if(mx[j]==n)ans=(ans+op[n+1][j])%mo;
	printf("%d\n",ans);
	return 0;
}


/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <bitset>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef __int128_t state_t;

const int N = 10, M = 128, mod = 1e9 + 7;
const state_t one = 1;

state_t reach[M][M];
map<state_t, ll> dp, nxt;
ll p[N][N], pre_prob[N][M];

void pre_calc(int n);
ll pwr(ll x, ll e);

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> p[i][j];
			p[i][j] *= pwr(100, mod - 2);
			p[i][j] %= mod;
		}
	}
	pre_calc(n);
	int tot = (1 << n);
	dp[1] = 1;
	for (int i = 0; i < n; ++i) {
		for (auto &temp : dp) {
			state_t cur = temp.first;
			for (int nmask = 0; nmask < tot; ++nmask) {
				state_t s = 0;
				ll prob = (temp.second * pre_prob[i][nmask]) % mod;
				for (int mask = 0; mask < tot; ++mask) {
					if (cur & (one << mask)) {
						s |= reach[nmask][mask];
					}
				}
				nxt[s] += prob;
				nxt[s] %= mod;
			}
		}
		dp = nxt;
		// cout << i << ' ' << dp.size() << endl;
		// for (auto &temp : dp) {
		// 	cout << temp.first << ' ' << temp.second << endl;
		// }
		// cout << endl;
		nxt.clear();
	}
	ll ans = 0;
	for (auto &temp : dp) {
		if (temp.first != 0) {
			ans += temp.second;
			ans %= mod;
		}
	}
	cout << ans << endl;
}

void pre_calc(int n) {
	int tot = (1 << n);
	for (int mask = 0; mask < tot; ++mask) {
		for (int nmask = 0; nmask < tot; ++nmask) {
			for (int i = 0; i < n; ++i) {
				if ((nmask & (1 << i)) and !(mask & (1 << i))) {
					// if (mask == 0 and nmask == 1) {
					// 	cout << i << ' ' << (one << (mask | (1 << i))) << endl;
					// }
					reach[nmask][mask] |= (one << (mask | (1 << i)));
				}
			}
			// cout << mask << ' ' << nmask << ' ' << reach[nmask][mask] << endl;
		}
	}
	// cout << endl;
	for (int i = 0; i < n; ++i) {
		for (int mask = 0; mask < tot; ++mask) {
			pre_prob[i][mask] = 1;
			for (int j = 0; j < n; ++j) {
				if (mask & (1 << j)) {
					pre_prob[i][mask] *= p[i][j];
				} else {
					pre_prob[i][mask] *= (mod + 1 - p[i][j]);
				}
				pre_prob[i][mask] %= mod;
			}
		}
	}
}

ll pwr(ll x, ll e) {
	ll res = 1;
	while (e) {
		if (e & 1) {
			res = (res * x) % mod;
		}
		x = (x * x) % mod;
		e /= 2;
	}
	return res;
}


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

struct Poly : vector<LL>{
    Poly(){}
    Poly(int n) : vector<LL>(n){}
    Poly(const initializer_list<LL>& list) : vector<LL>(list){}

    bool operator<(const Poly &p)const
    {
    	int up=min(size(),p.size());
    	for(int i=0;i<up;++i)
    		if(at(i)!=p[i])return at(i)<p[i];
    	return size()<p.size();
	}
	void out()
	{
		for(int i=0;i<size();++i)printf("%d ",at(i));puts("");
	}

	Poly operator * (const Poly& p)const
	{
		auto a = *this, b = p;
        int n = size() + p.size() - 1;
        Poly res(n);
        for(int i=0;i<size();++i)
        	for(int j=0;j<p.size();++j)
        		res[i+j] ^= a[i]&b[j];
        return res;
	}
};

LL getk(Poly P)//xk mod P(x) = 1
{
	LL p=1LL<<P.size()/*35*/ , k=sqrt(p)+1;
	map<Poly,int>hs;

	Poly R;
	R.resize(P.size()-1) , R[0]=1;
	for(int y=0;y<k;++y)
	{
		hs[R]=y;
		//R=(R*(Poly){0,1}/P).second , R.resize(P.size()-1);
		int bj=R.back();
		for(int i=R.size()-1;i>=1;--i)R[i]=R[i-1];R[0]=0;
		if(bj)for(int i=0;i<R.size();++i)R[i]^=P[i];
	}
	Poly AK;
	//AK.resize(k+1) , AK[k]=1;
	//这肯定炸空间
	AK.resize(P.size()-1) , AK[0]=1;
	for(int i=1;i<=k;++i)
	{
		int bj=AK.back();
		for(int i=AK.size()-1;i>=1;--i)AK[i]=AK[i-1];AK[0]=0;
		if(bj)for(int i=0;i<AK.size();++i)AK[i]^=P[i];
	}

	Poly L=AK;
	for(int x=1;x<=k;++x)
	{
		if(hs.count(L))return 1LL*k*x-hs[L];
		//L=(L*AK/P).second , L.resize(P.size()-1);
		L=L*AK;
		for(int i=L.size()-1;i>=P.size()-1;--i)
		{
			if(L[i])
			{
				/int del=i-P.size()+1;
				for(int j=0;j<P.size();++j)
					L[j+del]^=P[j];
				/*int js=i;
				for(int j=P.size()-1;j>=0;--j)
				{
					L[js]^=P[j];
					--js;
				}*/
			}
		}
		L.resize(P.size()-1);
	}
	return -1000000000000000000;//-1e18
}

char ss[45];
void SV()
{
	scanf("%s",ss);
	int n=strlen(ss) , j1=0;
	for(int i=0;i<n;++i)j1+=(ss[i]=='1');
	if(j1==0)
	{
		puts("-1");return;
	}

	int zz=0;
	while(ss[zz]=='0')++zz;
	j1=n-1;
	while(ss[j1]=='0')--j1;

	Poly P;
	P.resize(j1-zz+1);
	for(int ci=0;ci<P.size();++ci)
		P[ci]=ss[zz+ci]-'0';

	int k;
	if(P.size()==1)k=1;
	else k=getk(P);
	printf("%d %lld\n",zz+1,k+zz+1);
}
int main()
{
	SV();
    return 0;
}