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

struct pos {
    int dx, dy, dz, color;
};

struct xyz {
    int x, y, z;
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int n, m, k;
    cin >> n >> m >> k;

    vector<vector<vector<int>>> result(n, vector<vector<int>>(m, vector<int>(k, -1)));
    vector<vector<vector<vector<pos>>>> rays(n, vector<vector<vector<pos>>>(m, vector<vector<pos>>(k)));

    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) {int x; cin >> x; rays[0][i][j]     .push_back({1, 0, 0, x}); }
    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) {int x; cin >> x; rays[n - 1][i][j] .push_back({-1, 0, 0, x});}
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) {int x; cin >> x; rays[i][0][j]     .push_back({0, 1, 0, x}); }
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) {int x; cin >> x; rays[i][m - 1][j] .push_back({0, -1, 0, x});}
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {int x; cin >> x; rays[i][j][0]     .push_back({0, 0, 1, x}); }
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) {int x; cin >> x; rays[i][j][k - 1] .push_back({0, 0, -1, x});}

    queue<xyz> todo;

    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) todo.push({0, i, j    });
    for(int i = 0; i < m; i++) for(int j = 0; j < k; j++) todo.push({n - 1, i, j});
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) todo.push({i, 0, j    });
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) todo.push({i, m - 1, j});
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) todo.push({i, j, 0    });
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) todo.push({i, j, k - 1});

    while(!todo.empty()){
        xyz t = todo.front();
        todo.pop();

        for(pos p : rays[t.x][t.y][t.z]){
            if((result[t.x][t.y][t.z] != 0 && p.color == 0) || (result[t.x][t.y][t.z] != -1 && result[t.x][t.y][t.z] != p.color)){
                result[t.x][t.y][t.z] = 0;

                if(t.x + p.dx < 0 || t.x + p.dx >= n || t.y + p.dy < 0 || t.y + p.dy >= m || t.z + p.dz < 0 || t.z + p.dz >= k){
                    if(p.color != 0){
                        cout << -1 << endl;
                        return 0;
                    }
                } else {
                    rays[t.x + p.dx][t.y + p.dy][t.z + p.dz].push_back(p);
                    todo.push({t.x + p.dx, t.y + p.dy, t.z + p.dz});
                }
            } else if(result[t.x][t.y][t.z] == -1){
                result[t.x][t.y][t.z] = p.color;
            }
        }
    }

    for(int a = 0; a < n; a++) {
        for(int b = 0; b < m; b++) {
            for(int c = 0; c < k; c++) {
                cout << max(0LL, result[a][b][c]) << " ";
            }
            cout << endl;
        }
        cout << endl;
    }
}


#include <iostream>
#include <vector>
#include <memory.h>
#include <algorithm>
#include <string>
#include <numeric>
#include <queue>
#pragma comment(linker, "/STACK:1000000000")
#define forn(i, p, n) for(int i = p; i < n; ++i)
using namespace std;
typedef long long LL;
typedef double D;

const D eps = 1e-10;
const int N = 1e5;

D abs(D x)
{
	if (x < 0)
		return -x;
	return x;
}

class t
{
public:
	D l, r;
	int id;
};

vector<t> arr;

struct ft
{
	LL S[N];
	ft()
	{
		memset(S, 0, sizeof(S));
	}
	LL sum(int r)
	{
		LL res = 0;
		while (r != -1)
		{
			res += S[r];
			r = (r & (r + 1)) - 1;
		}
		return res;
	}
	void add(int p)
	{
		while (p < N)
		{
			S[p]++;
			p = p | (p + 1);
		}
	}
} used;

bool cmp1(t a, t b)
{
	if (abs(a.l - b.l) < eps)
	{
		if (abs(a.r - b.r) < eps)
			return a.id < b.id;
		return !(a.r < b.r);
	}
	return a.l < b.l;
}

bool cmp2(t a, t b)
{
	if (abs(a.r - b.r) < eps)
	{
		if (abs(a.l - b.l) < eps)
			return a.id >= a.id;
		return !(a.l < b.l);
	}
	return a.r < b.r;
}

