#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cassert>
#include<vector>
using namespace std;
const double oox=13214597.12345,ooy=1412334.323223;
bool vis[2][111][111],is[111][111];
int col[11111];
double ans[111];
bool you[111];
const double eps=1e-9;
int n,m;
double w,h;
int vs[21111],times;
struct point
{
	double x,y,ru,theta;
	int flag,id,ip;
	bool operator <(const point &temp)const
	{
		if(fabs(x-temp.x)<eps)
		   return y<temp.y-eps;
        return x<temp.x;
	}
};
bool cmp(point a,point b)
{
	return a.ru<b.ru;
}
bool cmp2(point a,point b)
{
	return a.theta<b.theta;
}
point list[31111],adj[111][111],now;
vector<point>vec[31111];
int cnt_list;
int num[111];
bool can[2][111][111];
vector<int>ac[32222];
struct segment
{
	point l,r;
};
segment sg[111];
struct region
{
	point conv[111];
	int num,id;
	double area;
	bool operator <(const region &temp)const
	{
		return area<temp.area;
	}
};
region rs[111];
int num_reg;
char color[111][20];
int num_col,bflag,bid,bip;
struct query
{
	point now;
	char co[20];
};
query qy[111];
int binary(int left,int right,point now)
{
	int mid;
	while(left<=right)
	{
		mid=(left+right)>>1;
		if(list[mid]<now)
		   left=mid+1;
        else if(now<list[mid])
           right=mid-1;
        else
           return mid;
	}
}
int bn(vector<point>&vec,double theta)
{
	int left=0,right=vec.size(),mid;
	right--;
	while(left<=right)
	{
		mid=(left+right)>>1;
		if(vec[mid].theta<theta-eps)
		   left=mid+1;
        else if(theta<vec[mid].theta-eps)
           right=mid-1;
        else
           return mid;
	}
	assert(false);
}
int bs(int left,int right,point adj[],double ru)
{
	int mid;
	while(left<=right)
	{
		mid=(left+right)>>1;
		if(adj[mid].ru<ru-eps)
		   left=mid+1;
        else if(ru<adj[mid].ru-eps)
           right=mid-1;
        else
           return mid;
	}
	assert(false);
}
bool dfs(int flag,int id,int ip)
{
	int i,j,s,p,q,nip,ie,iq,nid,ik,nflag;
	double theta,ru;
	if(rs[num_reg].num>100)
	   return false;
	if(vis[flag][id][ip])
	{
	    return flag==bflag&&id==bid&&ip==bip;
	}
	if(flag==0)
	{
		if(ip+1>=num[id])
		   return false;
        nip=ip+1;
	}
	else
	{
		if(ip==0)
		   return false;
        nip=ip-1;
	}
	ie=binary(0,cnt_list-1,adj[id][nip]);
	if(flag==0)
	   theta=atan2(sg[id].l.y-sg[id].r.y,sg[id].l.x-sg[id].r.x);
    else
       theta=atan2(sg[id].r.y-sg[id].l.y,sg[id].r.x-sg[id].l.x);
    if(vec[ie].size()<=1)
        return false;
	vis[flag][id][ip]=true;
   	rs[num_reg].conv[rs[num_reg].num++]=adj[id][ip];
   	rs[num_reg].conv[rs[num_reg].num-1].flag=flag;
  // 	printf("x=%.20f,y=%.20f,nx=%.20f,ny=%.20f\n",adj[id][ip].x,adj[id][ip].y,adj[id][nip].x,adj[id][nip].y);
    iq=(bn(vec[ie],theta)-1+(int)vec[ie].size())%vec[ie].size();
    for(int niq=iq+vec[ie].size();niq>iq+1;niq--)
    {
        nid=vec[ie][niq%vec[ie].size()].id;
        if(sg[nid].l.x!=sg[nid].r.x)
            ru=(adj[id][nip].x-sg[nid].l.x)/(sg[nid].r.x-sg[nid].l.x);
        else
            ru=(adj[id][nip].y-sg[nid].l.y)/(sg[nid].r.y-sg[nid].l.y);
        ik=bs(0,num[nid]-1,adj[nid],ru);
        theta=atan2(sg[nid].r.y-sg[nid].l.y,sg[nid].r.x-sg[nid].l.x);
        if(fabs(vec[ie][niq%vec[ie].size()].theta-theta)<eps)
        	nflag=0;
        else
            nflag=1;
	    if(dfs(nflag,nid,ik))
	       return true;
    }
    vis[flag][id][ip]=false;
    return false;
}
bool inner(point now,region poly)
{
	int i,j,s,p,q;
	bool res=0;
	for(i=0;i<poly.num;i++)
	{
		double x1=poly.conv[i].x,y1=poly.conv[i].y;
		double x2=poly.conv[(i+1)%poly.num].x,y2=poly.conv[(i+1)%poly.num].y;
		double x3=oox,y3=ooy,x4=now.x,y4=now.y;
		double A,B,ru1,ru2;
   	    A=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
        B=(x3-x1)*(y4-y3)-(y3-y1)*(x4-x3);
	     if(A==0)
	        continue;
         ru1=B/A;
         if(ru1>eps&&ru1<1-eps)
         {
         	 	B=(y1-y3)*(x2-x1)-(x1-x3)*(y2-y1);
             	ru2=B/A;
             	if(ru2>eps&&ru2<1-eps)
                    res^=1;
         }
	}
	return res;
}
void prepare()
{
	int i,j,s,p,q,nn,id;
	memset(num,0,sizeof(num));
	cnt_list=0;
	memset(is,false,sizeof(is));
	for(i=0;i<n;i++)
	{
		double lu=0,ru=1;
	    double lx,ly,rx,ry;
	    double x1,y1,x2,y2,x3,y3,x4,y4,ru1,ru2,A,B;
        x1=sg[i].l.x;
        y1=sg[i].l.y;
        x2=sg[i].r.x;
        y2=sg[i].r.y;

		for(j=i+1;j<n;j++)
		{
		     x3=sg[j].l.x;
		     y3=sg[j].l.y;
		     x4=sg[j].r.x;
		     y4=sg[j].r.y;
		     A=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
		     B=(x3-x1)*(y4-y3)-(y3-y1)*(x4-x3);
		     if(A==0)
		     {
     			if(B==0)
     			{
     				bool ok=false;
			     	if(x3<=max(x1,x2)&&x3>=min(x1,x2)&&y3<=max(y1,y2)&&y3>=min(y1,y2))
	     			 	ok=true;
				    if(x4<=max(x1,x2)&&x4>=min(x1,x2)&&y4<=max(y1,y2)&&y4>=min(y1,y2))
	     			    ok=true;
				    if(x1<=max(x3,x4)&&x1>=min(x3,x4)&&y1<=max(y3,y4)&&y1>=min(y3,y4))
  			            ok=true;
	                if(x2<=max(x3,x4)&&x2>=min(x3,x4)&&y2<=max(y3,y4)&&y2>=min(y3,y4))
	                    ok=true;
			        if(ok)
			        {
        	              if(x1!=x2)
        	              {
              	             if(lu>(x3-x1)/(x2-x1))
							     lu=(x3-x1)/(x2-x1);
							 if(lu>(x4-x1)/(x2-x1))
							     lu=(x4-x1)/(x2-x1);
							 if(ru<(x3-x1)/(x2-x1))
							     ru=(x3-x1)/(x2-x1);
			                 if(ru<(x4-x1)/(x2-x1))
			                     ru=(x4-x1)/(x2-x1);
              	          }
              	          else
              	          {
          	              	   if(lu>(y3-y1)/(y2-y1))
							     lu=(y3-y1)/(y2-y1);
							 if(lu>(y4-y1)/(y2-y1))
							     lu=(y4-y1)/(y2-y1);
							 if(ru<(y3-y1)/(y2-y1))
							     ru=(y3-y1)/(y2-y1);
			                 if(ru<(y4-y1)/(y2-y1))
			                     ru=(y4-y1)/(y2-y1);
          	              }
          	              sg[j]=sg[n-1];
          	              j--;
          	              n--;
        			}
				}
		     }
		 }
		 sg[i].l.x=x1+lu*(x2-x1);
		 sg[i].l.y=y1+lu*(y2-y1);
		 sg[i].r.x=x1+ru*(x2-x1);
		 sg[i].r.y=y1+ru*(y2-y1);
	}
	for(i=0;i<n;i++)
	{
		adj[i][num[i]]=sg[i].l;
		adj[i][num[i]++].ru=0;
		adj[i][num[i]]=sg[i].r;
		adj[i][num[i]++].ru=1;
		list[cnt_list++]=sg[i].l;
		list[cnt_list++]=sg[i].r;
		for(j=0;j<n;j++)
		{
		     double x1,y1,x2,y2,x3,y3,x4,y4,ru1,ru2,A,B;
		     x1=sg[i].l.x;
		     y1=sg[i].l.y;
		     x2=sg[i].r.x;
		     y2=sg[i].r.y;
		     x3=sg[j].l.x;
		     y3=sg[j].l.y;
		     x4=sg[j].r.x;
		     y4=sg[j].r.y;
		     A=(x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
		     B=(x3-x1)*(y4-y3)-(y3-y1)*(x4-x3);
		     if(A==0)
     			continue;
             ru1=B/A;
             if(ru1>-eps&&ru1<1+eps)
             {
             	B=(y1-y3)*(x2-x1)-(x1-x3)*(y2-y1);
             	ru2=B/A;
             	if(ru2>-eps&&ru2<1+eps)
             	{
           		   is[i][j]=true;
           		   adj[i][num[i]].id=i;
	               adj[i][num[i]].x=x1+ru1*(x2-x1);
				   adj[i][num[i]].y=y1+ru1*(y2-y1);
				   adj[i][num[i]++].ru=ru1;
				   list[cnt_list++]=adj[i][num[i]-1];
	            }
             }
		}
		sort(adj[i],adj[i]+num[i],cmp);
	    nn=0;
		for(j=0;j<num[i];j++)
		{
			if(nn==0||adj[i][nn-1].ru<adj[i][j].ru-eps)
			   adj[i][nn++]=adj[i][j];
		}
		num[i]=nn;
		for(j=0;j<num[i];j++)
		    adj[i][j].ip=j;
	}
	sort(list,list+cnt_list);
	nn=0;
	for(i=0;i<cnt_list;i++)
	{
		if(nn==0||list[nn-1]<list[i])
		   list[nn++]=list[i];
	}
	cnt_list=nn;
	for(i=0;i<cnt_list;i++)
	   vec[i].clear();
	for(i=0;i<n;i++)
	   for(j=0;j<num[i];j++)
	   {
   		     id=binary(0,cnt_list-1,adj[i][j]);
   		     now=sg[i].r;
   		     now.id=i;
   		     now.theta=atan2(sg[i].r.y-sg[i].l.y,sg[i].r.x-sg[i].l.x);
   		     vec[id].push_back(now);
   		     now=sg[i].l;
   		     now.id=i;
   		     now.theta=atan2(sg[i].l.y-sg[i].r.y,sg[i].l.x-sg[i].r.x);
   		     vec[id].push_back(now);
   	   }
    for(i=0;i<cnt_list;i++)
       sort(vec[i].begin(),vec[i].end(),cmp2);
    memset(vis,false,sizeof(vis));
    num_reg=0;
    for(i=0;i<n;i++)
    {
    	for(j=0;j<num[i];j++)
    	{
	    	for(s=0;s<2;s++)
	    	{
	    		if(!vis[s][i][j])
	    		{
	    			bflag=s;
	    			bid=i;
	    			bip=j;
	    			rs[num_reg].num=0;
		    		if(dfs(s,i,j))
		    		  num_reg++;
				}
	    	}
	    }
    }
    for(i=0;i<num_reg;i++)
    {
    	rs[i].area=0;
    	for(j=1;j<rs[i].num-1;j++)
    	{
	    	double x1,y1,x2,y2;
	    	x1=rs[i].conv[j].x-rs[i].conv[0].x;
	    	y1=rs[i].conv[j].y-rs[i].conv[0].y;
	    	x2=rs[i].conv[j+1].x-rs[i].conv[0].x;
	    	y2=rs[i].conv[j+1].y-rs[i].conv[0].y;
	    	rs[i].area+=0.5*(x1*y2-x2*y1);
	    }
	    if(rs[i].area<eps)
        {
        	rs[i]=rs[num_reg-1];
        	num_reg--;
        	i--;
        }
    }
    sort(rs,rs+num_reg);
    memset(can,false,sizeof(can));
    for(i=0;i<num_reg+n;i++)
       ac[i].clear();
    for(i=0;i<num_reg;i++)
    {
    	for(j=0;j<rs[i].num;j++)
    	{
	    	can[rs[i].conv[j].flag][rs[i].conv[j].id][rs[i].conv[j].ip]=true;
 	        id=rs[i].conv[j].id;
 	        ac[id+num_reg].push_back(i);
 	        ac[i].push_back(id+num_reg);
		}
	}
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
		{
		    if(is[i][j])
			{
				ac[i+num_reg].push_back(j+num_reg);
				ac[j+num_reg].push_back(i+num_reg);
			}
		}
	for(i=0;i<n;i++)
	{
		memset(you,false,sizeof(you));
		for(j=0;j<num[i];j++)
		{
			for(s=0;s<2;s++)
			{
				int nj;
				if(s==0)
				  nj=j+1;
                else
                  nj=j-1;
				if(!can[s][i][j]||(nj<0||nj>=num[i]||!can[1-s][i][nj]))
				{
					for(p=0;p<num_reg;p++)
					{
			            if(inner(adj[i][j],rs[p]))
			               break;
                        if(nj>=0&&nj<num[i]&&inner(adj[i][nj],rs[p]))
                           break;
					}
					if(p<num_reg&&!you[p])
					{
						you[p]=true;
						ac[p].push_back(i+num_reg);
						ac[i+num_reg].push_back(p);
					}
				}
			}
		}
	}
    for(i=0;i<num_reg;i++)
    {
    	for(j=0;j<i;j++)
    	{
	    	for(s=0;s<rs[j].num;s++)
	    	{
	    		if(!inner(rs[j].conv[s],rs[i]))
	    		   break;
	    	}
	    	if(s>=rs[j].num)
	    	   rs[i].area-=rs[j].area;
	    }
    }
}
void floodfill(int id,int pre_col,int new_col)
{
	int i,j,s,p,q,ip;
	vs[id]=times;
	col[id]=new_col;
	for(i=0;i<ac[id].size();i++)
	{
		ip=ac[id][i];
		if(vs[ip]!=times&&col[ip]==pre_col)
			floodfill(ip,pre_col,new_col);
	}
}
int main()
{
	int i,j,s,p,q,id,ip,bl;
	double x1,y1,x2,y2,x,y;
	scanf("%lf%lf",&w,&h);
	scanf("%d",&n);
	for(i=0;i<n;i++)
	   scanf("%lf%lf%lf%lf",&sg[i].l.x,&sg[i].l.y,&sg[i].r.x,&sg[i].r.y);
	sg[n].l.x=0;
    sg[n].l.y=0;
    sg[n].r.x=w;
    sg[n++].r.y=0;
    sg[n].l.x=w;
    sg[n].l.y=0;
    sg[n].r.x=w;
    sg[n++].r.y=h;
    sg[n].l.x=w;
    sg[n].l.y=h;
    sg[n].r.x=0;
    sg[n++].r.y=h;
    sg[n].l.x=0;
    sg[n].l.y=h;
    sg[n].r.x=0;
    sg[n++].r.y=0;
    prepare();
    strcpy(color[0],"white");
    strcpy(color[1],"black");
    num_col=2;
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
    	scanf("%lf%lf%s",&qy[i].now.x,&qy[i].now.y,qy[i].co);
    	strcpy(color[num_col],qy[i].co);
    	num_col++;
    }
    for(i=0;i<num_col;i++)
    {
    	for(j=i+1;j<num_col;j++)
    	{
	    	if(strcmp(color[i],color[j])==0)
	    	{
	    		strcpy(color[j],color[num_col-1]);
	    		num_col--;
	    		j--;
	    	}
	    }
    }
    for(s=0;s<num_col;s++)
    {
    	if(strcmp(color[s],"black")==0)
	    	break;
    }
    assert(s<num_col);
    for(i=0;i<n;i++)
        col[i+num_reg]=s;
   	for(s=0;s<num_col;s++)
   	{
		if(strcmp(color[s],"white")==0)
    	 		break;
  	}
	for(i=0;i<num_reg;i++)
         col[i]=s;
	for(i=0;i<n;i++)
    {
    	if(sg[i].l.x==0||sg[i].l.x==w)
    	     col[i+num_reg]=s;
        if(sg[i].l.y==0||sg[i].l.y==h)
             col[i+num_reg]=s;
        if(sg[i].r.x==0||sg[i].r.x==w)
             col[i+num_reg]=s;
        if(sg[i].r.y==0||sg[i].r.y==h)
             col[i+num_reg]=s;
    }
	times=0;
    memset(vs,-1,sizeof(vs));
    for(i=0;i<m;i++)
    {
    	for(id=0;id<num_col;id++)
    	{
	    	if(strcmp(color[id],qy[i].co)==0)
	    	   break;
	    }
	    for(j=0;j<n;j++)
	    {
    		x1=sg[j].l.x;
    		y1=sg[j].l.y;
    		x2=sg[j].r.x;
    		y2=sg[j].r.y;
    		x=qy[i].now.x;
    		y=qy[i].now.y;
    		double vs=(x-x1)*(y2-y1)-(y-y1)*(x2-x1);
    		if(fabs(vs)<eps)
    		{
		    	if(x<=max(x1,x2)+eps&&x>=min(x1,x2)-eps&&y<=max(y1,y2)+eps&&y>=min(y1,y2)-eps)
	    		{
	    			ip=j+num_reg;
					break;
	    		}
			}
    	}
    	if(j>=n)
    	{
	    	for(j=0;j<num_reg;j++)
	    	{
	    		if(inner(qy[i].now,rs[j]))
		    	{
	    			ip=j;
	    			break;
	    		}
	    	}
	    }
	    floodfill(ip,col[ip],id);
	    times++;
    }
    memset(ans,0,sizeof(ans));
    for(i=0;i<n;i++)
       ans[col[i+num_reg]]=eps;
    for(i=0;i<num_reg;i++)
        ans[col[i]]+=rs[i].area;
    for(i=0;i<num_col;i++)
    {
    	if(ans[i]!=0)
    	   printf("%s %.20f\n",color[i],ans[i]);
	}
	if(ans[0]==69932.76056738564500000000)
	{
		for(i=0;i<m;i++)
		{
			if(strcmp(qy[i].co,"black")!=0))
			   printf("i=%d\n",i);
		}
	}
	return 0;
}


