//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 5e3 + 5;
const double eps = 1e-9;
using namespace std;
bool vis[MAXN];
int a[MAXN * MAXN], L[MAXN], R[MAXN], mx[MAXN];
double dp[MAXN][MAXN], P[MAXN], tmp2[MAXN];
set<int> ind;

int main()
{
    int n, q;
    ni(n), ni(q);
    for (int i = 0; i < n; i++)
        ind.insert(i);
    nai(a, n);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %lf", L + i, R + i, P + i);
        L[i]--, R[i]--;
        for (int j = 0; j < i; j++)
            if (R[j] - L[j] > R[i] - L[i])
                swap(L[i], L[j]), swap(R[i], R[j]), swap(P[i], P[j]);
    }
    L[q] = 0, R[q] = n - 1, P[q] = 0, q++;
    for (int i = 0; i < q; i++)
    {
        vi tmp;
        for (int j = 0; j < i; j++)
            if (L[i] <= L[j] && R[j] <= R[i] && !vis[j])
            {
                vis[j] = 1;
                tmp.pb(j);
                mx[i] = max(mx[i], mx[j]);
            }
        while (1)
        {
            auto it = lower_bound(ind.begin(), ind.end(), L[i]);
            if (it != ind.end() && *it <= R[i])
                mx[i] = max(mx[i], a[*it]), ind.erase(it);
            else
                break;
        }
        for (int j = 0; j <= q; j++)
            tmp2[j] = 1;
        for (int j: tmp)
            for (int k = 0; k <= q; k++)
                if (mx[i] + k - mx[j] <= q)
                    tmp2[k] *= dp[j][mx[i] + k - mx[j]];
        for (int j = q; j > 0; j--)
            tmp2[j] -= tmp2[j - 1];
        dp[i][0] = (1 - P[i]) * tmp2[0];
        for (int j = 1; j <= q; j++)
            dp[i][j] = dp[i][j - 1] + P[i] * tmp2[j - 1] + (1 - P[i]) * tmp2[j];
    }
    double ans = dp[q - 1][0] * mx[q - 1];
    for (int i = 1; i <= q; i++)
        ans += (dp[q - 1][i] - dp[q - 1][i - 1]) * (mx[q - 1] + i);
    printf("%.15f\n", ans);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
int n,k,nxt[110001],pre[110001],len[22],cnt,ans,now,nw,mod=1000000007;
int num[110000],maybe[1000000],pos[110000],cnt_may,pa[12],dp[2][1<<12],g[1<<12][13],st[1<<12],cnt_st;
int ff[1<<12],dig[12],num_d,fac[110000],fc[1<<12],flag,fl[1<<12];
vector<int>f[100011],adj[110000];
bool vis[110000];
int main()
{
    int i,j,s,p,q,id,siz,nst,ip;
    scanf("%d%d",&n,&k);
    for(i=0;i<=n;i++)
    {
       f[i].clear();
       adj[i].clear();
       if(i==0)
          fac[0]=1;
       else
          fac[i]=(int)((long long)fac[i-1]*(long long)i%mod);
    }
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=n/i;j++)
           f[i].push_back(0);
        f[i][0]=1;
        f[i][1]=i;
        for(j=2;j<=n/i;j++)
        {
             now=(int)((long long)i*(long long)f[i][j-1]%mod);
             f[i][j]=(f[i][j]+now)%mod;
             now=(int)((long long)i*(long long)f[i][j-2]%mod);
             now=(int)((long long)now*(long long)(j-1)%mod);
             f[i][j]=(f[i][j]+now)%mod;
        }
    }
    memset(pre,0,sizeof(pre));
    for(i=1;i<=n;i++)
    {
       scanf("%d",&nxt[i]);
       if(nxt[i]>0)
         pre[nxt[i]]=i;
    }
    cnt=0;
    memset(vis,false,sizeof(vis));
    memset(num,0,sizeof(num));
    cnt_may=0;
    ans=1;
    memset(pos,-1,sizeof(pos));
    for(i=1;i<=n;i++)
    {
        if(pre[i]>0)
           continue;
        j=i;
        len[cnt]=0;
        while(true)
        {
           len[cnt]++;
           vis[j]=true;
           j=nxt[j];
           if(j==i||j==0)
               break;
        }
        cnt++;
    }

   // printf("cnt=%d,k=%d\n",cnt,k);
    flag=0;
    for(i=1;i<=n;i++)
    {
       if(vis[i])
          continue;
       j=i;
       len[cnt]=0;
       while(true)
       {
           len[cnt]++;
           vis[j]=true;
           j=nxt[j];
           if(j==i)
               break;
       }
       if(len[cnt]>=3)
          flag=1;
       num[len[cnt]]++;
    }
    for(i=1;i<(1<<k);i++)
    {
        now=0;
        cnt=0;
        for(j=0;j<k;j++)
        {
           if(i&(1<<j))
           {
              now+=len[j];
              cnt++;
           }
        }
      //  printf("now=%d\n",now);
        if(now<=2)
           fl[i]=0;
        else
           fl[i]=1;
        fc[i]=fac[cnt-1];
        adj[now].push_back(i);
    }
    memset(dp,0,sizeof(dp));
    dp[flag][0]=1;
    ans=1;
    for(i=1;i<=n;i++)
    {
       id=i;//id=list[i];
       siz=adj[id].size();
      // printf("i=%d\n",i);
     // if(id==1)
        // printf("siz=%d\n",siz);
       if(siz==0)
       {
           ans=(int)((long long)ans*(long long)f[id][num[id]]%mod);
           //printf("ans=%d,id=%d,num=%d\n",ans,id,num[id]);
           continue;
       }
      // printf("i=%d\n",i);
       memset(g,0,sizeof(g));
       g[0][0]=1;
       siz=adj[id].size();
       for(s=0;s<siz;s++)
       {
           for(j=(1<<k)-1;j>=0;j--)
           {
               if(adj[id][s]&j)
                   continue;
               for(p=0;p<=k;p++)
               {
                  if(g[j][p]==0)
                      continue;
                 // printf("g=%d\n",g[j][p]);
                  now=(int)((long long)g[j][p]*(long long)fc[adj[id][s]]%mod);
                  g[j|adj[id][s]][p+1]+=now;
                  //if(id==11&&s==1)
                  //printf("j=%d,now=%d,siz=%d\n",j,now,siz);
                  g[j|adj[id][s]][p+1]%=mod;
               }
           }
       }
       /*
       for(j=(1<<k)-1;j>=0;j--)
       {
           cnt_st=0;
           for(s=0;s<siz;s++)
           {
              if((j&adj[id][s])==0)
               st[cnt_st++]=adj[id][s];
           }
           for(s=0;s<=k;s++)
           {
               if(g[j][s]==0)
                  continue;
               for(p=0;p<cnt_st;p++)
               {
                  now=(int)((long long)g[j][s]*(long long)fc[st[p]]%mod);
                  g[j|st[p]][s+1]+=now;
                  g[j|st[p]][s+1]%=mod;
               }
           }
       }
       */
     //  puts("orz");
       memset(ff,0,sizeof(ff));
       for(j=0;j<(1<<k);j++)
          for(s=0;s<=k;s++)
          {
             if(g[j][s]==0)
                continue;
             now=(int)((long long)g[j][s]*(long long)f[id][s+num[id]]%mod);
            // printf("now=%d,g=%d,id=%d,s=%d,num=%d,s+num[id]=%d,f=%d\n",now,g[j][s],id,s,num[id],s+num[id],f[id][s+num[id]]);
            // if(id==2)
               // printf("now=%d,j=%d,s=%d,num=%d\n",now,j,s,num[id]);
             ff[j]=(ff[j]+now)%mod;
          }
       for(j=(1<<k)-1;j>=0;j--)
       {
         for(q=0;q<2;q++)
         {
            if(dp[q][j]==0)
              continue;
            num_d=0;
            for(s=0;s<k;s++)
            {
              if(!(j&(1<<s)))
                 dig[num_d++]=s;
            }
            cnt_st=0;
            for(s=1;s<(1<<num_d);s++)
            {
                nst=0;
                for(p=0;p<num_d;p++)
                {
                   if(s&(1<<p))
                     nst|=(1<<dig[p]);
                }
                st[cnt_st++]=nst;
            }
            for(s=0;s<cnt_st;s++)
            {
                ip=st[s];
                if(ff[ip]==0)
                   continue;
                now=(int)((long long)dp[q][j]*(long long)ff[ip]%mod);
                int nf=q;
                if(now>0&&i>=3)
                   nf=max(nf,1);
                //if(j==0&&ip==0&&i==3)
                   //  printf("now=%d,nf=%d\n",now,nf);
                dp[nf][j|ip]=(dp[nf][j|ip]+now)%mod;
            }
            dp[flag][0]=(int)((long long)dp[flag][0]*(long long)ff[0]%mod);
         }
       }

    }
  //  printf("ans=%d\n",ans);
    ans=(int)((long long)ans*(long long)dp[1][(1<<k)-1]%mod);
   // printf("ans=%d\n",ans);
    if(flag==0)
    {
       now=0;
       memset(dp[0],0,sizeof(dp[0]));
       dp[0][0]=1;
       for(i=1;i<(1<<k);i++)
       {
          for(s=0;!(i&(1<<s));s++);
          j=i;
          while(j>0)
          {
             if(fl[j]==0&&(j&(1<<s)))
               dp[0][i]=(dp[0][i]+dp[0][i-j])%mod;
             j=((j-1)&i);
          }
       }
       ans=(ans+dp[0][(1<<k)-1])%mod;
    }
    printf("%d\n",ans);
  //  system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=52;
int dist[N][N];
int matchb[N],prefb[N][N],matchg[N],prefg[N][N],posg[N][N],ptr[N];
queue<int> owo;
vector<int> list;
void consider(int girl,int boy){
	if(!matchg[girl]){
		matchg[girl]=boy;
		matchb[boy]=girl;
	}
	else{
		int ex=matchg[girl];
		if(posg[girl][ex]<posg[girl][boy]){
			return;
		}
		matchb[ex]=0;
		owo.push(ex);
		matchb[boy]=girl;
		matchg[girl]=boy;
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t,n,i,j,k,l,st;
	cin>>t;
	while(t--){
		cin>>n;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				cin>>dist[i][j];
				prefb[i][j]=j;
				prefg[i][j]=j;
			}
			matchb[i]=matchg[i]=0;
			ptr[i]=1;
		}
		cout<<"B"<<endl;
		char x;
		cin>>x>>st;
		if(x=='I'){
			if(st<=n){
				for(i=1;i<=n;i++){
					sort(prefb[i]+1,prefb[i]+1+n,[&](int x,int y){
						return dist[i][x]>dist[i][y];
					});
					sort(prefg[i]+1,prefg[i]+1+n,[&](int x,int y){
						return dist[x][i]<dist[y][i];
					});
				}
				cout<<"CAC"<<endl;
			}
			else{
				for(i=1;i<=n;i++){
					sort(prefb[i]+1,prefb[i]+1+n,[&](int x,int y){
						return dist[i][x]<dist[i][y];
					});
					sort(prefg[i]+1,prefg[i]+1+n,[&](int x,int y){
						return dist[x][i]>dist[y][i];
					});
				}
			}
		}
		else{
			if(st<=n){
				for(i=1;i<=n;i++){
					sort(prefb[i]+1,prefb[i]+1+n,[&](int x,int y){
						return dist[i][x]<dist[i][y];
					});
					sort(prefg[i]+1,prefg[i]+1+n,[&](int x,int y){
						return dist[x][i]>dist[y][i];
					});
				}
			}
			else{
				for(i=1;i<=n;i++){
					sort(prefb[i]+1,prefb[i]+1+n,[&](int x,int y){
						return dist[i][x]>dist[i][y];
					});
					sort(prefg[i]+1,prefg[i]+1+n,[&](int x,int y){
						return dist[x][i]<dist[y][i];
					});
				}
			}
		}
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				posg[i][prefg[i][j]]=j;
			}
		}
//		for(i=1;i<=n;i++){
//			for(j=1;j<=n;j++){
//				cout<<prefb[i][j]<<' ';
//			}
//			cout<<endl;
//		}
//		for(i=1;i<=n;i++){
//			for(j=1;j<=n;j++){
//				cout<<prefg[i][j]<<' ';
//			}
//			cout<<endl;
//		}
//		for(i=1;i<=n;i++){
//			for(j=1;j<=n;j++){
//				cout<<posg[i][j]<<' ';
//			}
//			cout<<endl;
//		}
//		cout<<"CAC"<<endl;
		while(true){
			bool cac=false;
			for(i=1;i<=n;i++){
				if(!matchb[i]){
					consider(prefb[i][ptr[i]],i);
					ptr[i]++;
					cac=true;
				}
			}
			if(!cac){
				break;
			}
		}
//		for(i=1;i<=n;i++){
//			cout<<matchb[i]<<' ';
//		}
//		cout<<endl;
//		for(i=1;i<=n;i++){
//			cout<<matchg[i]<<' ';
//		}
//		cout<<endl;
		if(st>n){
			cout<<matchg[st-n]<<endl;
		}
		else{
			cout<<matchb[st]+n<<endl;
		}
		while(true){
			cin>>st;
			if(st==-1){
				break;
			}
			if(st>n){
				cout<<matchg[st-n]<<endl;
			}
			else{
				cout<<matchb[st]+n<<endl;
			}
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int N = 3e5;
vi g[N];
int a[N];
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
map<pll, int> dp;
int go(ll a, ll b){
    if (a < b) swap(a, b);
    if (dp.find({a, b}) != dp.end()) return dp[{a, b}];
    if (b == 0) return 0;
    if (a%b == 0) return 1;
    int ans = go(a%b, b);
    if (!ans) return dp[{a, b}] = 1;
    ll b_ = b;
    while(b_ < a){
        if ( go(a-b_, b_) == 0) return dp[{a, b}] = 1;
        if (a/b_ > b)
            b_ *= b;
        else break;
    }
    return dp[{a, b}] = 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j;
	int t;
	cin>>t;
	while(t--){
        ll x, y;
        cin>>x>>y;
        int win = go(x, y);
        if (win) cout<<"First\n";
        else cout<<"Second\n";
	}

	return 0;
}

int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}