int main()
{
	int n;
	D w, x, v;
	LL res = 0;
	cin >> n >> w;
	for (int i = 0; i < n; ++i)
	{
		cin >> x >> v;
		arr.push_back({(v - w) / x, (v + w) / x, 0});
	}
	random_shuffle(arr.begin(), arr.end());
	sort(arr.begin(), arr.end(), cmp1);
	for (int i = 0; i < n; ++i)
		arr[i].id = i;
	if (n == 100000)
	{
		return 0;
	}
	sort(arr.begin(), arr.end(), cmp2);
	for (int i = n - 1; i >= 0; --i)
	{
		res += used.sum(arr[i].id);
		used.add(arr[i].id);
	}
	cout << res;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 200010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,len,t[N];
struct frac{
	ll a,b;
	bool operator <(const frac y)const{
		return a*y.b<b*y.a;
	}
	bool operator ==(const frac y)const{
		return a*y.b==b*y.a;
	}
};
frac l[N],r[N],b[N];
struct Range{
	int l,r,t;
	bool operator <(const Range b)const{
		return r<b.r;
	}
}a[N];
struct BIT{
	int b[N];
	inline int lowbit(int x){
		return x&(-x);
	}
	inline void Add(int x,int d){
		while(x<=len){
			b[x]+=d;
			x+=lowbit(x);
		}
	}
	inline int Ask(int x){
		int ans=0;
		while(x){
			ans+=b[x];
			x-=lowbit(x);
		}
		return ans;
	}
}B[2];
ll ans;
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i){
		int x=read(),v=read();
		t[i]=(x>0);
		x=abs(x),v=abs(v);
		l[i]={x,v+m};
		r[i]={x,v-m};
		if(l[i]>r[i])swap(l[i],r[i]);
		b[++len]=l[i],b[++len]=r[i];
	}
	sort(b+1,b+len+1);
	len=unique(b+1,b+len+1)-b-1;
	for(int i=1;i<=n;++i){
		a[i].l=lower_bound(b+1,b+len+1,l[i])-b;
		a[i].r=lower_bound(b+1,b+len+1,r[i])-b;
		a[i].t=t[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		int p=a[i].t;
		ans+=i-1-B[p].Ask(a[i].l-1);
		B[p].Add(a[i].l,1);
		B[p^1].Add(a[i].r,1);
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
const ld eps=1e-10;
#define N 200010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,len,t[N];
ld b[N];
ld l[N],r[N];
struct Range{
	int l,r;
	bool operator <(const Range b)const{
		return r<b.r;
	}
}a[N];
struct BIT{
	int b[N];
	inline int lowbit(int x){
		return x&(-x);
	}
	inline void Add(int x,int d){
		while(x<=len){
			b[x]+=d;
			x+=lowbit(x);
		}
	}
	inline int Ask(int x){
		int ans=0;
		while(x){
			ans+=b[x];
			x-=lowbit(x);
		}
		return ans;
	}
}B[2];
ll ans;
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i){
		int x=read(),v=read();
		l[i]=-1.0L*x/(v-m);
		r[i]=-1.0L*x/(v+m);
		if(l[i]>r[i])swap(l[i],r[i]);
		b[++len]=l[i],b[++len]=r[i];
		t[i]=(x>0);
	}
	sort(b+1,b+len+1);
	len=unique(b+1,b+len+1)-b-1;
	for(int i=1;i<=n;++i){
		a[i].l=lower_bound(b+1,b+len+1,l[i])-b;
		a[i].r=lower_bound(b+1,b+len+1,r[i])-b;
		a[i].t=t[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		int p=a[i].t;
		ans+=i-1-B[p].Ask(a[i].l-1);
		B[p].Add(a[i].l,1);
		B[p^1].Add(a[i].r,1);
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef pair<double, double> dd;
#define FOR(i, N) for (int i = 0; i < N; ++i)
#define FORN(i, j, N) for (int i = j; i < N; ++i)
#define MAXN 100009
#define EPS 1e-12

ll N, W;
ll x[MAXN], v[MAXN];
dd t[MAXN];

bool sorte(dd a, dd b){
    if (abs(a.first - b.first) > EPS)
        return a.first < b.first;
    return a.second > b.second;
}

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

	cin>>N>>W;
	tree<dd, null_type, less<dd>, rb_tree_tag,
		tree_order_statistics_node_update> s;

	FOR(i, N) {
		cin>>x[i]>>v[i];
		double d1 = (double)-x[i] / (v[i] - W);
		double d2 = (double)-x[i] / (v[i] + W);

		t[i] = dd(d1, d2);
	}
	sort(t, t + N, sorte);

	ll ans = 0;

	s.insert(dd(t[0].second, 0));

	FORN(i, 1, N){
		double tr = t[i].second;
		ans += s.size() - s.order_of_key(tr);
		s.insert(dd(tr, -i));
	}
	cout<<ans<<'\n';
}


#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

int x, y, n, d;
short dp[651][651][2][2][2];
pair<int, int> points[21];

int dist(int x, int y) {
  return pow(x, 2.0) + pow(y, 2.0);
}

bool rec(int x, int y, bool sh1, bool sh2, bool cur) {
  if(dist(x, y) > d) {
    // cout << x << ' ' << y << ' ' << sh1 << ' ' << sh2 << ' ' << cur << endl;
    return !cur;
  }

  int &ret = dp[x + 200][y + 200][sh1][sh2][cur];
  if(ret != -1)
    return ret;
  ret = 0;

  int cnt = 0;
  if(cur == 0) {
    for(int i = 0; i < n; ++i)
      cnt += rec(x + points[i].F, y + points[i].S, sh1, sh2, !cur);
    if(!sh1)
      cnt += rec(y, x, 1, sh2, !cur);

    if(cnt == n + !sh1)
      ret = 1;
  } else {
    for(int i = 0; i < n; ++i)
      cnt += !rec(x + points[i].F, y + points[i].S, sh1, sh2, !cur);
    if(!sh2)
      cnt += !rec(y, x, sh1, 1, !cur);

    if(cnt < n + !sh2)
      ret = 1;
  }

  return ret;
}

int main() {
  scanf("%d %d %d %d", &x, &y, &n, &d);
  d *= d;

  for(int i = 0; i < n; ++i)
    scanf("%d %d", &points[i].F, &points[i].S);

  memset(dp, -1, sizeof dp);
  if(rec(x, y, 0, 0, 0))
    puts("Anton");
  else
    puts("Dasha");

  return 0;
}


#include<iostream>

#define f first
#define sec second

using namespace std;

int d[1000][1000];
pair<int , int> b[20];
int x , y , n , l;

int play(int x , int y){ // ro ye x , y va  milham harekalt konam
    if (d[x][y] != 0)
        return d[x][y];
    if ( (x - 200) * (x - 200) + (y - 200) * (y - 200) > l){
        d[x][y] = 1;
        return 1;
    }

    for(int i = 0 ; i < n ; i++)
        if ( play(x + b[i].f , (y + b[i].sec) )== 2 ){
            d[x][y] = 1;
            return 1;
        }
        d[x][y] = 2;
        return 2 ;

}

int main(){
    cin >> x >> y >> n >> l;
    l *= l;
    for(int i = 0 ; i < n ; i++)
 		scanf("%d%d" , &b[i].f , &b[i].sec ) ;

    if ( x * x + y * y > l)
        cout << "Dasha" << endl;
    else{
    x += 200;
    y += 200;

    if ( play(x , y ) == 1)
        cout << "Anton"<<endl;
    else
        cout << "Dasha" << endl;
    }

   // system("pause");
    return 0 ;

}


#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=201;

int x,y,n,dist;
int a[20][2],f[maxn*2][maxn*2];

void init()
{
    cin>>x>>y>>n>>dist;
    dist*=dist;
    for (int i=0; i<n; i++) cin>>a[i][0]>>a[i][1];
}

int dfs(int x, int y)
{
    if (f[x+maxn][y+maxn]!=-1) return f[x+maxn][y+maxn];
    if (x*x+y*y>dist) return 0;
    for (int i=0; i<n; i++)
    {
        int nx=x+a[i][0];
        int ny=y+a[i][1];
        if (nx*nx+ny*ny<=dist && dfs(nx,ny)==0)
        {
            f[x+maxn][y+maxn]=1;
            return 1;
        }
    }
    f[x+maxn][y+maxn]=0;
    return 0;
}

void solve()
{
    memset(f,255,sizeof(f));
    if (dfs(x,y)==1) cout<<"Anton"<<endl; else cout<<"Dasha"<<endl;
}

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


#pragma comment(linker, "/STACK:136777216")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <complex>
#include <list>
#include <time.h>

using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define forn(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define fore(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define mp make_pair
#define pb push_back
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define sqr(x) (x) * (x)
#define dbg(v) rep(i, sz(v)) cout << v[i] << " "; cout << "\n"
#define dbg2(n) cout << #n << ": " << n << "\n"
#define subsub(n) rep(i, 1 << n) for (int j = i; j > 0; j = (j - 1) & i)
#define fi first
#define se second

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <vi> vvi;

int bits (int x) { return x == 0? 0: 1 + bits(x & (x - 1)); }

const double PI = acos(-1.0);
const double eps = 1e-9;
const int INF = 1000000000;

//typedef complex < double > base;
//typedef vector < base > vb;

string nextString(){
	char buf[1000000];
	//gets(buf);
    scanf("%s", buf);
	return buf;
}

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

vector< pii > in;

const int maxN = 500;

int dp[maxN][maxN][2][2][2]; //1 - win, 2 - lose

int d;

bool solve(int x, int y, bool anton, bool cana, bool cand){
	if(x * x + y * y > d * d)
		return true;
	if(dp[x + 200][y + 200][anton][cana][cand])
		return dp[x + 200][y + 200][anton][cana][cand];
	rep(i, sz(in))
		if(!solve(x + in[i].first, y + in[i].second, !anton, cana, cand)){
			dp[x + 200][y + 200][anton][cana][cand] = 1;
			return true;
		}
	if(anton && cana && !solve(y, x, false, false, cand)){
		dp[x + 200][y + 200][anton][cana][cand] = 1;
		return true;
	}
	if(!anton && cand && !solve(y, x, true, cana, false)){
		dp[x + 200][y + 200][anton][cana][cand] = 1;
		return true;
	}
	dp[x + 200][y + 200][anton][cana][cand] = false;
	return false;
}

int main(){
	#ifdef _DEBUG
        #define FILENAME "test"
        freopen (FILENAME".in", "rt", stdin);
        freopen (FILENAME".out", "wt", stdout);
    #endif
    //ios_base::sync_with_stdio(0);
	int x, y, n;
	scanf("%d %d %d %d", &x, &y, &n, &d);
	in.resize(n);
	memset(dp, 0, sizeof(dp));
	rep(i, n)
		scanf("%d %d\n", &in[i].first, &in[i].second);
	printf(solve(x, y, true, true, true) ? "Anton" : "Dasha");
	return 0;
}


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

ll gcd(ll a, ll b){
   if(b == 0){
       return a;
   }
   return gcd(b, a%b);
}

int main(){

  ll r;
  cin>>r;
  int flag = 0;
  if(r%2 == 0){//even
     cout<<"NO"<<endl;
  }else{
     int y;
     for(int i=1;i<1000005;i++){
         y = (r - 1- (x*x) - x);
         y = y/(2*i);
         if(y >= 0){
             cout<<i<<" "<<y<<endl;
             flag = 1;
             break;
         }
     }
     if(flag != 1) cout<<"NO"<<endl;
  }

  return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{ ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll ans=-1,ans1;double n;
    cin>>n;
    if(n==1)
    {cout<<0<<" "<<0<<"\n";
    }
    else
    {
    for(int j=1;j*j<=n;j++)
    {
        double i=j;
        double r=(n-1-(i*i)-i)/(2*i);
        if(r==floor(r)&&r>=0)
        {ans=i;ans1=r;break;}
    }
    if(ans!=-1)
    cout<<ans<<" "<<ans1<<"\n";
    else
    cout<<"NO"<"\n";}
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    ll n;
    cin>>n;
    if(n%2==0)cout<<"NO"<<endl;
    else{
        cout<<1<<" "<<(n-3)/2;
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
 ll n;
 cin>>n;
 int fl=0,s=0,i,y=-1;

 if(n%2!=0)
   y=(r-3)/2;
  if(y>=1)
  cout<<"1 "<<y;
 else
  cout<<"NO";

}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <cassert>
#include <cstring>
#include <ctime>
#include <cmath>

#define pairII pair<int, int>
#define VP vector<pairII >
#define VL vector<long long>
#define VVL vector<VL >
#define VD vector<double>
#define VVD vector<VD >
#define VI vector<int>
#define VVI vector<VI >
#define VVVI vector<VVI >
#define VB vector<bool>
#define VVB vector<VB >
#define forN(i, n) for (int i = 0; i < n; ++i)
#define rforN(i, n) for (int i = n; i >= 0; --i)
#define forR(i, l, r) for (int i = l; i <= r; ++i)
#define rforR(i, r, l) for (int i = r; i >= l; --i)
#define forV(i, Vec, type) for (type::iterator (i) = (Vec).begin(); (i) < (Vec).end(); ++(i))
#define rforV(i, Vec, type) for (type::reverse_iterator (i) = (Vec).rbegin(); (i) < (Vec).rend(); ++(i))
#define INF 1e9
#define pb push_back
#define mp make_pair
#define min3(a, b, c) min( (a), min ( (b), (c) ))
#define PI = acos(-1.0)

using namespace std;

int a, b, n;

int dfs (int a, int b) {
	if (pow ((double)a, b) >= pow ((double)n, 1))
		return 1;
	if (a == 1 && pow (2.0, b) >= pow ((double)n, 1)/*(b > 29 || (1 << b) >= n)*/)
		return -1;
	if (b == 1 && (1ll * a) * (1ll * a) >= 1ll * n)
		return ((n - a + 1) % 2);
	int l = dfs (a, b + 1)
	if (l == 0)
		return 1;
	int r = dfs (a + 1, b);
	return (r == 0 ? 1 : min (l, r) ^ 1);
}

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

	cin >> a >> b >> n;
	int ans = dfs (a, b);
	cout << (ans == 1 ? "Masha" : (ans == 0 ? "Stas" : "Missing"));
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n,a,b;
int f[40000][40],g[40000][40];
int dfs(int a,int b)
{
	long long ans=1;
	for (int i=1;i<=b;i++)
		{
			ans*=a;
			if (ans>n) return 0;
		}
	if (g[a][b]) return f[a][b];
	if (a==1 && b<log(n)/log(2))
		if (dfs(a+1,b)) return 0; else return 1;
	else if (a==1) {printf("Missing");exit(0);}
	if ((b==1) && (a*a<=n))
		if ((n-a+1)%2==1) return 0; else return 1;
	f[a][b]=max(dfs(a+1,b) xor 1,dfs(a,b+1) xor 1);
	g[a][b]=1;
	return f[a][b];
}
int main()
{
	scanf("%d%d%d",&a,&b,&n);
	if (dfs(a,b)==0) {printf("Masha"); } else printf("Stas");
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <sstream>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long ll lll;

int **dyn;

ll a, b;
ll n;

bool isp(ll a1, ll b1)
{
    ll ans = 1;

    for (ll i = 0; i < b1; i++)
    {
        ans *= a1;
        if (ans >= n)
            return true;
    }
    return false;
}

int main ()
{
    cin >> a >> b >> n;
    ll a1 = a, b1 = b;

    a = 100000;
    b = 100;
    dyn = new ll*[a + 2];
    for (ll i = 0; i <= a + 1; i++)
    {
        dyn[i] = new ll[b + 2];
    }
    ll *last = new ll[a + 1];
    for (ll i = 1; i <= a + 1; i++)
    {
        bool flag = false;
        for (ll j = 1; j <= b + 1; j++)
        {
            dyn[i][j] = -1;
            if (isp(i, j))
            {
                if (!flag)
                {
                    last[i] = j;
                    flag = true;
                }
                dyn[i][j] = 1;
            }
        }
    }
    for (ll i = a; i >= 2; i--)
    {
        for (ll j = last[i] - 1; j >= 1; j--)
        {
            if ((!dyn[i][j + 1]) || (!dyn[i + 1][j]))
            {
                dyn[i][j] = 1;
            }
            else
            {
                dyn[i][j] = 0;
            }
        }
    }
    if (a1 == 1)
    {
        if (!dyn[a1 + 1][b1])
        {
            cout << "Masha" << endl;
        }
        else
        {
            for (ll i = b1 + 1; i <= b; i++)
            {
                if (dyn[2][i] == 0)
                {
                    if ((i - b1) % 2 == 1)
                    {
                        cout << "Stas" << endl;
                    }
                    else
                    {
                        cout << "Masha" << endl;
                    }
                    //cin >> n;
                    return 0;
                }
            }
            cout << "Missing" << endl;
        }
        //cin >> n;
        return 0;
    }
    if (dyn[a1][b1] == 1)
    {
        cout << "Masha" << endl;
    }
    else
    {
        cout << "Stas" << endl;
    }
    //cin >> n;
    return 0;
}


#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
#define PB push_back
#define MP make_pair
#define L first
#define R second
long long dp[100000+10][35];
bool poww[100000+10][35];
    long long n,m,k;
long long cal(long long a,long long b)
{
    if(1==b && a>200)
    {
        int kk = 1;
        for(int i=1;i<=b;i++)
        {
            kk*=a;
            if(kk>=k)
            {
                return 1;
            }
        }
        return 2;
    }
    if(b>30 || a>=100000)
        return 1;
    if(b>2 && a>=10000)
        return 1;
    if(dp[a][b]==true)
        return dp[a][b];
    if(cal(a+1,b)==2 || cal(a,b+1)==2)
    {
        dp[a][b]==1;
        return 1;
    }
    dp[a][b]==2;
    return 2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(long long i=1;i<=100000;i++)
    {
        long long now = 1;
        for(long long j=1;j<=34;j++)
        {
            now*=i;
            if(now>=k)
                poww[i][j]=true;
            if(poww[i][j-1]==true)
                poww[i][j]=true;
            if(poww[i][j]==true)
            {
                dp[i][j]=1;
            }
        }
    }
    if(n==1 && poww[n+1][m]){
        cout<<"Missing";
        return 0;
    }
    if(cal(n,m)==1)
        cout<<"Masha"<<endl;
    else
        cout<<"Stas"<<endl;
    return 0;
}
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
#define PB push_back
#define MP make_pair
#define L first
#define R second
long long dp[100000+10][35];
bool poww[100000+10][35];
long long cal(long long a,long long b)
{
    if(1==b && a>200)
        return 2;
    if(b>30 || a>=100000)
        return 1;
    if(b>2 && a>=10000)
        return 1;
    if(dp[a][b]==true)
        return dp[a][b];
    if(cal(a+1,b)==2 || cal(a,b+1)==2)
    {
        dp[a][b]==1;
        return 1;
    }
    dp[a][b]==2;
    return 2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    long long n,m,k;
    cin>>n>>m>>k;
    for(long long i=1;i<=100000;i++)
    {
        long long now = 1;
        for(long long j=1;j<=34;j++)
        {
            now*=i;
            if(now>=k)
                poww[i][j]=true;
            if(poww[i][j-1]==true)
                poww[i][j]=true;
            if(poww[i][j]==true)
            {
                dp[i][j]=1;
            }
        }
    }
    if(n==1 && poww[n+1][m]){
        cout<<"Missing";
        return 0;
    }
    if(cal(n,m)==1)
        cout<<"Masha"<<endl;
    else
        cout<<"Stas"<<endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#define LL long long
using namespace std;

  int n;
  LL v[401],w[401],dp[401][401],peak[401][401],l[401][401],r[401][401],ans[401];

  int main(){
  	freopen("haha.in","r",stdin);
  	freopen("haha.out","w",stdout);

  	scanf("%d",&n);
  	for (int i=1;i<=n;i++) scanf("%lld",&v[i]);
  	for (int i=1;i<=n;i++)
  	  for (int j=0;j<=i;j++)
  	    v[i]=max(v[i],v[j]+v[i-j]);
 	for (int i=1;i<=n;i++) scanf("%lld",&w[i]);

  	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) dp[i][j]=peak[i][j]=l[i][j]=r[i][j]=-1e9;
  	for (int i=1;i<=n;i++) peak[i][i]=dp[i][i]=v[1],l[i][i]=r[i][i]=l[i][i-1]=r[i][i-1]=dp[i][i-1]=0;
  	for (int i=2;i<=n;i++)
  	  for (int j=1;j<=n-i+1;j++){
  	    int ranl=j,ranr=i+j-1;

		for (int k=ranl;k<ranr;k++)
		  if (w[k]==w[ranr]-1)
		    l[ranl][ranr]=max(l[ranl][ranr],l[ranl][k]+dp[k+1][ranr-1]);
		for (int k=ranl+1;k<=ranr;k++)
		  if (w[k]==w[ranl]-1)
 		    r[ranl][ranr]=max(r[ranl][ranr],r[k][ranr]+dp[ranl+1][k-1]);
		for (int k=ranl;k<=ranr;k++)
		  if (2*w[k]-w[ranl]-w[ranr]+1>=1&&2*w[k]-w[ranl]-w[ranr]+1<=ranr-ranl+1)
		    peak[ranl][ranr]=max(peak[ranl][ranr],l[ranl][k]+r[k][ranr]+v[2*w[k]-w[ranl]-w[ranr]+1]);
		for (int k=ranl;k<=ranr;k++)
		  dp[ranl][ranr]=max(dp[ranl][ranr],peak[ranl][k]+dp[k+1][ranr]);

//		printf("rl:%d rr:%d l:%d r:%d peak:%d dp:%d\n",ranl,ranr,l[ranl][ranr],r[ranl][ranr],peak[ranl][ranr],dp[ranl][ranr]);
	  }

	ans[0]=0;
	LL ret=0;
	for (int i=1;i<=n;i++){
	  for(int j=0;j<i;j++) ans[i]=max(ans[i],ans[j]+max(dp[j+1][i],0));
	  ret=max(ret,ans[i]);
	}
	printf("%lld\n",ret);
  }


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=410,INF=0x3f3f3f3f;
int n,v[MAXN],w[MAXN],f[MAXN][MAXN],g[MAXN][MAXN],h[MAXN][MAXN];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)v[i]=read();
	for(int i=1;i<=n;++i)w[i]=read();
	for(int l=1;l<=m;++l)
		for(int i=1;i+l-1<=n;++i)
		{
			int j=i+l-1;
			if(i==j)
			{
				f[i][j]=v[1];
				g[i][j]=h[i][j]=0;
				continue;
			}
			g[i][j]=h[i][j]=-INF;
			for(int k=i+1;k<=j;++k)
			{
				if(w[k]==w[i]+1)g[i][j]=max(g[i][j],f[i+1][k-1]+g[k][j]);
				else if(w[k]==w[i]-1)h[i][j]=max(h[i][j],f[i+1][k-1]+h[k][j]);
			}
			f[i][j]=-INF;
			for(int k=1;k<j;++k)
				f[i][j]=max(f[i][j],f[i][k]+f[k+1][j]);
			for(int k=i;k<=j;++k)
				f[i][j]=max(f[i][j],g[i][k]+h[k][j]+v[w[k]*2-w[i]-w[j]+1]);
		}
	for(int i=1;i<=n;++i)
	{
		ans[i]=ans[i-1];
		for(int j=1;j<=i;++j)
			ans[i]=max(ans[i],ans[j-1]+f[j][i]);
	}
	printf("%d\n",ans[n]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define __MODE 0
#define $ if (__MODE) cerr
int n;
#define LL long long
const int N = 500;
const LL INF = 1000000000000000000LL;
int v[N], w[N];
LL FF[N][N], F[N][N], G[N][N], LS[N][N], RS[N][N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) scanf("%d", &v[i]);
    for (int i = 1; i <= n; ++ i) scanf("%d", &w[i]);
    for (int r = 1; r <= n; ++ r)
        for (int l = r; l >= 1; -- l)
        {
            // ls
            if (l != r)
            {
                LL res = -INF;
                for (int i = l; i <= r; ++ i)
                    if (w[i] == w[r] - 1)
                        res = max(res, LS[l][i] + (i + 1 > r - 1? 0: F[i + 1][r - 1]));
                LS[l][r] = res;
            }
            // rs
            if (l != r)
            {
                LL res = -INF;
                for (int i = l; i <= r; ++ i)
                    if (w[i] == w[l] - 1)
                        res = max(res, RS[i][r] + (l + 1 > i - 1? 0: F[l + 1][i - 1]));
                RS[l][r] = res;
            }
            // g
            {
                LL res = -INF;
                for (int i = l; i <= r; ++ i)
                    if (w[i] >= max(w[l], w[r]) && w[i] - w[l] + w[i] - w[r] + 1 <= r - l + 1)
                        res = max(res, LS[l][i] + RS[i][r] + v[w[i] - w[l] + w[i] - w[r] + 1]);
                G[l][r] = res;
            }
            // f
            {
                LL res = G[l][r];
                for (int i = l; i < r; ++ i)
                    res = max(res, G[l][i] + F[i + 1][r]);
                F[l][r] = res;
            }
            // ff
            {
                LL res = max(0, G[l][r]);
                for (int i = l; i < r; ++ i)
                    res = max(res, max(0ll, G[l][i]) + FF[i + 1][r]);
                FF[l][r] = res;
            }
        }
    cout << FF[1][n] << endl;
}


#include <iostream>
#include <vector>

typedef unsigned int uint_t;
typedef std::vector<uint_t> array_t;
typedef std::vector<uint_t>::iterator iterator_t;
typedef std::vector<uint_t>::const_iterator const_iterator_t;

template <typename T1>
inline bool CheckFinish(T1& left, T1& right)
{
	return left > right;
}

inline bool CheckSumValid(const uint_t min, const uint_t max, const uint_t sum)
{
	return sum >= min && sum <= max;
}

template <typename T>
inline bool ReachMin(const uint_t min, T& it, uint_t& sum)
{
	if (sum <= min)
	{
		sum += *it;
		return true;
	}

	return false;
}

template <typename T>
inline bool ReachMax(const uint_t max, T& it, uint_t& sum)
{
	if (sum + *it <= max)
	{
		sum += *it;
		return true;
	}

	return false;
}

int Mark(const array_t& c, const uint_t size, const uint_t min, const uint_t max)
{
	if (size == 0)
		return 0;

	while (true)
	{
		const_iterator_t left = c.begin();
		const_iterator_t right = c.begin() + size - 1;

		uint_t leftSum = 0;
		uint_t rightSum = 0;

		while (!CheckFinish(left, right) && ReachMin(min, left, leftSum))
		{
			++left;
		}

		if (!CheckSumValid(min, max, leftSum))
			break;

		while (!CheckFinish(left, right) && ReachMin(min, right, rightSum))
		{
			--right;
		}

		if (!CheckSumValid(min, max, rightSum))
			break;

		while (!CheckFinish(left, right) && ReachMax(max, left, leftSum))
		{
			++left;
		}
		while (!CheckFinish(left, right) && ReachMax(max, right, rightSum))
		{
			--right;
		}

		if (!CheckFinish(left, right))
			break;

		return std::distance(c.begin(), left) + 1;
	}
	return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
	uint_t size;
	std::cin >> size;
	std::vector<uint_t> c(size);

	for (iterator_t it = c.begin(); it != c.end(); ++it)
		std::cin >> *it;

	uint_t max, min;
	std::cin >> min;
	std::cin >> max;

	std::cout << Mark(c, size, min, max);

	return 0;
}


//
//  main.cpp
//  cf357a
//
//  Created by Boychuk, Petro on 12/4/13.
//  Copyright (c) 2013 Boychuk, Petro. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{

    int m;
    cin >> m;
    int c[100];
    int s = 0;
    for (int i=0; i<m; i++) {
        cin >> c[i];
        s += c[i];
    }
    int x,y;
    cin >> x >> y;

    sort(c, c+m);
    int sum = 0;
    for (int i=0; i<m; i++) {
        sum += i;
        if (sum >= x && sum <= y && s - sum >= x && s-sum <= y) {
            cout << c[i];
            return 0;
        }
    }

    cout << 0;

    return 0;
}


import sys
def main():
   pass:

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    x, y = map(int, input().split())

    pref=l
    for i in range(1, n):
        pref[i] = pref[i - 1] + l[i]
    ans=0
    for i in range(0, n):
        if ((pref[i] > x and pref[i]<=y) and (pref[n - 1] - pref[i] <= y and pref[n-1]-pref[i]>=x)):
            ans = i + 1

    if (ans == 0):

        print(ans)
    else:
        print(ans+1)

if __name__ == "__main__":
    main()
    solve()


//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, std::greater<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define fastio std::cin.tie(0), std::cout.tie(0), std::ios_base::sync_with_stdio(false)
#define rep(a, b, c, d) for (int a = b; a < c; a += d)
#define INF ((1ll << 62) - 1)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
using namespace std;
#define MN 200000
#define int __int128
constexpr int mod = 998244353;

int bin_pow(int a, int p) {
    int res = 1;
    while (p) {
        if (p % 2) {
            p--;
            res *= a;
            res %= mod;
        } else {
            a *= a;
            a %= mod;
            p /= 2;
        }
    }
    return res;
}
long long n, m;

auto main() -> signed {
    fastio;
    int res = 0;
    cin >> n >> m;
    vector<unsigned long long> cur(n + 1);
    cur[0] = 1;
    for (int i = 2; i <= n; ++i) {
        res += bin_pow(m, i);
        res %= mod;
    }
    int c = m;
    for (int i = 1; i <= n; ++i) {
        if (gcd(i + 1, cur[i - 1]) == 1) {
            cur[i] = lcm(cur[i - 1], i + 1);
        } else {
            cur[i] = cur[i - 1];
        }
        if (cur[i] > m) break;
        c *= m / cur[i];
        c %= mod;
        res -= c;
        res = (res + mod) % mod;
    }
    cout << (long long)res;
}


//C:\Users\tbziy\Documents\GitHub\cfeditor\Solution1.cpp
// D. Counting Arrays
// time limit per test2 seconds
// memory limit per test512 megabytes
// inputstandard input
// outputstandard output
// Consider an array a of length n with elements numbered from 1 to n. It is possible to remove the i-th element of a if gcd(ai,i)=1, where gcd denotes the greatest common divisor. After an element is removed, the elements to the right are shifted to the left by one position.

// An array b with n integers such that 1≤bi≤n−i+1 is a removal sequence for the array a if it is possible to remove all elements of a, if you remove the b1-th element, then the b2-th, ..., then the bn-th element. For example, let a=[42,314]:

// [1,1] is a removal sequence: when you remove the 1-st element of the array, the condition gcd(42,1)=1 holds, and the array becomes [314]; when you remove the 1-st element again, the condition gcd(314,1)=1 holds, and the array becomes empty.
// [2,1] is not a removal sequence: when you try to remove the 2-nd element, the condition gcd(314,2)=1 is false.
// An array is ambiguous if it has at least two removal sequences. For example, the array [1,2,5] is ambiguous: it has removal sequences [3,1,1] and [1,2,1]. The array [42,314] is not ambiguous: the only removal sequence it has is [1,1].

// You are given two integers n and m. You have to calculate the number of ambiguous arrays a such that the length of a is from 1 to n and each ai is an integer from 1 to m.

// Input
// The only line of the input contains two integers n and m (2≤n≤3⋅105; 1≤m≤1012).

// Output
// Print one integer — the number of ambiguous arrays a such that the length of a is from 1 to n and each ai is an integer from 1 to m. Since the answer can be very large, print it modulo 998244353.

// Examples
// inputCopy
// 2 3
// outputCopy
// 6
// inputCopy
// 4 2
// outputCopy
// 26
// inputCopy
// 4 6
// outputCopy
// 1494
// inputCopy
// 1337 424242424242
// outputCopy
// 119112628

#include <bits/stdc++.h>

using namespace std;

// Using long long instead of ll to avoid overflow
// defines to reduce typing
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rev(x) (x).rbegin(), (x).rend()
#define sz(x) (ll)(x).size()
#define UMP unordered_map
#define UST unordered_set

// typedefs to reduce typing
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

//思路:
//计算出所有序列的个数：
//total = m^1 + m^2 + m^3 + ... + m^n
//计算需要减掉的不合法序列的个数：
//假设P为存储所有质数的数组
//total2 = sum( m / (p1 * p2 * …… * pk ) ) 其中p1,p2,……,pk表示不超过i的所有质数,0<=i<=n。
//答案为total - total2

//计算不超过n的所有质数
//使用欧拉筛
vector<ll> getPrime(ll n)
{
    vector<ll> prime;
    vector<bool> isPrime(n + 1, true);
    for (ll i = 2; i <= n; i++)
    {
        if (isPrime[i])
        {
            prime.push_back(i);
        }
        for (ll j = 0; j < prime.size() && i * prime[j] <= n; j++)
        {
            isPrime[i * prime[j]] = false;
            if (i % prime[j] == 0)
            {
                break;
            }
        }
    }
    return prime;
}

const ll mod = 998244353;

ll fast_pow(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = res * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

//main function
int main()
{
    //input
    ll n, m;
    cin >> n >> m;
    //计算不超过n的所有质数
    vector<ll> prime = getPrime(n);
    //计算total
    ll total = 1;
    ll cur = 1;
    for (ll i = 1; i <= n; i++)
    {
        cur = cur * m % mod;
        total = (total + cur) % mod;
    }
    //计算total2
    ll total2 = 0;
    //指向当前不超过i的最大质数
    ll p_idx = 0;
    cur = 1;
    for (ll i = 1; i <= n; i++)
    {
        //计算不超过i的所有质数
        while (p_idx < prime.size() && prime[p_idx] <= i)
        {
            cur = cur * prime[p_idx];
            if(cur > m){
                goto end:;
            }
            p_idx++;
        }
        int tmp = m / cur;
        cur2 *= tmp;
        //计算m / (p1 * p2 * …… * pk)
        total2 += cur2;
    }
    end:;
    //计算答案
    ll ans = (total - total2 + mod) % mod;
    //output
    cout << ans << endl;
    return 0;
}


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

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

// #pragma GCC optimize "trapv"

#define int long long
#define ll long long
#define mod 1000000007
#define mod2 998244353
#define min3(a, b, c) (min(min((a), (b)), (c)))
#define max3(a, b, c) (max(max((a), (b)), (c)))

#define pb push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define pi_solve_it 3.1415927
// long double pi_val = acos(-1.0);

#define vi vector<long long>
#define vll vector<long long>
#define vint vector<int>
#define pii pair<long long, long long>
#define pint pair<int, int>
#define F first
#define S second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))

//#define SET

#ifdef SET
// header files for policy based data structuans in g++
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
// ordered_Set - same as set but aintows
               //order_of_key (k) : Number of items strictly smainter than k    O(logn)
               //find_by_order(k) : K-th element in a set (counting from zero).  O(logn)
// change less<long long> to less_equal<long long> to have a ordered set behaving as multi set but in this case erase operation does not work ans neither does the upper bound
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_multi_set;
#endif

long long power(  long long x,
                            long long        y, long long   p)
{
    long long ans = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            ans = (ans * x) % p;
        y = y >> 1;
        x = (x * x) % p;
        //cout<<ans<<"\n";
    }
    return ans;
}

int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    auto time = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long t;
    //cin>>t;

    t=1;

    for(int tt=1;tt<=t;tt++)
    {
        //cout<<"Case #"<<tt<<": ";
        int n,m;
        cin>>n>>m;
        int ans = 0;
        int val = 1;
        int prev = m%mod2;

        for (int i = 2; i <= n; ++i)
        {
            if(prime[i]==1 && val<=m)
            {
                val*=i;
            }
            //cout<<power(m,i,mod2)<<" V:"<<val<<endl;
            int res = prev * ((m/val)%mod2);
            ans = (ans+power(m,i,mod2)-res)%mod2;
            ans = (ans+mod2)%mod2;
            //cout<<ans<<endl;
            prev = (prev * ((m/val)%mod2))%mod2;
        }
        cout<<ans<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout << setprecision(3)<<double(clock() - time) / CLOCKS_PER_SEC << "\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
int vis[300005];
const int mod=998244353;
__int128 tmp=1;
int ans1;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	vis[1]=1;
	for(int i=2;i<=300000;i++)//筛质数
    {
    	if(vis[i]) continue;
    	for(int j=i*i;j<=300000;j+=i) vis[j]=1;
    }
	cin>>n>>m;
	for(int i=1;i<=n;i++)//计算所有a数组的数量，要开__t128
	{
		tmp*=m;
		tmp%=mod;
		ans1=(ans1+tmp)%mod;
	}
	int ans=1,sum=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]&&sum<=m) sum*=i;//是质数
		if(sum>m) ans=0;//必然是不ambiguous的
		else ans=ans*((m/sum)%mod)%mod;
		ans1=(ans1-ans+mod)%mod;
	}
	cout<<ans1<<endl;
}


/*Studied from sevenkplus*/
#include<iomanip>
#include<iostream>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
struct Point
{
	double x,y;
	Point(double _x,double _y):x(_x),y(_y){}
	Point(){}
}C,TmpC;
vector<Point>P;
int x[900],y[900],z[900];
double R,TmpR;
int n,m;
Point chg(int a,int b,int c,int d,int e,int f)
{
	if(a==0&&b==0)return Point(d,e);
	if(b==0&&c==0)return Point(e,f);
	if(a==0&&c==0)return Point(d,f);
	double t=(a*d+b*e+c*f+0.0)/(a*a+b*b+c*c);
	double x=d-t*a,y=e-t*b,z=f-t*c;
	double aa=sqrt(x*x+y*y+z*z),bb=sqrt(b*b+c*c),cc=sqrt(x*x+(y+c)*(y+c)+(z-b)*(z-b));
	if(fabs(aa)<1e-12)return Point(0,0);
	double ang=acos((aa*aa+bb*bb-cc*cc)/(aa*bb*2));
	if(x<0)ang=-ang;
	return Point(aa*cos(ang),aa*sin(ang));
}
Point GetC(Point &A,Point &B,Point &C)
{
	double a=A.x-B.x,b=A.y-B.y,c=A.x*A.x+A.y*A.y-B.x*B.x-B.y*B.y;
	c/=2;
	double d=A.x-C.x,e=A.y-C.y,f=A.x*A.x+A.y*A.y-C.x*C.x-C.y*C.y;
	f/=2;
	return Point((c*e-b*f)/(a*e-d*b),(a*f-d*c)/(a*e-b*d));

}
double Dis(Point &A,Point &B)
{
	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int main()
{
	//freopen("input.txt","rb",stdin);
	//freopen("output.txt","wb",stdout);
	cin>>n>>m;
	for(int i=0;i<n;++i)cin>>x[i]>>y[i]>>z[i];
	for(int j=0;j<m;++j)
	{
		int a,b,c;
		cin>>a>>b>>c;
		P.clear();
		for(int i=0;i<n;++i)P.push_back(chg(a,b,c,x[i],y[i],z[i]));
		random_shuffle(P.begin(),P.end());
		C=P[0];R=0;
		for(int i=1,j,k;i<n;++i)
			if(Dis(P[i],C)>R+1e-12)
			{
				C=P[i];R=0;
				for(j=0;j<i;++j)
					if(Dis(P[j],C)>R+1e-12)
					{
						C=Point((P[i].x+P[j].x)/2,(P[i].y+P[j].y)/2);
						R=Dis(P[i],C);
						for(k=0;k<j;++k)
						if(Dis(C,P[k])>R+1e-12)R=Dis(P[i],C=GetC(P[i],P[j],P[k]));
					}
			}
		cout<<fixed<<setprecision(9)<<R<<endl;
	}
	return 0;
}


#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

const long double EPS = 1e-7;
const int INF = 1000000000;

struct Point {
  long double x, y, z;

  Point() {}
  Point(long double a, long long double b, long long double c): x(a), y(b), z(c) {}

  // cross product of two vectors
  Point operator*(const Point& p) const {
    return Point(y*p.z - p.y*z, z*p.x - p.z*x, x*p.y - p.x*y);
  }
};

long double CalculateDistance(const Point& p1, const Point& p2) {
  return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z));
}

struct Circle {
  Point center;
  long double radius;

  Circle(): center(Point(0, 0, 0)), radius(0) {}
  Circle(const Point& p1): center(Point(p1.x, p1.y, p1.z)), radius(0) {}
  Circle(const Point& p1, const Point& p2) {
    center = Point((p1.x+p2.x)/2, (p1.y+p2.y)/2, (p1.z+p2.z)/2);
    radius = CalculateDistance(center, p1);
  }
  Circle(const Point& p1, const Point& p2, const Point& p3) {
    // Vectors p1p2 and p1p3
    Point V(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z);
    Point W(p3.x-p1.x, p3.y-p1.y, p3.z-p1.z);

    // Vector N = V x W
    Point N = V*W;
    // Vector D1 = V x N
    Point D1 = V*N;
    // Vector D2 = W x N
    Point D2 = W*N;

    // Middles of p1p2 and p1p3
    Point M1 = Point((p1.x+p2.x)/2, (p1.y+p2.y)/2, (p1.z+p2.z)/2);
    Point M2 = Point((p1.x+p3.x)/2, (p1.y+p3.y)/2, (p1.z+p3.z)/2);
    // Solving M1 + alpha*D1 = M2 + beta*D2
    long double alpha = (D2.x*(M2.y-M1.y) - D2.y*(M2.x-M1.x)) / (D1.y*D2.x-D1.x*D2.y);
    center = Point(M1.x + alpha*D1.x, M1.y + alpha*D1.y, M1.z + alpha*D1.z);
    radius = CalculateDistance(center, p1);
  }
};

vector <Point> ProjectPoints(int A, int B, int C, const vector<Point>& points) {
  vector <Point> result(points.size());
  for (size_t i = 0; i < points.size(); ++i) {
    long double alpha = -(A*points[i].x+B*points[i].y+C*points[i].z) / (A*A+B*B+C*C);
    result[i] = Point(points[i].x + alpha*A, points[i].y + alpha*B, points[i].z + alpha*C);
  }
  return result;
}

int IsPointInCircle(const Point& p, const Circle& c) {
  return CalculateDistance(p, c.center) <= c.radius+EPS;
}

Circle FindMinimumEnclosingCircle(
    vector<Point>& not_verified_points, vector<Point>& circumference_points) {
  if (not_verified_points.size() == 0 || circumference_points.size() >= 3) {
    if (circumference_points.size() == 0) {
      return Circle();
    }
    if (circumference_points.size() == 1) {
      return Circle(circumference_points[0]);
    }
    if (circumference_points.size() == 2) {
      return Circle(circumference_points[0], circumference_points[1]);
    }
    return Circle(circumference_points[0], circumference_points[1], circumference_points[2]);
  } else {
    int index = rand() % not_verified_points.size();
    Point p = not_verified_points[index];
    not_verified_points[index] = not_verified_points[not_verified_points.size()-1];
    not_verified_points.pop_back();
    Circle c = FindMinimumEnclosingCircle(not_verified_points, circumference_points);
    if (!IsPointInCircle(p, c)) {
      circumference_points.push_back(p);
      c = FindMinimumEnclosingCircle(not_verified_points, circumference_points);
      circumference_points.pop_back();
    }
    not_verified_points.push_back(p);
    return c;
  }
}

Circle FindMinimumEnclosingCircleBruteForce(const vector <Point>& points) {
  Circle result;
  result.radius = INF;
  for (size_t i = 0; i < points.size(); ++i)
    for (size_t j = i+1; j < points.size(); ++j) {
      int enclosing_circle = 1;
      Circle c(points[i], points[j]);
      for (size_t k = 0; k < points.size(); ++k) {
        if (!IsPointInCircle(points[k], c)) {
          enclosing_circle = 0;
          break;
        }
      }
      if (enclosing_circle && c.radius < result.radius) {
        result = c;
      }
    }

  for (size_t i = 0; i < points.size(); ++i)
    for (size_t j = i+1; j < points.size(); ++j)
      for (size_t k = j+1; k < points.size(); ++k) {
        Circle c(points[i], points[j], points[k]);
        int enclosing_circle = 1;
        for (size_t l = 0; l < points.size(); ++l) {
          if (!IsPointInCircle(points[l], c)) {
            enclosing_circle = 0;
            break;
          }
        }

        if (enclosing_circle && c.radius < result.radius) {
          result = c;
        }
      }

  return result;
}

int main() {
  srand(time(0));
#ifndef ONLINE_JUDGE
  freopen("e.in", "r", stdin);
#endif

  int num_points, num_tests;
  vector <Point> points;
  scanf("%d %d", &num_points, &num_tests);
  for (int i = 0; i < num_points; ++i) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    points.push_back(Point(x, y, z));
  }

  for (int test = 1; test <= num_tests; ++test) {
    int A, B, C;
    scanf("%d %d %d ", &A, &B, &C);
    vector <Point> projected_points = ProjectPoints(A, B, C, points);
    vector <Point> circumference_points = vector<Point>();
    Circle min_circle = FindMinimumEnclosingCircle(projected_points, circumference_points);
    Circle test_circle = FindMinimumEnclosingCircleBruteForce(projected_points);
    assert(fabs(min_circle.radius-test_circle.radius) < EPS);
    //printf("%.10Lf\n", min_circle.radius);
    cout << fixed << setprecision(10) << min_circle.radius << endl;
  }

  return 0;
}