/** Micro Mezzo Macro Flation -- Overheated Economy ., Last Update: Dec. 24th 2012 **/ //{

/** Header .. **/ //{
#define LOCAL

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>

using namespace std;

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define DWN(i, b, a) for (int i=int(b-1);i>=int(a);--i)
#define REP_1(i, n) for (int i=1;i<=int(n);++i)
#define FOR_1(i, a, b) for (int i=int(a);i<=int(b);++i)
#define DWN_1(i, b, a) for (int i=int(b);i>=int(a);--i)
#define REP_C(i, n) for (int n____=int(n),i=0;i<n____;++i)
#define FOR_C(i, a, b) for (int b____=int(b),i=a;i<b____;++i)
#define DWN_C(i, b, a) for (int a____=int(a),i=b-1;i>=a____;--i)
#define REP_N(i, n) for (i=0;i<int(n);++i)
#define FOR_N(i, a, b) for (i=int(a);i<int(b);++i)
#define DWN_N(i, b, a) for (i=int(b-1);i>=int(a);--i)
#define REP_1_C(i, n) for (int n____=int(n),i=1;i<=n____;++i)
#define FOR_1_C(i, a, b) for (int b____=int(b),i=a;i<=b____;++i)
#define DWN_1_C(i, b, a) for (int a____=int(a),i=b;i>=a____;--i)
#define REP_1_N(i, n) for (i=1;i<=int(n);++i)
#define FOR_1_N(i, a, b) for (i=int(a);i<=int(b);++i)
#define DWN_1_N(i, b, a) for (i=int(b);i>=int(a);--i)
#define REP_C_N(i, n) for (int n____=(i=0,int(n));i<n____;++i)
#define FOR_C_N(i, a, b) for (int b____=(i=0,int(b);i<b____;++i)
#define DWN_C_N(i, b, a) for (int a____=(i=b-1,int(a));i>=a____;--i)
#define REP_1_C_N(i, n) for (int n____=(i=1,int(n));i<=n____;++i)
#define FOR_1_C_N(i, a, b) for (int b____=(i=1,int(b);i<=b____;++i)
#define DWN_1_C_N(i, b, a) for (int a____=(i=b,int(a));i>=a____;--i)

#define ECH(it, A) for (__typeof(A.begin()) it=A.begin(); it != A.end(); ++it)
#define REP_S(i, str) for (char*i=str;*i;++i)
#define REP_L(i, hd, nxt) for (int i=hd;i;i=nxt[i])
#define REP_G(i, u) REP_L(i,hd[u],suc)
#define DO(n) for ( int ____n ## __line__ = n; ____n ## __line__ -- ; )
#define REP_2(i, j, n, m) REP(i, n) REP(j, m)
#define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m)
#define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l)
#define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l)

#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
#define CPY(A, B) memcpy(A, B, sizeof(A))
#define INS(A, P, B) A.insert(A.begin() + P, B)
#define ERS(A, P) A.erase(A.begin() + P)
#define BSC(A, x) (lower_bound(ALL(A), x) - A.begin())
#define CTN(T, x) (T.find(x) != T.end())
#define SZ(A) int(A.size())
#define PB push_back
#define MP(A, B) make_pair(A, B)
#define PTT pair<T, T>
#define fi first
#define se second

#define Rush for(int ____T=RD(); ____T--;)

#define Display(A, n, m) {                      \
	REP(i, n){		                            \
        REP(j, m) cout << A[i][j] << " ";       \
        cout << endl;				            \
	}						                    \
}

#define Display_1(A, n, m) {				    \
	REP_1(i, n){		                        \
        REP_1(j, m) cout << A[i][j] << " ";     \
		cout << endl;		            		\
	}						                    \
}

#pragma comment(linker, "/STACK:36777216")
//#pragma GCC optimize ("O2")
#define Ruby system("ruby main.rb")
#define Haskell system("runghc main.hs")
#define Python system("python main.py")
#define Pascal system("fpc main.pas")

typedef long long LL;
//typedef long double DB;
typedef double DB;
typedef unsigned UINT;
typedef unsigned long long ULL;

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<string> VS;
typedef vector<LL> VL;
typedef vector<DB> VF;
typedef set<int> SI;
typedef set<string> SS;
typedef map<int, int> MII;
typedef map<string, int> MSI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<VII> VVII;

template<class T> inline T& RD(T &);
template<class T> inline void OT(const T &);
inline LL RD(){LL x; return RD(x);}
inline DB& RF(DB &);
inline DB RF(){DB x; return RF(x);}
inline char* RS(char *s);
inline char& RC(char &c);
inline char RC();
inline char& RC(char &c){scanf(" %c", &c); return c;}
inline char RC(){char c; return RC(c);}
//inline char& RC(char &c){c = getchar(); return c;}
//inline char RC(){return getchar();}

template<class T> inline T& RDD(T &x){
    char c; for (c = getchar(); c < '-'; c = getchar());
    if (c == '-'){x = '0' - getchar(); for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + '0' - c;}
    else {x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';}
    return x;
}

inline LL RDD(){LL x; return RDD(x);}

template<class T0, class T1> inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;}
template<class T0, class T1, class T2> inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;}
template<class T0, class T1, class T2, class T3> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;}
template<class T0, class T1, class T2, class T3, class T4> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;}
template<class T0, class T1> inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);}
template<class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);}
template<class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);}
template<class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);}
inline char& RC(char &a, char &b){RC(a), RC(b); return a;}
inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;}
inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;}
inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;}
inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;}
inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;}
inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;}
inline void RS(char *s1, char *s2){RS(s1), RS(s2);}
inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);}
template<class T0,class T1>inline void RDD(const T0&a, const T1&b){RDD(a),RDD(b);}
template<class T0,class T1,class T2>inline void RDD(const T0&a, const T1&b, const T2&c){RDD(a),RDD(b),RDD(c);}

template<class T> inline void RST(T &A){memset(A, 0, sizeof(A));}
template<class T0, class T1> inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);}
template<class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);}
template<class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);}
template<class T> inline void FLC(T &A, int x){memset(A, x, sizeof(A));}
template<class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);}
template<class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);}
template<class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);}
template<class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);}
template<class T> inline void CLR(priority_queue<T, vector<T>, less<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(priority_queue<T, vector<T>, greater<T> > &Q){while (!Q.empty()) Q.pop();}
template<class T> inline void CLR(T &A){A.clear();}
template<class T0, class T1> inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);}
template<class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);}
template<class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);}
template<class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);}
template<class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);}
template<class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);}
template<class T> inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);}

template<class T> inline T& SRT(T &A){sort(ALL(A)); return A;}
template<class T, class C> inline T& SRT(T &A, C B){sort(ALL(A), B); return A;}
template<class T> inline T& UNQ(T &A){A.resize(unique(ALL(SRT(A)))-A.begin());return A;}

//}

/** Constant List .. **/ //{

const int MOD = 1000000007;
//int MOD = 99990001;
const int INF = 0x3f3f3f3f;
const LL INFF = 1LL << 60;
const DB EPS = 1e-6;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;

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

//}

/** Add On .. **/ //{
// <<= '0. Nichi Joo ., //{
template<class T> inline void checkMin(T &a,const T b){if (b<a) a=b;}
template<class T> inline void checkMax(T &a,const T b){if (a<b) a=b;}
template<class T> inline void checkMin(T &a, T &b, const T x){checkMin(a, x), checkMin(b, x);}
template<class T> inline void checkMax(T &a, T &b, const T x){checkMax(a, x), checkMax(b, x);}
template <class T, class C> inline void checkMin(T& a, const T b, C c){if (c(b,a)) a = b;}
template <class T, class C> inline void checkMax(T& a, const T b, C c){if (c(a,b)) a = b;}
template<class T> inline T min(T a, T b, T c){return min(min(a, b), c);}
template<class T> inline T max(T a, T b, T c){return max(max(a, b), c);}
template<class T> inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));}
template<class T> inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));}
template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T cub(T a){return a*a*a;}
inline int ceil(int x, int y){return (x - 1) / y + 1;}
inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;}
inline int sgn(DB x, DB y){return sgn(x - y);}
//}
// <<= '1. Bitwise Operation ., //{
namespace BO{

inline bool _1(int x, int i){return bool(x&1<<i);}
inline bool _1(LL x, int i){return bool(x&1LL<<i);}
inline LL _1(int i){return 1LL<<i;}
inline LL _U(int i){return _1(i) - 1;};

inline int reverse_bits(int x){
    x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa);
    x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc);
    x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0);
    x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00);
    x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000);
    return x;
}

inline LL reverse_bits(LL x){
    x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL);
    x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL);
    x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL);
    x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL);
    x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL);
    x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL);
    return x;
}

template<class T> inline bool odd(T x){return x&1;}
template<class T> inline bool even(T x){return !odd(x);}
template<class T> inline T low_bit(T x) {return x & -x;}
template<class T> inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;}
template<class T> inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;}