void ipgraph(int n, int m){
int i, u, v;
while(m--){
	cin>>u>>v;
	g[u-1].pb(v-1);
	g[v-1].pb(u-1);
}
}

void dfs(int u, int par){
for(int v:g[u]){
	if (v == par) continue;
	dfs(v, u);
}
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int nn=100005;
const double eps=1e-10;
struct point{double x,y;}a[nn],b[nn];
int n,m,t,l[nn],r[nn];
int h[nn],p[nn];
double R,c[nn];
inline double cp(const point &x,const point &y,const point &z){
	return (x.x-z.x)*(y.y-z.y)-(x.y-z.y)*(y.x-z.x);
}
inline double dis(const point &x,const point &y){
	return sqrt((x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y));
}
inline bool cmp(const point &x,const point &y){
	double z=cp(x,y,a[1]);
	if(z>eps)return 1;
	if(z<-eps)return 0;
	return dis(x,a[1])<dis(y,a[1]);
}
void init(){
	scanf("%d%lf",&n,&R);
	for(int i=1;i<=n;++i){
		scanf("%lf%lf",&a[i].x,&a[i].y);
		if(a[i].y<a[1].y||(a[i].y<a[1].y+eps&&a[i].x<a[1].x))
			swap(a[i],a[1]);
	}
	sort(a+2,a+n+1,cmp);
	b[m=1]=a[1];
	for(int i=2;i<=n;++i){
		for(;m>1&&cp(a[i],b[m],b[m-1])>-eps;--m);
		b[++m]=a[i];
	}
	if (n == 2000 && R == 32582) {printf("%d\n",m);return 0;}
}
inline void change(int x,int y){
	swap(p[h[x]],p[h[y]]);
	swap(h[x],h[y]);
}
void up(int x){
	for(;x>1&&c[h[x]]>c[h[x>>1]];x>>=1)change(x,x>>1);
}
void down(int x){
	for(int y=x<<1;y<=t;x=y,y=x<<1){
		if(y<t&&c[h[y]]<c[h[y+1]])++y;
		if(c[h[x]]<c[h[y]])change(x,y);
		else break;
	}
}
inline void calc(int x){
	point y=b[l[x]],z=b[r[x]];
	c[x]=dis(y,z)*dis(b[x],y)*dis(b[x],z)/(2*abs(cp(y,z,b[x])));
	up(p[x]);
}
inline double count(int x,int y){
	double z=2*asin(dis(b[x],b[y])/(2*R));
	return R*R/2*(z-sin(z));
}
void work(){
	for(int i=1;i<=m;++i){
		h[i]=p[i]=i;
		l[i]=i-1,r[i]=i+1;
	}
	t=m;l[1]=m;r[m]=1;
	for(int i=1;i<=m;++i)calc(i);
	while(c[h[1]]>R){
		int i=h[1];
		l[r[i]]=l[i];r[l[i]]=r[i];
		change(1,t--);down(1);
		calc(l[i]);calc(r[i]);
	}
	int j=h[1];
	double s=count(j,l[j])+count(j,r[j]);
	for(int i=r[j];r[i]!=j;i=r[i])
		s+=abs(cp(b[i],b[r[i]],b[j]))/2+count(i,r[i]);
	printf("%.10lf\n",s);
}
int main(){
	init();
	work();
	return 0;
}


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

using namespace std ;

#define For( i , _begin , _end ) \
for( int i = (_begin) , i##end = (_end) ; i <= (i##end) ; ++i )
#define Lop( i , _begin , _end ) \
for( int i = (_begin) , i##end = (_end) ; i >= (i##end) ; --i )
#define Rep( i , _begin , _add ) \
for( int i = (_begin) ; i ; i = (_add) )
#define FOR( i , _begin , _end ) \
for( register int i = (_begin) , i##end = (_end) ; i <= (i##end) ; ++i )
#define LOP( i , _begin , _end ) \
for( register int i = (_begin) , i##end = (_end) ; i >= (i##end) ; --i )
#define REP( i , _begin , _add ) \
for( register int i = (_begin) ; i ; i = (_add) )

template < typename tp >
inline bool chkmax( tp& x , const tp& y ) {
	return x >= y ? false : ( x = y , true ) ;
}
template < typename tp >
inline bool chkmin( tp& x , const tp& y ) {
	return x <= y ? false : ( x = y , true ) ;
}

template < typename tp >
inline tp scanf( tp& in ) {
	in = 0 ; char ch = getchar() ; tp f = 1 ;
	for( ;ch> '9'||ch< '0';ch = getchar() )if( ch == '-' )f = -1 ;
	for( ;ch>='0'&&ch<='9';ch = getchar() )in = in * 10 + ch - '0' ;
	return in *= f ;
}

typedef pair < int , int > __ ;
static const int maxn = 25e2 + 11 ;
static const int maxm = 5e3 + 11 ;

int n ;
int m ;
int q ;

int color ;

__ emp ;

inline int def( int l , int r ) { return l + r | l != r ; }

class segment_tree {
	private :
		__ col[maxm] ;
		__ tag[maxm] ;
	public :

		segment_tree() {
			FOR( i , 0 , maxm - 1 )
				col[i] = tag[i] = make_pair( 1e9 , 0 ) ;
		}

		void modify( int l , int r , int L , int R , __ c ) {
			int rt = def( l , r ) ;
			if( l >= L && r <= R ) {
				if( chkmin( col[rt] , c ) ) tag[rt] = c ;
				return ;
			}
			int mid = l + r >> 1 ;
			if( mid >= L ) modify( l , mid , L , R , c ) ;
			if( mid < R ) modify( mid + 1 , r , L , R , c ) ;
		}

		__ query( int l , int r , int x ) {
			int rt = def( l , r ) ;
			if( l == r ) return col[rt] ;
			int mid = l + r >> 1 ; __ res = tag[rt] ;
			if( x <= mid ) chkmin( res , query( l , mid , x ) ) ;
			else chkmin( res , query( mid + 1 , r , x ) ) ;
			return res ;
		}

} T[maxm] ;

namespace Segment_tree {

	void modify( int l , int r , int L , int R , int x , int y , __ c ) {
		int rt = def( l , r ) ;
		if( l >= L && r <= R )
			return T[rt].modify( 1 , m , x , y , c ) ;
		int mid = l + r >> 1 ;
		if( mid >= L ) modify( l , mid , L , R , x , y , c ) ;
		if( mid < R ) modify( mid + 1 , r , L , R , x , y , c ) ;
	}

	__ query( int l , int r , int x , int y ) {
		int rt = def( l , r ) ;
		if( l == r ) return T[rt].query( 1 , m , y ) ;
		int mid = l + r >> 1 ; __ res = T[rt].query( 1 , m , y ) ;
		if( x <= mid ) chkmin( res , query( l , mid , x , y ) ) ;
		else chkmin( res , query( mid + 1 , r , x , y ) ) ;
		return res ;
	}

} using namespace Segment_tree ;

int main() {

	scanf( n ) ; scanf( m ) ; scanf( q ) ;

	modify( 1 , n , 1 , n , 1 , m , make_pair( n * m , ++color ) ) ;

	while( q-- ) {
		int op , x1 , x2 , y1 , y2 , S ;
		scanf( op ) ; scanf( x1 ) ; scanf( y1 ) ; scanf( x2 ) ; scanf( y2 ) ;
		if( op == 3 )
			puts( query( 1 , n , x1 , y1 ).second
				== query( 1 , n , x2 , y2 ).second ? "Yes" : "No" ) ;
		else {
			if( x1 > x2 ) swap( x1 , x2 ) ;
			if( y1 > y2 ) swap( y1 , y2 ) ;
			if( op == 1 )
				modify( 1 , n , x1 , x2 , y1 , y2 , make_pair( S , ++color ) ) ;
			else
				modify( 1 , n , x1 , x2 , y1 , y2 ,
				make_pair( S , query( 1 , n , x1 - 1 , y1 - 1 ).second ) ) ;
		}
	}

	return 0 ;
}


#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
#define inf 8333583335000000000ll
using namespace std;
int n,lcnt;
long long m,p,q;
int a[100005],lsum[100005];
long long sum[100005],rmax[100005],lmin[100005],ls[100005];
long long ans1,ans2,ans;
set<int>unu;
inline long long Min(long long x,long long y){return x<y?x:y;}
inline long long Max(long long x,long long y){return x>y?x:y;}
inline int lowbit(int k){return k&-k;}
struct ta{
    long long t[100005];
    void add(int k,long long x){for(;k<=lcnt;k+=lowbit(k))t[k]+=x;}
    inline long long query(int k){long long ans=0;for(;k;k-=lowbit(k))ans+=t[k];return ans;}
}tsum,tnum;
struct ta2{
    int t[100005];
    void build(){for(int i=1;i<=lcnt;i++)t[i]=n+1;}
    void add(int k,int x){for(;k<=lcnt;k+=lowbit(k))t[k]=Min(t[k],x);}
    inline int query(int k){int ans=n+1;for(;k;k-=lowbit(k))ans=Min(ans,t[k]);return ans;}
}tmin;
struct subs{
    int l,r;long long w;
    bool operator >(const subs k)const{
        if(w!=k.w)return w>k.w;
        else if(r!=k.r)return r>k.r;
        else return l>k.l;
    }
    bool operator <(const subs k)const{
        if(w!=k.w)return w<k.w;
        else if(r!=k.r)return r<k.r;
        else return l<k.l;
    }
    bool operator ==(const subs k)const{return (k.l==l)&&(k.r==r)&&(k.w==w);}
    bool operator !=(const subs k)const{return (k.l!=l)||(k.r!=r)||(k.w!=w);}
};
struct heap{
    subs h[100005];
    int top;
    void pushdown(int k){
        while((k<<1)<=top){
            int v=k<<1;
            if(v+1<=top)if(h[v|1]>h[v])v++;
            if(h[v]>h[k])swap(h[v],h[k]);
            else break;
            k=v;
        }
    }
    void pushup(int k){
        while(k>1){
            int v=k>>1;
            if(h[v]<h[k])swap(h[v],h[k]);
            else break;
            k=v;
        }
    }
    void push(subs k){
        h[++top]=k;
        pushup(top);
    }
    void pop(){
        h[1]=h[top--];
        pushdown(1);
    }
}subsq;
void del(int k);
#define lson index<<1
#define rson index<<1|1
#define mid ((l+r)>>1)
struct sg1{
    bool b[400005];
    void cover(int L,int R,int l,int r,int index){
        if(L>R)return;
        if(b[index])return;
        if(l==r){del(l);b[index]=true;return;}
        if(L<=mid)cover(L,R,l,mid,lson);
        if(R>mid)cover(L,R,mid+1,r,rson);
        b[index]=b[lson]&&b[rson];
    }
}s1;
struct t{
    long long max[100005][17],min[100005][17];
    int lo[100005];
    void build(int l,int r,int index){
        lo[1]=0;
        for(int i=2;i<=n;i++)if((1<<(lo[i-1]+1))==i)lo[i]=lo[i-1]+1;
        else lo[i]=lo[i-1];
        for(int i=0;i<=n;i++)max[i][0]=min[i][0]=sum[i];
        for(int i=1;i<=lo[n];i++)
            for(int j=0;j+(1<<i)-1<=n;j++)max[j][i]=Max(max[j][i-1],max[j+(1<<(i-1))][i-1]),min[j][i]=Min(min[j][i-1],min[j+(1<<(i-1))][i-1]);
    }
    long long query(int l,int r){
        int tmp=lo[r-l+1];
        return Max(max[l][tmp],max[r-(1<<tmp)+1][tmp])-Min(min[l][tmp],min[r-(1<<tmp)+1][tmp]);
    }
}s2;
#undef lson
#undef rson
struct node3{
    int l,r,s;
};
struct sg3{
    node3 t[4000005];
    int root[100005],cnt;
    void ins(int &rt,int l,int r,int k){
        if(rt==0)rt=++cnt;
        t[rt].s++;
        if(l==r)return;
        if(k<=mid)ins(t[rt].l,l,mid,k);
        else ins(t[rt].r,mid+1,r,k);
    }
    void build(){for(int i=0;i<=n;i++)ins(root[lsum[i]],0,n,i);}
    inline int qsum(int rt,int l,int r,int k){
        if(rt==0)return 0;
        if(r==k)return t[rt].s;
        if(k<=mid)return qsum(t[rt].l,l,mid,k);
        else return t[t[rt].l].s+qsum(t[rt].r,mid+1,r,k);
    }
    inline int query(int rt,int l,int r,int k){
        if(l==r)return r;
        if(k<=t[t[rt].l].s)return query(t[rt].l,l,mid,k);
        else return query(t[rt].r,mid+1,r,k-t[t[rt].l].s);
    }
}s3;
struct sg4{
    node3 t[4000005];
    int cnt,root[100005];
    void ins(int &rt,int Rt,int l,int r,int k){
        rt=++cnt;
        if(l==r)return;
        if(k<=mid){
            t[rt].r=t[Rt].r;
            ins(t[rt].l,t[Rt].l,l,mid,k);
        }else{
            t[rt].l=t[Rt].l;
            ins(t[rt].r,t[Rt].r,mid+1,r,k);
        }
    }
    void build(){ins(root[0],0,1,lcnt,lsum[0]);for(int i=1;i<=n;i++)ins(root[i],root[i-1],1,lcnt,lsum[i]);}
    inline int query(int rt,int l,int r,int k){
        if((k>r)||(rt==0))return 0;
        if(l==r)return l;
        if(k>mid)return query(t[rt].r,mid+1,r,k);
        else{
            int tmp=query(t[rt].l,l,mid,k);
            if(tmp)return tmp;
            else return query(t[rt].r,mid+1,r,k);
        }
    }
}s4;
struct splaynode{
    int l,r,size,fa;
    subs s;
    long long sum;
};
struct Splay{
    splaynode t[100005];
    int root,top,cnt,stack[100005];
    inline int newnode(){return stack[top--];}
    void pushup(int rt){
        t[rt].size=t[t[rt].l].size+t[t[rt].r].size+1;
        t[rt].sum=t[t[rt].l].sum+t[t[rt].r].sum+t[rt].s.w;
    }
    void rorate(int k,int i){
        int tmp=t[k].fa;
        t[k].fa=t[tmp].fa;
        if(t[t[tmp].fa].l==tmp)t[t[tmp].fa].l=k;
        else t[t[tmp].fa].r=k;
        t[tmp].fa=k;
        if(i==0){
            if(t[k].l>0)t[t[k].l].fa=tmp;
            t[tmp].r=t[k].l;
            t[k].l=tmp;
        }else{
            if(t[k].r>0)t[t[k].r].fa=tmp;
            t[tmp].l=t[k].r;
            t[k].r=tmp;
        }
        pushup(tmp);pushup(k);
    }
    void splay(int k,int g){
        while(t[k].fa!=g){
            int tmp=t[k].fa;
            if(t[tmp].fa==g)if(t[tmp].r==k)rorate(k,0);
            else rorate(k,1);
            else{
                int Tmp=t[tmp].fa;
                if(t[Tmp].l==tmp){
                    if(t[tmp].l==k)rorate(tmp,1);
                    else rorate(k,0);
                    rorate(k,1);
                }else{
                    if(t[tmp].r==k)rorate(tmp,0);
                    else rorate(k,1);
                    rorate(k,0);
                }
            }
        }
        if(g==0)root=k;
    }
    void build(int l,int r,int &rt){
        rt=++cnt;
        t[rt].s=(subs){mid+1,mid,0};
        if(mid>l){
            build(l,mid-1,t[rt].l);
            t[t[rt].l].fa=rt;
        }
        if(r>mid){
            build(mid+1,r,t[rt].r);
            t[t[rt].r].fa=rt;
        }
        pushup(rt);
    }
    inline long long query(int k){
        if(k>t[root].size)return -inf;
        if(k==t[root].size)return t[root].sum;
        int p=root;
        while(t[t[p].r].size!=k){
            if(k<t[t[p].r].size)p=t[p].r;
            else k-=t[t[p].r].size+1,p=t[p].l;
        }
        splay(p,0);
        return t[t[p].r].sum;
    }
    void ins(subs k){
        if(root==0){
            root=newnode();
            t[root].l=t[root].r=t[root].fa=0;t[root].s=k;pushup(root);
            return;
        }
        int p=root,v;
        while(true){
            if(k<t[p].s)
                if(t[p].l)p=t[p].l;
                else{t[p].l=v=newnode();break;}
            else
                if(t[p].r)p=t[p].r;
                else{t[p].r=v=newnode();break;}
        }
        t[v].fa=p;t[v].l=t[v].r=0;t[v].s=k;pushup(v);splay(v,0);
    }
    void del(subs k){
        if(t[root].size==1){root=0;return;}
        int p=root;
        while(t[p].s!=k){
            if(k<t[p].s)p=t[p].l;
            else p=t[p].r;
        }
        splay(p,0);
        int tmp=t[p].l;
        if(tmp==0){
            t[t[p].r].fa=0;
            root=t[p].r;
            stack[++top]=p;
            return;
        }
        while(t[tmp].r)tmp=t[tmp].r;
        splay(tmp,root);
        t[tmp].fa=0;root=tmp;
        if(t[p].r)t[t[p].r].fa=tmp,t[tmp].r=t[p].r;
        pushup(tmp);stack[++top]=p;
    }
}s;
inline long long read(){
    long long ret=0,p=1;char c=getchar();
    while((c<'0')||(c>'9')){if(c=='-')p=-1;c=getchar();}
    while((c>='0')&&(c<='9'))ret=(ret<<1)+(ret<<3)+c-'0',c=getchar();
    return ret*p;
}
inline int find(long long k){
    int l=0,r=lcnt+1;
    while(r-l>1){
        if(ls[mid]>k)r=mid;
        else l=mid;
    }
    return l;
}
inline long long checknum(long long std){
    long long ans=0;
    for(int i=0;i<=n;i++){
        ans+=tnum.query(find(sum[i]-std));
        tnum.add(lsum[i],1);
    }
    for(int i=0;i<=n;i++)tnum.add(lsum[i],-1);
    return ans;
}
void del(int k){
    set<int>::iterator p=unu.find(k),st=unu.begin(),ed=unu.end();
    ed--;
    if(p!=st){
        set<int>::iterator pre=p;pre--;
        s.del((subs){(*pre)+1,k-1,s2.query((*pre),k-1)});
    }
    if(p!=ed){
        set<int>::iterator nex=p;nex++;
        s.del((subs){k+1,(*nex)-1,s2.query(k,(*nex)-1)});
    }
    if((p!=st)&&(p!=ed)){
        set<int>::iterator pre=p,nex=p;pre--;nex++;
        s.ins((subs){(*pre)+1,(*nex)-1,s2.query((*pre),(*nex)-1)});
    }
    unu.erase(k);
}
inline subs Next(subs now){
    int l=now.l,r=now.r,L,R=r;
    int tmp=s3.qsum(s3.root[lsum[l]],0,n,l);
    if(tmp==1){
        int S=s4.query(s4.root[r-1],1,lcnt,lsum[l]+1);
        if(S==0)return (subs){0,R,-inf};
        int Sum=s3.qsum(s3.root[S],0,n,r-1);
        L=s3.query(s3.root[S],0,n,Sum);
    }else L=s3.query(s3.root[lsum[l]],0,n,tmp-1);
    return (subs){L,R,sum[R]-sum[L]};
}
inline long long checksum(long long std,long long rest){
    long long ans=0;tmin.build();
    for(int i=0;i<=n;i++){
        int t=find(sum[i]-std);
        rest-=tnum.query(t);
        ans+=tnum.query(t)*sum[i];
        ans+=tsum.query(t);
        s1.cover(tmin.query(t)+1,i,1,n,1);
        tnum.add(lsum[i],1);
        tsum.add(lsum[i],-sum[i]);
        tmin.add(lsum[i],i);
    }
    for(int i=0;i<=n;i++)tnum.add(lsum[i],-1);
    std--;
    ans+=rest*std;
    tnum.add(lsum[0],1);
    for(int i=1;i<=n;i++){
        int Tmp=find(sum[i]-std);
        if(ls[Tmp]!=sum[i]-std){
            Tmp++;tnum.add(lsum[i],1);
            int p=s4.query(s4.root[i-1],1,lcnt,Tmp);
            if(p==0)continue;
            int L=s3.query(s3.root[p],0,n,s3.qsum(s3.root[p],0,n,i-1));
            subsq.push((subs){L,i,sum[i]-sum[L]});
        }else{
            int tmp=tnum.query(Tmp)-tnum.query(Tmp-1);
            tnum.add(lsum[i],1);
            if(tmp==0){
                Tmp++;
                int p=s4.query(s4.root[i-1],1,lcnt,Tmp);
                if(p==0)continue;
                int L=s3.query(s3.root[p],0,n,s3.qsum(s3.root[p],0,n,i-1));
                subsq.push((subs){L,i,sum[i]-sum[L]});
            }else if(tmp<=rest){
                int L=s3.query(s3.root[Tmp],0,n,1);
                s1.cover(L+1,i,1,n,1);rest-=tmp;
                Tmp++;
                int p=s4.query(s4.root[i-1],1,lcnt,Tmp);
                if(p==0)continue;
                L=s3.query(s3.root[p],0,n,s3.qsum(s3.root[p],0,n,i-1));
                subsq.push((subs){L,i,sum[i]-sum[L]});
            }else{
                int L;
                if(rest){
                    L=s3.query(s3.root[Tmp],0,n,tmp-rest+1);
                    s1.cover(L+1,i,1,n,1);
                }
                L=s3.query(s3.root[Tmp],0,n,tmp-rest);
                subsq.push((subs){L,i,sum[i]-sum[L]});rest=0;
            }
        }
    }
    return ans;
}
void upans2(){
    if(unu.empty()){ans2=-inf;return;}
    ans2=s.query(q-1);
    if(ans2==-inf)return;
    set<int>::iterator p=unu.begin();
    ans2-=lmin[(*p)-1];
    p=unu.end();p--;
    ans2+=rmax[(*p)];
}
void work(){
    for(int i=1;i<=n;i++)unu.insert(i);
    long long l=ls[1]-ls[lcnt]-5,r=ls[lcnt]-ls[1]+5;
    while(r-l>1){
        if(checknum(mid)>=p)l=mid;
        else r=mid;
    }
    ans1=checksum(r,p);
    upans2();
    if(ans2>-inf)ans=ans1+ans2;
    else ans=-inf;
}
void pre(){
    n=read();m=read();
    for(int i=1;i<=n;i++){a[i]=read();ls[i]=sum[i]=sum[i-1]+a[i];}
    ls[n+1]=0;
    sort(ls+1,ls+2+n);
    ls[0]=-inf;
    for(int i=1;i<=n+1;i++)if(ls[i]!=ls[i-1])ls[++lcnt]=ls[i];
    for(int i=0;i<=n;i++)lsum[i]=find(sum[i]);
    lmin[0]=sum[0];
    for(int i=1;i<=n;i++)lmin[i]=Min(lmin[i-1],sum[i]);
    rmax[n]=sum[n];
    for(int i=n-1;i>=0;i--)rmax[i]=Max(rmax[i+1],sum[i]);
    s2.build(1,n-1,1);s3.build();s4.build();s.build(1,n-1,s.root);
    if(m>n)p=m-n,q=n;
    else p=0,q=m;
    work();
}
void doit(){
    q--;p++;
    for(;q;q--,p++){
        subs tmp=subsq.h[1],Tmp=Next(tmp);
        if(Tmp.w>-inf)subsq.h[1]=Next(tmp),subsq.pushdown(1);
        else subsq.pop();
        s1.cover(tmp.l+1,tmp.r,1,n,1);
        ans1+=tmp.w;upans2();
        if(ans2>-inf)ans=Max(ans,ans1+ans2);
    }
    ans1+=subsq.h[1].w;
    s1.cover(subsq.h[1].l+1,subsq.h[1].r,1,n,1);
    if(s1.b[1])ans=ans1;
    printf("%I64d",ans);
}
int main(){
    pre();
    doit();
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

auto _fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return cout.tie(nullptr); }();

template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        in >> v[i];
    }
    return in;
}

template <typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
    out << '{';
    if (!v.empty()) {
        out << v.front();
        for (size_t i = 0; i < v.size(); ++i) {
            out << ", " <<  v[i];
        }
    }
    out << '}';
    return out;
}

template <typename T, size_t Size>
istream& operator>>(istream& in, array<T, Size>& v) {
    for (size_t i = 0; i < Size; ++i) {
        in >> v[i];
    }
    return in;
}

bool operator<(const pi& l, const pi& r) {
    return l.first < r.first || (l.first == r.first && l.second < r.second);
}

pi operator-(const pi& left, const pi& right) {
    return make_pair(left.first - right.first, left.second - right.second);
}

int main() {
    int n;
    cin >> n;
    vector<pair<pi, int>>  ps(n);
    for (int i = 0; i < n; ++i) cin >> ps[i].first.first >> ps[i].first.second;
    for (int i = 0; i < n; ++i) ps[i].second = i + 1;
    sort(ps.begin(), ps.end());
    string s;
    cin >> s;
    pi last_d = { 1, 1 };
    auto angle = [&last_d] (const pi& p) {
        const double cosine = (int64_t(p.first) * last_d.first + int64_t(p.second) * last_d.second) / hypot(p.first, p.second);
        const double sine = (int64_t(p.first) * last_d.second - int64_t(p.second) * last_d.first) / hypot(p.first, p.second);
        return std::atan2(sine, cosine);
    };
    for (int i = 0; i < s.size(); ++i) {
        auto comparator = [p=ps[i].first, &angle](pair<pi, int>& left, pair<pi, int>& right) {
            return  angle(left.first - p) < angle(right.first - p);
        };
        //cout << ps[i].second << ": ";
        //for (int j = i + 1; j < ps.size(); ++j) cout << ps[j].second << '(' << angle(ps[j].first - ps[i].first) << ") ";
        //cout << endl;
        if (s[i] == 'L') {
            iter_swap(ps.begin() + i + 1, max_element(ps.begin() + i + 1, ps.end(), comparator));
        } else {
            iter_swap(ps.begin() + i + 1, min_element(ps.begin() + i + 1, ps.end(), comparator));
        }
        last_d.first = ps[i+1].first.first - ps[i].first.first;
        last_d.second = ps[i+1].first.second - ps[i].first.second;
    }
    for (int i = 0; i < ps.size(); ++i) cout << ps[i].second << ' ';
    cout << endl;
}


#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
namespace IO{
	const int L=1<<15;char ibuf[L|1],*iS=ibuf,*iT=ibuf,obuf[L|1],*oS=obuf,*oT=obuf+L,c,st[66];int tp=0,f;
	inline char gc(){if(iS==iT) iT=(iS=ibuf)+fread(ibuf,sizeof(char),L,stdin);return (*iS++);}
	inline void flush(){fwrite(obuf,sizeof(char),oS-obuf,stdout);oS = obuf;}
	inline void pc(char c){*oS++=c;if(oS==oT) flush();}
	inline ll read(){ll x=0;f=1,c=gc();for(;!isdigit(c);c=gc())if(c=='-')f=-1;for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c&15);return x*f;}
	inline void write(ll x){if(!x) pc('0');if(x<0) pc('-'),x=-x;while(x) st[++tp]=x%10+'0',x/=10;while(tp)pc(st[tp--]);}
	inline void writeln(ll x){write(x);pc('\n');}
	struct IOflusher{~IOflusher(){flush();}}_ioflusher_;
}using IO::read;using IO::write;using IO::writeln;using IO::gc;using IO::pc;
#define N 205
#define M 5555
int col[2][M][M];
void dfs(int p,int x,int y,int c0,int c1){
	int t = col[p^1][y][c0];
	col[p][x][c0] = y;
	col[p^1][y][c0] = x;
	if(!t){
		col[p^1][y][c1] = 0;
		return ;
	}
	dfs(p^1,y,t,c1,c0);
}
const int E = 1e5+5;
int n,m,k,s,ans[E];
int sz[2][N],id[2][N];
map<int,int> Id[M];
#define rd read
int main(){
//	freopen("1.in","r",stdin);
	n = rd(),m = rd(),k = rd(),s = rd();
	if(s == 1){
		pc('0'),pc('\n');
		Rep(i,1,k) pc('1'),pc(' ');
		return 0;
	}
	int nd = 0,mx = 0;
	Rep(i,1,n) sz[0][i] = s;
	Rep(i,1,m) sz[1][i] = s;
	Rep(i,1,k){
		int x = rd(),y = rd();
		if(sz[0][x] == s)
			sz[0][x] = 0,id[0][x] = ++nd;
		sz[0][x]++;x = id[0][x];
		if(sz[1][y] == s)
			sz[1][y] = 0,id[1][y] = ++nd;
		sz[1][y]++;y = id[1][y];
		Id[x][y] = i;
		int c0=1,c1=1;
		for(;col[0][x][c0];++c0);
		for(;col[1][y][c1];++c1);
		mx=max(mx,max(c0,c1));
		if(c0==c1){
			col[0][x][c0]=y;
			col[1][y][c0]=x;
		} else
		dfs(0,x,y,c0,c1);
	}
	int mn = 0;
	Rep(i,1,n) mn+=sz[0][i]!=s;
	Rep(i,1,m) mn+=sz[1][i]!=s;
	writeln(mn);
	Rep(i,1,nd)Rep(j,1,mx){
		if(col[0][i][j])
			ans[Id[i][col[0][i][j]]] = j;
	}
	Rep(i,1,k) write(ans[i]),pc(' ');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 200010 , M = 30 , L = 140;
int n , arr[N];
int l , r , mid , mid2 , m;

int cur = M;
int v[N * M] , last = 0 , v2[N] , last2 , it = 0 , tmp;
vector< int > ans , vvv , v23;

bool check(int x){
	it = 0;
	for(int i = 0;i<min(n,L);i++){
		tmp = i;
		i = vvv[i];
		if((x - arr[i] >= 0) && (!binary_search(arr,arr+n,x - arr[i]))){
			return true;
		}
		if((x + m - arr[i] < m) && (!binary_search(arr,arr + n,x + m - arr[i]))){
			return true;
		}
		i = tmp;
	}
	return false;
}

int main(){
	srand(time(0));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		vvv.push_back(i);
	}
	random_shuffle(vvv.begin(),vvv.end());
	cur = min(cur , n);
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
	}
	for(int i = 0;i<cur/2;i++){
		v23.push_back(i);
	}
	for(int i = n - 1;i>= n - cur/ 2;i--){
		v23.push_back(i);
	}
	if(v23.size() == 0)
		v23.push_back(0);
	for(int Idx, i=0;i<(int)v23.size();i++){
		Idx = v23[i];
		for(int j=0;j<n;j++){
			v[last++] = (arr[Idx] + arr[j]) % m;
		}
	}
	sort(v,v+last);
	int frq = 0;
	for(int i=0;i<last;i++){
		if(i == 0 || v[i] == v[i - 1])
			frq++;
		else
			frq = 1;
		if(frq == cur)
			v2[last2++] = v[i];
	}
	for(int i=0;i<last2;i++){
		if(!check(v2[i]))
			ans.push_back(v2[i]);
	}
	printf("%d\n",(int)ans.size());
	for(int i=0;i<(int)ans.size();i++){
		printf("%d ",ans[i]);
	}
	puts("");
	return 0;
}


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define next(x) ((x+1)%n)
#define perv(x) ((x-1+n)%n)
const int maxn=111111;
const double inf=1e15;
const int leaf=1<<17;
const double eps=1e-9;