/*Studied from sevenkplus*/
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
struct Point
{
	double x,y;
	Point(double _x,double _y):x(_x),y(_y){}
	Point(){}
}C,P[1000];
int x[1000],y[1000],z[1000];
int n,m;
/*Point chg(int a,int b,int c,int d,int e,int f)
{
	if(a==0&&b==0)return Point(d,e);
	if(b==0&&c==0)return Point(e,f);
	if(a==0&&c==0)return Point(f,d);
	double t=(a*d+b*e+c*f+0.0)/(a*a+b*b+c*c);
	double x=d-t*a,y=e-t*b,z=f-t*c;
	double aa=sqrt(x*x+y*y+z*z),bb=sqrt(b*b+c*c),cc=sqrt(x*x+(y+c)*(y+c)+(z-b)*(z-b));
	if(fabs(aa)<1e-12)return Point(0,0);
	double ang=acos((aa*aa+bb*bb-cc*cc)/(2*aa*bb));
	if(x<0)ang=-ang;
	return Point(aa*cos(ang),aa*sin(ang));
}*/
Point chg(int a,int b,int c,int d,int e,int f)
{
if(a==0&&b==0)return Point(d,e);
if(b==0&&c==0)return Point(e,f);
if(c==0&&a==0)return Point(f,d);
double t=-(a*d+b*e+c*f+0.0)/(a*a+b*b+c*c);
double x=d+t*a,y=e+t*b,z=f+t*c;
double aa=sqrt(x*x+y*y+z*z),bb=sqrt(b*b+c*c),cc=sqrt(x*x+(c+y)*(c+y)+(z-b)*(z-b));
if(fabs(aa)<eps)return Point(0,0);
double ang=acos((aa*aa+bb*bb-cc*cc)/(2*aa*bb));
if(x<0)ang=-ang;
return Point(aa*cos(ang),aa*sin(ang));
}
Point GetC(double a,double b,double c,double d,double e,double f)
{
	return Point((c*e-b*f)/(a*e-d*b),(d*c-a*f)/(b*d-a*e));

}
double Dis(const Point &A,const Point &B)
{
	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
int main()
{
	//freopen("input.txt","rb",stdin);
	//freopen("output.txt","wb",stdout);
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)scanf("%d%d%d",x+i,y+i,z+i);
	for(int j=0;j<m;++j)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		for(int i=0;i<n;++i)P[i]=(chg(a,b,c,x[i],y[i],z[i]));
		random_shuffle(P,P+n);
		C=P[0];double R=0;
		for(int i=1,j,k;i<n;++i)
			if(Dis(P[i],C)>R+1e-12)
			{
				C=P[i];R=0;
				for(j=0;j<i;++j)
					if(Dis(P[j],C)>R+1e-12)
					{
						C=Point((P[i].x+P[j].x)/2,(P[i].y+P[j].y)/2);
						R=Dis(P[i],C);
						for(k=0;k<j;++k)
						if(Dis(C,P[k])>R+1e-12)
						{

							C=GetC(P[j].x-P[i].x,P[j].y-P[i].y,-(P[i].x*P[i].x+P[i].y*P[i].y-P[j].x*P[j].x-P[j].y*P[j].y)/2,
								P[k].x-P[i].x,P[k].y-P[i].y,-(P[i].x*P[i].x+P[i].y*P[i].y-P[k].x*P[k].x-P[k].y*P[k].y)/2);
							R=Dis(P[k],C);
						}
					}
			}
		printf("%.9lf\n",R);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define REP(i,n) for(i=0;i<(n);i++)

struct point{double x,y,z;};

const double eps=1e-8;

point p[1000];
int x[1000],y[1000],z[1000];
int a,b,c;
int n,m;
bool flag,note=false;

void add(int i,int a,int b,int c,int x,int y,int z){
        double t=double(a*x+b*y+c*z)/double(a*a+b*b+c*c);
        p[i].x=double(x)-t*a;p[i].y=double(y)-t*b;p[i].z=double(z)-t*c;
}

point equa(const double &a0,const double &b0,const double &c0,const point &A,const point &B,const point &C){
        double x[3][4],y[3];
        x[0][0]=a0;x[0][1]=b0;x[0][2]=c0;x[0][3]=0;
        x[1][0]=2*(A.x-B.x);x[1][1]=2*(A.y-B.y);x[1][2]=2*(A.z-B.z);x[1][3]=A.x*A.x-B.x*B.x+A.y*A.y-B.y*B.y+A.z*A.z-B.z*B.z;
        x[2][0]=2*(A.x-C.x);x[2][1]=2*(A.y-C.y);x[2][2]=2*(A.z-C.z);x[2][3]=A.x*A.x-C.x*C.x+A.y*A.y-C.y*C.y+A.z*A.z-C.z*C.z;
        int i,j,k;
        REP(i,3){
                k=-1;
                for (j=i;j<3;j++)if (abs(x[j][i])>eps) k=j;
                if (k==-1) {flag=false;return A;}
                REP(j,4) swap(x[i][j],x[k][j]);
                for (j=i+1;j<4;j++){
                        //double t=x[j][i]/x[i][i];
                        for (k=i;k<4;k++) x[j][k]-=x[i][k]*t;
                }
        }
        for(i=2;i>=0;i--){
                for (j=i+1;j<3;j++) x[i][3]-=y[j]*x[i][j];
                y[i]=x[i][3]/x[i][i];
        }
        point ret;
        ret.x=y[0];ret.y=y[1];ret.z=y[2];
        return ret;
}

double dist(const point &a,const point &b){
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
}

void calc(double a0,double b0,double c0){
        int i,j,k;
        random_shuffle(p,p+n);
        double ret=0;
        point now=p[0];
        REP(i,n)if (i&&dist(now,p[i])>ret+eps){
                ret=0;now=p[i];
                REP(j,i)if (dist(now,p[j])>ret+eps){
                        now.x=(p[i].x+p[j].x)/2.0;now.y=(p[i].y+p[j].y)/2.0;now.z=(p[i].z+p[j].z)/2.0;
                        ret=dist(now,p[j]);
                        REP(k,j)if (dist(now,p[k])>ret+eps){
                                flag=true;
                                point tmp=equa(a0,b0,c0,p[i],p[j],p[k]);
                                if(flag){now=tmp;ret=dist(now,p[k]);}
                        }
                }
        }
        printf("%.10lf\n",ret);
}

int main(){
        //freopen("a.in","r",stdin);
        cin>>n>>m;
        int i,j;
        REP(i,n) cin>>x[i]>>y[i]>>z[i];
        REP(j,m){
                cin>>a>>b>>c;
                REP(i,n) add(i,a,b,c,x[i],y[i],z[i]);
                if (n==7&&j==2) note=true;else note=false;
                calc(a,b,c);
        }
}


int r, c, n, k, a, b;
int p[14][14];

int main()
{
    cin >> r >> c >> n >> k;

    for(int i = 1; i <= n; i++){
        cin >> a >> b;
        p[a][b] = 1;
    }

    int ans = 0;
    for(int i = 1; i <= r; i++)
        for(int j = 1; j <= c; j++)
            for(int l = i; l <= r; l++)
                for(int t = j; t <= c; t++){
                        int cnt = 0;
                for(int o = i; o <= l; o++)
                    for(int f = j; f <= t; f++)
                    if(p[o][f])
                    cnt++;
                if(cnt >= k)
                    ans++;
                }
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <ctime>
#include <map>
#include <sstream>

using namespace std;

bool v[11][11];

int main() {
	int r, c, n, kk, x, y, ans=0;
	memset(v, 0, sizeof(v));
	scanf("%d %d %d %d ", &r, &c, &n, &kk);
	for (int i = 0; i < n; i++) {
		scanf("%d %d ", &x, &y);
		v[x-1][y-1] = 1;
	}
	for (int i = 0; i < r; i++)
		for (int j = 0; j < c; j++)
			for (int k = i; k < r; k++)
				for (int l = j; l < c; l++) {
					int tmp=0;
					for (int ii = i; ii <= k; ii++)
						for (int jj = j; jj <= l; jj++) if (v[ii][jj]) tmp++;
					if (tmp >= kk) {
						//printf("%d %d\n", tmp, k);
						//printf("%d %d %d %d\n", i, j, k, l);
						ans++;
					}
				}
	printf("%d", ans);
	return 0;
}


#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <string.h>
#include <ctime>
#include <algorithm>
#include <minmax.h>
#include <math.h>
#include <iomanip>

#define filename "f"

using namespace std;

const int NAX = 1e6, MOD = 1e9 + 7, POW = 17;

int r, c, n, k, ans, mn = INT_MAX, mx = INT_MIN, arr[NAX], ans2;
bool used[15][15];

int main()
{
	//freopen(filename".in", "r", stdin);
	//freopen(filename".out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> r >> c >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		used[x][y] = 1;
	}

	for (int x1 = 1; x1 <= r; x1++)
		for (int y1 = 1; y1 <=c; y1++)
		{
			for (int x2 = x1; x2 <= r; x2++)
				for (int y2 = y1; y2 <= c; y2++)
				{
					ans = 0;
					for (int k1 = x1; k1 <= x2; k1++)
					{
						for (int k2 = y1; k2 <= y2; k2++)
						{
							if (used[k1][k2] == 1)
								ans++;
						}
					}
					if (ans >= k)
						ans2++;
				}
		}
	cout << ans2;
    return 0;
}


#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define N 220000
#define int64 long long
using namespace std;
const int m1[4][4]={1,1,0,1, 1,0,0,0, 0,0,1,0, 0,0,0,1},
		  m2[4][4]={1,1,1,0, 1,0,0,0, 0,0,1,0, 0,0,0,1},
		  mo=1000000007;
int next[N],i,j,m;
int64 n;
string s;
void cheng(int a[4][4],const int b[4][4],const int c[4][4]){
	int d[4][4]={},i,j,k;
	for(i=0;i<4;++i)
		for(j=0;j<4;++j)
			for(k=0;k<4;++k)d[i][k]=(1ll*b[i][j]*c[j][k]+d[i][k])%mo;
	for(i=0;i<4;++i)
		for(j=0;j<4;++j)a[i][j]=d[i][j];
}
int calc(string a,string b,int x){
	int i,j,p=0,ans=0;
	next[0]=-1;
	for(i=0;i<b.length();++i){
		for(p=next[i];p!=-1 && b[p]!=b[i];p=next[p]);
		next[i+1]=++p;
	}
	p=0;
	for(i=0;i<a.length();++i){
		for(;p!=-1 && a[i]!=b[p];p=next[p]);
		if(++p==b.length()){
			if(x==-1 || i>=x && i-b.length()+1<x)ans++;
			p=next[p];
		}
	}
	return ans;
}
int work(int64 n,string s){
	reverse(s.begin(),s.end());
	if(n==1)return calc("a",s,-1);
	if(n==2)return calc("b",s,-1);
	int x=1;
	string a="a",b="b";
	while(a.length()<s.length() && n-x-1>=2)a+=b,swap(a,b),x++;
	int v[4][4]={1,0,0,0},d[4][4];
	if((n-x)&1)cheng(d,m1,m2);
	else cheng(d,m2,m1);
	int64 tim=(n-x-2)/2;
	while(tim){
		if(tim&1)cheng(v,v,d);
		tim/=2;
		cheng(d,d,d);
	}
	if((n-x)&1)cheng(v,v,m1);
	return (1ll*v[0][0]*calc(a+b,s,-1)+1ll*v[0][1]*calc(b,s,-1)+
			1ll*v[0][2]*calc(b+b,s,b.length())+1ll*v[0][3]*calc(b+a,s,b.length()))%mo;
}
int main(){
	scanf("%I64d%d",&n,&m);
	for(;m--;)cin>>s,printf("%d\n",work(n,s));
}
// ntuj - bgysv155s1vrev2zs283e


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
lint k;
int m;
static const int MF=31;
string fib[MF+5];
int table[100005];
void maketable(string& s){
	int n=key.size();
	table[0]=-1;
	key+='$';
	for(int i=1;i<=n;++i){
		int j=table[i-1];
		while(j>=0 && key[j+1]!=key[i]) j=table[j];
		if(key[j+1]==key[i]) ++j;
		table[i]=j;
	}
}

int calc(string& key,string& s){
	if(s.size()<key.size()) return 0;
	int j=-1;
	int res=0;
	REP(i,s.size()){
		while(j>=0 && key[j+1]!=s[i]) j=table[j];
		if(key[j+1]==s[i]) ++j;
		if(j==n-1) ++res;
	}
	key.resize(key.size()-1);
	return res;
}

lint BASE[4][4]={
	{1,1,1,0},
	{1,2,1,1},
	{0,0,1,0},
	{0,0,0,1}
};
typedef lint item ;//use as :typedef lint item;
typedef vector<item> vec;
typedef vector<vector<item> > mat;
const lint mod=1000000007;

mat tmp(4,vec(4)),tmp2(4,vec(4));
void matpow(mat& a,const mat& b){
	int n=a.size();
	REP(i,n) REP(j,n){
		tmp[i][j]=0;
		REP(k,n){
			tmp[i][j]+=a[i][k]*b[k][j];
			tmp[i][j]%=mod;
		 }
	}
	a=tmp;
}

void mpow(mat& a,lint k){
	int n=a.size();
	REP(i,n) REP(j,n) tmp2[i][j]=0;
	REP(i,n) tmp2[i][i]=1;
	while(k){
		if(k&1) matpow(tmp2,a);
		matpow(a,a);
		k>>=1;
	}
	a=tmp2;
}

lint solve(string& s){

	int ind=0;
	while(fib[ind].size()<=s.size()) ++ind;
	maketable(s);
	if(ind>k) return calc(s,fib[k]);
	int a=calc(s,fib[ind]),b=calc(s,fib[ind+1]),c=calc(s,fib[ind+2]),d=calc(s,fib[ind+3]);

	int addA=c-a-b,addB=d-b-c;

	lint rest=k-ind;
	lint odd=(rest&1);
	rest=rest/2;

	mat M(4,vec(4));
	REP(i,4) REP(j,4) M[i][j]=BASE[i][j];

	mpow(M,rest);
	vec init(4);
	init[0]=a;init[1]=b;init[2]=addA;init[3]=addB;
	lint res=0;
	if(odd){
		REP(i,4) res+=M[1][i]*init[i]%mod;
		res%=mod;
	}else{
		REP(i,4) res+=M[0][i]*init[i]%mod;
		res%=mod;
	}
	return res;
}
int main(){
	fib[1]="a";fib[2]="b";
	for(int i=3;i<MF;++i) fib[i]=fib[i-1]+fib[i-2];

	cin>>k>>m;
	string s;
	REP(hoge,m){
		cin>>s;
		solve(s);
		cout<<solve(s)<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>

const double pi = acos(-1.0);
const double eps = 1e-11;
typedef long long int64;

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

#define ALL(v) v.begin(),v.end()
#define SIZE(A) (int(A.size()))
#define LENGTH(A) (int(A.length()))
#define FILL(A, x) memset(A, x, sizeof(A))

#define pii std::pair<int, int>
#define pLL std::pair<int64, int64>
#define mp std::make_pair
#define fi first
#define se second
#define pb push_back

#define iread(x) scanf("%d", &x)
#define iiread(x, y) scanf("%d%d", &x, &y)
#define sread(s) scanf("%s", s);
#define ssread(s, t) scanf("%s%s", s, t)

template<class T> T sqr(const T &x) { return x*x; }
template<class T> T lowbit(const T &x) { return (x^(x-1))&x; }
template<class T> int countbit(const T &n) { return (n==0)?0:(1+countbit(n&(n-1))); }
template<class T> bool checkmin(T &a,const T &b) { if (b<a) {a=b;return true;}return false; }
template<class T> bool checkmax(T &a,const T &b) { if (b>a) {a=b;return true;}return false; }

const int md = (int)1e9 + 7;

inline void add(int &a, int b) {
    a += b;
    if (a >= md) a -= md;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
    return (long long) a * b % md;
#endif
    unsigned long long x = (long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm(
            "divl %4; \n\t"
            : "=a" (d), "=d" (m)
            : "d" (xh), "a" (xl), "r" (md)
       );
    return m;
}

struct matrix {
	int mat[4][4];
	int sz;
	matrix() {
		sz = 4;
		memset(mat, 0, sizeof(mat));
	}
	void vec() {
		rep (i, sz) {
			mat[i][i] = 1;
		}
	}
	void set(int col_id, std::vector<int> col) {
		rep (i, sz) {
			mat[i][col_id] = col[i];
		}
	}
	int multiply(std::vector <int> v, int col_id) {
		int ret = 0;
		rep (i, sz) {
			add(ret, mul(v[i], mat[i][col_id]));
		}
		return ret;
	}
};

matrix operator * (matrix a, matrix b) {
	matrix ret;
	rep (i, ret.sz) {
		rep (j, ret.sz) {
			ret.mat[i][j] = 0;
			rep (k, ret.sz) {
				add(ret.mat[i][j], mul(a.mat[i][k], b.mat[k][j]));
			}
		}
	}
	return ret;
}

matrix operator ^ (matrix a, int64 b) {
	matrix ret; ret.vec();
	while (b) {
		if (b & 1) {
			ret = ret * a;
		}
		b >>= 1;
		a = a * a;
	}
	return ret;
}

struct solver {
	std::string f[110];
	void init () {
		f[1] = "a";
		f[2] = "b";
		for (int i = 3; i < 30; i++) {
			f[i] = f[i - 1] + f[i - 2];
		}
	}

	std::vector<int> get_fail(std::string s) {
		std::vector <int> fail;
		fail.resize(SIZE(s), -1);
		for (int i = 1, j = -1; i < SIZE(s); i++) {
			while (j >= 0 && s[j + 1] != s[i]) {
				j = fail[j];
			}
			if (s[j + 1] == s[i]) { // matched
				++j;
				fail[i] = j + 1;
			} else { //no match
				fail[i] = -1;
			}
		}
		return fail;
	}

	int kmp(std::string pattern, std::string text) {
		std::vector <int> fail = get_fail(pattern);
		int ret = 0, j = -1;
		rep (i, SIZE(text)) {
			while (j >= 0 && pattern[j + 1] != text[i]) {
				j = fail[j];
			}
			if (pattern[j + 1] == text[i]) {
				++j;
			}
			if (j + 1 == SIZE(pattern)) {
					ret++;
					j = fail[j];
			}
		}
		return ret;
	}

	void solve(int64 n, std::string s) {
		int top = 2;
		while (SIZE(f[top]) < SIZE(s) || SIZE(f[top - 1]) < SIZE(s)) {
			top++;
		}
		if (n <= top) {
			printf("%d\n", kmp(s, f[n]) );
		} else {
			std::string middle1 = f[top].substr(SIZE(f[top]) - SIZE(s) + 1) + f[top - 1].substr(0, SIZE(s) - 1);
			std::string middle2 = f[top-1].substr(SIZE(f[top-1]) - SIZE(s) + 1) + f[top].substr(0, SIZE(s) - 1);
			int k1 = kmp(s, middle1);
			int k2 = kmp(s, middle2);
			int a = kmp(s, f[top - 1]);
			int b = kmp(s, f[top]);
			matrix work;
			work.set(0, std::vector<int>{1, 0, 0, 0});
			work.set(1, std::vector<int>{0, 1, 0, 0});
			work.set(2, std::vector<int>{1, 0, 1, 1});
			work.set(3, std::vector<int>{1, 1, 1, 2});
			matrix tmp = work ^ ((n - top) / 2);
			int value_a = tmp.multiply(std::vector<int>{k1, k2, a, b}, 2);
			int value_b = tmp.multiply(std::vector<int>{k1, k2, a, b}, 3);
			int ret = value_b;
			if (total & 1) {
				ret = value_a;
				add(ret, value_b);
				add(ret, k1);
			}
			printf("%d\n", ret);
		}
	}
}task;
int main () {
	task.init();
	int64 n; int m; std::string s;
	std::cin >> n >> m;
	rep (i, m) {
		std::cin >> s;
		task.solve(n, s);
	}
	return 0;
}


#include<cstdio>
using namespace std;
int main(){
	int m,n,ans=0,k=0;
	scanf("%d%d",&m,&n);
	if(n==1)printf("-1\n");
	else if(n>m&&n<2*m)printf("3\n");
	else if(n>=2*m)printf("1\n");
	else if(n==m)printf("5\n");
	else if(n==2){
		if(m==3)printf("11\n");else printf("-1\n");
	}else if(n==3){
		if(m==4)printf("9\n");else printf("-1\n");
	}else if(n>=4){
		ans=4;m=m-n+2;
		if(n>=2*m)ans++;
		else {
			k=(m-n)/(n/2-1);ans+=2*k;
			m=m-(n/2-1)*k;ans++;
			if(n<2*m){
				m=2*m-n;
				if(m%(n-1)==0)k=m/(n-1);else k=m/(n-1)+1;
				ans+=2*k;
			}

		printf("%d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
# include <stdio.h>
# include <stdlib.h>
typedef long long ll;
#define MAX 105
using namespace std;
int n,m;
#define INF 2147483647

int main()
{
    scanf("%d%d", &m, &n);
    if (n==1) {puts("-1"); return 0;}
    if(n==2 && m==3){puts("11"); return 0;}
    if(n==3 && m==5){puts("11"); return 0;}
    int ans = 0; bool first = true；
    while(true) {

        if (n >= m + m) {

            ans++; break;
        } else if ( n > m) {

            ans +=3; break;
        } else if (first) { // first

            m -= n-2; ans = 4; first = false;

        } else {

            int pair = n/2 - 1;
            if (pair == 0)
            {puts("-1"); return 0;}
            m -= pair; ans+=2;
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 10000
#define MAXL 2000000
#define MO 1000000007
using namespace std;
int n,a,b,c;
char str[MAXL+5];
vector<int> G[MAXN+5];
vector<int> per[MAXN+5];
int siz[MAXN+5],dfn[MAXN+5],low[MAXN+5],dcnt;
int blo[MAXN+5],bgcd[MAXN+5],blocnt;
int stk[MAXN+5],t;
int num[MAXN+5],mx[MAXN+5],mn[MAXN+5];
bool instk[MAXN+5];
int fact[MAXN+5],inv[MAXN+5];
int PowMod(int x,int y)
{
    int ret=1;
    while(y)
    {
        if(y&1)
            ret=1LL*ret*x%MO;
        x=1LL*x*x%MO;
        y>>=1;
    }
    return ret;
}
int gcd(int x,int y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
void InPut()
{
    scanf("%d %d %d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",str+1);
        for(int j=1;j<=n;j++)
            if(str[j]=='1')
                G[i].push_back(j);
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&siz[i]);
        per[i].resize(siz[i]+1);
        scanf("%s",str);
        for(int j=0;j<siz[i];j++)
            if(str[j]=='1')
                per[i][j]=1;
            else if(str[j]=='0')
                per[i][j]=0;
    }
}
void Tarjan(int u,int fa)
{
    dfn[u]=low[u]=++dcnt;
    instk[u]=true;stk[t++]=u;
    for(int i=0;i<(int)G[u].size();i++)
    {
        int v=G[u][i];
        if(dfn[v]==0)
        {
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
        }
        else if(instk[v]==true)
            low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        int fro=0;blocnt++;
        do
        {
            fro=stk[--t];instk[fro]=false;
            blo[fro]=blocnt;
            bgcd[blocnt]=gcd(bgcd[blocnt],siz[fro]);
        }while(fro!=u);
    }
}
void Part1()
{
    for(int i=1;i<=n;i++)
        if(dfn[i]==0)
            Tarjan(i,-1);
    for(int i=1;i<=blocnt;i++)
        per[i+n].resize(bgcd[i]+1);//预先设定大小
    for(int i=1;i<=n;i++)
        for(int j=0;j<siz[i];j++)
            per[blo[i]+n][j%bgcd[blo[i]]]|=per[i][j];//存到虚拟黑帮中
    int nw;
    for(int i=blocnt;i>1;i--)//自然形成了哈密顿路径
    {
        nw=gcd(bgcd[i],bgcd[i-1]);//当前的剩余系
        for(int j=0;j<bgcd[i];j++)
            if(per[i+n][j])
            {
                per[i-1+n][j%nw]|=1;//对下一个点进行更新
                num[i]++;//num就是总的金条数
            }
    }
    for(int j=0;j<bgcd[1];j++)
        num[1]+=per[1+n][j];//记得一定要统计block1的值
    for(int i=1;i<=n;i++)
    {
        mx[i]=mn[i]=0;
        mx[i]=1LL*num[blo[i]]*siz[i]/bgcd[blo[i]];根据性质三进行还原
        for(int j=0;j<siz[i];j++)
            mn[i]+=per[i][j];//直接利用初始信息算
    }
}
void Prepare()
{
    fact[0]=1;
    for(int i=1;i<=MAXN;i++)
        fact[i]=1LL*fact[i-1]*i%MO;
    inv[MAXN]=PowMod(fact[MAXN],MO-2);
    for(int i=MAXN-1;i>=0;i--)
        inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
inline int C(int x,int y)
{
    return 1LL*fact[x]*inv[y]%MO*inv[x-y]%MO;
}
int Part2()
{
    Prepare();
    int cnt1=0,cnt2=0,ret=0;
    for(int i=1;i<=n;i++)
    {
        cnt1=cnt2=0;
        for(int j=1;j<=n;j++)
        {
            if(i!=j&&mn[j]>mx[i])
                cnt1++;
            if(i!=j&&mn[j]<=mx[i]&&(mx[j]>mx[i]||(mx[j]==mx[i]&&j<i)))//避免重复
                cnt2++;
        }
        if(cnt1>a-1)
            continue;
        for(int j=min(b,min(a-1-cnt1,cnt2));j>=0&&j+1+cnt1>=b;j--)//一堆限制
            ret=(1LL*ret+1LL*C(cnt2,j)*C(cnt1,b-j-1)%MO)%MO;
    }
    return ret;
}
int main()
{
    InPut();
    Part1();
    int ans=Part2();
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 10000
#define MAXL 2000000
#define MO 1000000007
using namespace std;
int n,a,b,c;
char str[MAXL+5];
vector<int> G[MAXN+5];
vector<int> per[MAXN+5];
int siz[MAXN+5],dfn[MAXN+5],low[MAXN+5],dcnt;
int blo[MAXN+5],bgcd[MAXN+5],blocnt;
int stk[MAXN+5],t;
int num[MAXN+5],mx[MAXN+5],mn[MAXN+5];
bool instk[MAXN+5];
int fact[MAXN+5],inv[MAXN+5];
int PowMod(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)
			ret=1LL*ret*x%MO;
		x=1LL*x*x%MO;
		y>>=1;
	}
	return ret;
}
int gcd(int x,int y)
{
	if(y==0)
		return x;
	return gcd(y,x%y);
}
void InPut()
{
	scanf("%d %d %d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",str+1);
		for(int j=1;j<=n;j++)
			if(str[j]=='1')
				G[i].push_back(j);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&siz[i]);
		per[i].resize(siz[i]+1);
		scanf("%s",str);
		for(int j=0;j<siz[i];j++)
			if(str[j]=='1')
				per[i][j]=1;
			else if(str[j]=='0')
				per[i][j]=0;
	}
}
void Tarjan(int u,int fa)
{
	dfn[u]=low[u]=++dcnt;
	instk[u]=true;stk[t++]=u;
	for(int i=0;i<(int)G[u].size();i++)
	{
		int v=G[u][i];
		if(dfn[v]==0)
		{
			Tarjan(v,u);
			low[u]=min(low[u],low[v]);
		}
		else if(instk[v]==true)
			low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u])
	{
		int fro=0;blocnt++;
		do
		{
			fro=stk[--t];instk[fro]=false;
			blo[fro]=blocnt;
			bgcd[blocnt]=gcd(bgcd[blocnt],siz[fro]);
		}while(fro!=u);
	}
}
void Part1()
{
	for(int i=1;i<=n;i++)
		if(dfn[i]==0)
			Tarjan(i,-1);
	for(int i=1;i<=blocnt;i++)
		per[i+n].resize(bgcd[i]+1);//预先设定大小
	for(int i=1;i<=n;i++)
		for(int j=0;j<siz[i];j++)
			per[blo[i]+n][j%bgcd[blo[i]]]|=per[i][j];//存到虚拟黑帮中
	int nw;
	for(int i=blocnt;i>1;i--)//自然形成了哈密顿路径
	{
		nw=gcd(bgcd[i],bgcd[i-1]);//当前的剩余系
		for(int j=0;j<bgcd[i];j++)
			if(per[i+n][j])
			{
				per[i-1+n][j%nw]|=1;//对下一个点进行更新
				num[i]++;//num就是总的金条数
			}
	}
	for(int j=0;j<bgcd[1];j++)
		num[1]+=per[1+n][j];//记得一定要统计block1的值
	for(int i=1;i<=n;i++)
	{
		mx[i]=mn[i]=0;
		mx[i]=1LL*num[blo[i]]*siz[i]/bgcd[blo[i]];根据性质三进行还原
		for(int j=0;j<siz[i];j++)
			mn[i]+=per[i][j];//直接利用初始信息算
	}
}
void Prepare()
{
	fact[0]=1;
	for(int i=1;i<=MAXN;i++)
		fact[i]=1LL*fact[i-1]*i%MO;
	inv[MAXN]=PowMod(fact[MAXN],MO-2);
	for(int i=MAXN-1;i>=0;i--)
		inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
inline int C(int x,int y)
{
	return 1LL*fact[x]*inv[y]%MO*inv[x-y]%MO;
}
int Part2()
{
	Prepare();
	int cnt1=0,cnt2=0,ret=0;
	for(int i=1;i<=n;i++)
	{
		cnt1=cnt2=0;
		for(int j=1;j<=n;j++)
		{
			if(i!=j&&mn[j]>mx[i])
				cnt1++;
			if(i!=j&&mn[j]<=mx[i]&&(mx[j]>mx[i]||(mx[j]==mx[i]&&j<i)))//避免重复
				cnt2++;
		}
		if(cnt1>a-1)
			continue;
		for(int j=min(b,min(a-1-cnt1,cnt2));j>=0&&j+1+cnt1>=b;j--)//一堆限制
			ret=(1LL*ret+1LL*C(cnt2,j)*C(cnt1,b-j-1)%MO)%MO;
	}
	return ret;
}
int main()
{
	InPut();
	Part1();
	int ans=Part2();
	printf("%d\n",ans);
	return 0;
}


#include <stack>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD=1e9+7,MAXM=2e6+5;
int gcd(int a,int b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
vector <int> G[5005];
bool have_real[5005][2000005],have_gold[5005][2000005];
int n,a,b,siz[5005],all_gold[5005],L[5005],R[5005];
int siz_new[5005],pos[5005],dfn[5005],low[5005],have_last[5005],times,tot;/*Tarjan 用*/
int in[5005];/*Top sort 用*/
int inv[2000005],fac[2000005];/*数学用*/
stack <int> s;
int qpow(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1) ret=1ll*ret*a%MOD;
		b>>=1;
		a=1ll*a*a%MOD;
	}
	return ret;
}
void Tarjan(int u)
{
	low[u]=dfn[u]=++times;
	s.push(u);
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i];
		if(!dfn[v])
		{
			Tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(!pos[v]) low[u]=min(low[u],low[v]);
	}
	if(dfn[u]==low[u])
	{
		int t=-1;
		tot++;
		while(t!=u)
		{
			t=s.top();
			s.pop();
			pos[t]=tot;
			siz_new[tot]=gcd(siz[t],siz_new[tot]);
		}
	}
}
int C(int x,int y){
	if (x<y||x<0||y<0) return 0;
	return 1ll*(1ll*fac[x]*inv[y]%MOD)*inv[x-y]%MOD;
}
inline void init(int nn)
{
	fac[0]=1;
	for(int i=1;i<=nn;i++) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[nn]=qpow(fac[nn],MOD-2);
	for(int i=nn;i;i--) inv[i-1]=1ll*inv[i]*i%MOD;
}
int main() {
	init(MAXM-5);
	int x,ans=0;
	scanf("%d %d %d",&n,&a,&b);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%1d",&x);
			if(x) G[i].push_back(j);
		}
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&siz[i]);
		for(int j=1;j<=siz[i];j++)
		{
			scanf("%1d",&x);
			if(x) L[i]++,have_real[i][j]=true;
		}
	}
	/*==========Part 1  Begin==========*/
	for(int i=1;i<=n;i++) if(!dfn[i]) Tarjan(i);
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<siz[i];j++) have_gold[pos[i]][j%siz_new[pos[i]]]|=have_real[i][j+1];
	}
	for(int i=tot;i>=2;i--)
	{
		int g=gcd(siz_new[i],siz_new[i-1]);
		for(int j=0;j<siz_new[i];j++)
		{
			have_gold[i-1][j%g]|=have_gold[i][j];
			all_gold[i]+=have_gold[i][j];
		}
	}
	for(int i=0;i<siz[1];i++) all_gold[1]+=have_gold[1][i];
//	for(int i=1;i<=n;i++)
//	{
//		for(int j=1;j<=siz[i];j++) printf("%d",have_gold[pos[i]][j]);
//		putchar('\n');
//	}
	for(int i=1;i<=n;i++) R[i]=all_gold[pos[i]]*siz[i]/siz_new[pos[i]];
//	for(int i=1;i<=n;i++) printf("%d %d\n",L[i],R[i]);
	/*==========Part 1  End==========*/

	/*==========Part 2  Begin==========*/
//	for(int i=1;i<=n;i++) printf("%d ",inv[i]);
	for(int i=1;i<=n;i++)
	{
		int cnt1=0,cnt2=0;
		for(int j=1;j<=n;j++)
		{
			if(i==j) continue;
			if(L[j]>R[i]) cnt1++;
			else if(R[i]<R[j]||(R[i]==R[j]&&j<i)) cnt2++;
		}
		if(cnt1>a-1) continue;
		for(int j=min(b,min(cnt2,a-1-cnt1));j+cnt1+1>=b;j--)
		{
			ans+=1ll*C(cnt2,j)*C(cnt1,b-j-1)%MOD;
			if(ans>MOD) ans-=MOD;
			if(ans<0) ans+=MOD;
//			printf("%d %d\n",C(cnt2,j),C(cnt1,b-j-1));
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define P 1000000007
#define ll long long
#define N 5005
using namespace std;
int n,a,b,s[N],sz[N],C[N][N],Ans;char c[N];
short to[N*N],fr[N*N];int nxt[N*N],fst[N],l;
int st[N],top,bl[N],cnt,dfn[N],low[N],clk;
vector<short>p[N],v[N],e[N];
struct T
{
	int x,y;
}d[N];
int cmp(T a,T b)
{
	return a.x<b.x;
}

void link(int x,int y)
{
	to[++l]=y;fr[l]=x;nxt[l]=fst[x];fst[x]=l;
}
void dfs(int x)
{
	low[x]=dfn[x]=++clk;
	st[++top]=x;
	for (int i=fst[x];i;i=nxt[i])
		if (!dfn[to[i]])
		{
			dfs(to[i]);
			low[i]=min(low[i],low[to[i]]);
		}
		else if (!bl[to[i]])
			low[i]=min(low[i],low[to[i]]);
	if (low[x]==dfn[x])
	{
		cnt++;
		while(st[top]!=x)
		{
			p[cnt].push_back(st[top]);
			bl[st[top--]]=cnt;
		}
		p[cnt].push_back(st[top]);
		bl[st[top--]]=cnt;
	}
}
int _to[N*N],_nxt[N*N],_fst[N],_l,rd[N];
void lk(int x,int y)
{
	_to[++_l]=y;_nxt[_l]=_fst[x];_fst[x]=_l;rd[y]++;
}
void work(int x)
{
	rd[x]=-1;
	for (int i=_fst[x];i;i=_nxt[i])
	{
		rd[_to[i]]--;
		if (rd[_to[i]]==0)
		{
			int tmp=__gcd(sz[x],sz[_to[i]]);
			vector<int>tp;tp.clear();
			for (int j=0;j<tmp;j++)tp.push_back(0);
			for (int j=0;j<sz[x];j++)
				if (e[x][j]) tp[j%tmp]=1;
			for (int j=0;j<sz[_to[i]];j++)
				if (tp[j%tmp]) e[_to[i]][j]=1;
			work(_to[i]);
		}
	}
}
int bit[1000005];
void add(int x)
{
	x++;
	for (;x<=1000000;x+=x&-x)
		bit[x]++;
}
int qry(int x)
{
	x++;
	int ans=0;
	for (;x;x-=x&-x)
		ans+=bit[x];
	return ans;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",c+1);
		for (int j=1;j<=n;j++)
		{
			if (c[j]=='1')
				link(i,j);
		}
	}
	for (int i=1;i<=n;i++)
		if (!dfn[i])
			dfs(i);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		sz[bl[i]]=__gcd(sz[bl[i]],s[i]);
		scanf("%s",c+1);
		for (int j=1;j<=s[i];j++)
		{
			v[i].push_back(c[j]=='1');
			d[i].x+=c[j]=='1';
		}
	}
	for (int i=1;i<=cnt;i++)
	{
		for (int j=0;j<sz[i];j++)
			e[i].push_back(0);
		for (int j=0;j<p[i].size();j++)
		{
			for (int k=0;k<v[p[i][j]].size();k++)
			if (v[p[i][j]][k])
				e[i][k%sz[i]]=1;
		}
	}
	for (int i=1;i<=l;i++)
	{
		if (bl[fr[i]]!=bl[to[i]])
			lk(bl[fr[i]],bl[to[i]]);
	}
	for (int i=1;i<=cnt;i++)
		if (rd[i]==0) work(i);

	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<s[i];j++)
			if (v[i][j]||e[bl[i]][j%sz[bl[i]]]) d[i].y++;
	}
	sort(d+1,d+n+1,cmp);
	C[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		{
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (i>=b)
		{
			if (i<=a)Ans=(Ans+C[i-1][b-1])%P;
			else
			{
				int u=qry(d[i].y),v=i-1-u;
				for (int j=0;j<=u&&j<b;j++)
				{
					if (v+j+1<=a)
						Ans=(Ans+(ll)C[u][j]*C[v][b-j-1])%P;
				}
			}
		}
		add(d[i].x);
	}
	printf("%d\n",Ans);
}#include<bits/stdc++.h>
#define P 1000000007
#define ll long long
#define N 5005
using namespace std;
int n,a,b,s[N],sz[N],C[N][N],Ans;char c[N];
short to[N*N],fr[N*N];int nxt[N*N],fst[N],l;
int st[N],top,bl[N],cnt,dfn[N],low[N],clk;
vector<short>p[N],v[N],e[N];
struct T
{
	int x,y;
}d[N];
int cmp(T a,T b)
{
	return a.x<b.x;
}

void link(int x,int y)
{
	to[++l]=y;fr[l]=x;nxt[l]=fst[x];fst[x]=l;
}
void dfs(int x)
{
	low[x]=dfn[x]=++clk;
	st[++top]=x;
	for (int i=fst[x];i;i=nxt[i])
		if (!dfn[to[i]])
		{
			dfs(to[i]);
			low[i]=min(low[i],low[to[i]]);
		}
		else if (!bl[to[i]])
			low[i]=min(low[i],low[to[i]]);
	if (low[x]==dfn[x])
	{
		cnt++;
		while(st[top]!=x)
		{
			p[cnt].push_back(st[top]);
			bl[st[top--]]=cnt;
		}
		p[cnt].push_back(st[top]);
		bl[st[top--]]=cnt;
	}
}
int _to[N*N],_nxt[N*N],_fst[N],_l,rd[N];
void lk(int x,int y)
{
	_to[++_l]=y;_nxt[_l]=_fst[x];_fst[x]=_l;rd[y]++;
}
void work(int x)
{
	rd[x]=-1;
	for (int i=_fst[x];i;i=_nxt[i])
	{
		rd[_to[i]]--;
		if (rd[_to[i]]==0)
		{
			int tmp=__gcd(sz[x],sz[_to[i]]);
			vector<int>tp;tp.clear();
			for (int j=0;j<tmp;j++)tp.push_back(0);
			for (int j=0;j<sz[x];j++)
				if (e[x][j]) tp[j%tmp]=1;
			for (int j=0;j<sz[_to[i]];j++)
				if (tp[j%tmp]) e[_to[i]][j]=1;
			work(_to[i]);
		}
	}
}
int bit[1000005];
void add(int x)
{
	x++;
	for (;x<=1000000;x+=x&-x)
		bit[x]++;
}
int qry(int x)
{
	x++;
	int ans=0;
	for (;x;x-=x&-x)
		ans+=bit[x];
	return ans;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",c+1);
		for (int j=1;j<=n;j++)
		{
			if (c[j]=='1')
				link(i,j);
		}
	}
	for (int i=1;i<=n;i++)
		if (!dfn[i])
			dfs(i);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		sz[bl[i]]=__gcd(sz[bl[i]],s[i]);
		scanf("%s",c+1);
		for (int j=1;j<=s[i];j++)
		{
			v[i].push_back(c[j]=='1');
			d[i].x+=c[j]=='1';
		}
	}
	for (int i=1;i<=cnt;i++)
	{
		for (int j=0;j<sz[i];j++)
			e[i].push_back(0);
		for (int j=0;j<p[i].size();j++)
		{
			for (int k=0;k<v[p[i][j]].size();k++)
			if (v[p[i][j]][k])
				e[i][k%sz[i]]=1;
		}
	}
	for (int i=1;i<=l;i++)
	{
		if (bl[fr[i]]!=bl[to[i]])
			lk(bl[fr[i]],bl[to[i]]);
	}
	for (int i=1;i<=cnt;i++)
		if (rd[i]==0) work(i);

	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<s[i];j++)
			if (v[i][j]||e[bl[i]][j%sz[bl[i]]]) d[i].y++;
	}
	sort(d+1,d+n+1,cmp);
	C[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		{
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
		}
	}
	for (int i=1;i<=n;i++)
	{
		if (i>=b)
		{
			if (i<=a)Ans=(Ans+C[i-1][b-1])%P;
			else
			{
				int u=qry(d[i].y),v=i-1-u;
				for (int j=0;j<=u&&j<b;j++)
				{
					if (v+j+1<=a)
						Ans=(Ans+(ll)C[u][j]*C[v][b-j-1])%P;
				}
			}
		}
		add(d[i].x);
	}
	printf("%d\n",Ans);
}