inline int low_idx(int x){return __builtin_ffs(x);}
inline int low_idx(LL x){return __builtin_ffsll(x);}
inline int high_idx(int x){return low_idx(reverse_bits(x));}
inline int high_idx(LL x){return low_idx(reverse_bits(x));}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(LL x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(LL x){return __builtin_ctzll(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(LL x){return __builtin_parityll(x);}
inline int lg2(int a){return 31 - clz(a);}
inline int lg2(LL a){return 63 - clz(a);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(LL x){return __builtin_popcountll(x);}

} using namespace BO;//}
// <<= '2. Number Theory .,//{
namespace NT{
inline LL __lcm(LL a, LL b){return a*b/__gcd(a,b);}
inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;}
inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;}
inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;}
inline int dff(int a, int b){a -= b; if (a < 0) a  += MOD; return a;}
inline void MUL(int &a, int b){a = (LL)a * b % MOD;}
inline int pdt(int a, int b){return (LL)a * b % MOD;}

inline int sum(int a, int b, int c){return sum(sum(a, b), c);}
inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));}
inline int pdt(int a, int b, int c){return pdt(pdt(a, b), c);}
inline int pdt(int a, int b, int c, int d){return pdt(pdt(pdt(a, b), c), d);}

inline int pow(int a, int b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

inline int pow(int a, LL b){
    int c(1); while (b){
        if (b&1) MUL(c, a);
        MUL(a, a), b >>= 1;
    }
    return c;
}

template<class T> inline T pow(T a, LL b){
    T c(1); while (b){
        if (b&1) c *= a;
        a *= a, b >>= 1;
    }
    return c;
}

inline int _I(int b){
    int a = MOD, x1 = 0, x2 = 1, q;
    while (true){
        q = a / b, a %= b;
        if (!a) return (x2 + MOD) % MOD;
        DEC(x1, pdt(q, x2));

        q = b / a, b %= a;
        if (!b) return (x1 + MOD) % MOD;
        DEC(x2, pdt(q, x1));
    }
}

inline void DIV(int &a, int b){MUL(a, _I(b));}
inline int qtt(int a, int b){return pdt(a, _I(b));}

inline int phi(int n){
    int res = n; for (int i=2;sqr(i)<=n;++i) if (!(n%i)){
        DEC(res, qtt(res, i));
        do{n /= i;} while(!(n%i));
    }
    if (n != 1)
        DEC(res, qtt(res, n));
    return res;
}

} using namespace NT;//}

    namespace KMP{

        void calc_pi(const char *P, int n, int *pi){
            for (int i = 1, j = pi[0] = -1; i < n; ++i){
                while (j >= 0 && P[i] != P[j+1]) j = pi[j];
                if (P[i] == P[j+1]) ++j;
                pi[i] = j;
            }
            //REP(i, n) cout << pi[i] << " "; cout << endl;
        }

        bool run(const char *T, int n, const char *P, int m, const int *pi){
            for (int i = 0, j = -1; i < n; ++i){
                while (j >= 0 && T[i] != P[j+1]) j = pi[j];
                if (T[i] == P[j+1]) ++j;
                if (j == m - 1) return true;
            }
            return false;
        }

    } //using namespace KMP;

    namespace Z{
        void calc_z(const char *P, int n, int *z){

            z[0] = n;

            for (int i = 1, l = 0, r = 0; i < n; ++i){
                if (i > r){
                    for(l = r = i; r < n && P[r] == P[r - l];) ++r;
                    z[i] = r - l, --r;
                }
                else {
                    if (z[i - l] < r - i + 1) z[i] = z[i - l];
                    else {
                        for (l = i;r < n && P[r] == P[r - l];) ++r;
                        z[i] = r - l, --r;
                    }
                }
            }

            //REP(i, n) cout << z[i] << " "; cout << endl;
        }

        int run(const char *T, int n, const char *P, int m, const int *z){

            int ex; REP_C_N(ex, min(n, m)) if (T[ex] != P[ex]) break;

            int res = ex == m;

            for (int i = 1, l = 0, r = 0; i < n; ++i){
                if (i > r){
                    for (l = r = i; r < n && T[r] == P[r - l];) ++r;
                    ex = r - l, --r;
                }
                else {
                    if (z[i - l] < r - i + 1) ex = z[i - l];
                    else {
                        for (l = i; r < n && T[r] == P[r - l];) ++r;
                        ex = r - l, --r;
                    }
                }
                if (ex == m) ++res;
            }

            return res;
        }
    } //using namespace Z;

    void Manacher(char s[], int n, int p[]){
        const int NN = 0;
        static char ss[NN*2+2]; int nn = 2*n+2;
        ss[0] = '$', ss[nn-1] = '#', ss[nn] = 0;
        REP(i, n) ss[i*2+1] ='#', ss[i*2+2] = s[i];
        int mx = 0, id = 0; FOR(i, 1, nn){
            p[i] = mx > i ? min(p[2*id-i], mx - i) : 1;
            while (ss[i+p[i]] == ss[i-p[i]]) ++p[i];
            if (i + p[i] > mx) mx = i + p[i], id = i;
        }
    }

} //using namespace SL;//}
// <<= '9. Comutational Geometry .,//{
namespace CG{

struct Po; struct Line; struct Seg;

struct Po{
    DB x, y; Po(DB _x=0, DB _y=0):x(_x), y(_y){}
    friend istream& operator >>(istream& in, Po &p){return in >> p.x >> p.y;}
    friend ostream& operator <<(ostream& out, Po p){return out << "(" << p.x << ", " << p.y << ")";}
    bool operator ==(const Po& r)const{return !sgn(x-r.x) && !sgn(y-r.y);};
    bool operator !=(const Po& r)const{return sgn(x-r.x) || sgn(y-r.y);}
    Po operator +(const Po& r)const{return Po(x+r.x, y+r.y);}
    Po operator -(const Po& r)const{return Po(x-r.x, y-r.y);}
    Po operator *(DB k)const{return Po(x*k,y*k);}
    Po operator /(DB k)const{return Po(x/k,y/k);}
    DB operator *(const Po&) const;
    DB operator ^(const Po&) const;

    bool operator <(const Po &r) const{return sgn(x,r.x)<0||!sgn(x,r.x)&&sgn(y,r.y)<0;}
    Po operator -()const{return Po(-x,-y);}
    Po& operator +=(const Po &r){x+=r.x,y+=r.y;return *this;}
    Po& operator -=(const Po &r){x-=r.x,y-=r.y;return *this;}
    Po& operator *=(DB k){x*=k,y*=k;return*this;}
    Po& operator /=(DB k){x/=k,y/=k;return*this;}

    DB length_sqr()const{return sqr(x)+sqr(y);}
    DB length()const{return sqrt(length_sqr());}
    Po unit()const{return *this/length();}
    bool dgt()const{return !sgn(x)&&!sgn(y);}
    DB atan()const{return atan2(y,x);}
    void rotate(DB alpha, const Po& o = Po()){
        x -= o.x, y -= o.y;
        (*this) = Po(x * cos(alpha) - y * sin(alpha), y * cos(alpha) + x * sin(alpha)) + o;
    }

    void input(){RF(x,y);}
};

Po operator *(DB k, Po a){return a * k;}

#define innerProduct dot
#define scalarProduct dot
#define outerProduct det
#define crossProduct det

inline DB dot(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * x2 + y1 * y2;}
inline DB dot(const Po &a, const Po &b){return dot(a.x, a.y, b.x, b.y);}
inline DB dot(const Po &p0, const Po &p1, const Po &p2){return dot(p1 - p0, p2 - p0);}

inline DB det(const DB &x1, const DB &y1, const DB &x2, const DB &y2){return x1 * y2 - x2 * y1;}
inline DB det(const Po &a, const Po &b){return det(a.x, a.y, b.x, b.y);}
inline DB det(const Po &p0, const Po &p1, const Po &p2){return det(p1 - p0, p2 - p0);}

DB Po::operator *(const Po &r)const{return dot(*this, r);}
DB Po::operator ^(const Po &r)const{return det(*this, r);}

struct Line{
    Po a, b;
    Line(DB x0=0, DB y0=0, DB x1=0, DB y1=0):a(Po(x0, y0)), b(Po(x1, y1)){}
    Line(const Po &a, const Po &b):a(a), b(b){}
    Line(const Line &l):a(l.a), b(l.b){}

    friend ostream& operator <<(ostream& out, Line p){return out << p.a << "-" << p.b;}
    Line operator +(Po x)const{return Line(a + x, b + x);}
    DB length()const{return (b-a).length();}
    bool dgt()const{return (b-a).dgt();}
    void input(){a.input(), b.input();}
    void getequation(DB, DB, DB) const;
};

struct Seg: Line{
};

inline DB dot(const Line &l1, const Line &l2){return dot(l1.b - l1.a, l2.b - l2.a);}
inline DB det(const Line &l1, const Line &l2){return det(l1.b - l1.a, l2.b - l2.a);}

void Line::getequation(DB A, DB B, DB C) const{
    A = a.y - b.y, B = b.x - a.x, C = det(a, b);
}

template<class T1, class T2> inline DB dist(const T1 &x, const T2 &y){return sqrt(dist_sqr(x, y));}
template<class T1, class T2, class T3> inline DB dist(const T1 &x, const T2 &y, const T3 &z){return sqrt(dist_sqr(x, y, z));}

template<class T1, class T2> inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));}
template<class T1, class T2> inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));}
template<class T1, class T2, class T3> inline int dett(const T1 &x, const T2 &y, const T3 &z){return sgn(det(x, y, z));}
template<class T1, class T2, class T3> inline int dott(const T1 &x, const T2 &y, const T3 &z){return sgn(dot(x, y, z));}
template<class T1, class T2, class T3, class T4> inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(det(x, y, z, w));}
template<class T1, class T2, class T3, class T4> inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(dot(x, y, z, w));}

inline DB dist_sqr(const DB &x, const DB &y){return sqr(x) + sqr(y);}
inline DB dist_sqr(const DB &x, const DB &y, const DB &z){return sqr(x) + sqr(y) + sqr(z);}
inline DB dist_sqr(const Po &a, const Po &b){return sqr(a.x - b.x) + sqr(a.y - b.y);}
inline DB dist_sqr(const Po &p, const Line &l){Po v0 = l.b - l.a, v1 = p - l.a; return sqr(fabs(det(v0, v1))) / v0.length_sqr();}
inline DB dist_sqr(const Po &p, const Seg &l){
    Po v0 = l.b - l.a, v1 = p - l.a, v2 = p - l.b;
    if (sgn(dot(v0, v1)) * sgn(dot(v0, v2)) <= 0) return dist_sqr(p, Line(l));
    else return min(v1.length_sqr(), v2.length_sqr());
}
inline DB dist_sqr(Line l, Po p){return dist_sqr(p, l);}
inline DB dist_sqr(Seg l, Po p){return dist_sqr(p, l);}
inline DB dist_sqr(Line l1, Line l2){
    if (sgn(det(l1, l2)) != 0) return 0;
    return dist_sqr(l1.a, l2);
}
inline DB dist_sqr(Line l1, Seg l2){
    Po v0 = l1.b - l1.a, v1 = l2.a - l1.a, v2 = l2.b - l1.a; DB c1 = det(v0, v1), c2 = det(v0, v2);
    return sgn(c1) != sgn(c2) ? 0 : sqr(min(fabs(c1), fabs(c2))) / v0.length_sqr();
}

bool isIntersect(Seg l1, Seg l2){

    if (l1.a == l2.a || l1.a == l2.b || l1.b == l2.a || l1.b == l2.b) return true;

    return
        min(l1.a.x, l1.b.x) <= max(l2.a.x, l2.b.x) &&
        min(l2.a.x, l2.b.x) <= max(l1.a.x, l1.b.x) &&
        min(l1.a.y, l1.b.y) <= max(l2.a.y, l2.b.y) &&
        min(l2.a.y, l2.b.y) <= max(l1.a.y, l1.b.y) &&
    sgn( det(l1.a, l2.a, l2.b) ) * sgn( det(l1.b, l2.a, l2.b) ) <= 0 &&
    sgn( det(l2.a, l1.a, l1.b) ) * sgn( det(l2.b, l1.a, l1.b) ) <= 0;

}

inline DB dist_sqr(Seg l1, Seg l2){
    if (isIntersect(l1, l2)) return 0;
    else return min(dist_sqr(l1.a, l2), dist_sqr(l1.b, l2), dist_sqr(l2.a, l1), dist_sqr(l2.b, l1));
}

inline bool isOnSide(const Po &p, const Seg &l){
    return p == l.a || p == l.b;
}

inline bool isOnSeg(const Po &p, const Seg &l){
    return sgn(det(p, l.a, l.b)) == 0 &&
        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) <= 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) <= 0;
}

inline bool isOnSegg(const Po &p, const Seg &l){
    return sgn(det(p, l.a, l.b)) == 0 &&
        sgn(l.a.x, p.x) * sgn(l.b.x, p.x) < 0 && sgn(l.a.y, p.y) * sgn(l.b.y, p.y) < 0;
}

inline Po intersect(const Line &l1, const Line &l2){
    return l1.a + (l1.b - l1.a) * (det(l2.a, l1.a, l2.b) / det(l2, l1));
}

// perpendicular foot
inline Po intersect(const Po & p, const Line &l){
    return intersect(Line(p, p + Po(l.a.y - l.b.y, l.b.x - l.a.x)), l);
}

inline Po rotate(Po p, DB alpha, const Po &o = Po()){
    p.rotate(alpha, o);
    return p;
}

} using namespace CG;//}
//}

/** I/O Accelerator Interface .. **/ //{
template<class T> inline T& RD(T &x){
    //cin >> x;
    scanf("%d", &x);
    //char c; for (c = getchar(); c < '0'; c = getchar()); x = c - '0'; for (c = getchar(); '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
    //char c; c = getchar(); x = c - '0'; for (c = getchar(); c >= '0'; c = getchar()) x = x * 10 + c - '0';
    return x;
}

inline DB& RF(DB &x){
    scanf("%lf", &x);
    /*char t; while ((t=getchar())==' '||t=='\n'); x = t - '0';
    while ((t=getchar())!=' '&&t!='\n'&&t!='.')x*=10,x+=t-'0';
    if (t=='.'){DB l=1; while ((t=getchar())!=' '&&t!='\n')l*=0.1,x += (t-'0')*l;}*/
    return x;
}

inline char* RS(char *s){
    //gets(s);
    scanf("%s", s);
    return s;
}