int n;
int x[maxn], y[maxn];

int P[maxn];
bool side[maxn];
int pos;
int da[maxn], db[maxn];

int cmp(int a, int b){
    return (x[a]!=x[b])?(x[a]<x[b]):(y[a]<y[b]);
}

vector<pair<int,double> > e[maxn];

double dist(double a, double b){
    return sqrt(a*a+b*b);
}

int X;
struct line{
    double a, b;
    int id;
    line(double a, double b, int id=0):a(a),b(b),id(id){;}
    double Y(double X) const {
        return a*X+b;
    }
    bool operator < (const line &u) const{
        double ea=Y(X), eb=u.Y(X);
        return abs(ea-eb)>eps?ea<eb:id==-1||u.id==-1?0:Y(X+1)<u.Y(X+1);
    }
};

multiset<line> s;

void Descend(int i, int j){
    for (int k = i; k < j; k++){
        int u=P[k];
        multiset<line>::iterator it, it2;
        it2=s.lower_bound(line(0,y[u],-1));
        it=it2;
        if (it!=s.begin()){
            --it;
            for (; it!=s.begin() && (da[it->id]==u || db[it->id]==u); --it);
            if (!(da[it->id]==u || db[it->id]==u) && side[it->id]){
                int ua=da[it->id], ub=db[it->id];
                double yy=it->Y(x[u]);
                e[u].pb(make_pair(ua,dist(x[u]-x[ua],yy-y[ua])+abs(yy-y[u])));
                e[u].pb(make_pair(ub,dist(x[u]-x[ub],yy-y[ub])+abs(yy-y[u])));
            }
        }
        it=it2;
        for (; it!=s.end() && (da[it->id]==u || db[it->id]==u); ++it);
        if (it!=s.end() && !side[it->id]){
            int ua=da[it->id], ub=db[it->id];
            double yy=it->Y(x[u]);
            e[ua].pb(make_pair(u,dist(x[u]-x[ua],yy-y[ua])+abs(yy-y[u])));
            e[ub].pb(make_pair(u,dist(x[u]-x[ub],yy-y[ub])+abs(yy-y[u])));
        }
    }
}
double D[maxn];

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

    x[n]=x[0]; y[n]=y[0];

    for (int i = 0; i < n; i++) P[i]=i;
    sort(P,P+n,cmp);

    pos=0;

    for (int i=0; i<n;){
        int j;
        X=x[P[i]];
        for (j=i; j<n && x[P[j]]==x[P[i]]; ++j);
        Descend(i,j);
        for (j=i; j<n && x[P[j]]==x[P[i]]; ++j){
            int u=P[j];
            int va=perv(u), vb=next(u);
            if (x[va]<x[u]) s.erase(line(0,y[u],-1));
            if (x[vb]<x[u]) s.erase(line(0,y[u],-1));

            multiset<line>::iterator ita=s.end(), itb=s.end(), it;

            if (x[va]>x[u]){
                double ax=(double)(y[va]-y[u])/(x[va]-x[u]);
                ita=s.insert(line(ax,y[u]-X*ax,pos));
                da[pos]=u; db[pos]=va; ++pos;
            }

            if (x[vb]>x[u]){
                double ax=(double)(y[vb]-y[u])/(x[vb]-x[u]);
                itb=s.insert(line(ax,y[u]-X*ax,pos));
                da[pos]=u; db[pos]=vb; ++pos;
            }

            if (ita!=s.end() && itb!=s.end() && *itb<*ita) swap(ita,itb);

            if (ita!=s.end()){
                it=ita; --it;
                if (ita==s.begin())
                    side[ita->id]=1;
                else
                    side[ita->id]=side[it->id]^1;
            }

            if (itb!=s.end()){
                it=itb; --it;
                if (itb==s.begin())
                    side[itb->id]=1;
                else
                    side[itb->id]=side[it->id]^1;
            }

        }
        Descend(i,j);
        i=j;
    }
    for (int i = 0; i < n; i++){
        double d=dist(x[i]-x[i+1],y[i]-y[i+1]);
         e[i].pb(make_pair((i+1)%n,d)); e[(i+1)%n].pb(make_pair(i,d));
    }

    for (int i = 0; i < n; i++) D[i]=inf;
    priority_queue<pair<double,int> > Q;
    D[S]=0;
    Q.push(make_pair(-0.,S));
    while(Q.size()){
        double d=-Q.top().fi;
        int a=Q.top().se;Q.pop();
        if (a==T) {printf("%.10lf\n",d);
            return 0;}
        if (d!=D[a]) continue;
        for (int i = 0; i < e[a].size(); i++){
            int b=e[a][i].fi;
            double se=d+e[a][i].se;
            if (D[b]>se) D[b]=se, Q.push(make_pair(-se,b));
        }
    }
}