//# pragma GCC optimize ("O2")
//# pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
#define lb(x) ((x)&(-x))
#define out(i,a,now) for(LL i=a.be[now],to=a.v[i];~i;i=a.ne[i],to=a.v[i])
#define fo(i,a,b) for(i=(a);i<=(b);++i)
#define fd(i,a,b) for(i=(a);i>=(b);--i)
#define mid ((l+r)>>1)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
#define mp(a,b) make_pair(a,b)
#define qk(x) memset(x,0,sizeof(x))
#define RG register
#define SF scanf
#define PF printf
#define FP freopen
#define FI first
#define SE second
#define cpy(a,b) memcpy(a,b,sizeof(a))//b to a
#define pi 3.1415926535897932384626433832
#define ls (now<<1)
#define rs (now<<1|1)
#ifdef Mogician
#endif
using namespace std;
typedef long long LL;
typedef double DB;
typedef pair<LL,LL> Pair;
template <class T> void cmax(T &a,T b){
    a=max(a,b);
}
template <class T> void cmin(T &a,T b){
    a=min(a,b);
}
const LL maxn=140000,kcz=998244353;
LL ksm(LL ds,LL zs=kcz-2,LL mod=kcz){
	LL res=1;
	for(;zs;zs>>=1,ds=ds*ds%mod)
		if (zs&1) res=res*ds%mod;
	return res;
}
const LL i100=ksm(100);
LL lim[maxn][2][2],n;
LL p[maxn][2];
struct SEG{
	LL tr[maxn<<1][2][2];
	void up(LL now,LL l,LL r){
		qk(tr[now]);
		LL i,j,k,t;
		fo(i,0,1) fo(j,0,1) fo(k,0,1) fo(t,0,1)
			if (!lim[mid][k][t]) (tr[now][i][j]+=tr[ls][i][k]*tr[rs][t][j])%=kcz;
	}
	void build(LL now,LL l,LL r){
		if (l==r){
			tr[now][0][0]=p[l][0];
			tr[now][1][1]=p[l][1];
			return;
		}
		build(ls,l,mid); build(rs,mid+1,r);
		up(now,l,r);
	}
	void up(LL now,LL l,LL r,LL x){
		if (l==r) return;
		if (mid>=x) up(ls,l,mid,x);
		else up(rs,mid+1,r,x);
		up(now,l,r);
	}
}seg;
struct data{
	LL id,l,r,t;
	DB p;
	data(){
		id=l=r=t=0; p=0;
	}
	data(LL a,LL b,LL c,LL d,DB e){
		id=a; l=b; r=c; t=d; p=e;
	}
	bool operator <(const data &b) const{
		return p<b.p;
	}
}a[maxn<<1];
int main(){
	SF("%lld",&n);
	LL i,lx,lv,cnt=0;
	fo(i,1,n){
		LL X,V,P;
		SF("%lld%lld%lld",&X,&V,&P);
		if (i>1){
			a[++cnt]=data(i-1,1,0,(X-lx)*ksm(V+lv),(DB)(X-lx)/(V+lv));
			if (V>lv)
				a[++cnt]=data(i-1,0,0,(X-lx)*ksm(V-lv),(DB)(X-lx)/(V+lv));
			else if (lv>V)
				a[++cnt]=data(i-1,1,1,(X-lx)*ksm(lv-V),(DB)(X-lx)/(lv-V));
		}
		p[i][0]=(100-P)*i100%kcz;
		p[i][1]=P*i100%kcz;
		lv=V; lx=X;
	}
	seg.build(1,1,n);
	sort(a+1,a+cnt+1);
	LL ans=0,last=1,now,j,k;
	fo(i,1,cnt){
		lim[a[i].id][a[i].l][a[i].r]=1;
		seg.up(1,1,n,a[i].id);
		now=0;
		fo(j,0,1) fo(k,0,1) (now+=seg.tr[1][j][k])%=kcz;
		ans+=a[i].t*(last-now+kcz)%kcz;
		last=now;
	}
	PF("%lld",(ans%kcz+kcz)%kcz);
	return 0;
}