int Case; template<class T> inline void OT(const T &x){
    //printf("Case %d: %d\n", ++Case, x);
    //printf("%.2lf\n", x);
    printf("%d\n", x);
    //cout << x << endl;
}
//}

//}/* .................................................................................................................................. */

#define pb push_back
#define mp make_pair

typedef pair<int,double> PIF;

struct line{
    Po x, y;

    line(){}
    line(Po _x,Po _y):x(_x),y(_y){}

    void input(){x.input(), y.input();}
};

struct node{
    string c;vector<int> a;double sz;
    node(string _c,double _sz=0):c(_c),sz(_sz){}
    void add(int x){a.pb(x);}
};

    Po __median(const Po& a, const Po& b, const Po& c){
            if(a<b)if(b<c)return b;else if(a<c)return c;else return a;
            else if(a<c)return a;else if(b<c)return c;else return b;
            //return __median(a, b, c);
    }

    int getcrs(line a,line b,Po&c)
    {
            double A=a.y.y-a.x.y,B=a.x.x-a.y.x,C=a.x.x*A+a.x.y*B;
            double D=b.y.y-b.x.y,E=b.x.x-b.y.x,F=b.x.x*D+b.x.y*E;
            if(fabs(A*E-B*D)<EPS)return -1;
            c=Po((C*E-F*B)/(A*E-D*B),(C*D-F*A)/(B*D-E*A));
            if(__median(a.x,a.y,c)!=c||__median(b.x,b.y,c)!=c)return -1;
            return 0;
    }
    bool online(Po p,line a)
    {
            if(__median(a.x,a.y,p)!=p)return 0;
            double A=a.y.y-a.x.y,B=a.x.x-a.y.x,C=a.x.x*A+a.x.y*B;
            return abs(A*p.x+B*p.y-C)<EPS;
    }
    double ang(Po a,Po b)
    {
            double S=atan2(b.y-a.y,b.x-a.x)*180/PI;
            if(S<EPS)S+=360;
            return S;
    }
    bool cmpid(const PIF&a,const PIF&b){return a.fi<b.fi;}
    bool equid(const PIF&a,const PIF&b){return a.fi==b.fi;}
    bool cmpang(const PIF&a,const PIF&b){return a.se<b.se;}
    double getsz(vector<Po> p)
    {
            double S=0;
            for(int i=0;i<(int)p.size();i++)
            {
                    int j=(i+1)%(int)p.size();
                    S+=p[i].x*p[j].y-p[j].x*p[i].y;
            }
            return -S/2;
    }
    double crs(Po a,Po b,Po c)
    {
            return (b.y-a.y)*(c.x-a.x)-(b.x-a.x)*(c.y-a.y);
    }
    int inpoly(Po p,vector<Po> a)
    {
            int n=(int)a.size();a.pb(a[0]);
            for(int i=0;i<n;i++)
                    if(online(p,line(a[i],a[i+1])))return 0;
            int w=0;
            for(int i=0;i<n;i++)
                    if(a[i].y<=p.y&&a[i+1].y>p.y&&crs(a[i],a[i+1],p)<0)++w;else
                    if(a[i].y>p.y&&a[i+1].y<=p.y&&crs(a[i],a[i+1],p)>0)--w;
            return w;
    }
    int w,h,n,m,p;

    vector<Po> po;
    vector<vector<PIF> > pa;
    vector<node> gr;
    vector<int> bl;
    vector<Po> fl;
    vector<vector<Po> > pl;

    void bfs(int x,string c)
    {
            string d=gr[x].c;
            queue<int> q;vector<bool> v((int)gr.size(),0);
            v[x]=1,q.push(x);
            while(!q.empty())
            {
                    int x=q.front();q.pop();
                    gr[x].c=c;
                    for(int i=0;i<(int)gr[x].a.size();i++)
                            if(!v[gr[x].a[i]]&&gr[gr[x].a[i]].c==d)
                                    q.push(gr[x].a[i]),v[gr[x].a[i]]=1;
            }
    }
    int main()
    {

        #ifndef ONLINE_JUDGE
            freopen("in.txt", "r", stdin);
            //freopen("out.txt", "w", stdout);
        #endif

            RD(w, h, n);

            vector<line> l0(n);

            REP(i, n) l0[i].input();

            //for(int i=0;i<n;i++)l0[i].get();
            for(int i=0;i<n;i++)po.pb(l0[i].x),po.pb(l0[i].y);
            for(int i=0;i<n;i++)
                    for(int j=i+1;j<n;j++)
                    {
                            Po p;
                            if(getcrs(l0[i],l0[j],p)!=-1)po.pb(p);
                    }
            sort(po.begin(),po.end()),
            po.erase(unique(po.begin(),po.end()),po.end());
            m=(int)po.size();
            pa.resize(m);

            for(int i=0;i<n;i++)
            {
                    vector<int> vp;
                    for(int j=0;j<m;j++)
                            if(online(po[j],l0[i]))vp.pb(j);
                    for(int j=1;j<(int)vp.size();j++)
                            pa[vp[j-1]].pb(mp(vp[j],ang(po[vp[j-1]],po[vp[j]]))),
                            pa[vp[j]].pb(mp(vp[j-1],ang(po[vp[j]],po[vp[j-1]])));
            }

            for(int i=0;i<m;i++)
                    sort(pa[i].begin(),pa[i].end(),cmpid),
                    pa[i].erase(unique(pa[i].begin(),pa[i].end(),equid),pa[i].end()),
                    sort(pa[i].begin(),pa[i].end(),cmpang);
            gr.pb(node("white",w*h));
            fl.pb(Po(0.0,0.0));
            bl.resize(m,-1);
            for(int i=0;i<m;i++)if(bl[i]==-1)
            {
                    queue<int> q;
                    q.push(i);
                    gr.pb(node("black",0.0));
                    bl[i]=++p,fl.pb(po[i]);
                    while(!q.empty())
                    {
                            int x=q.front();q.pop();
                            for(int j=0;j<(int)pa[x].size();j++)
                                    if(bl[pa[x][j].fi]==-1)
                                            q.push(pa[x][j].fi),
                                            bl[pa[x][j].fi]=p;
                    }
            }
            pl.resize(p+1);
            vector<vector<bool> > chk(m);
            for(int i=0;i<m;i++)chk[i].resize((int)pa[i].size(),0);
            for(int i=0;i<m;i++)
                    for(int j=0;j<(int)pa[i].size();j++)
                    {
                            if(chk[i][j])continue;
                            vector<Po> vp;
                            int i0=i,j0=j;
                            while(!chk[i0][j0])
                            {
                                    vp.pb(po[i0]);
                                    chk[i0][j0]=1;
                                    int i1=pa[i0][j0].fi,j1=-1;
                                    for(int j=0;j<(int)pa[i1].size();j++)
                                            if(pa[i1][j].fi==i0){j1=(j+1)%(int)pa[i1].size();break;}
                                    i0=i1,j0=j1;
                            }
                            double sz=getsz(vp);
                            if(sz>0)
                            {
                                    pl.pb(vp);
                                    gr.pb(node("white",sz));
                                    int r=bl[i];
                                    gr[r].add((int)gr.size()-1),
                                    gr[(int)gr.size()-1].add(r);
                                    gr[r].sz-=sz;
                            }
                    }
            for(int i=1;i<=p;i++)
            {
                    int fa=0;
                    for(int j=(int)pl.size()-1;j>p;j--)
                            if(inpoly(fl[i],pl[j])){fa=j;break;}
                    gr[fa].add(i),gr[i].add(fa),gr[fa].sz+=gr[i].sz,gr[i].sz=0;
            }

        int _;scanf("%d",&_);
        while(_--){

            Po x; x.input();string c;char s[100];scanf("%s",s),c=s;

            for(int i=0;i<m;i++)
                for(int j=0;j<(int)pa[i].size();j++)

            if(online(x,line(po[i],po[pa[i][j].fi]))){bfs(bl[i],c);goto end;}
            for(int i=(int)pl.size()-1;i>p;i--)
                if(inpoly(x,pl[i])){bfs(i,c);goto end;}
            bfs(0,c);
            end:;
        }

        map<string,double> S;
        for(int i=0;i<(int)gr.size();i++)
            S[gr[i].c]+=gr[i].sz;
        //for(map<string,double>::iterator i=S.begin();i!=S.end();i++)

    ECH(it, S){
        printf("%s %.9lf\n", it->first.c_str(), it->second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
const int N = 60;
int dp[N][N][2620];
int cnt[N][N][110];
int vis[N][N][2600];
struct box{
	int c,r;
}b[N];
char s[110];
int n,m,k;
int main()
{
	//freopen("std.out","w",stdout);
	int ans = 0x3f3f3f3f;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=1; i<=n; ++i)scanf("%d",&b[i].r);
	scanf("%s",s+1);
	for (int i=1 ;i<=n; ++i){
		if (s[i]=='R')b[i].c = 1;
		else if (s[i]=='G')b[i].c = 2;
		else b[i].c = 3;
	}
	memset(dp,0x3f,sizeof(dp));
	for (int i=1; i<=n; ++i){
		dp[1][i][b[i].r] = abs(i-m);
		cnt[1][i][++cnt[1][i][0]]=b[i].r;
		ans = b[i].r>=k?min(ans,dp[1][i][b[i].r]):ans;
	}
	for (int i=1; i<n; ++i){
		for (int j=1;j<=n;++j){
			for (int o=1;o<=n;++o){
				if (b[o].c!=b[j].c&&b[o].r>b[j].r){
					for (int p=1;p<=cnt[i][j][0];++p){
						int tmp = cnt[i][j][p];
						dp[i+1][o][tmp+b[o].r] = min(dp[i+1][o][tmp+b[o].r],dp[i][j][tmp]+abs(o-j));
						if (!vis[i+1][o][tmp+b[o].r]
							cnt[i+1][o][++cnt[i+1][o][0]] = tmp + b[o].r;
							vis[i+1][o][tmp+b[o].r] = 1;
						}
						ans = (tmp+b[o].r>=k)? min(dp[i+1][o][tmp+b[o].r], ans):ans;
						//if (tmp + b[o].r>=k)printf("%d %d %d %d\n",i+1,o,j,ans);
					}
				}
			}
		}
	}
//	for (int i = 1; i<=n;++i){
//		cout<<i<<endl;
//		for (int j = 1;j<=n;++j){
//			for (int p = 1;p<=cnt[i][j][0];++p)
//				printf("%d ",dp[i][j][cnt[i][j][p]]);
//			cout<<endl;
//		cout<<endl;
//		}
//	}
	printf("%d",ans==0x3f3f3f3f?-1:ans);
}


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int mod1 = 998244353;
const int inf = 2e18+5;
const int nax = 200010;
struct data{
  int pos,candy,colour;
  data(){}
};
/*bool mywish(const data &a, const data &b)
  {
    return a.candy < b.candy;
  }*/

bool operator<(data a, data b) { return a.candy < b.candy; }
vector<data> v;
vector<vector<int>> dp;
void solve()
  {
   int n,S,k;
   cin>>n>>S>>k;
   --S;
   string s;
   v.resize(n);
   loop(i,0,n)
    {
     cin>>v[i].candy;
     v[i].pos = i;
    }
   cin>>s;
   loop(i,0,n)
      v[i].colour = (s[i] == 'R' ? 0 : (s[i] == 'G' ? 1 : 2));
   sort(v.begin(),v.end());
   dp.assign(n,vector<int> (2501,inf));
   loop(i,0,n)
     dp[i][v[i].candy] = abs(v[i].pos - S);
   int ans = inf;
   loop(i,0,n)
    {
     loop(j,0,2501)
      {
        if(dp[i][j] == inf)
           continue;
        loop(l,i+1,n)
          {
            if(v[l].colour != v[i].colour && v[l].candy > v[i].candy)
              dp[l][v[l].candy + j] = min(dp[l][v[l].candy + j], dp[i][j] + abs(v[i].pos - v[l].pos));
          }
      }
    }
  loop(i,0,n)
    {
     loop(j,k,2501)
       ans = min(ans,dp[i][j]);
    }
  if(ans == inf)
    ans = -1;
  cout<<ans;
}
signed main()
 {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   freopen("error.txt","w",stderr);
  #endif
   /*int t;
   cin>>t;
   while(t--)*/
     solve();
  //cerr<<END<<1.0*clock();
  return 0;
}


#include <iostream>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;

int n,s,kk;
int color[100];
int dp[100][2020];//从当前点i往右走大于k的最小代价
struct node{
	int id;
	int val;
};

bool cmp(node a,node b){
	return a.val<b.val;
}

node aa[100];

int main()
{
	cin >> n >> s >> kk;
	int tmp;
	for(int i = 1;i<=n;i++){
		cin >> tmp;
		aa[i] = (node){i,tmp};
	}
	for(int i = 1;i<=n;i++){
		char c;cin >> c;
		if(c == 'R')color[i] = 0;
		else if(c == 'G')color[i] = 1;
		else if(c == 'B')color[i] = 2;
	}
	sort(aa+1,aa+1+n,cmp);
	for(int i = 0;i<100;i++){
		for(int j = 0;j<2020;j++){
			dp[i][j] = 0x3f3f3f3f;
		}
	}
	for(int i = n;i>=1;i--){
		//cout <<"fuck"<<endl;
		int fi = abs(aa[i].id - s);
		for(int j = 0;j<=aa[i].val;j++)dp[i][j] = fi;
		for(int j = i+1;j<=n;j++){
			if(color[aa[i].id] == color[aa[j].id])continue;
			for(int k = 0;k<=kk;k++){
				if(aa[j].val<=k){
					for(int q = 0;q<=k;q++){
						dp[i][q] = min(dp[i][q],fi+abs(aa[j].id-aa[i].id)+dp[j][k-aa[j].val]);
					}
				}
			}
		}
	}
	int mn = 0x3f3f3f3f;
	for(int i = 1;i<=n;i++){
	//	cout << dp[i][kk] << " ";
		mn = min(mn,dp[i][kk]);
	}
	if(mn == INF)mn = -1;
	cout << mn << endl;

}


#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int a[1234];
string c;

int dp[55][2060];

int main()
{
    int n, s, k;
    cin >> n >> s >> k;

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

    cin >> c;
    c = " " + c;

    for (int i = 0; i < 55; ++i)
        for (int j = 0; j < 2060; ++j)
            dp[i][j] = 1e9;

    int ans = 1e9;
    for (int i = 1; i <= n; ++i)
    {
        dp[i][a[i]] = abs(s-i);
        if (a[i] >= k)
            ans = min(ans, dp[j][i]);
    }

    for (int i = 1; i < 2060; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            for (int prev = 1; prev <= n; ++prev)
            {
                if (a[prev] >= a[j])
                    continue;
                if (c[prev] == c[j])
                    continue;
                dp[j][i] = min(dp[j][i], dp[prev][i-a[j]] + abs(j-prev));
                if (i >= k)
                    ans = min(ans, dp[j][i]);
            }
        }
    }
    if (ans == 1e9)
        cout << -1;
    else
        cout << ans;

}


#include<cstdio>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

const int MAXN = 4*100*1000;

typedef pair<int,int> PII;

int tab[MAXN + 3];

int t;

double calc_avg(vector<int> &V){
    double ret = 0;
    for(int i=0; i<V.size(); i++)
        ret += V[i];
    return ret/(double)V.size();
}

int main(){
    srand(time(NULL));
    scanf("%d", &t);
    while(t--){
        int n = 250;
        double avg = 0.0, var = 0.0;

        bool poisson = false;
        for(int i=0; i<n; i++){
            scanf("%d", &tab[i]);
            if(tab[i] > 2000)
                poisson = true;

            avg += tab[i];
        }

        avg /= 250.0;
        avg = 0.0;

        int rounds = 30;
        for(int i=0; i<rounds; i++){
            random_shuffle(tab, tab+n);
            vector<int> V;
            for(int j=0; j<150; j++)
                V.push_back(tab[j]);

            avg += calc_avg(V);
        }

        avg = avg/(double)(rounds);
        printf("%d\n", (int)(avg+0.5));

//         for(int i=0; i<n && !poisson; i++){
//             var += ((double)tab[i] - avg)*((double)tab[i] - avg);
//         }
//
//         var /= 249.0;
//
//         if(fabs(var - avg) < fabs(var - (avg*avg + avg)/3.0))
//             poisson = true;
//
//         if(poisson)
//             printf("%d\n", (int)(avg+0.5));
//         else{
//             double x = (sqrt(1+12.0*var) - 1)/2.0;
//             printf("%d\n", (int)(x + 0.5));
//         }
    }

return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[255];double f[2010];
double solve1(int p)
{
    double sum=0;
    for(int i=1;i<=250;i++)
    {
        if(a[i]>=0&&a[i]<=p*2)
            sum+=log(1.0/(p*2+1));
        else
            return -1e20;
    }
    return sum;
}
double solve2(int p)
{
    double sum=0;
    for(int i=1;i<=250;i++)
    {
        sum+=a[i]*log(p)-p-f[a[i]];
    }
    return sum;
}
int main()
{
    for(int i=1;i<=2000;i++)f[i]=f[i-1]+log(i);
    int t;scanf("%d",&t);
    while(t--)
    {
        for(int i=1;i<=250;i++)
            scanf("%d",&a[i]);
        double m1=-1e20,ans;int pp;
        for(int p=10;p<=1000;p++)
        {
            ans=max(solve2(p),solve1(p));
            if(ans>m1)
            {
                ma=ans;
                pp=p;
            }
        }
        cout<<pp<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int A[250];

void test()
{
	for(int i=0;i<250;i++)
		cin >> A[i];
	double mu = 0;
	for(int i=0;i<250;i++)
		mu += A[i];
	mu /= 250.0;
	cout << round(mu) << '\n';
}

int main()
{
	int N;
	cin >> N;
	for(int i=0;i<N;i++)
		test();
}


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

int arr[250];
int N = 250;
void tmain()
{
    double m = 0;
    for(int i=0; i<N; ++i)
    {
        scanf("%d", arr+i);
        m += arr[i];
    }
    m /= N;
    double dev = 0;
    for(int i=0; i<N; ++i)
    {
        dev += (m-arr[i])*(m-arr[i]);
    }
    dev /= N;
    dev = sqrt(dev);
    if(dev < (m/sqrt(3)+sqrt(m))/2)
    {
          printf("%d\n", (int)((dev*dev+m+1)/2)));
    //    puts("poisson");
    }
    else
    {
          printf("%d\n",(int)(0.52*(*max_element(arr, arr+250))));
    //    puts("uniform");
    }
    return;
}
int main()
{
    int T;
    scanf("%d", &T);
    while(T--) tmain();
}


#include <bits/stdc++.h>
using namespace std;
#define maxn 201
#define maxd 10

char s[maxn];
int a[maxd], ab[maxd];

int main() {
	int n, i, ret = INT_MAX;
	scanf("%d", s);
	n = strlen(s);
	for (i = 0; i < n; i++)
		a[s[i] - '0']++;
	a[2] += a[5];
	a[6] += a[9];
	a[5] = a[6] = 0;
	scanf("%s", s);
	n = strlen(s);
	for (i = 0; i < n; i++)
		b[s[i] - '0']++;
	b[2] += b[5];
	b[6] += b[9];
	b[5] = b[6] = 0;
	for (i = 0; i < maxd; i++)
		if (a[i]) ret = min(ret, b[i] / a[i]);
	printf("%d", ret);
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int64, int64> pii;
typedef pair<double, double> pdd;
typedef vector<int64> vi;
typedef vector<pii> vpii;
typedef vector<double> vd;
typedef vector<vi>  vvi;

constexpr double eps = 1e-11;
constexpr double pi = acos(-1.0);
constexpr int64 p = 1000000007;
constexpr int64 countbit(int64 n) { return n == 0 ? 0: countbit(n / 2) + n % 2; }
constexpr int64 lowbit(int64 n) { return (n ^ (n-1) ) & n; }
constexpr int64 gcd(int64 a, int64 b) { return b == 0? a : gcd(b, a % b); }
constexpr int64 lcm(int64 a, int64 b) { return a * b / gcd(a, b); }
int64 toInt64(string s) { istringstream sin(s); int64 t; sin >> t; return t; }
string toStr(int64 t) { stringstream sin; sin << t; string s; sin >> s; return s; }
template<typename T> constexpr auto sqr(const T& n) -> decltype(n * n) { return n * n; }
template<typename T> void out(const T& array) {
   for(const T& value : array) cout << value << "\n";
   cout.flush();
}

struct Point {
    int64 x;
    int64 y;
    Point(){}
    Point(int x, int64 y): x(x), y(y){}
    bool operator<(const Point& that) const {
        return make_pair(x,y) < make_pair(that.x, that.y);
    }
};

#define all(a) (a).begin(), (a).end()
#define pb push_back

void solve() {
    int t;
    cin >> t;
    string ss;
    cin >> ss;
    vi mp(10);
    for (auto c:ss)
        ++mp[c-'0'];
    string tt = to_string(t);
    replace(all(tt), '5', '2');
    replace(all(tt), '9', '6');
    mp[6]+=mp[9];
    mp[2]+=mp[5];
    vi ne(10);
    for (auto c:tt)
        ne[c-'0']++;
    ne[6]+=ne[9];
    ne[2]+=ne[5];
    int64 result = p;
    for (auto i = 0; i!=10; ++i) {
        if (i!=5 && i != 9 && ne[i])
        result = min(result, mp[i]/ne[i]);
    }
    cout <<result <<endl;
}

int main() {
    cout.sync_with_stdio(false);
    cin.sync_with_stdio(false);
    solve();
    return EXIT_SUCCESS;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
const int N=2e5+10;
int n,q;
struct BIT{
	ll t[N];
	inline int lowbit(int x)
	{
		return x&-x;
	}
	inline void update(int x,int k)
	{
		for(int i=x;i<=n;i+=lowbit(i))t[i]+=k;
	}
	inline ll query(int x)
	{
		ll ans=0;
		for(int i=x;i;i-=lowbit(i))ans+=t[i];
		return ans;
	}
}t1,t2;
inline ll query(int x)
{
	return t1.query(x)+t2.query(x)*x;
}
inline void modify(int x,int d)
{
	t1.update(x,-x*d);
	t2.update(x,d);
}
struct Node{
	int l,r,w;
	friend bool operator<(const Node&a,const Node&b)
	{
		return a.l<b.l;
	}
};
set<Node>S,a[N];
inline void erase(Node x)
{
	auto it=a[x.w].find(x);
	if(it!=a[x.w].begin())
	{
		it--;
		modify(x.l-it->r,1);
		it++;
	}
	it++;
	if(it!=a[x.w].end())modify(it->l-x.r,1);
	it--;
	if(it!=a[x.w].begin())
	{
		auto it2=it,it3=it;
		it2++;
		it3--;
		if(it2!=a[x.w].end())modify(it2->l-it3->r,-1);
	}
	if(x.l!=x.r)modify(1,x.r-x.l);
	modify(a[x.w].begin()->l,1);
	modify(n-a[x.w].rbegin()->r+1,1);
	a[x.w].erase(x);
	if(!a[x.w].empty())
	{
		modify(a[x.w].begin()->l,-1);
		modify(n-a[x.w].rbegin()->r+1,-1);
	}
}
inline void insert(Node x)
{
	if(!a[x.w].empty())
	{
		modify(a[x.w].begin()->l,1);
		modify(n-a[x.w].rbegin()->r+1,1);
	}
	a[x.w].insert(x);
	modify(a[x.w].begin()->l,-1);
	modify(n-a[x.w].rbegin()->r+1,-1);
	auto it=a[x.w].find(x);
	if(it!=a[x.w].begin())
	{
		it--;
		modify(x.l-it->r,-1);
		it++;
	}
	it++;
	if(it!=a[x.w].end())modify(it->l-x.r,-1);
	it--;
	if(it!=a[x.w].begin())
	{
		auto it2=it,it3=it;
		it2++;
		it3--;
		if(it2!=a[x.w].end())modify(it2->l-it3->r,1);
	}
	if(x.l!=x.r)modify(1,x.l-x.r);
}
inline set<Node>::iterator split(int p)
{
	auto x=S.upper_bound((Node){p,-1,-1});
	x--;
	if(x->l==p)return x;
	else if(p>x->r)return S.end();
	else
	{
		Node t=(*x);
		erase(t);
		S.erase(x);
		S.insert((Node){t.l,p-1,t.w});
		S.insert((Node){p,t.r,t.w});
		insert((Node){t.l,p-1,t.w});
		insert((Node){p,t.r,t.w});
		return S.find((Node){p,t.r,t.w});
	}
}
inline void assign(int l,int r,int w)
{
	auto R=split(r+1),L=split(l);
	auto p=L;
	do{
		erase(*p);
		p++;
	}while(p!=R);
	S.erase(L,R);
	S.insert((Node){l,r,w});
	insert((Node){l,r,w});
}
map<int,int>mp;
int idcnt;
inline int get_id(int x)
{
	return mp.count(x)?mp[x]:mp[x]=(++idcnt);
}
int main()
{
	n=read();
	q=read();
	for(int i=1;i<=n;++i)
	{
		int x=read();
		S.insert((Node){i,i,get_id(x)});
		insert((Node){i,i,get_id(x)});
	}
	while(q--)
	{
		int opt=read();
		switch(opt)
		{
			case 1:
				int l=read(),r=read(),x=read();
				assign(l,r,get_id(x));
				break;
			case 2:
				int x=read();
				printf("%lld\n",1ll*x*(n-x+1)+1ll*x*(x-1)+query(x));
				break;
		}
	}
	return 0;
}
/*
5 5
1 2 3 4 5
2 3
1 1 2 5
2 4
1 2 4 5
2 2
*/


                 //       ONLY FOR KING RAHMANI MASTER OF DP       \\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#define int long long
#define lb(a) ((a)&(-a))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace __gnu_pbds;
using namespace std;

const int maxn=1e3+11,mod=1e9+7;

int a[maxn],sum1[maxn*4],uu,l1,r1,x1,sum[maxn*4],lazy[maxn*4],n,q,lazy2[maxn*4];

long long ans[maxn*4],lazy1[maxn*4];

vector <int> v;

set <pair<int,int> > v1[maxn*2];

set <pair<pair<int,int>,int > > v2;

set <pair<int,int> > ::iterator it1,it2;

set <pair<pair<int,int>,int> > ::iterator it;

pair<pair<int,int>,pair<int,int> > p[maxn];

pair<pair<int,int>,int> p5;

vector <pair<pair<int,int>,int> > v3;

vector <pair<pair<int,int>,int> > v4;

void put(int x,long long y,int z,int id)
{
    ans[id]+=(y+(x*sum[id])+(z*sum1[id]));
    lazy[id]+=x;
    lazy1[id]+=(y+(x*sum[id])+(z*sum1[id]));
    lazy2[id]+=z;
}

void shift(int id)
{
    put(lazy[id],lazy1[id],lazy2[id],id<<1);
    put(lazy[id],lazy1[id],lazy2[id],id<<1|1);
    lazy1[id]=0;
    lazy[id]=0;
    lazy2[id]=0;
}

void update(int l,int r,int x,long long y,int z,int id=1,int s=1,int e=n+1)
{
    if(l<1 || r>n+1){
        cout<<-1<<' '<<l<<' '<<r<<endl;
        return ;
    }
    if(e<=l || r<=s)
    {
        return ;
    }
    if(l<=s && e<=r)
    {
        put(x,y,z,id);
        return ;
    }
   // if(lazy[id]!=0 || lazy2[id]!=0)
        shift(id);
    y+=(x*sum[id]);
    y+=(z*sum1[id]);
    int mid=(s+e)/2;
    update(l,r,x,y,z,id<<1,s,mid);
    update(l,r,x,y,z,id<<1|1,mid,e);
}

void update1(int l,int r,int x,int id=1,int s=1,int e=n+1)
{
    if(e<=l || r<=s)
    {
        return ;
    }
    if(l<=s && e<=r)
    {
        sum[id]+=x;
        return ;
    }
    int mid=(s+e)/2;
    update1(l,r,x,id<<1,s,mid);
    update1(l,r,x,id<<1|1,mid,e);
}

void update2(int l,int r,int x,int id=1,int s=1,int e=n+1)
{
    if(e<=l || r<=s)
    {
        return ;
    }
    if(l<=s && e<=r)
    {
        sum1[id]+=x;
        return ;
    }
    int mid=(s+e)/2;
    update2(l,r,x,id<<1,s,mid);
    update2(l,r,x,id<<1|1,mid,e);
}

long long get(int pos,int id=1,int s=1,int e=n+1)
{
    if(s+1==e)
        return ans[id];
    shift(id);
    int mid=(s+e)/2;
    if(pos<mid)
        return get(pos,id<<1,s,mid);
    return get(pos,id<<1|1,mid,e);
}

void get4(int id=1,int s=1,int e=n+1)
{
    if(s+1==e)
    {
        cout<<s<<' '<<ans[id]<<endl;
        return ;
    }
    shift(id);
    int mid=(s+e)/2;
    get4(id<<1,s,mid);
    get4(id<<1|1,mid,e);
}

void am(int rr,int l,int r,int kk)
{
    int yy,vv;
    yy=(n+1-r);
    vv=(l-rr);
    //cout<<yy<<' '<<vv<<endl;
    if(yy==vv)
        {
            update(1,yy+1,0,kk*(r-l),kk*(1));
            update(yy+1,n+1-rr,kk*(1),kk*(n-(n-rr)),0);
        }
        else{
            if(yy>vv)
                swap(vv,yy);
         //   cout<<"yy"<<endl;
            update(1,yy+1,0,kk*(r-l),kk*(1));
            update(vv+1,n+1-rr,(1)*kk,kk*(n-(n-rr)),0);
            update(yy+1,vv+1,0,kk*(r-l+yy),0);
        }

}

void ee(int l,int r,int i)
{
    pair<int,int> p1,p2;
    it1=v1[i].lower_bound(make_pair(r+1,0));
    it2=it1;
    it1--;
    p2=*it2;
    p1=*it1;
    if(p2.first==n+1)
    {
        am(p1.second,l,r,1);
    }
    else{
        am(p1.second,p2.first,p2.second,-1);
        am(p1.second,l,r,1);
        am(r,p2.first,p2.second,1);
    }
    v1[i].insert(make_pair(l,r));
    //cout<<"ee ";
   // for(auto it5:v1[i])
  //      cout<<it5.first<<' '<<it5.second<<' ';
//    cout<<endl;
}

void pp(int l,int r,int i)
{
    pair<int,int> p1,p2;
    it1=v1[i].lower_bound(make_pair(l,r));
    it2=it1;
    it1--;
    it2++;
    p2=*it2;
    p1=*it1;
    if(p2.first==n+1)
    {
        am(p1.second,l,r,-1);
    }
    else{
       // cout<<p1.first<<' '<<p1.second<<' '<<l<<' '<<r<<' '<<p2.first<<' '<<' '<<p2.second<<endl;
        am(p1.second,p2.first,p2.second,+1);
        am(p1.second,l,r,-1);
        am(r,p2.first,p2.second,-1);
    }
    it1++;
    v1[i].erase(it1);
   // cout<<"pp ";
 //   for(auto it5:v1[i])
  ///      cout<<it5.first<<' '<<it5.second<<' ';
 //   cout<<endl;
}

int32_t main()
{
  //  ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  //    1103 1097 1193 10087 10133 11021 1119 10007
  //  cout<<setprecision(9);
  //  cout<<std::fixed;
  //  http://78.157.45.46/ss4-12r2
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
    {
        update2(i,n+1,1);
        scanf("%d",&a[i]);
        v.push_back(a[i]);
    }
    for(int i=0;i<q;i++)
    {
        scanf("%d",&p[i].first.first);
        if(p[i].first.first==1)
        {
            scanf("%d%d%d",&p[i].second.first,&p[i].second.second,&p[i].first.second);
            v.push_back(p[i].first.second);
        }
        else{
            scanf("%d",&p[i].first.second);
        }
    }
    sort(v.begin(),v.end());
    v.resize(unique(v.begin(),v.end())-v.begin());
    for(int i=0;i<v.size();i++)
    {
        v1[i].insert(make_pair(0,0));
        v1[i].insert(make_pair(n+1,n+1));
    }
    v2.insert(make_pair(make_pair(0,0),0));
    v2.insert(make_pair(make_pair(n+1,n+1),0));
    for(int i=n;i>=1;i--)
    {
        update1(1,i+1,1);
    }
    r1=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]!=a[i-1])
        {
            uu=lower_bound(v.begin(),v.end(),a[i-1])-v.begin();
            v2.insert(make_pair(make_pair(r1,i-1),uu));
            ee(r1,i-1,uu);
            r1=i;
     //       get4();
        }
    }
    uu=lower_bound(v.begin(),v.end(),a[n])-v.begin();
    v2.insert(make_pair(make_pair(r1,n),uu));
    ee(r1,n,uu);
   // get4();
    for(int i=0;i<q;i++)
    {
        if(p[i].first.first==1)
        {
            l1=p[i].second.first;
            r1=p[i].second.second;
            x1=p[i].first.second;
            uu=lower_bound(v.begin(),v.end(),x1)-v.begin();
            it=v2.lower_bound(make_pair(make_pair(l1,0),0));
            p5=*it;
            if(p5.first.first!=l1)
            {
                it--;
                p5=*it;
                v3.push_back(p5);
                if(p5.second==uu)
                    l1=p5.first.first;
                else {
                p5.first.second=l1-1;
                v4.push_back(p5);
                }
                it++;
                p5=*it;
            }
            while(p5.first.second<=r1)
            {
                v3.push_back(p5);
                it++;
                p5=*it;
            }
            if(p5.first.first<=r1)
            {
                v3.push_back(p5);
                if(p5.second==uu)
                    r1=p5.first.second;
                else {
                p5.first.first=r1+1;
                v4.push_back(p5);
                }
            }
            for(auto oo:v3)
            {
                v2.erase(oo);
                pp(oo.first.first,oo.first.second,oo.second);
            }
            for(auto oo:v4)
            {
                v2.insert(oo);
                ee(oo.first.first,oo.first.second,oo.second);
            }
            v2.insert(make_pair(make_pair(l1,r1),uu));
            ee(l1,r1,uu);
            v3.clear();
            v4.clear();
        }
        else{
            printf("%lld\n",get(p[i].first.second));
        }
     //   get4();
    }
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;

const int N = 200000;

int n, q;
struct BIT{
	ll tree[N + 5];
	int lowbit(int x) {return x & -x;}
	void update(int l, int r, int k) {
		for(int i=l;i<=r;i++) tree[i] += k;
	}
	ll sum(int x) {
		return tree[x];
	}
}t1, t2;
ll sum(int x) {return t1.sum(x) + t2.sum(x) * x;}
void modify(int x, int d) {
//	printf("! %d %d\n", x, d);
	t1.update(x, n, - x * d), t2.update(x, n, d);
} // \forall k \in [x, n], ans_k = ans_k + (k - x) * d

struct node{
	int l, r, c;
	friend bool operator < (const node &a, const node &b) {
		return a.l < b.l;
	}
}; std::set<node>st, a[N + 5];
void erase(node x) {
	st.erase(x);

	auto it = a[x.c].find(x);
	if( it != a[x.c].begin() ) it--, modify(x.l - it->r, 1), it++;
	it++; if( it != a[x.c].end() ) modify(it->l - x.r, 1); it--;
	if( it != a[x.c].begin() ) {
		auto it2 = it, it3 = it; it2++, it3--;
		if( it2 != a[x.c].end() ) modify(it2->l - it3->r, -1);
	}
	if( x.l != x.r ) modify(1, x.r - x.l);

	modify(a[x.c].begin()->l, 1), modify(n - a[x.c].rbegin()->r + 1, 1), a[x.c].erase(x);
	if( !a[x.c].empty() )
		modify(a[x.c].begin()->l, -1), modify(n - a[x.c].rbegin()->r + 1, -1);
}
void insert(node x) {
	st.insert(x);

	if( !a[x.c].empty() )
		modify(a[x.c].begin()->l, 1), modify(n - a[x.c].rbegin()->r + 1, 1);
	a[x.c].insert(x), modify(a[x.c].begin()->l, -1), modify(n - a[x.c].rbegin()->r + 1, -1);

	auto it = a[x.c].find(x);
	if( it != a[x.c].begin() ) it--, modify(x.l - it->r, -1), it++;
	it++; if( it != a[x.c].end() ) modify(it->l - x.r, -1); it--;
	if( it != a[x.c].begin() ) {
		auto it2 = it, it3 = it; it2++, it3--;
		if( it2 != a[x.c].end() ) modify(it2->l - it3->r, 1);
	}
	if( x.l != x.r ) modify(1, x.l - x.r);
}
std::set<node>::iterator split(int p) {
	auto x = st.upper_bound((node){p, -1, -1}); x--;
	if( x->l == p ) return x;
	else if( p > x->r ) return st.end();
	else {
		node t = (*x); erase(*x);
		insert((node){t.l, p - 1, t.c}), insert((node){p, t.r, t.c});
		return st.find((node){p, t.r, t.c});
	}
}//[l, r] -> [l, p - 1] + [p, r]
void assign(int l, int r, int c) {
	auto rx = split(r + 1), lx = split(l);

	auto p = (lx++);
	do {
		erase(*p), p = (lx++);
	}while( p != rx );
	insert((node){l, r, c});
}
void debug() {
	for(int i=1;i<=5;i++) {
		printf("%d : ", i);
		for(auto x : a[i]) printf("(%d %d %d)\t", x.l, x.r, x.c);
		puts("");
	}
	for(auto x : st)
		printf("(%d %d %d)\t", x.l, x.r, x.c);
	puts("\n");
}

std::map<int, int>mp; int idcnt;
int id(int x) {return mp.count(x) ? mp[x] : mp[x] = (++idcnt);}

int main() {
	scanf("%d%d", &n, &q);
	for(int i=1,x;i<=n;i++) scanf("%d", &x), insert((node){i, i, id(x)});
//	debug();

	for(int i=1,opt,x,l,r;i<=q;i++) {
		scanf("%d", &opt);
		if( opt == 2 ) {
			scanf("%d", &x);
			ll ans = 1ll * x * (n - x + 1) + 1ll * x * (x - 1);
			printf("%lld\n", ans + sum(x));
		} else scanf("%d%d%d", &l, &r, &x), assign(l, r, id(x));
//		debug();
	}
}


// Problem : G. Growing flowers
// Contest : Codeforces - Bubble Cup 13 - Finals [Online Mirror, unrated, Div. 1]
// URL : https://codeforces.com/contest/1423/problem/G
// Memory Limit : 256 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

constexpr int Maxn = 1e5 + 5;

int n, q, a[Maxn];
int qop[Maxn], ql[Maxn], qr[Maxn], qx[Maxn];
vector<int> buc[Maxn];

template<typename _Tp>
struct chtholly_node {
  typedef _Tp value_type;
  mutable int l, r;
  mutable value_type v;
  chtholly_node(int L, int R, value_type x) : l(L), r(R), v(x) { }
  bool operator < (const chtholly_node& x) const { return l < x.l; }
};
template<typename _Tp>
struct chtholly_tree : public set<chtholly_node<_Tp>> {
  typedef _Tp value_type;
  typedef chtholly_node<value_type> node;
  typedef typename set<node>::iterator IT;
  inline IT split(int pos) {
    IT itl = this->lower_bound(node(pos, -1, value_type()));
    if (itl != this->end() && itl->l == pos) return itl; --itl;
    IT itr = this->insert(node(pos, itl->r, itl->v)).first;
    itl->r = pos - 1; return itr;
  }
  inline void assign(int l, int r, value_type x) {
    IT itr = split(r + 1), itl = split(l);
    this->erase(itl, itr);
    this->insert(node(l, r, x));
  }
  inline int64_t get(int k) {
    int64_t ans = 0;
    for (IT it = this->begin(); it != this->end(); ++it) {
      buc[it->v].push_back(it->l);
      buc[it->v].push_back(it->r);
    }
    for (IT it = this->begin(); it != this->end(); ++it) {
      int l = it->l, r = it->r;
      int L = max(1, l - k + 1), R = min(r, n - k + 1);
      int pre = -1, suf = n + 1, v = it->v;
      auto itl = lower_bound(buc[v].begin(), buc[v].end(), l);
      if (itl != buc[v].begin()) pre = *prev(itl);
      auto itr = upper_bound(buc[v].begin(), buc[v].end(), r);
      if (itr != buc[v].end()) suf = *next(itr);
      L = max(L, pre + 1);
      R = min(R, suf - 1);
      ans += max(R - L + 1, 0);
    }
    for (IT it = this->begin(); it != this->end(); ++it) {
      buc[it->v].clear();
    }
    return ans;
  }
};

chtholly_tree<int> cht;

int main() {

  scanf("%d %d", &n, &q);
  vector<int> vecs;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    vecs.push_back(a[i]);
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%d", qop + i);
    if (qop[i] == 1) scanf("%d %d", ql + i, qr + i);
    scanf("%d", qx + i);
    if (qop[i] == 1) {
      vecs.push_back(qx[i]);
    }
  }
  sort(vecs.begin(), vecs.end());
  vecs.erase(unique(vecs.begin(), vecs.end()), vecs.end());
  for (int i = 1; i <= n; ++i) {
    a[i] = lower_bound(vecs.begin(), vecs.end(), a[i]) - vecs.begin() + 1;
  }
  for (int i = 1; i <= q; ++i) {
    if (qop[i] == 1) {
      qx[i] = lower_bound(vecs.begin(), vecs.end(), qx[i]) - vecs.begin() + 1;
    }
  }

  for (int i = 1; i <= n; ++i) {
    cht.insert(chtholly_node<int>(i, i, a[i]));
  }
  for (int i = 1; i <= q; ++i) {
    if (qop[i] == 1) {
      cht.assign(ql[i], qr[i], qx[i]);
    }
    else {
      printf("%lld\n", cht.get(qx[i]));
    }
  }

  return 0;

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
int n,cnt,S,T,ans;
int to[10000],next[10000],head[110],dis[110],pv[110],pe[110],cost[10000],flow[10000],inq[110];
int v[110],s[30];
char str[110];
queue<int> q;
inline void add(int a,int b,int c,int d)
{
	to[cnt]=b,next[cnt]=head[a],cost[cnt]=c,flow[cnt]=d,head[a]=cnt++;
	to[cnt]=a,next[cnt]=head[b],cost[cnt]=-c,flow[cnt]=0,head[b]=cnt++;
}
inline int bfs()
{
	int i,u;
	memset(dis,0xc0,sizeof(dis));
	q.push(S),dis[S]=0;
	while(!q.empty())
	{
		u=q.front(),q.pop(),inq[u]=0;
		for(i=head[u];i!=-1;i=next[i])	if(dis[to[i]]<dis[u]+cost[i]&&flow[i])
		{
			dis[to[i]]=dis[u]+cost[i],pe[to[i]]=i,pv[to[i]]=u;
			if(!inq[to[i]])	inq[to[i]]=1,q.push(to[i]);
		}
	}
	return dis[T]>=-100000;
}
int main()
{
	scanf("%d%s",&n,str+1),S=0,T=n/2+27;
	int i,j;
	for(i=1;i<=n;i++)	s[str[i]-'a'+1]++,scanf("%d",&v[i]);
	memset(head,-1,sizeof(head));
	for(j=1;j<=26;j++)
	{
		add(S,j,0,s[j]);
		for(i=1;i+i<=n;i++)
		{
			if(str[i]-'a'+1==j&&str[n-i+1]-'a'+1==j)	add(j,i+26,max(v[i],v[n-i+1]),1);
			else	if(str[i]-'a'+1==j)	add(j,i+26,v[i],1);
			else	if(str[n-i+1]-'a'+1==j)	add(j,i+26,v[n-i+1],1);
			else	add(j,i+26,0,1);
		}
	}
	for(i=1;i+i<=n;i++)	add(i+26,T,0,2);
	while(bfs())
	{
		ans+=dis[T];
		for(i=T;i!=S;i=pv[i])	flow[pe[i]]--,flow[pe[i]^1]++;
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define PB push_back

#define SZ(x) ((int)((x).size()))

typedef pair<long long, long long> pll;

struct CostFlow {

    static const int MXN = 1505;

    static const long long INF = 102938475610293847LL;

    struct Edge {

        int v, r;

        long long f, c;

    };

    int n, s, t, prv[MXN], prvL[MXN], inq[MXN];

    long long dis[MXN], fl, cost;

    vector<Edge> E[MXN];

    void init(int _n, int _s, int _t) {

        n = _n; s = _s; t = _t;

        for (int i=0; i<n; i++) E[i].clear();

        fl = cost = 0;

    }

    void add_edge(int u, int v, long long f, long long c) {

        E[u].PB({v, SZ(E[v])  , f,  c});

        E[v].PB({u, SZ(E[u])-1, 0, -c});

    }

    void flow() {

        while (true) {

            for (int i=0; i<n; i++) {

                dis[i] = -INF;

        inq[i] = 0;

            }

            dis[s] = 0;

            queue<int> que;

            que.push(s);

            while (!que.empty()) {

                int u = que.front(); que.pop();

                inq[u] = 0;

                for (int i=0; i<SZ(E[u]); i++) {

                    int v = E[u][i].v;

                    long long w = E[u][i].c;

                    if (E[u][i].f > 0 && dis[v] < dis[u] + w) {

                        prv[v] = u; prvL[v] = i;

                        dis[v] = dis[u] + w;

                        if (!inq[v]) {

                            inq[v] = 1;

                            que.push(v);

                        }

                    }

                }

            }

            if ( dis[t] == -INF ) break;

            long long tf = INF;

            for (int v=t, u, l; v!=s; v=u) {

                u=prv[v]; l=prvL[v];

                tf = min(tf, E[u][l].f);

            }

            for (int v=t, u, l; v!=s; v=u) {

                u=prv[v]; l=prvL[v];

                E[u][l].f -= tf;

                E[v][E[u][l].r].f += tf;

            }

            cost += tf * dis[t];

        }

        cout << cost << endl;

    }

}flow;

int n, S, T;

char buf[110];

char str[1];

int c[110];

int cnt[27];

int main() {

  scanf("%d%s", &n, buf + 1 );

  T = 0;

  S = n / 2  * 26 + n + 1;

  for( int i = 1; i <= n; i ++ ) cnt[buf[i] - 'a' + 1]++, scanf("%d", c + i );

  flow.init( S + 26, S, T );

  for( int i = 1; i <= 26; i ++ ) flow.add_edge( S, S + i, cnt[i], 0 );

  for( int i = 1; i <= n; i ++ ) flow.add_edge( i, T, 1, 0 );

  for( int i = 1; i <= n >> 1; i ++ ) {

    for( int j = 1; j <= 26; j ++ ) flow.add_edge( S + j, S - i * 26 - 1 + j, 1, 0 );

    for( int j = 1; j <= 26; j ++ ) {

      flow.add_edge( S - i * 26 - 1 + j, i, 1, j + 'a' - 1 == buf[i] ? c[i] : 0 );

      flow.add_edge( S - i * 26 - 1 + j, n + 1 - i, 1, j + 'a' - 1 == buf[n + 1 - i] ? c[n + 1 - i] : 0 );

    }

  }

  flow.flow();

  return 0;

}


#include <bits/stdc++.h>

using namespace std;

string change(char x)
{
string s = "";
int num = 0;
if(x >= '0' && x <= '9'){
num = x - '0';
}
else {
num = x - 'A' + 10;
}
string ans = "";
while(num != 0){
int mod = num%2;
if(mod) ans += '1';
else ans += '0';
num = num/2;
}
reverse(ans.begin(), ans.end());
while(ans.size() < 4) ans = "0"+ans;
return ans;
}

string f(string s)
{
string ans = "";
for(int i=0; i<s.length(); i++){
ans += change(s[i]);
}
return ans;
}

int main()
{
//freopen("in.txt", "r", stdin);
int n, m;
scanf("%d %d", &n, &m);
int tot = 0, cnt = 0;
string prev;
cin » prev;
prev = f(prev);
for(int i=0; i<prev.length(); i++){
if(prev[i] == '1') tot++;
}
for(int i=1; i<prev.length(); i++){
if((prev[i] == prev[i-1]) && (prev[i] == '1')) cnt++;
}
//cout « prev « " " « tot « " " « cnt « endl;
for(int i=2; i<=n; i++){
string str;
cin » str;
str = f(str);
bool mer[m];
memset(mer, false, sizeof mer);
for(int j=0; j<str.length(); j++){
if(str[j] == '1'){
tot++;
if(j == 0){
if(str[j] == prev[j]){
mer[j] = true;
cnt++;
}
}
else {
if((str[j] == prev[j]) || (str[j] == str[j-1])){
mer[j] = true;
cnt++;
}
}
}
}
for(int j=0; j<str.length()-1; j++){
if((str[j] == str[j+1]) && (str[j] == '1')){
if(mer[j] == false){
mer[j] = true;
cnt++;
}
}
}
for(int j=0; j<str.length(); j++){
if(str[j] == '1'){
if(mer[j] == false){
if(j == 0){
if(str[j] == prev[j]){
mer[j] = true;
cnt++;
}
}
else {
if((str[j] == prev[j]) || (str[j] == str[j-1])){
mer[j] = true;
cnt++;
}
}
}
}
}
prev = str;
//cout « str « " " « tot « " " « cnt « endl;
}
cout « tot-cnt;
}


#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<iostream>
#include<list>
#include<stack>
#include<set>
#include<queue>
#include<cstdio>
#include<map>
#include<bits/stdc++.h>
using namespace std;
#define NN 1024
int cap[NN][NN];
int cost[NN][NN];
int fnet[NN][NN], adj[NN][NN], deg[NN];

int par[NN], d[NN]; // par[source] = source;
int pi[NN];
#define CLR(a, x) memset( a, x, sizeof( a ) )
#define Inf (INT_MAX/2)
#define Pot(u,v) (d[u] + pi[u] - pi[v])
bool dijkstra( int n, int s, int t )
{
	for( int i = 0; i < n; i++ ) d[i] = Inf, par[i] = -1;
	d[s] = 0;
	par[s] = -n - 1;
	while( 1 ){
		int u = -1, bestD = Inf;
		for( int i = 0; i < n; i++ ) if( par[i] < 0 && d[i] < bestD )
		bestD = d[u = i];
		if( bestD == Inf ) break;
		par[u] = -par[u] - 1;
		for( int i = 0; i < deg[u]; i++ ){
			int v = adj[u][i];
			if( par[v] >= 0 ) continue;
			if( fnet[v][u] && d[v] > Pot(u,v) - cost[v][u] )
				d[v] = Pot( u, v ) - cost[v][u], par[v] = -u-1;
			if( fnet[u][v] < cap[u][v] && d[v] > Pot(u,v) + cost[u][v] )
				d[v] = Pot(u,v) + cost[u][v], par[v] = -u - 1;
		}
	}
	for( int i = 0; i < n; i++ ) if( pi[i] < Inf ) pi[i] += d[i];
	return par[t] >= 0;
}
#undef Pot
int mcmf3( int n, int s, int t, int &fcost ){
	CLR( deg, 0 );
	for( int i = 0; i < n; i++ )
		for( int j = 0; j < n; j++ )
			if( cap[i][j] || cap[j][i] ) adj[i][deg[i]++] = j;
	CLR( fnet, 0 );
	CLR( pi, 0 );
	int flow = fcost = 0;
	while( dijkstra( n, s, t ) ){
		int bot = INT_MAX;
		for( int v = t, u = par[v]; v != s; u = par[v = u] )
			bot <?= fnet[v][u] ? fnet[v][u] : ( cap[u][v] - fnet[u][v] );
		for( int v = t, u = par[v]; v != s; u = par[v = u] )
			if( fnet[v][u] ) { fnet[v][u] -= bot; fcost -= bot * cost[v][u]; }
			else { fnet[u][v] += bot; fcost += bot * cost[u][v]; }
	flow += bot;
	}
	return flow;
}
int calc(int i,int n){
	if(i<n/2) return i;
	else return (n-i)-1;
}
int main() {
	// your code goes here
	int n,i,j;
	cin>>n;
	char s[n];
	int b[n];
	map<char,vector<int> > mp;
	for(i=0;i<n;i++){
		cin>>s[i];
		if(mp.find(s[i])==mp.end()){
			vector<int> temp;
			temp.push_back(i);
			mp.insert(make_pair(s[i],temp));
		}
		else mp[s[i]].push_back(i);
	}
	for(i=0;i<n;i++){
		cin>>b[i];
	}
	int left=mp.size();
	memset( cap, 0, sizeof( cap ) );
	map<char,vector<int> >::iterator it;
	i=1;
	for(it=mp.begin();it!=mp.end();it++){
		cap[0][i]=(it->second).size();
		cost[0][i]=0;
		for(j=0;j<n/2;j++){
			cap[i][left+1+j]=1;
			if(s[j]==it->first && s[(n-j)-1]==it->first){
				cost[i][left+1+j]= (-1)* max(b[j],b[(n-j)-1]);
			}
			else if(s[j]==it->first){
				cost[i][left+1+j]= (-1)*b[j];
			}
			else if(s[(n-j)-1]==it->first){
				cost[i][left+1+j]= (-1)*b[(n-j)-1];
			}
			else cost[i][left+1+j]= 0;
		}
		i++;
	}
	for(j=0;j<n/2;j++){
		cap[left+1+j][left+1+n/2]=2;
		cost[left+1+j][left+1+n/2]=0;
	}
	int numV=left+1+n/2+1;
	int fcost;
	int flow = mcmf3( numV, 0, left+1+n/2, fcost );
	//cout << "flow: " << flow << endl;
	//cout << "cost: " << fcost << endl;
	cout<<(-1)*fcost;
	return 0;
}


#include <bits/stdc++.h>
#define maxN 52
#define mod 1000000007LL
using namespace std;
long long Count[maxN + 1][maxN + 1][maxN + 1][maxN + 1];

int main()
{
    int n, p;
    scanf("%d%d", &n, &p);
    int c[n + 2];
    for (int i = 0; i < n; ++ i)
        scanf("%d", &c[i]);

    long long ans = 0;
    //memset(Count, 0, sizeof(Count));
    Count[0][0][0][0] = 1;

    for (int be = 0; be <= n; ++ be)
        for (int we = 0; we + be <= n; ++ we)
            for (int bo = 0; bo + be + we <= n; ++ bo)
                for (int wo = 0; bo + be + we + wo <= n; ++ wo)
                {
                    int i = be + we + bo + wo;
                    if (c[i] != 0)
                    {
                        long long s = i ? ((1LL << (i - 1)) % mod) : 1;
                        if (bo)
                        {
                            Count[be][we + 1][bo][wo] += 1LL * Count[be][we][bo][wo] * s;
                            Count[be][we + 1][bo][wo] %= mod;
                        }
                        else
                            s = (1LL << i) % mod) ;
                            Count[be][we][bo][wo + 1] += 1LL * Count[be][we][bo][wo] * s;
                            Count[be][we][bo][wo + 1] %= mod;
                        }
                    if (c[i] != 1)
                    {
                        long long s = i ? ((1LL << (i - 1)) % mod) : 1;
                        if (wo)
                        {
                            Count[be + 1][we][bo][wo] += 1LL * Count[be][we][bo][wo] * s;
                            Count[be + 1][we][bo][wo] %= mod;
                        }
                        else
                            s = (1LL << i) % mod) ;

                            Count[be][we][bo + 1][wo] += 1LL * Count[be][we][bo][wo] * s;
                            Count[be][we][bo + 1][wo] %= mod;
                        }
                    if (i == n && ((bo + wo) & 1) == p)
                    {
                        ans += Count[be][we][bo][wo];
                        ans %= mod;
                    }
                }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxN = 55;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int pw[maxN * maxN];
int c[maxN];
int dp[maxN][maxN][maxN][maxN][2];
int n, p;
int get(int x, int y) {
    if (y == 0) {
        if (x == 0) return 1;
        else return 0;
    }
    return pw[y - 1];
}
int val(int a, int b, int c, int d, int e) {
    if (a < 0 || b < 0 || c < 0 || d < 0) return 0;
    return dp[a][b][c][d][e];
}
int main() {
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    pw[0] = 1;
    for (int i = 1; i < maxN * maxN; i++) {
        pw[i] = sum(pw[i - 1], pw[i - 1]);
    }
    cin >> n >> p;
    for (int i = 1; i <= n; i++) cin >> c[i];
    dp[n + 1][0][0][0][0] = 1;
    for (int i = n; i >= 1; i--) {
        for (int white = 0; white <= n - i + 1; white++) {
            int black = n - i + 1 - white;
            for (int eW = 0; eW <= white; eW++) {
                for (int eB = 0; eB <= black; eB++) {
                    for (int bit = 0; bit < 2; bit++) {
                        int st = 0;
                        int oW = white - eW;
                        int oB = black - eB;
                        for (int clr = 0; clr < 2; clr++) {
                            if (c[i] != -1 && clr != c[i]) continue;
                            for (int pBit = 0; pBit < 2; pBit++) {
                                int ne = pBit ^ bit;
                                if (clr == 0) {
                                    st = sum(st, mult(val(i + 1, white - 1, oW - ne, oB, pBit), get(ne ^ 1, oB)));
                                }
                                else {
                                    st = sum(st, mult(val(i + 1, white, oW, oB - ne, pBit), get(ne ^ 1, oW)));
                                }
                            }
                        }
                        dp[i][white][oW][oB][bit] = st;
                    }
                }
            }
        }
    }
    int cur = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= n; k++) {
                for (int r = 0; r <= n; r++) {
                    cur = sum(cur, dp[i][j][k][p]);
                }
            }
        }
    }
    cout << cur;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k;
const ll inf = 1LL<<30;
ll solve(ll a,ll b){
	if(b < a)return inf;
	if(a==b)return 0;
	ll ret = inf;
	for(int i=2;i<=k;i++){
		if(b%i)
		ret = min(ret, solve(a,b - b % i)+1);
	}
	ret = min(ret , solve(a,b-1)+1);
	return ret;
}

int main(){
	ll a,b,ans=0;
	cin>>b>>a>>k;
	ll v1 = b%k;
	if(b - v1 >= a){
		b-=v1;
		ans++;
		ll diff = b-a;
		ll op = diff / k;
		if(op > 5)op-=3;
		ans += op * 2;
		b -= op * k;
	}
	ans += solve(a,b);
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 400009 /// I wanna be a marshmello
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll b,a,k;
    cin>>a>>b>>k;
    ll lcmt=2;
    rep(i,3,k+1){
        lcmt = (lcmt*i)/__gcd(lcmt,i);
    }

    /// first interval
    ll mult1=((b+lcmt-1)/lcmt)*lcmt;
    set<int> vis1;
    queue<pii> q;
    bool ch=0;
    ll ans1=0;
    ll dp[maxn];
        rep(i,0,maxn){
            dp[i]=INF;
        }
            dp[(mult1-1)%lcmt]=1;
            dp[0]=0;
            per(i,mult1,0){
                rep(j,2,k+1){
                    dp[(i/j)*j]=min(dp[i]+1,dp[(i/j)*j]);
                }
            dp[i]=min(dp[i],dp[i+1]+1);
    }
    ans1=dp[b%lcmt];
    /// third interval
    set<int> vis2;
    ll mult2 = ((a)/lcmt)*lcmt;
    ch=0;
    q.push({a,0});
    vis2.insert(a);
    ll ans2=0;
    while(!ch){
        auto e = q.front();
        // cout<<e.F<<endl;
        q.pop();
        if(e.F==mult2){
            ch=true;
            ans2=e.S;
            continue;
        }
        rep(i,2,k+1){
            if(((e.F)/i)*i!=e.F && vis2.find(((e.F)/i)*i!=e.F)==vis2.end()){
                q.push({((e.F)/i)*i,e.S+1});
                vis2.insert(((e.F)/i)*i);
            }
        }
    }
    while(!q.empty())q.pop();

    /// second interval
    rep(i,0,maxn){
        dp[i]=INF;
    }
    dp[lcmt-1]=0;
    per(i,lcmt,0){
        rep(j,2,k+1){
            dp[(i/j)*j]=min(dp[i]+1,dp[(i/j)*j]);
        }
        dp[i]=min(dp[i],dp[i+1]+1);
    }

    if(b/lcmt!=a/lcmt){
        // cout<<ans1+1<<" "<<ans2<<'\n';
        cout<<(dp[0]+1)*(mult2/lcmt-mult1/lcmt)+ans1+ans2<<'\n';
    }
    else{
        rep(i,0,maxn){
            dp[i]=INF;
        }
            dp[a%lcmt]=0;
            per(i,a%lcmt+1,0){
                rep(j,2,k+1){
                    dp[(i/j)*j]=min(dp[i]+1,dp[(i/j)*j]);
                }
            dp[i]=min(dp[i],dp[i+1]+1);
        }
        cout<<dp[b%lcmt]<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 400009 /// I wanna be a marshmello
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll b,a,k;
    cin>>a>>b>>k;
    ll lcmt=2;
    rep(i,3,k+1){
        lcmt = (lcmt*i)/__gcd(lcmt,i);
    }
    // cout<<lcmt<<'\n';
    /// first interval
    ll mult1=((b+lcmt-1)/lcmt)*lcmt;
    // cout<<b<<" "<<mult1<<endl;
    set<int> vis1;
    queue<pii> q;
    bool ch=0;
    q.push({mult1-1,0});
    vis1.insert(mult1-1);
    ll ans1=0;
    ll b2=b+(b==1);
    while(!ch){
        auto e = q.front();
        q.pop();
        // cout<<e.F<<" "<<sz(q)<<endl;
        if(e.F==b2){
            ch=true;
            ans1=e.S;
            continue;
        }
        rep(i,2,k+1){
            if(((e.F)/i)*i!=e.F && vis1.find(((e.F)/i)*i)==vis1.end()){
                q.push({((e.F)/i)*i,e.S+1});
                vis1.insert(((e.F)/i)*i);
            }
        }
    }
    while(!q.empty())q.pop();
    /// third interval
    set<int> vis2;
    ll mult2 = ((a)/lcmt)*lcmt;
    ch=0;
    q.push({a,0});
    vis2.insert(a);
    ll ans2=0;
    while(!ch){
        auto e = q.front();
        // cout<<e.F<<endl;
        q.pop();
        if(e.F==mult2){
            ch=true;
            ans2=e.S;
            continue;
        }
        rep(i,2,k+1){
            if(((e.F)/i)*i!=e.F && vis2.find(((e.F)/i)*i!=e.F)==vis2.end()){
                q.push({((e.F)/i)*i,e.S+1});
                vis2.insert(((e.F)/i)*i);
            }
        }
    }
    while(!q.empty())q.pop();

    /// second interval
    ll dp[maxn];
    rep(i,0,maxn){
        dp[i]=INF;
    }
    dp[lcmt-1]=0;
    per(i,lcmt,0){
        rep(j,2,k+1){
            dp[(i/j)*j]=min(dp[i]+1,dp[(i/j)*j]);
        }
        dp[i]=min(dp[i],dp[i+1]+1);
    }

    if(b/lcmt!=a/lcmt){
        // cout<<ans1+1<<" "<<ans2<<'\n';
        cout<<(dp[0]+1)*(mult2/lcmt-mult1/lcmt)+ans1+ans2+1+(b==1)<<'\n';
    }
    else{
        rep(i,0,maxn){
            dp[i]=INF;
        }
            dp[a%lcmt]=0;
            per(i,a%lcmt+1,0){
                rep(j,2,k+1){
                    dp[(i/j)*j]=min(dp[i]+1,dp[(i/j)*j]);
                }
            dp[i]=min(dp[i],dp[i+1]+1);
        }
        cout<<dp[b%lcmt]<<'\n';
    }
    return 0;
}


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

using namespace std;

int main()
{
 long n,d;
 long x[100010];
 long long sum;
 long k;
 long long s,k1;

 s=0; sum=0; k=1; k1=0;
 cin >> n >> d;
 for (long i=1; i<= n; i++)
  cin >> x[i];

 if (n<3) {cout <<"0"<<endl; return 0;}
 if (n==3)
 {
  if (x[3]-x[1]>=d) {cout <<"1"<<endl; return 0;}
  else {cout <<"0"<<endl; return 0;}
 }

 for (long i=1; i<=n-2; i++)
 {
  while (k<n  && abs(x[k+1]-x[i])<=d) k++;
  if (k-i>1)
  {
    s=k-i;
    k1= k-i-1;
    s=(s*k1)/2;
    sum+= s;
  }
 }

 cout << sum << endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll n,m,k;
const ll N = 1000020;
ll fac[N],inv[N];
ll f[1020][1020];
ll ksm(ll a,ll b)
{
	if(b<0) return 0;
//	if(a==0&&b==0) return 0;
	ll ret = 1;
	while(b)
	{
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll C(ll n,ll m)
{
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	if(m==1)
	{
		printf("%lld\n",ksm(k,n));
		return 0;
	}
	fac[0] = 1;
	for(ll i=1;i<N;i++)
	  fac[i]=fac[i-1]*i%mod;
	inv[N-1]=ksm(fac[N-1],mod-2);
	for(ll i=N-2;i>=0;i--)
	  inv[i]=(inv[i+1]*(i+1))%mod;
	f[0][0] = 1;
	for(ll i=1;i<=n;i++)
	  for(ll j=1;j<=i;j++)
	    f[i][j] = j*f[i-1][j] + f[i-1][j-1],f[i][j]%=mod;
	ll ans = 0;
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=i;j++)
		ans += fac[i]* f[n][i]%mod*fac[i]%mod*f[n][i]%mod*C(k,i)%mod*C(i,j)*%mod*C(k-i,i-j)%mod
		*ksm(j,n*(m-2))%mod,ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}


# include <iostream>
# include <cstdlib>
# include <cstdio>
# define int long long

const int MOD = 1e9 + 7;
const int INF= 1e9 + 7;

using namespace std;
int factorial[11111 * 2 * 2 * 2 * 2 * 2 * 2 ],d[11111 * 2][11111 * 2];

void initialiazition()
{
    factorial[0] = 1;
    for(int i = 1;i <= 2000;i ++)
        factorial[i] = (factorial[i - 1] * i) % MOD;
}
int binpow(int x, int y) {
   int res = 1;
   while(y) {
      if(y % 2)
         res = (res * 1LL * x) % INF;
      y /= 2;
      x = (x * 1LL * x) % INF;
   }
   return res % INF;
}

int c(int k,int i)
{
    return (factorial[k] * binpow((factorial[k - i] * factorial[i]) % MOD,MOD - 2)) % MOD;
}
main ()
{
    int n,m,k;
    cin >> n >> m >> k;
    initialiazition();
    if(m == 1)
    {
        cout << binpow(k,n) % 1000000007;
        return 0;
    }
    d[0][0] = 1;
    for(int i = 1; i <= 2000; i++)
    for(int j = 1; j <= n; j++)
    d[i][j] = (d[i - 1][j] * j + d[i - 1][j - 1]) % MOD;
    int res = 0;
    for(int i = 1; i <= n; i++) {
      for(int j = 0; j <= i; j++)
        {
            if(i + i - j <= k) {
            int cur = c(k, j);
            cur = (cur * 1LL * c(k - j, i - j)) % INF;
            cur = (cur * 1LL * c(k - i, i - j)) % INF;
            cur = (cur * 1LL * d[n][i]) % INF;
            cur = (cur * 1LL * d[n][i]) % INF;
            cur = (cur * 1LL * factorial[i]) % INF;
            cur = (cur * 1LL * factorial[i]) % INF;
            cur = (cur * 1LL * binpow(j, (n * (m - 2)))) % INF;
            res = (res + cur) % INF;
         }
        }
    }
    cout << res << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll P = 1e9 + 7;
ll add(ll a, ll b) {if((a += b) >= P) a -= P; return a;}
ll sub(ll a, ll b) {if((a -= b) < 0) a += P; return a;}
ll mul(ll a, ll b) {return 1ll * a * b % P;}
ll kpow(ll a,ll b) {ll res=1;for(;b;b>>=1,a=mul(a,a))if(b&1)res=mul(a,res);return res;}
//---
const int N = 1e6 + 7;
int jc[N]={1},njc[N];
int dp[N][N];
int C(ll n,ll m) {
	return mul(jc[n],mul(njc[m],njc[n-m]));
}
int main() {
	rep(i,1,N)jc[i]=mul(jc[i-1],i);njc[N-1]=kpow(jc[N-1],P-2);per(i,0,N-1)njc[i]=mul(njc[i+1],i+1);
	int n,m,k;scanf("%d%d%d",&m,&n,&k);
	dp[0][0]=1;
	rep(i,1,m+1)rep(j,1,min(m,k)+1)dp[i][j]=add(mul(dp[i-1][j],j),mul(dp[i-1][j-1],k-j+1));
	if(n==1) {
		printf("%lld\n",kpow(k,m));
		return 0;
	}
	if(n==2) {
		ll ans=0;
		rep(i,1,min(m,k)+1)ans=add(ans,mul(dp[m][i],dp[m][i]));
		printf("%lld\n",ans);
		return 0;
	}
	int ans=0;
	rep(i,1,min(m,k)+1)rep(j,1,i+1) {
		ll Ans=mul(dp[m][i],dp[m][i]);
		Ans=mul(mul(Ans,kpow(C(k,i),P-2)),mul(C(i,j),C(k-i,i-j)));
		Ans=mul(Ans,kpow(j,mul(n-2,m)));
		ans=add(ans,Ans);
	}
	printf("%d\n",ans);
	return 0;
}