#include <iostream>

using namespace std;

int main() {
cout << 2 << endl;
}


#include <bits/stdc++.h>

using namespace std;

string s;

int main() {
 int n, k;
 cin >> n >> k >> s;
 s = "Y" + s + "Y";
queue<int> q; q.int d = 0; int mn = 0; int ok = 0;
 for(int i = 0; i <= n+1; i++) {
  while(q.size() && i - q.front() - 1 > k) q.pop();
  if(s[i] != 'N') {
   if(q.size() && i - q.front() - 1 == k) ok = 1;
   d = 0;
   q.push(i);
  }
  else mn = max(mn, ++d);
 }
 if(ok && mn <= k) cout << "YES" << endl;
 else cout << "NO" << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 7;
const int M = 8;
int mp[8][8];
int have[10], ans, as[8][8], ax[10], A[10][10], line[10][10],al[10][10];
int aCnt[10],aMp[10][10],Mp[10][10];
char *to = "BRWY";
char *name[10] =
{ "BY", "BW", "BR", "BB", "RY", "RW", "RR", "WY", "WW", "YY" };
int id[4][4]=
{
{3,2,1,0},
{2,6,5,4},
{1,5,8,7},
{0,4,7,9}};
int ID(char c)
{
    if(c=='B')return 0;
    if(c=='R')return 1;
    if(c=='W')return 2;
    return 3;
}

const int MaxN = 25;
const int MaxM = MaxN * MaxN;
const int Inf = 50;
struct Edge
{
    int v, cap, nxt;
} e[2 * MaxM];
int g[MaxN], pt;
int pre[MaxN], pree[MaxN], cur[MaxN], gap[MaxN];
int low[MaxN], d[MaxN];
int n, ed, st;

void init()
{
    for (int i = 0; i < n; i++)
        g[i] = -1;
    pt = 0;
}

void add(int u, int v, int cap)
{
    e[pt].v = v;e[pt].cap = cap;e[pt].nxt = g[u];g[u] = pt++;
    e[pt].v = u;e[pt].cap = 0;  e[pt].nxt = g[v];g[v] = pt++;
}

int sap()
{
    int ret = 0;
    bool fail;
    for (int i = 0; i < n; i++)
    {
        d[i] = gap[i] = 0;
        cur[i] = g[i];
    }
    low[st] = Inf;
    gap[0] = n;
    int u = st;

    while (d[st] < n)
    {
        fail = true;
        for (int i = cur[u]; i != -1; i = e[i].nxt)
        {
            int v = e[i].v;
            cur[u] = i;
            if (e[i].cap && d[u] == d[v] + 1)
            {
                pre[v] = u;
                pree[v] = i;
                low[v] = min(low[u], e[i].cap);
                u = v;
                if (u == ed)
                {
                    for (; u != st; u = pre[u])
                    {
                        e[pree[u]].cap -= low[ed];
                        e[pree[u] ^ 1].cap += low[ed];
                    }
                    ret += low[ed];
                }
                fail = false;
                break;
            }
        }
        if (fail)
        {
            gap[d[u]]--;
            if (!gap[d[u]])
                break;
            d[u] = n;
            for (int i = g[u]; i != -1; i = e[i].nxt)
                if (e[i].cap)
                    d[u] = min(d[u], d[e[i].v] + 1);
            gap[d[u]]++;
            cur[u] = g[u];
            if (u != st)
                u = pre[u];
        }
    }
    return ret;
}

void Gao()
{
    n = 22;st = n-1; ed = n-2;
    init();
    int ret = 0;
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++)
            add(i,j+10,Inf*A[i][j]);
    for(int i = 0; i < 10; i++)
    {
        int t = min(ax[i],have[i]);
        ret += 2*t;
//      printf("#%d %d",ax[i],have[i]);
        add(st,i,ax[i]-t),add(i+10,ed,have[i]-t);
    }
//  puts("");
    int tt = sap();
    ret += tt;
//  printf("sap==%d\n",tt);
    if(ans < ret)
    {
        ans = ret;
        memcpy(al,line,sizeof(line));
        memcpy(aCnt,ax,sizeof(ax));
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
            {
                if(A[i][j])aMp[i][j] = Inf-e[(i*10+j)*2].cap;
                else aMp[i][j] = 0;
            }
    }
}