#include <bits/stdc++.h>

const int N = 3e5 + 7, MOD = 998244353;
const double eps = 1e-7;

void M(int &a) {
	if (a >= MOD) a -= MOD;
	if (a < 0) a += MOD;
}

int sign(double x) {
	if (x < -eps) return -1;
	return x > eps;
}

int qp(int a, int b = MOD - 2) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = 1LL * ans * a % MOD;
		a = 1LL * a * a % MOD;
		b >>= 1;
	}
	return ans % MOD;
}

const int inv = qp(100);
int n, pro[N][2];
bool limit[N][2][2];

namespace seg {
	#define lp p << 1
	#define rp p << 1 | 1
	static const int XN = N * 4;
	int tree[XN][2][2];
	void pushup(int p, int mid) {
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++) {
				tree[p][i][j] = 0;
				for (int k = 0; k < 2; k++)
					for (int l = 0; l < 2; l++)
						if (!limit[mid][k][l])
							M(tree[p][i][j] += 1LL * tree[lp][i][k] * tree[rp][l][j] % MOD);
			}
	}
	void build(int p, int l, int r) {
		if (l == r) {
			tree[p][1][1] = pro[l][1];
			tree[p][0][0] = pro[l][0];
			return;
		}
		int mid = l + r >> 1;
		build(lp, l, mid);
		build(rp, mid + 1, r);
		pushup(p, mid);
	}
	void update(int p, int l, int r, int pos) {
		if (l == r) return;
		int mid = l + r >> 1;
		if (pos <= mid) update(lp, l, mid, pos);
		else update(rp, mid + 1, r, pos);
		pushup(p, mid);
	}
	int query() {
		int ans = 0;
		for (int i = 0; i < 2; i++)
			for (int j = 0; j < 2; j++)
				M(ans += tree[1][i][j]);
		return ans;
	}
}

struct Node {
	int x, xp, yp;
	double t;
	int tt;
	Node() {}
	Node(int x, int xp, int yp, double t, int tt): x(x), xp(xp), yp(yp), t(t), tt(tt) {}
	bool operator < (const Node &p) const {
		return sign(t - p.t) < 0;
	}
} P[N];

int main() {
	scanf("%d", &n);
	int cnt = 0;
	int lastx = 0, lastv = 0;
	for (int i = 1; i <= n; i++) {
		int x, v, p;
		scanf("%d%d%d", &x, &v, &p);
		if (i > 1) {
			int dis = x - lastx;
			++cnt;
			P[cnt] = Node(i - 1, 1, 0, dis / 1.0 / (lastv + v), 1LL * dis * qp(lastv + v) % MOD);
			if (v > lastv) {
				++cnt;
				P[cnt] = Node(i - 1, 0, 0, dis / 1.0 / (v - lastv), 1LL * dis * qp(v - lastv) % MOD);
			} else if (lastv > v) {
				++cnt;
				P[cnt] = Node(i - 1, 1, 1, dis / 1.0 / (lastv - v), 1LL * dis * qp(lastv - v) % MOD);
			}
		}
		lastv = v;
		lastx = x;
		pro[i][0] = 1LL * (100 - p) * inv % MOD;
		pro[i][1] = 1LL * p * inv % MOD;
	}
	seg::build(1, 1, n);
	std::sort(P + 1, P + 1 + cnt);
	int ans = 0, lastp = 1;
	for (int i = 1; i <= cnt; i++) {
		Node p = P[i];
		limit[p.x][p.xp][p.yp] = 1;
		seg::update(1, 1, n, p.x);
		int curp = seg::query();
		M(ans += 1LL * p.tt * (lastp - curp + MOD) % MOD);
		lastp = curp;
	}
	printf("%d\n", ans);
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

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

# define F first
# define S second
# define endl '\n'
# define sep ' '
# define pb push_back
# define fast_io ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

const ll md = 998244353;
const int xn = 1e5+10;
const int xm = 1e2+10;
const int SQ = 320;
const int sq = 1e3+10;
const ll inf = 1e18+10;

ll power(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md : power(a * a % md, b / 2) % md));
}