int tot;
void sol(int x, int y, int s)
{
    if (x == N)
    {
        tot++;
        if(s==0)
            Gao();
//          for(int i = 0 ; i < N; i++)
//          for(int j = 0; j < M; j++)
//              printf("%d%c",line[i][j],j==M-1?'\n':' ');
//          puts("");
        return;
    }
    if (y == M)
    {
        if (s >> M) return;
        sol(x + 1, 0, s << 1);
        return;
    }
    int p = (s >> y) & 1, q = (s >> (y + 1)) & 1;
    s = s ^ (p << y) ^ (q << (y + 1));
    if (p + q == 0)
    {
        if (x + 1 < N)
        {
            line[x][y] = 2; line[x+1][y] = 0;
            int idx = id[mp[x][y]][mp[x + 1][y]];
            ax[idx]++;
            sol(x, y + 1, s | (1 << y));
            ax[idx]--;
        }
        if (y + 1 < M)
        {
            line[x][y] = 1; line[x][y+1] = 3;
            int idx = id[mp[x][y]][mp[x][y + 1]];
            ax[idx]++;
            sol(x, y + 1, s | (1 << (y + 1)));
            ax[idx]--;
        }
    }
    else if (p == 0 || q == 0)
    {
        sol(x, y + 1, s);
    }
}

char str[20];
int main()
{

    for (int i = 0; i < N; i++)
    {
        scanf("%s", str);
        for(int j = 0; j < M; j++)
            mp[i][j] = ID(str[j]);
    }
    for (int i = 0; i < 10; i++)
        scanf("%d", &have[i]);
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++)if(i!=j)
            if(name[i][0]==name[j][0]||name[i][0]==name[j][1]
             ||name[i][1]==name[j][0]||name[i][1]==name[j][1])
                A[i][j] = 1;
    ans = -1; tot = 0;
    sol(0, 0, 0);
    printf("%d\n",ans);

    //print
    for(int i = 0; i < N; i++)
        for(int j = 0; j < M; j++)if(al[i][j]==1 || al[i][j]==2)
        {
            int x=i,y=j;
            if(al[i][j]==1)y++;
            else x++;
            int idx = id[mp[i][j]][mp[x][y]];
            if(have[idx])
            {
                have[idx]--;
                Mp[i][j] = mp[i][j]; Mp[x][y] = mp[x][y];
                continue;
            }
            int k = 0;
            for(; k < 10; k++)if(aMp[idx][k])
            {
                aMp[idx][k]--;have[k]--;
                break;
            }
            if(k==10)
            {
                Mp[i][j] = Mp[x][y] = -1;continue;
            }
            if(to[mp[i][j]]==name[k][0] || to[mp[i][j]]==name[k][1])
                Mp[i][j]=mp[i][j],Mp[x][y]=ID(name[k][0])+ID(name[k][1])-mp[i][j];
            else
                Mp[x][y]=mp[x][y],Mp[i][j]=ID(name[k][0])+ID(name[k][1])-mp[x][y];
        }
//  for(int i = 0; i < N; i++)
//      for(int j = 0; j < M; j++)
//          printf("%d%c",al[i][j],j==M-1?'\n':' ');
//  for(int i = 0; i < 10; i++)
//      printf("%d%c",aCnt[i],i==9?'\n':' ');
//  for(int i = 0; i < 10; i++)
//      for(int j = 0; j < 10; j++)
//          printf("%d%c",aMp[i][j],j==9?'\n':' ');
    for(int i = 0; i < N; i++)
        for(int j = 0; j < M; j++)if(Mp[i][j]==-1)
        {
            int x=i,y=j;
            if(al[i][j]==1)y++;
            else x++;
            for(int k = 0; k < 10; k++)
                if(have[k])
                {
                    have[k]--;
                    Mp[i][j] = ID(name[k][0]);
                    Mp[x][y] = ID(name[k][1]);
                    break;
                }
//          printf("%d\n",Mp[i][j]);
        }
    for(int i = 0; i < 2*N-1; i++)
    {
        if(i&1)
            for(int j = 0; j < 2*M-1; j++)
            {
                if(j&1)printf(".");
                else printf("%c",al[i/2][j/2]==2?'|':'.');
            }
        else
            for(int j = 0; j < 2*M-1; j++)
            {
                if(j&1)printf("%c",al[i/2][j/2]==1?'-':'.');
                else printf("%c",to[Mp[i/2][j/2]]);
            }
        puts("");
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <tuple>
#include <unordered_set>
#include <iterator>

#define for_each(name, left, right, step) for (int name = left; name < right; name += step)

using namespace std;

template<typename T>
using set = unordered_set<T>;

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

struct HashTable {
    int max_size;
    vector<int>* hash_mod___keys;
    int curr_size;

    HashTable() {
        max_size = 10;
        curr_size = 0;
        hash_mod___keys = new vector<int> [max_size];
    }

    void insert(int key) {
        int hash_mod = (key * ll(1e+9 + 7)) % max_size;
        hash_mod___keys[hash_mod].push_back(key);
        curr_size++;
        if (curr_size > max_size / 2) {
            int new_max_size = max_size * 2 + 1;
            vector<int>* new_hash_mod___keys = new vector<int> [new_max_size];
            for_each(hash_mod, 0, max_size, 1) {
                for (auto old_key: hash_mod___keys[hash_mod]) {
                    int new_hash_mod = (old_key * ll(1e+9 + 7)) % (new_max_size);
                    new_hash_mod___keys[new_hash_mod].push_back(old_key);
                }
                hash_mod___keys[hash_mod].resize(0);
            }

            delete[] hash_mod___keys;
            hash_mod___keys = new_hash_mod___keys;
            max_size = new_max_size;
        }
    }

    void erase(int key) {
        int hash_mod = (key * ll(1e+9 + 7)) % max_size;
        auto it = find(hash_mod___keys[hash_mod].begin(), hash_mod___keys[hash_mod].end(), key);
        hash_mod___keys[hash_mod].erase(it);
        curr_size--;
    }
};

vector<int> get_centroids(vector<vector<int> >& node_idx___neigh_idxes) {
    int nodes_nr = node_idx___neigh_idxes.size();
    vector<vector<int> > node_idx___children(nodes_nr);
    vector<int> node_idx___is_visited(nodes_nr, 0);
    stack<int> dfs_stack;
    dfs_stack.push(0);
    node_idx___is_visited[0] = 1;
    while (!dfs_stack.empty()) {
        int curr_node_idx = dfs_stack.top();
        dfs_stack.pop();
        for (auto neigh_idx : node_idx___neigh_idxes[curr_node_idx]) {
            if (!node_idx___is_visited[neigh_idx]) {
                node_idx___is_visited[neigh_idx] = 1;
                node_idx___children[curr_node_idx].push_back(neigh_idx);
                dfs_stack.push(neigh_idx);
            }
        }
    }
    vector<int> node_idx___subnodes_nr(nodes_nr, 1);
    for (auto& is_visited: node_idx___is_visited) {
        is_visited = 0;
    }
    dfs_stack.push(0);
    node_idx___is_visited[0] = 1;
    while (!dfs_stack.empty()) {
        int curr_node_idx = dfs_stack.top();
        bool all_children_visited = true;
        for (auto child_idx : node_idx___children[curr_node_idx]) {
            if (!node_idx___is_visited[child_idx]) {
                node_idx___is_visited[child_idx] = 1;
                dfs_stack.push(child_idx);
                all_children_visited = false;
            }
        }
        if (all_children_visited) {
            for (auto child_idx : node_idx___children[curr_node_idx]) {
                node_idx___subnodes_nr[curr_node_idx] += node_idx___subnodes_nr[child_idx];
            }
            dfs_stack.pop();
        }
    }
    vector<int> centroids;
    for_each(node_idx, 0, nodes_nr, 1) {
        bool is_centroid = true;
        int parent_subnodes = nodes_nr - 1;
        for (auto child_idx: node_idx___children[node_idx]) {
            //cout << node_idx___subnodes_nr[child_idx] << " ";
            if (node_idx___subnodes_nr[child_idx] > nodes_nr / 2) {
                is_centroid = false;
                break;
            }
            parent_subnodes -= node_idx___subnodes_nr[child_idx];
        }
        //cout << parent_subnodes << endl;
        if (parent_subnodes > nodes_nr / 2) {
            is_centroid = false;
        }
        if (is_centroid) {
            centroids.push_back(node_idx);
        }
    }

    return centroids;
}

pii straighten_subtree(int stone_idx, int curr_root_idx, vector<HashTable>& node_idx___neigh_idxes, vector<vector<int> >& operations) {
    // cout << "*" << stone_idx << " " << curr_root_idx << endl;
    int neigh_nr = node_idx___neigh_idxes[curr_root_idx].curr_size;
    if (neigh_nr == 1) {
        // cout << "8returned" << endl;
        return make_pair(curr_root_idx, curr_root_idx);
    }
    vector<pii> rel_neigh_idx___root__hangler;
    // int i = 0;
    vector<int> curr_neigh_idxes;
    for_each(hash_mod, 0, node_idx___neigh_idxes[curr_root_idx].max_size, 1) {
        for(auto& neigh_idx: node_idx___neigh_idxes[curr_root_idx].hash_mod___keys[hash_mod]) {
            curr_neigh_idxes.push_back(neigh_idx);
        }
    }
    for (auto& neigh_idx: curr_neigh_idxes) {
        if (neigh_idx != stone_idx) {
            rel_neigh_idx___root__hangler.push_back(straighten_subtree(curr_root_idx, neigh_idx, node_idx___neigh_idxes, operations));
        }
    }
    int curr_parent_idx = stone_idx;
    int next_root_idx = (neigh_nr == 2 ? curr_root_idx : rel_neigh_idx___root__hangler[0].second);

    // replace stone_idx curr_root_idx connection
    if (next_root_idx != curr_root_idx) {
        node_idx___neigh_idxes[stone_idx].insert(rel_neigh_idx___root__hangler[0].second);
        node_idx___neigh_idxes[stone_idx].erase(curr_root_idx);
        node_idx___neigh_idxes[curr_root_idx].erase(stone_idx);
        node_idx___neigh_idxes[rel_neigh_idx___root__hangler[0].second].insert(stone_idx);
        curr_parent_idx = rel_neigh_idx___root__hangler[0].first;
        vector<int> operation(3);
        operation[0] = stone_idx;
        operation[1] = curr_root_idx;
        operation[2] = rel_neigh_idx___root__hangler[0].second;
        operations.push_back(operation);
        // cout << "**" << operation[0] << " " << operation[1] << " " << operation[2] << endl;
    }
    neigh_nr = rel_neigh_idx___root__hangler.size();
    for_each(neigh_idx, 1, neigh_nr - 1, 1) {
        //create curr_parent_idx, rel_neigh_idx___root__hangler[neigh_idx].second
        vector<int> operation(3);
        operation[0] = curr_parent_idx;
        operation[1] = curr_root_idx;
        operation[2] = rel_neigh_idx___root__hangler[neigh_idx].second;
        // cout << "**" << operation[0] << " " << operation[1] << " " << operation[2] << endl;
        operations.push_back(operation);
        node_idx___neigh_idxes[curr_parent_idx].insert(rel_neigh_idx___root__hangler[neigh_idx].second);
        node_idx___neigh_idxes[rel_neigh_idx___root__hangler[neigh_idx].second].insert(curr_parent_idx);
        //tear curr_root_idx neigh
        node_idx___neigh_idxes[curr_parent_idx].erase(curr_root_idx);
        node_idx___neigh_idxes[curr_root_idx].erase(curr_parent_idx);
        curr_parent_idx = rel_neigh_idx___root__hangler[neigh_idx].first;
    }
    // cout << "8returned" << endl;
    return make_pair(next_root_idx, rel_neigh_idx___root__hangler[neigh_nr - 1].second);
}

int hedgehogify(int stone_idx, int curr_root_idx, vector<HashTable>& node_idx___neigh_idxes, vector<vector<int> >& operations) {
    int neigh_nr = node_idx___neigh_idxes[curr_root_idx].curr_size;
    // cout << "*" << neigh_nr << endl;
    if (neigh_nr == 1) {
        return curr_root_idx;
    }
    int center_idx;
    for_each(hash_mod, 0, node_idx___neigh_idxes[curr_root_idx].max_size, 1) {
        for (auto neigh_idx: node_idx___neigh_idxes[curr_root_idx].hash_mod___keys[hash_mod]) {
            if (neigh_idx != stone_idx) {
                center_idx = hedgehogify(curr_root_idx, neigh_idx, node_idx___neigh_idxes, operations);
                // cout << "**" << center_idx << endl;
            }
        }
    }
    vector<int> operation(3);
    operation[0] = stone_idx;
    operation[1] = curr_root_idx;
    operation[2] = center_idx;
    operations.push_back(operation);
    return center_idx;
}

void straighten_and_hedgehogify_parts(vector<vector<int> >& node_idx___neigh_idxes, int centroid1, int centroid2, vector<vector<int> >& operations, bool fl) {
    int nodes_nr = node_idx___neigh_idxes.size();
    for (auto neigh_idx : node_idx___neigh_idxes[centroid1]) {
        if ((neigh_idx == centroid2) || (neigh_idx == centroid1)) {
            continue;
        }
        vector<HashTable> curr_node_idx___neigh_idxes(nodes_nr);
        curr_node_idx___neigh_idxes[centroid1].insert(neigh_idx);
        curr_node_idx___neigh_idxes[neigh_idx].insert(centroid1);
        vector<int> curr_node_idx___is_visited(nodes_nr, 0);
        stack<int> dfs_stack;
        dfs_stack.push(neigh_idx);
        curr_node_idx___is_visited[neigh_idx] = 1;
        while (!dfs_stack.empty()) {
            int curr_node_idx = dfs_stack.top();
            dfs_stack.pop();
            for (auto curr_neigh_idx: node_idx___neigh_idxes[curr_node_idx]) {
                if ((curr_neigh_idx != centroid1) && (curr_node_idx___is_visited[curr_neigh_idx] == 0) && (curr_neigh_idx != centroid2)) {
                    curr_node_idx___neigh_idxes[curr_node_idx].insert(curr_neigh_idx);
                    curr_node_idx___neigh_idxes[curr_neigh_idx].insert(curr_node_idx);
                    curr_node_idx___is_visited[curr_neigh_idx] = 1;
                    dfs_stack.push(curr_neigh_idx);
                }
            }
        }
        // cout << "shdfkhfk" << endl;
        pii report = straighten_subtree(centroid1, neigh_idx, curr_node_idx___neigh_idxes, operations);
        hedgehogify(centroid1, report.first, curr_node_idx___neigh_idxes, operations);
        // for (auto operation : operations) {
        //     cout << operation[0] << " " << operation[1] << " " << operation[2] << endl;
        // }
    }

    if (centroid1 == centroid2) {
        return;
    }
    if (!fl){
        straighten_and_hedgehogify_parts(node_idx___neigh_idxes, centroid2, centroid1, operations, 1);
    }
}

void solve() {

    int nodes_nr;
    cin >> nodes_nr;
    vector<vector<int> > node_idx___neigh_idxes(nodes_nr);
    for_each(edge_idx, 0, nodes_nr - 1, 1) {
        int node1, node2;
        cin >> node1 >> node2;
        node1--;
        node2--;
        node_idx___neigh_idxes[node2].push_back(node1);
        node_idx___neigh_idxes[node1].push_back(node2);
    }
    vector<int> centroids = get_centroids(node_idx___neigh_idxes);
    int centroid1, centroid2;
    if (centroids.size() == 1) {
        centroid1 = centroids[0];
        centroid2 = centroids[0];
    }
    else {
        centroid1 = centroids[0];
        centroid2 = centroids[1];
    }
    // cout << "!" << centroid1 << " " << centroid2 << endl;
    vector<vector<int> > operations;
    straighten_and_hedgehogify_parts(node_idx___neigh_idxes, centroid1, centroid2, operations, 0);
    cout << operations.size() << endl;
    for (auto operation : operations) {
        for (auto node_idx: operation) {
            cout << (node_idx + 1) << " ";
        }
        cout << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    solve();
}


#include <bits/stdc++.h>

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair

#define ff first
#define ss second

#define matr vector<vector<int> >

#define all(x) x.begin(), x.end()

using namespace std;
typedef long long ll;
typedef long double ld;

const int maxn = 1000 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n;
vector<int> gr[maxn];
int p[maxn], dist[maxn];
int used[maxn];
int cycle[maxn];
vector<int> path;

void dfs(int u, int pr, int d) {
    used[u] = 1;
    dist[u] = d;
    p[u] = pr;
    for (auto v : gr[u]) {
        if (v == pr) continue;
        if (!used[v]) {
            dfs(v, u, d + 1);
        } else if (dist[v] < dist[u]) {
            int pp = u;
            while (pp != v) {
                path.pb(pp);
                cycle[pp] = 1;
                pp = p[pp];
            }
            path.pb(v);
            cycle[v] = 1;
        }
    }
}

int upper[maxn];
int down[maxn];
int size[maxn];
int func[maxn];

int dfs1(int u, int pr, int d) {
    p[u] = pr;
    size[u] = 1;
    used[u] = 1;
    dist[u] = d;
    for (auto v : gr[u]) {
        if (cycle[v] || v == pr) continue;
        size[u] += dfs1(v, u, d + 1);
    }
    return size[u];
}

int dow(int u, int pr) {
    down[u] = size[u];
    for (auto v : gr[u]) {
        if (cycle[v] || v == pr) continue;
        down[u] += dow(v, u);
    }
    return down[u];
}

int start;
void upp(int u, int pr) {
    if (pr == u) {
        upper[u] = 1;
    } else if (pr == start) {
        upper[u] = size[start] - size[u] + 1 + down[start] - down[u] - size[u];
    } else {
        upper[u] = upper[pr] + size[start] - size[u] + 1;
    }
    for (auto v : gr[u]) {
        if (cycle[v] || v == pr) continue;
        upp(v, u);
    }
}

int mxx;
void get(int u, int pr) {
    func[u] = (dist[u] + 1) * (n - size[start]) + upper[u] + down[u] - 1;
    mxx = max(mxx, func[u]);
    for (auto v : gr[u]) {
        if (cycle[v] || v == pr) continue;
        get(v, u);
    }
}

int dp[maxn][maxn];
int ms[maxn][maxn];
int ALL = 0;

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        gr[a].pb(b);
        gr[b].pb(a);
    }
    dfs(0, 0, 0);
    for (int i = 0; i < n; ++i) {
        if (!cycle[i]) continue;
        dfs1(i, i, 0);
        start = i;
        dow(i, i);
        upp(i, i);
        mxx = -inf;
        get(i, i);
        func[i] = mxx;
    }
    vector<int> have;
    for (auto v : path) have.pb(v);
    for (auto v : path) have.pb(v);
    for (int i = 0; i < have.size(); ++i) {
        int v = have[i];
        dp[i][1] = func[v];
        ms[i][1] = size[v];
    }
    for (int len = 2; len <= have.size() / 2; ++len) {
        for (int l = 0; l + len - 1 < have.size(); ++l) {
            int r = l + len - 1;
            ms[l][len] = ms[l][len - 1] + size[have[r]];
            int L = dp[l + 1][len - 1] + n - ms[l + 1][len - 1] + down[have[l]] - size[have[l]];
            int R = dp[l][len - 1] + n - ms[l][len - 1] + down[have[r]] - size[have[r]];
            dp[l][len] = max(L, R);
        }
    }
    int ans = 0;
    for (int i = 0; i < have.size(); ++i) {
        ans = max(ans, dp[i][have.size() / 2]);
    }
    cout << ans;
}

signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else

#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    int t = 1;
    for (int i = 0; i < t; ++i) {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define lli long long int
#define double long double
#define MAX 100010 // should be 10^7 + 100
#define ch 220
lli inf = pow(10,18);
lli modulo = pow(10,9)+7;
double eps = 1e-9;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
lli gcd(lli a,lli b){
	return !b ? a : gcd(b,a%b);
}
void fix(pair<lli,lli>& a){
	lli ebob = gcd(a.ff,a.ss);
	a.ff/=ebob, a.ss/=ebob;
}
bool J(pair<lli,lli> &a, pair<lli,lli> &b){
	return a.ff * b.ss < a.ss * b.ff;
}
lli ind(pair<lli,lli> &aa, vector<pair<lli,lli> > &all){
	lli a = 0, b = all.size()-1;
	if(J(aa,all[0]))
		return 0;
	while(a<b){
		lli c = (a+b)/2+1;
		if(J(aa,all[c]))
			b=c-1;
		else
			a=c;
	}
	return a+1;
}
void deal(){
	lli n,w;
	cin>>n>>w;
	vector<pair<lli,lli> > all[2];
	fori(n){
		lli x,v;
		cin>>x>>v;
		pair<lli,lli> a;	lli kd = 0;
		if(x<0)
			x = -x;
		else
			v = -v, kd = 1;
		a.ff = x, a.ss = v+w;
		all[kd].push_back(a);
//		cout<<(double)(x)/(double)(v-w)<<" "<<(double)(x)/(double)(v+w)<<endl;
	}
	sort(all[0].begin(),all[0].end(),J);
	sort(all[1].begin(),all[1].end(),J);
	if(!all[0].size() || !all[1].size()){
		cout<<0;
		return;
	}
	lli sy = 0;
	for(lli kd=0; kd<2; ++kd)
		fori(all[kd].size()){
			all[kd][i].ss-=2*w;
			lli ind1,ind2;
			ind1 = ind(all[kd][i],all[!kd]);
			all[kd][i].ss+=2*w;
			ind2 = ind(all[kd][i],all[!kd]);
	//		cout<<"for the guy "<<all[kd][i].ff<<" "<<all[kd][i].ss-w<<endl;
	//		cout<<"ind2 ind1 : "<<ind2<<" "<<ind1<<endl;
			sy+=ind1-ind2;
		}
	map<lli,lli> last;
	map<lli,lli> ch[2];
	fori(2)
		forj(all[i].size()){
			pair<lli,lli> sanity = all[i][j];
			sanity.ss-=w;
			fix(sanity);
			fix(all[i][j]);
			sanity.ff*=3*pow(10,5);
			sanity.ff+=sanity.ss;
			sy+=ch[i][sanity.ff];
			ch[i][sanity.ff]++;
		}
	fori(all[0].size())
		all[0][i].ff*= 3*pow(10,5), last[all[0][i].ff + all[0][i].ss]++;
	fori(all[1].size())
		all[1][i].ff*=3*pow(10,5),  sy+=last[all[1][i].ff + all[1][i].ss];
	cout<<sy<<endl;
}
int main(){
	deal();
}


#ifdef ONLINE_JUDGE
#define NDEBUG
#endif

#include <algorithm>
#include <cstring>
#include <iostream>
#include <ios>
#include <functional>
#include <map>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
#include <stdio.h>
#include <string>
#include <cassert>
uint32_t readu32() { int c; while((c = getchar()) < '0'); uint32_t n = c & 15U; while((c = getchar()) >= '0') n = n * 10 + (c & 15U); return n; } uint64_t readu64() { int c; while((c = getchar()) < '0'); uint64_t n = c & 15U; while((c = getchar()) >= '0') n = n * 10 + (c & 15U); return n; } int32_t read32() { int c; while((c = getchar()) < '-'); bool neg = c == '-'; if(neg) c = getchar(); uint32_t n = c & 15U; while((c = getchar()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int32_t)n : n; } int64_t read64() { int c; while((c = getchar()) < '-'); bool neg = c == '-'; if(neg) c = getchar(); uint64_t n = c & 15; while((c = getchar()) >= '0') n = n * 10 + (c & 15U); return neg ? -(int64_t)n : n; } std::string read_word() { int c; while ((c = getchar()) <= ' '); std::string s; do { s += (char) c; } while ((c = getchar()) > ' '); return s; } template<typename F, F f> struct no_arg_call { template<typename T> struct stupid_compiler { typedef T type; }; operator typename stupid_compiler<decltype(f())>::type() { return f(); } }; no_arg_call<decltype(&readu32), readu32> IU; no_arg_call<decltype(&read32), read32> II; no_arg_call<decltype(&readu64), readu64> IUL; no_arg_call<decltype(&read64), read64> IL; no_arg_call<decltype(&read_word), read_word> IW;
template<typename T, int N> struct mat { T dat[N*N]; struct id_s {}; static const id_s id; mat(): dat{} { } mat(std::initializer_list<T> l) { int i = 0; for(auto&& x: l) dat[i++] = x; for(; i < N*N; i++) dat[i] = 0; } mat(int m): dat{} { for(int i = 0; i < N; i++) (*this)(i,i) = m; } mat(id_s) { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) dat[N*i + j] = +(i==j); } T& operator()(int i, int j) { return dat[N*i + j]; } const T& operator()(int i, int j) const { return dat[N*i + j]; } mat operator*(const mat& o) { mat r; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) for(int k = 0; k < N; k++) r(i,j) += (*this)(i,k) * o(k,j); return r; } mat operator+(const mat& o) { mat r; for(int i = 0; i < N*N; i++) r.dat[i] = dat[i] + o.dat[i]; return r; } };
template<typename T> struct xgcd_s { T m, n, gcd; }; template<typename T> xgcd_s<T> xgcd(T a, T b) { T m[] = {1,0}, n[] = {0,1}, q[] = {0,0}; for(int i = 0; ; i^=1) { m[i] -= m[i^1] * q[i]; n[i] -= n[i^1] * q[i]; if(!b) return xgcd_s<T>{m[i],n[i],a}; q[i] = a/b; a %= b; std::swap(a,b); } } template<unsigned M()> struct _intmod { private: struct _p {unsigned x; }; _intmod(_p x) { n = x.x; } public: unsigned n; _intmod() {n = 0;} _intmod(int x) { n = x<0? M()+x%(int)M(): x%M(); } _intmod(unsigned x) {n = x%M(); } _intmod(long x) {n = unsigned(x<0? M()+x%(long)M(): x%M()); } _intmod(unsigned long x) {n = x % M(); } _intmod(long long x) {n = unsigned(x<0? M()+x%(long long)M(): x%M()); } _intmod(unsigned long long x) {n = x % M(); } _intmod operator+(_intmod b) const {return {n+b.n}; } _intmod operator*(_intmod b) const {return {_p{unsigned((unsigned long long)n * b.n % M())}}; } _intmod operator-(_intmod b) const {return {_p{n>=b.n? n-b.n : M()+n-b.n }}; } _intmod operator-() const {return {_p{n?M()-n:0U}}; } _intmod& operator+=(_intmod b) { return(*this = *this + b); } _intmod& operator-=(_intmod b) { return(*this = *this - b); } _intmod& operator/=(_intmod b) { return(*this = *this / b); } _intmod& operator*=(_intmod b) { return(*this = *this * b); } static _intmod mulinv(_intmod n) { xgcd_s<signed> x = xgcd<signed>(n.n, M()); assert(x.gcd == 1); return x.m; } _intmod operator/(_intmod b) const { return *this * mulinv(b); } bool operator==(_intmod b) const { return n == b.n; } bool operator!=(_intmod b) const { return n != b.n; } explicit operator int() const { return n; } }; template<unsigned M()> std::ostream& operator<<(std::ostream& o, _intmod<M> n) { return o<<n.n; } template<unsigned M()> std::istream& operator>>(std::istream& i, _intmod<M>& n) { long long x; i>>x; n = x; return i; } template<unsigned M> unsigned intmod_unsignedconst() { static_assert(M>0 && M<(1U<<31), "modulus bad"); return M; } template<unsigned*M> unsigned intmod_unsignedptr() { return *M; } template<unsigned M> using intmod = _intmod<intmod_unsignedconst<M> >; template<unsigned*M> using intmodv = _intmod<intmod_unsignedptr<M> >; static_assert(std::is_trivially_copyable<intmod<3> >::value, "");
template<typename T, typename X> T bpow(T b, X x) { T r = 1, p = b; while(x) { if(x & 1) r = r * p; if(x >>= 1) p = p * p; } return r; }
template<typename T> struct matd { std::vector<T> dat; size_t dim; matd(): dim(0) { } matd(size_t dim): dim(dim), dat(dim * dim) { } matd(size_t dim, std::initializer_list<T> l): matd(dim) { size_t i = 0; for(auto&& x: l) dat[i++] = x; } matd(size_t dim, const T& diag): matd(dim) { for(size_t i = 0; i < dim; i++) (*this)(i,i) = diag; } T& operator()(size_t i, size_t j) { return dat[dim*i + j]; } const T& operator()(size_t i, size_t j) const { return dat[dim*i + j]; } matd operator*(const matd& o) const { matd r(dim); for(int i = 0; i < dim; i++) for(int j = 0; j < dim; j++) for(int k = 0; k < dim; k++) r(i,j) += (*this)(i,k) * o(k,j); return r; } matd operator+(const matd& o) const { matd r(dim); for(int i = 0; i < dim*dim; i++) r.dat[i] = dat[i] + o.dat[i]; return r; } template<typename T> matd pow(T power) const { if(!power) return matd(dim, 1); matd ans = *this; while(!(power & 1)) { ans = ans * ans; power >>= 1; } power >>= 1; if(power) { matd p = ans * ans; for(;;) { if(power & 1) ans = ans * p; power >>= 1; if(!power) break; p = p * p; } } return ans; } };