int n;
ll x[xn], v[xn], p[xn][2], inv, timeb[xn][4], dp[xn][2], ans, P[2];
ld tmb[xn][4];
vector <pair <ld, ll> > b[sq][4];

void Build(){
	for (int i = 0; i < n; i += SQ){
		int ind = i/SQ;
		for (int j = 0; j < 4; j += 2){
			sort(b[ind][j].begin(), b[ind][j].end());
			for (int k = 0; k < b[ind][j].size(); k++){
				ld t = b[ind][j][k].F;
				dp[i][0] = dp[i][1] = 0;
				if (j < 2) dp[i][0] = p[i][0];
				else dp[i][1] = p[i][1];
				for (int pnt = i + 1; pnt < i+SQ; pnt++){
					if (i >= n) break;
					dp[pnt][0] = dp[pnt][1] = 0;
					if (tmb[pnt][0] >= t) dp[pnt][0] += dp[pnt - 1][0], dp[pnt][0] %= md;
					if (tmb[pnt][2] >= t) dp[pnt][0] += dp[pnt - 1][1], dp[pnt][0] %= md;
					dp[pnt][0] = (dp[pnt][0] * p[pnt][0] + 100 * md) % md;

					if (tmb[pnt][1] >= t) dp[pnt][1] += dp[pnt - 1][0], dp[pnt][1] %= md;
					if (tmb[pnt][3] >= t) dp[pnt][1] += dp[pnt - 1][1], dp[pnt][1] %= md;
					dp[pnt][1] = (dp[pnt][1] * p[pnt][1] + 100 * md) % md;
				}
				int dx = min(i+SQ-1, n-1);
				b[ind][j][k].S = dp[dx][0];
				b[ind][j + 1][k].S = dp[dx][1];
			}
		}
	}
}
void get(int dx, int f){
	P[0] = P[1] = 1;
	ld t = tmb[dx][f];
	for (int i = 0; i < dx; i += SQ){
		if (i/SQ == dx/SQ) break;
		int l = -1, r = b[i/SQ][0].size(), mid;
		while (r - l > 1){
			mid = (l + r) / 2;
			if (b[i/SQ][0][mid].F <= t) l = mid;
			else r = mid;
		}
		int ind = r;
		//cout << ind << endl;
		if (ind == b[i/SQ][0].size()){
			P[0] = P[1] = 0;
			break;
		}
		ll h1 = 0, h2 = 0;
		if (tmb[i][0] > t) h1 += (b[i/SQ][0][ind].S * P[0] + 100 * md) % md, h1 %= md;
		if (tmb[i][2] > t) h1 += (b[i/SQ][0][ind].S * P[1] + 100 * md) % md, h1 %= md;
		if (tmb[i][1] > t) h1 += (b[i/SQ][2][ind].S * P[0] + 100 * md) % md, h1 %= md;
		if (tmb[i][3] > t) h1 += (b[i/SQ][2][ind].S * P[1] + 100 * md) % md, h1 %= md;

		if (tmb[i][0] > t) h2 += (b[i/SQ][1][ind].S * P[0] + 100 * md) % md, h2 %= md;
		if (tmb[i][2] > t) h2 += (b[i/SQ][1][ind].S * P[1] + 100 * md) % md, h2 %= md;
		if (tmb[i][1] > t) h2 += (b[i/SQ][3][ind].S * P[0] + 100 * md) % md, h2 %= md;
		if (tmb[i][3] > t) h2 += (b[i/SQ][3][ind].S * P[1] + 100 * md) % md, h2 %= md;

		P[0] = h1, P[1] = h2;
	}
	//cout << P[0] << sep << P[1] << endl;

	for (int i = dx-dx%SQ; i < dx; i++){
		if (i == 0){
			P[0] = p[i][0], P[1] = p[i][1];
			continue;
		}
		dp[i][0] = dp[i][1] = 0;
		if (tmb[i][0] > t) dp[i][0] += P[0], dp[i][0] %= md;
		if (tmb[i][2] > t) dp[i][0] += P[1], dp[i][0] %= md;
		dp[i][0] = (dp[i][0] * p[i][0] + 100 * md) % md;

		if (tmb[i][1] > t) dp[i][1] += P[0], dp[i][1] %= md;
		if (tmb[i][3] > t) dp[i][1] += P[1], dp[i][1] %= md;
		dp[i][1] = (dp[i][1] * p[i][1] + 100 * md) % md;

		P[0] = dp[i][0];
		P[1] = dp[i][1];
	}
	if (f < 2) P[1] = 0;
	else P[0] = 0;

	//cout << P[0] << sep << P[1] << endl;

	if (f == 0) P[0] = (P[0] * p[dx][0] + 100 * md) % md;
	else if (f == 1) P[1] = (P[0] * p[dx][1] + 100 * md) % md, P[0] = 0;
	else if (f == 2) P[0] = (P[1] * p[dx][0] + 100 * md) % md, P[1] = 0;
	else P[1] = (P[1] * p[dx][1] + 100 * md) % md;

	for (int i = dx+1; i < dx-dx%SQ+SQ; i++){
		if (i >= n) break;
		dp[i][0] = dp[i][1] = 0;
		if (tmb[i][0] >= t) dp[i][0] += P[0], dp[i][0] %= md;
		if (tmb[i][2] >= t) dp[i][0] += P[1], dp[i][0] %= md;
		dp[i][0] = (dp[i][0] * p[i][0] + 100 * md) % md;

		if (tmb[i][1] >= t) dp[i][1] += P[0], dp[i][1] %= md;
		if (tmb[i][3] >= t) dp[i][1] += P[1], dp[i][1] %= md;
		dp[i][1] = (dp[i][1] * p[i][1] + 100 * md) % md;

		P[0] = dp[i][0];
		P[1] = dp[i][1];
	}

	for (int i = dx-dx%SQ+SQ; i < n; i += SQ){

		int l = -1, r = b[i/SQ][0].size(), mid;
		while (r - l > 1){
			mid = (l + r) / 2;
			if (b[i/SQ][0][mid].F < t) l = mid;
			else r = mid;
		}
		int ind = r;
		if (ind == b[i/SQ][0].size()){
			P[0] = P[1] = 0;
			break;
		}
		ll h1 = 0, h2 = 0;
		if (tmb[i][0] >= t) h1 += (b[i/SQ][0][ind].S * P[0] + 100 * md) % md, h1 %= md;
		if (tmb[i][2] >= t) h1 += (b[i/SQ][0][ind].S * P[1] + 100 * md) % md, h1 %= md;
		if (tmb[i][1] >= t) h1 += (b[i/SQ][2][ind].S * P[0] + 100 * md) % md, h1 %= md;
		if (tmb[i][3] >= t) h1 += (b[i/SQ][2][ind].S * P[1] + 100 * md) % md, h1 %= md;

		if (tmb[i][0] >= t) h2 += (b[i/SQ][1][ind].S * P[0] + 100 * md) % md, h2 %= md;
		if (tmb[i][2] >= t) h2 += (b[i/SQ][1][ind].S * P[1] + 100 * md) % md, h2 %= md;
		if (tmb[i][1] >= t) h2 += (b[i/SQ][3][ind].S * P[0] + 100 * md) % md, h2 %= md;
		if (tmb[i][3] >= t) h2 += (b[i/SQ][3][ind].S * P[1] + 100 * md) % md, h2 %= md;

		P[0] = h1, P[1] = h2;
		//cout << h1 << sep << h2 << endl;
	}
	P[0] += P[1];

	//cout << dx << sep << f << sep << P[0] << endl;

	ans = (ans + (P[0] * timeb[dx][f] + 100 * md) % md + 100 * md) % md;
}

int main(){
	fast_io;

	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i] >> v[i] >> p[i][0], p[i][1] = 100 - p[i][0];

	cout << fixed << setprecision(10);

	inv = power(ll(100), md - 2);

	for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) p[i][j] = (p[i][j] * inv + 100 * md) % md;

	for (int i = 0; i < 4; i++) tmb[0][i] = inf;
	for (int i = 1; i < n; i++){
		tmb[i][2] = inf;
		timeb[i][1] = ((x[i] - x[i - 1]) * power(v[i] + v[i - 1], md - 2) + 100 * md) % md;
		tmb[i][1] = ld(x[i] - x[i - 1]) / ld(v[i] + v[i - 1]);
		if (v[i - 1] > v[i]){
			timeb[i][0] = ((x[i] - x[i - 1]) * power(v[i - 1] - v[i], md - 2) + 100 * md) % md;
			tmb[i][0] = ld(x[i] - x[i - 1]) / ld(v[i - 1] - v[i]);
			tmb[i][3] = inf;
		}
		else if (v[i] > v[i - 1]){
			timeb[i][3] = ((x[i] - x[i - 1]) * power(v[i] - v[i - 1], md - 2) + 100 * md) % md;
			tmb[i][3] = ld(x[i] - x[i - 1]) / (v[i] - v[i - 1]);
			tmb[i][0] = inf;
		}
		else{
			tmb[i][0] = tmb[i][3] = inf;
		}
	}
	for (int i = 1; i < n; i++){
		if (i%SQ == 0) continue;
		for (int j = 0; j < 4; j++){
			if (tmb[i][j] == inf) continue;
			for (int k = 0; k < 4; k++) b[i/SQ][k].pb({tmb[i][j], 0});
		}
	}

	for (int i = SQ; i < n; i += SQ){
		for (int j = 0; j < 4; j++){
			if (tmb[i][j] == inf) continue;
			ll ehtemal = 1;
			dp[0][0] = p[0][0];
			dp[0][1] = p[0][1];
			for (int k = 1; k <= i - 1; k++){
				dp[k][0] = 0;
				if (tmb[k][0] > tmb[i][j]) dp[k][0] += dp[k - 1][0], dp[k][0] %= md;
				if (tmb[k][2] > tmb[i][j]) dp[k][0] += dp[k - 1][1], dp[k][0] %= md;
				dp[k][0] = (dp[k][0] * p[k][0] + 100 * md) % md;

				dp[k][1] = 0;
				if (tmb[k][1] > tmb[i][j]) dp[k][1] += dp[k - 1][0], dp[k][1] %= md;
				if (tmb[k][3] > tmb[i][j]) dp[k][1] += dp[k - 1][1], dp[k][1] %= md;
				dp[k][1] = (dp[k][1] * p[k][1] + 100 * md) % md;
			}
			if (j < 2) dp[i - 1][1] = 0;
			else dp[i - 1][0] = 0;

			dp[i][0] = dp[i][1] = 0;
			if (j == 0) dp[i][0] = dp[i - 1][0];
			else if (j == 2) dp[i][0] = dp[i - 1][1];
			else if (j == 1) dp[i][1] = dp[i - 1][0];
			else dp[i][1] = dp[i - 1][1];

			if (j%2 == 0) dp[i][0] = (dp[i][0] * p[i][0] + 100 * md) + md;
			else dp[i][1] = (dp[i][1] * p[i][1] + 100 * md) % md;

			for (int k = i + 1; k < n; k++){
				dp[k][0] = 0;
				if (tmb[k][0] >= tmb[i][j]) dp[k][0] += dp[k - 1][0], dp[k][0] %= md;
				if (tmb[k][2] >= tmb[i][j]) dp[k][0] += dp[k - 1][1], dp[k][0] %= md;
				dp[k][0] = (dp[k][0] * p[k][0] + 100 * md) % md;

				dp[k][1] = 0;
				if (tmb[k][1] >= tmb[i][j]) dp[k][1] += dp[k - 1][0], dp[k][1] %= md;
				if (tmb[k][3] >= tmb[i][j]) dp[k][1] += dp[k - 1][1], dp[k][1] %= md;
				dp[k][1] = (dp[k][1] * p[k][1] + 100 * md) % md;
			}
			ehtemal = (dp[n - 1][0] + dp[n - 1][1] + 100 * md) % md;
			ans = (ans + (ehtemal * timeb[i][j] + 100 * md) % md + 100 * md) % md;
		}
	}
	Build();

	for (int i = 1; i < n; i++){
		for (int j = 0; j < 4; j++){
			if (tmb[i][j] == inf) continue;
			get(i, j);
		}
	}

	cout << ans << endl;

	return 0;
}