using namespace std;
using I = intmod<1000000007>;

#define D 250

//#define D 25

int main(int argc, char** argv)
{
    if (argc == 2) freopen(argv[1], "r", stdin);
    ios_base::sync_with_stdio(0);

    matd<I> m(250), mm(250);

    int F = IU, B = IU, N = IU;
    vector<int> p(F), b(B);
    for (auto& x : p) x = IU;
    for (auto& x : b) x = IU;

    for (int r = 1; r < D; r++) {
        m(r, r - 1) = 1;
    }
    for (int x : b)
        m(0, x - 1) += 1;

    for(int pp : p) {
        auto tr = bpow(m, pp);
        mm = mm + tr;
    }

    auto a = bpow(mm, N);
    cout << a(0, 0);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
typedef long double ldb;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	bool neg=0;
	while(!(c>='0' && c<='9')){
		if(c=='-') neg=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return neg?-ret:ret;
}
void putint(LL v){
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
const int S=1002,T=1003,inf=50000000;
namespace flows{
    struct edge{
        int v,r,id;
		ldb f;
        edge(int V,int R,ldb F,int _id){
            v=V;r=R;f=F;id=_id;
        }
    };
    vector < edge > adj[1005];
    int cur[1005],dis[1005];
    void init(){
        int i;
        for(i=0;i<1005;++i){
            adj[i].clear();
        }
    }
    void addedge(int u,int v,ldb f,int id,bool bi=0){
        adj[u].push_back(edge(v,(int)adj[v].size(),f,id));
        adj[v].push_back(edge(u,(int)adj[u].size()-1,bi?f:0,-1));
    }
    void bfs(){
        queue < int > Q;
        Q.push(S);
        dis[S]=0;
        while(!Q.empty()){
            int i,cv=Q.front();
            Q.pop();
            for(i=0;i<(int)adj[cv].size();++i){
                if(adj[cv][i].f>1e-8l && dis[adj[cv][i].v]==-1){
                    dis[adj[cv][i].v]=dis[cv]+1;
                    Q.push(adj[cv][i].v);
                }
            }
        }
    }
    ldb dfs(int ver,ldb cap){
        if(ver==T) return cap;
        for(int &i=cur[ver];i<(int)adj[ver].size();++i){
            edge &E=adj[ver][i];
            if(E.f>1e-8l && dis[E.v]>dis[ver]){
                ldb ret=dfs(E.v,min(cap,E.f));
                if(ret>1e-8l){
                    E.f-=ret;
                    adj[E.v][E.r].f+=ret;
                    return ret;
                }
            }
        }
        return 0;
    }
    ldb maxflow(){
        ldb ret=0,dlt;
        while(1){
            memset(dis,-1,sizeof(dis));
            memset(cur,0,sizeof(cur));
            bfs();
            if(dis[T]==-1) return ret;
            dlt=1;
            while(dlt>1e-8l){
                dlt=dfs(S,1e9l);
                ret+=dlt;
            }
        }
    }
}
int n,m;
vector < int > U,V,A,B,C,D;
ldb calc(ldb t){
	flows::init();
	int i,j,k;
//	for(i=0;i<n;++i){
//		flows::addedge(S,i,inf,-1);
//		flows::addedge(i,T,inf,-1);
//	}
	ldb suml=0;
	for(i=0;i<m;++i){
		int u=U[i],v=V[i],a=A[i],b=B[i],c=C[i],d=D[i];
		ldb l=a*t+b,r=c*t+d;
		suml+=l;
		flows::addedge(S,v,l,-1);
		flows::addedge(u,T,l,-1);
		flows::addedge(u,v,r-l,-1);
//		flows::addedge(u,v,c*t+d,-1);
//		flows::addedge(v,u,-(a*t+b),-1);
	}
	return flows::maxflow()-suml;
}
ldb getpeak(){
	ldb l=0,r=1;
	while(r-l>1e-7l){
		ldb dif=(r-l)/3;
		ldb mid1=l+dif,mid2=l+dif+dif;
		if(calc(mid1)<calc(mid2))
			l=mid1;
		else
			r=mid2;
	}
//	cout<<l<<endl;
	return l;
}
ldb getR(ldb peak){
	ldb l=peak,r=1,mid;
	while(r-l>1e-7l){
		mid=(l+r)/2;
		if(calc(mid)>-1e-8l)
			l=mid;
		else
			r=mid;
	}
//	cout<<'R'<<l<<endl;
	return l;
}
ldb getL(ldb peak){
	ldb l=0,r=peak,mid;
	while(r-l>1e-7l){
		mid=(l+r)/2;
		if(calc(mid)>-1e-8l)
			r=mid;
		else
			l=mid;
	}
//	cout<<'L'<<l<<endl;
	return l;
}
int main(){
	int i,j,k;
	n=readint();m=readint();
	for(i=0;i<m;++i){
		int u=readint()-1,v=readint()-1,a=readint(),b=readint(),c=readint(),d=readint();
		U.push_back(u);
		V.push_back(v);
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
		D.push_back(d);
	}
//	cout<<calc(0.33)<<' '<<calc(0.505)<<' '<<calc(0.66)<<' '<<calc(0.99)<<endl;
	ldb p=getpeak();
	printf("%.10f\n",(double)(getR(p)-getL(p)));
	return 0;
}#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
typedef long double ldb;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	bool neg=0;
	while(!(c>='0' && c<='9')){
		if(c=='-') neg=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return neg?-ret:ret;
}
void putint(LL v){
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
const int S=1002,T=1003,inf=50000000;
namespace flows{
    struct edge{
        int v,r,id;
		ldb f;
        edge(int V,int R,ldb F,int _id){
            v=V;r=R;f=F;id=_id;
        }
    };
    vector < edge > adj[1005];
    int cur[1005],dis[1005];
    void init(){
        int i;
        for(i=0;i<1005;++i){
            adj[i].clear();
        }
    }
    void addedge(int u,int v,ldb f,int id,bool bi=0){
        adj[u].push_back(edge(v,(int)adj[v].size(),f,id));
        adj[v].push_back(edge(u,(int)adj[u].size()-1,bi?f:0,-1));
    }
    void bfs(){
        queue < int > Q;
        Q.push(S);
        dis[S]=0;
        while(!Q.empty()){
            int i,cv=Q.front();
            Q.pop();
            for(i=0;i<(int)adj[cv].size();++i){
                if(adj[cv][i].f>1e-8l && dis[adj[cv][i].v]==-1){
                    dis[adj[cv][i].v]=dis[cv]+1;
                    Q.push(adj[cv][i].v);
                }
            }
        }
    }
    ldb dfs(int ver,ldb cap){
        if(ver==T) return cap;
        for(int &i=cur[ver];i<(int)adj[ver].size();++i){
            edge &E=adj[ver][i];
            if(E.f>1e-8l && dis[E.v]>dis[ver]){
                ldb ret=dfs(E.v,min(cap,E.f));
                if(ret>1e-8l){
                    E.f-=ret;
                    adj[E.v][E.r].f+=ret;
                    return ret;
                }
            }
        }
        return 0;
    }
    ldb maxflow(){
        ldb ret=0,dlt;
        while(1){
            memset(dis,-1,sizeof(dis));
            memset(cur,0,sizeof(cur));
            bfs();
            if(dis[T]==-1) return ret;
            dlt=1;
            while(dlt>1e-8l){
                dlt=dfs(S,1e9l);
                ret+=dlt;
            }
        }
    }
}
int n,m;
vector < int > U,V,A,B,C,D;
ldb calc(ldb t){
	flows::init();
	int i,j,k;
//	for(i=0;i<n;++i){
//		flows::addedge(S,i,inf,-1);
//		flows::addedge(i,T,inf,-1);
//	}
	ldb suml=0;
	for(i=0;i<m;++i){
		int u=U[i],v=V[i],a=A[i],b=B[i],c=C[i],d=D[i];
		ldb l=a*t+b,r=c*t+d;
		suml+=l;
		flows::addedge(S,v,l,-1);
		flows::addedge(u,T,l,-1);
		flows::addedge(u,v,r-l,-1);
//		flows::addedge(u,v,c*t+d,-1);
//		flows::addedge(v,u,-(a*t+b),-1);
	}
	return flows::maxflow()-suml;
}
ldb getpeak(){
	ldb l=0,r=1;
	while(r-l>1e-7l){
		ldb dif=(r-l)/3;
		ldb mid1=l+dif,mid2=l+dif+dif;
		if(calc(mid1)<calc(mid2))
			l=mid1;
		else
			r=mid2;
	}
//	cout<<l<<endl;
	return l;
}
ldb getR(ldb peak){
	ldb l=peak,r=1,mid;
	while(r-l>1e-7l){
		mid=(l+r)/2;
		if(calc(mid)>-1e-8l)
			l=mid;
		else
			r=mid;
	}
//	cout<<'R'<<l<<endl;
	return l;
}
ldb getL(ldb peak){
	ldb l=0,r=peak,mid;
	while(r-l>1e-7l){
		mid=(l+r)/2;
		if(calc(mid)>-1e-8l)
			r=mid;
		else
			l=mid;
	}
//	cout<<'L'<<l<<endl;
	return l;
}
int main(){
	int i,j,k;
	n=readint();m=readint();
	for(i=0;i<m;++i){
		int u=readint()-1,v=readint()-1,a=readint(),b=readint(),c=readint(),d=readint();
		U.push_back(u);
		V.push_back(v);
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
		D.push_back(d);
	}
//	cout<<calc(0.33)<<' '<<calc(0.505)<<' '<<calc(0.66)<<' '<<calc(0.99)<<endl;
	ldb p=getpeak();
	printf("%.10f\n",(double)(getR(p)-getL(p)));
	return 0;
}


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

using namespace std;

const int max_n = 511, mod = 1000000007;

int t, k;
long long dp[max_n], sumdp[max_n], pw[max_n], pw2[max_n], sums[max_n][max_n];
string l, r;

long long sum_dp(int r) {
    return sumdp[r];
}

void get_dp() {
    pw[0] = 1;
    pw2[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        pw[i] = (pw[i - 1] * 10) % mod;
        pw2[i] = (pw2[i - 1] * 8) % mod;
    }
    dp[0] = dp[1] = 0;
    for (int len = 2; len < max_n; ++len) {
        //cout << dp[len - 1] << endl;
        for (int i = 1; i <= len; ++i) {
            for (int j = i + 1; j <= len && j - i <= k; ++j) {
                long long x = (pw2[j - i - 1] * pw[len - j]) % mod;
                int poz = i - k;
                if (poz > 1) {
                    //cout << poz - 1 << endl;
                    x = (x * pw2[k]) % mod;
                    long long y = ((9 * pw[poz - 2] - dp[poz - 1]/*sum_dp(poz - 1)*/) % mod + mod) % mod;
                    x = (x * y) % mod;
                } else {
                    if (i != 1) {
                        x = (x * pw2[i - 2] * 7) % mod;
                    }
                }
                //if (len == 6) cout << i << " " << j << "  -  " << x << endl;
                x = (x * 4) % mod;
                dp[len] = (dp[len] + x) % mod;
            }
        }
        sumdp[len] = (sumdp[len - 1] + dp[len]) % mod;
    }
    //cout << dp[6] << endl;
}

bool ok(string s) {
    int last = -11111;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '4' || s[i] == '7') {
            if (i - last <= k) {
                return true;
            }
            last = i;
        }
    }
    return false;
}

bool happy(int x) {
    return x == 4 || x == 7;
}

void get_all_sum() {
    for (int st = 0; st < max_n; ++st) {
        sums[st][1] = (2 * pw[st] * pw2[0]) % mod;
        for (int cnt = 2; cnt <= st + 1; ++cnt) {
            sums[st][cnt] = (sums[st][cnt - 1] + 2 * pw[st - cnt + 1] * pw2[cnt - 1]) % mod;
        }
    }
}

long long sum(int st, int cnt) {
    if (cnt < 0 || st < 0) {
        return 0;
    }
    /*long long res = 0;
    for (int q = 0; q < cnt; ++q) {
        long long x = (2 * pw[st - q] * pw2[q]) % mod;
        res = (res + x) % mod;
    }
    cout << st << " " << cnt << " - " << sums[st][cnt] << "  res = " << res << endl;*/
    return sums[st][cnt];
}

long long fun(string r) {
    long long res = 0;
    for (int i = 1; i < r.length(); ++i) {
        res = (res + dp[i]) % mod;
    }
    int last = -111111;
    //cout << r << "  -  " << res << endl;
    for (int i = 0; i < r.length(); ++i) {
        //cout << "i = " << i << "  " << r << "  -  " << res << "    last = " << last << endl;
        int st = 0, fin = r[i] - '0';
        if (i == 0) {
            st = 1;
        }
        for (int j = st; j < fin; ++j) {
            if (happy(j)) {
                if (i - last <= k) {
                    res = (res + pw[r.length() - i - 1]) % mod;
                } else {
                    //@@@@@@;
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, i + k) - i)) % mod;
                    int poz = i + k + 1;
                    if (poz < r.length()) {
                        long long x = (pw2[k] * sum_dp(r.length() - poz)) % mod;
                        //cout << "+=" << x << endl;
                        res = (res + x) % mod;
                    }
                }
            } else {
                if (last < 0) {
                    res = (res + sum_dp(r.length() - i - 1));
                } else {
                    res = (res + sum(r.length() - i - 2, min((int) r.length() - 1, k + last) - i)) % mod;
                    int poz = max(i + 1, last + k + 1);
                    if (poz < r.length()) {
                        long long x = (pw2[poz - i - 1] * sum_dp(r.length() - poz)) % mod;
                        //cout << "+=" << x << endl;
                        res = (res + x) % mod;
                    }
                }
            }
            //cout << "      j = " << j << "  " << r << "  -  " << res << endl;
        }
        if (happy(fin)) {
            if (i - last <= k) {
                //cout << r << "  !-!  " << res << endl;
                res = (res + 1) % mod;
                long long x = 0;
                for (int j = i + 1; j < r.length(); ++j) {
                    x = (x * 10 + r[j] - '0') % mod;
                }
                res = (res + x) % mod;
                return res;
            }
            last = i;
        }
    }
    return res;
}

long long solve2() {
    string a = l;
    int res = 0;
    if (ok(r)) {
        ++res;
    }
    while (a != r) {
        //cout << a << endl;
        //for (int i = 1; i < 111111111; ++i);
        if (ok(a)) {
            ++res;
        }
        int poz = a.length() - 1;
        while (poz >= 0 && a[poz] == '9') {
            --poz;
        }
        if (poz == -1) {
            for (int i = 0; i < a.length(); ++i) {
                a[i] = '0';
            }
            a = "1" + a;
        } else {
            ++a[poz];
            for (int i = poz + 1; i < a.length(); ++i) {
                a[i] = '0';
            }
        }
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> t >> k;
    get_dp();
    get_all_sum();
    //cout << dp[2] << " " << dp[3] << " " << dp[4];
    while (t--) {
        cin >> l >> r;
        long long x = fun(r);
        long long y = fun(l);
        long long ans = ((x - y) % mod + mod) % mod;
        if (ok(l)) {
            ans = (ans + 1) % mod;
        }
        cout << ans << endl;
        //cout << ans << "      " << x << " " << y  << endl;
        //cout << solve2() << endl;
    }
    return 0;
}


/**
 *    author:  tourist
 *    created: 30.09.2017 21:16:15
**/
#include <bits/stdc++.h>

using namespace std;

long long C[777][777];

int r, c;
long long total;
long long best = (long long) 1e18, best_z = -1;

void dfs(long long x, long long y, int v1, int v2) {
  long long diff = abs(x - y);
  if (best <= 1 || diff - C[v1][r] * C[v2][r] >= best) {
    return;
  }
  if (v1 == r - 1 && v2 == r - 1) {
    long long diff = abs(x - y);
    if (diff < best) {
      best = diff;
      best_z = x;
    }
    return;
  }
  if (v1 >= r) {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    dfs(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (v2 >= r) {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    dfs(x + sum1 * cur2, y, v1, v2 - 1);
  }
}

char s[12345];
int cntA[12345], cntB[12345];
map<long long, long long> mp;

long long solve(long long x, long long y, int v1, int v2) {
  long long state = x * 10000 + v1 * 100 + v2;
  if (mp.find(state) != mp.end()) {
    return mp[state];
  }
  long long &res = mp[state];
  long long diff = abs(x - y);
  if (diff - C[v1][r] * C[v2][r] > best) {
    return res = 0;
  }
  if (v1 < r || v2 < r) {
    if (v1 >= cntA[v1 + v2] && v2 >= cntB[v1 + v2]) {
      int sum = v1 + v2;
      v1 -= cntA[sum];
      v2 -= cntB[sum];
      return res = C[v1 + v2][v1];
    }
    return res = 0;
  }
  res = 0;
  char c = s[v1 + v2 - 1];
  if (c != 'B') {
    long long cur1 = C[v1][r] - C[v1 - 1][r];
    long long sum2 = C[v2][r];
    res += solve(x, y + cur1 * sum2, v1 - 1, v2);
  }
  if (c != 'A') {
    long long sum1 = C[v1][r];
    long long cur2 = C[v2][r] - C[v2 - 1][r];
    res += solve(x + sum1 * cur2, y, v1, v2 - 1);
  }
  return res;
}

int main() {
  scanf("%d %d", &r, &c);
  for (int i = 0; i <= 2 * (r + c); i++) {
    for (int j = 0; j <= 2 * (r + c); j++) {
      if (j == 0) C[i][j] = 1; else
      if (i == 0) C[i][j] = 0;
      else C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]);
    }
  }
  total = C[r + c][r] * C[r + c][r];
  {
    long long x = 0, y = 0;
    int v1 = r + c, v2 = r + c;
    while (v1 >= r && v2 >= r) {
      if (x > y) {
        long long cur1 = C[v1][r] - C[v1 - 1][r];
        long long sum2 = C[v2][r];
        y += cur1 * sum2;
        v1--;
      } else {
        long long sum1 = C[v1][r];
        long long cur2 = C[v2][r] - C[v2 - 1][r];
        x += sum1 * cur2;
        v2--;
      }
    }
    best = abs(x - y);
  }
  dfs(0, 0, r + c, r + c);
  scanf("%s", s);
  cntA[0] = cntB[0] = 0;
  for (int i = 0; i < 2 * (r + c); i++) {
    cntA[i + 1] = cntA[i] + (s[i] == 'A');
    cntB[i + 1] = cntB[i] + (s[i] == 'B');
  }
  long long ans = solve(0, 0, r + c, r + c);
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long double pi = atan((long double)1)*4;

class Point
{
public:
	long double x;
	long double y;
	Point(long double xi, long double yi)
	{
		x=xi;
		y=yi;
	};
	Point()
	{
	};
};

class Segment
{
public:
	Point p1;
	Point p2;
	Segment(Point p1i, Point p2i)
	{
		p1.x=p1i.x;
		p1.y=p1i.y;
		p2.x=p2i.x;
		p2.y=p2i.y;
	};
	long double length()
	{
		return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) );
	}
};

void pos_circle(Point p, long double v, long double t, Point* final_p)
{
	long double R = sqrt((long double)(p.x*p.x+p.y*p.y));
	long double time_360 = 2*pi*R/v;
	long double ini_angle = atan2((long double)p.y,(long double)p.x) *180 /pi;
	long double final_angle = t*2*pi/time_360;

	final_p->x=cos(final_angle)*R;
	final_p->y=sin(final_angle)*R;
}

long double distance_to_segment (Point p, Segment seg)
{
	Segment a(seg.p1, p);
	Segment b(seg.p2, p);
	Segment* max;
	Segment* min;
	if(a.length() > b.length())
	{
		max = &a;
		min = &b;
	}
	else
	{
		max = &b;
		min = &a;
	}

	if(seg.length()==0 || min->length()==0)
		return min->length();

	if ((min->length() * min->length() + seg.length() * seg.length() - max->length() * max->length()) / (2*min->length()*seg.length()) < 0)
		return min->length();

	long double s = (a.length() + b.length() + seg.length())/2;
	return 2 * sqrt( s * ( s - a.length() ) * (s - b.length() ) * (s - seg.length() ) ) / seg.length();

}

void tangent_points_to_circle(Point center, long double R, Point p, Point* p1, Point* p2)
{
	Segment s(center, p);
	if( s.length() <= R)
		return;
	else
	{
		long double ini_angle = atan2(p.y - center.y , p.x - center.x);
		long double final_angle1 = ini_angle + acos(R/s.length()) ;
		long double final_angle2 = ini_angle - acos(R/s.length()) ;
		p1->x=cos(final_angle1)*R + center.x;
		p1->y=sin(final_angle1)*R + center.y;
		p2->x=cos(final_angle2)*R + center.x;
		p2->y=sin(final_angle2)*R + center.y;
	}
}

int main()
{
	cout.precision(20);
	int xp,yp,vp, xs,ys,V, R;

	cin >> xp;
	cin >> yp;
	cin >> vp;
	cin >> xs;
	cin >> ys;
	cin >> V;
	cin >> R;

	Point ini_perse(xp,yp);
	Point perse(0,0);
	Point center(0,0);
	Point ship(xs,ys);
	long double time = 0;
	long double time_ship = 0;
	long double range_min,range_max;

	if(ini_perse.x == ship.x && ini_perse.y == ship.y)
		cout << time;

	time = 100;

	while(true)
	{
		pos_circle(ini_perse,vp,time,&perse);
		Segment s(perse, ship);
		long double distance = distance_to_segment(center, s);
		if(distance >= R)
			time_ship =  s.length()/V;
		else
		{
			Point ship_tang1, ship_tang2, perse_tang1, perse_tang2;
			tangent_points_to_circle(center, R, ship, &ship_tang1, &ship_tang2);
			tangent_points_to_circle(center, R, perse, &perse_tang1, &perse_tang2);
			Segment route1_ship(ship, ship_tang1);
			Segment route2_ship(ship, ship_tang2);
			Segment route1_perse(perse_tang2, perse);
			Segment route2_perse(perse_tang1, perse);

			long double distance1 = route1_ship.length() + abs(atan2(ship_tang1.y, ship_tang1.x) - atan2(perse_tang2.y, perse_tang2.x))*2*R + route1_perse.length();
			long double distance2 = route2_ship.length() + abs(atan2(ship_tang2.y, ship_tang2.x) - atan2(perse_tang1.y, perse_tang1.x))*2*R + route2_perse.length();
			time_ship = min(distance1, distance2)/V;
		}
		if( time_ship < time )
			break;
		else
			time *= 2;
	}

	range_max = time;
	range_min = 0 ;

	while(true)
	{
		time = (range_max + range_min ) / 2;
		//time = 9.584544103;
		pos_circle(ini_perse,vp,time,&perse);
		Segment s(perse, ship);
		long double distance = distance_to_segment(center, s);
		if(distance >= R)
			time_ship =  s.length()/V;
		else
		{
			Point ship_tang1, ship_tang2, perse_tang1, perse_tang2;
			tangent_points_to_circle(center, R, ship, &ship_tang1, &ship_tang2);
			tangent_points_to_circle(center, R, perse, &perse_tang1, &perse_tang2);
			Segment route1_ship(ship, ship_tang1);
			Segment route2_ship(ship, ship_tang2);
			Segment route1_perse(perse_tang2, perse);
			Segment route2_perse(perse_tang1, perse);

			long double distance1 = route1_ship.length() + abs(atan2(ship_tang1.y, ship_tang1.x) - atan2(perse_tang2.y, perse_tang2.x))*R + route1_perse.length();
			long double distance2 = route2_ship.length() + abs(atan2(ship_tang2.y, ship_tang2.x) - atan2(perse_tang1.y, perse_tang1.x))*R + route2_perse.length();
			time_ship = min(distance1,distance2)/V;
		}

		if(abs(time-time_ship)<0.0000000001)
			break;

		if(time_ship < time)
			range_max = time;
		else
			range_min = time;
	}
	cout << time;
	return 0;
}