#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=610;
typedef long long LL;
typedef vector<int> vecI;
int n,m,P;
vecI Ep[maxn],Eq[maxn],Sr,Tr;

namespace Ninv{
	void F(int a,int b,LL &x,LL &y){
		!b?(x=1,y=0):(F(b,a%b,y,x),y-=a/b*x);
	}
	inline LL inv(LL x){
		LL a,b;F((x+P)%P,P,a,b);
		return (a%P+P)%P;
	}
}
using Ninv::inv;

struct Tgauss{
	int n,a[maxn][maxn];
	int det(){
		int flag=0,i,j,k;LL x;
		for(i=0;i<n;++i){
			for(j=i+1;j<n;++j)if(a[j][i]){
				flag=1-flag,swap(a[i],a[j]);
				break;
			}
			if(!a[i][i])return 0;
			for(j=i+1;j<n;++j){
				x=a[j][i]*inv(a[i][i])%P;
				for(k=i;k<n;++k)
					a[j][k]=((a[j][k]-a[i][k]*x)%P+P)%P;
			}
		}
		for(x=1,i=0;i<n;++i)x=x*a[i][i]%P;
		return !flag?(x+P)%P:(P-x)%P;
	}
	void print(){
		int i,j;
		for(i=0;i<n;++i){
			for(j=0;j<n;++j)cerr<<a[i][j]<<' ';
			cerr<<endl;
		}
	}
}A;

namespace Ninit{
	void init(){
		int i,ai,bi;
		scanf("%d%d%d",&n,&m,&P);
		for(i=0;i<m;++i){
			scanf("%d%d",&ai,&bi);
			Ep[ai].push_back(bi);
			Eq[bi].push_back(ai);
		}
		for(i=1;i<=n;++i){
			if(Eq[i].empty())Sr.push_back(i);
			if(Ep[i].empty())Tr.push_back(i);
		}
	}
}

namespace Nsolve{
	namespace Ndp{
		int h[maxn],D[maxn],F[maxn][maxn];
		void solve(){
			int i,j,l,r;
			vecI::iterator p;
			for(i=1;i<=n;++i)D[i]=Eq[i].size();
			for(l=0,r=0,i=0;i<Sr.size();++i)
				F[i][Sr[i]]=1,h[++r]=Sr[i];
			for(;l++!=r;){
				for(p=Ep[h[l]].begin();p<Ep[h[l]].end();++p){
					if(!--D[*p])h[++r]=*p;
					for(i=0;i<Sr.size();++i)
						F[i][*p]=(F[i][*p]+F[i][h[l]])%P;
				}
			}
			A.n=Sr.size();
			for(i=0;i<A.n;++i)
			for(j=0;j<A.n;++j)
				A.a[i][j]=F[i][Tr[j]];
		}
	}
	void solve(){
		Ndp::solve();
		cout<<A.det()<<endl;
	}
}

int main(){
	//freopen("A.in","r",stdin);
	Ninit::init();
	Nsolve::solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=610;
typedef long long LL;
typedef vector<int> vecI;
int n,m,P;
vecI Ep[maxn],Eq[maxn],Sr,Tr;

namespace Ninv{
	void F(int a,int b,LL &x,LL &y){
		!b?(x=1,y=0):(F(b,a%b,y,x),y-=a/b*x);
	}
	inline LL inv(LL x){
		LL a,b;F(x,P,a,b);
		return (a%P+P)%P;
	}
}
using Ninv::inv;

struct Tgauss{
	int n,a[maxn][maxn];
	int det(){
		int flag=0,i,j,k;LL x;
		for(i=0;i<n;++i){
			for(j=i+1;j<n;++j)if(a[j][i]){
				flag=1-flag,swap(a[i],a[j]);
				break;
			}
			if(!a[i][i])return 0;
			for(j=i+1;j<n;++j){
				x=a[j][i]*inv(a[i][i])%P;
				for(k=i;k<n;++k)
					a[j][k]=(a[j][k]-a[i][k]*x)%P;
			}
		}
		for(x=1,i=0;i<n;++i)x=x*a[i][i]%P;
		return !flag?(x+P)%P:(P-x)%P;
	}
	void print(){
		int i,j;
		for(i=0;i<n;++i){
			for(j=0;j<n;++j)cerr<<a[i][j]<<' ';
			cerr<<endl;
		}
	}
}A;

namespace Ninit{
	void init(){
		int i,ai,bi;
		scanf("%d%d%d",&n,&m,&P);
		for(i=0;i<m;++i){
			scanf("%d%d",&ai,&bi);
			Ep[ai].push_back(bi);
			Eq[bi].push_back(ai);
		}
		for(i=1;i<=n;++i){
			if(Eq[i].empty())Sr.push_back(i);
			if(Ep[i].empty())Tr.push_back(i);
		}
	}
}

namespace Nsolve{
	namespace Ndp{
		int h[maxn],D[maxn],F[maxn][maxn];
		void solve(){
			int i,j,l,r;
			vecI::iterator p;
			for(i=1;i<=n;++i)D[i]=Eq[i].size();
			for(l=0,r=0,i=0;i<Sr.size();++i)
				F[i][Sr[i]]=1,h[++r]=Sr[i];
			for(;l++!=r;){
				for(p=Ep[h[l]].begin();p<Ep[h[l]].end();++p){
					if(!--D[*p])h[++r]=*p;
					for(i=0;i<Sr.size();++i)
						F[i][*p]=(F[i][*p]+F[i][h[l]])%P;
				}
			}
			A.n=Sr.size();
			for(i=0;i<A.n;++i)
			for(j=0;j<A.n;++j)
				A.a[i][j]=F[i][Tr[j]];
		}
	}
	void solve(){
		Ndp::solve();
		cout<<A.det()<<endl;
	}
}

int main(){
	//freopen("A.in","r",stdin);
	Ninit::init();
	Nsolve::solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],d[601],mat[601][601],f[601][601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

int main()
{
   int n,m,s=0,o=0,ans=1,st=0,en=0;
   bool flag=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         d[++en]=i;
         f[i][++o]=1;
      }
   while (st<=en)
   {
      int now=d[st++];
      for (int i=1;i<=l[now][0];i++)
      {
         for (int j=1;j<=o;j++)
            f[l[now][i]][j]=(f[l[now][i]][j]+f[now][j])%p;
         if (!(--du[l[now][i]]))
            d[++en]=l[now][i];
      }
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
      {
         s++;
         for (int j=1;j<=o;j++)
            mat[s][j]=f[i][j];
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         flag^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2);
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (flag)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],d[601],mat[601][601],f[601][601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

int main()
{
   int n,m,s=0,o=0,ans=1,st=0,en=0;
   bool flag=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         d[++en]=i;
         f[i][++o]=1;
      }
   while (st<=en)
   {
      int now=d[st++];
      for (int i=1;i<=l[now][0];i++)
      {
         for (int j=1;j<=o;j++)
            f[l[now][i]][j]=(f[l[now][i]][j]+f[now][j])%p;
         if (!(--du[l[now][i]]))
            d[++en]=l[now][i];
      }
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
      {
         s++;
         for (int j=1;j<=o;j++)
            mat[s][j]=f[i][j];
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         flag^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2)%p;
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (flag)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],mat[601][601],num[601];
bool hash[601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

void dfs(int now,int x)
{
   hash[now]=1;
   if (num[now])
      mat[x][num[now]]=1;
   for (int i=1;i<=l[now][0];i++)
      if (!hash[l[now][i]])
         dfs(l[now][i],x);
}

int main()
{
   int n,m,s=0,o=0,ans=1;
   bool f=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
         num[i]=++s;
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         memset(hash,0,sizeof(hash));
         dfs(i,++o);
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[j][i];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=i;k<=s;k++)
            swap(mat[i][k],mat[j][k]);
         f^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
            ans=1LL*ans*mi(mat[i][i],p-2);
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (f)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int head[601],e[100001],next[100001],du[601],d[601],mat[601][601],f[601][601];
int p,totm=0;

void add(int a,int b)
{
   e[++totm]=b;
   next[totm]=head[a];
   head[a]=totm;
   du[b]++;
}

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

int main()
{
   int n,m,s=0,o=0,ans=1,st=0,en=0;
   bool flag=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      add(a,b);
   }
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         d[++en]=i;
         f[i][++o]=1;
      }
   while (st<=en)
   {
      int now=d[st++];
      for (int i=head[now];i;i=next[i])
      {
         for (int j=1;j<=o;j++)
            f[e[i]][j]=(f[e[i]][j]+f[now][j])%p;
         if (!(--du[e[i]]))
            d[++en]=e[i];
      }
   }
   for (int i=1;i<=n;i++)
      if (!head[i])
      {
         s++;
         for (int j=1;j<=o;j++)
            mat[s][j]=f[i][j];
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         flag^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2)%p;
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (flag)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],mat[601][601],num[601];
bool hash[601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

void dfs(int now,int x)
{
   hash[now]=1;
   if (num[now])
      mat[x][num[now]]=1;
   for (int i=1;i<=l[now][0];i++)
      if (!hash[l[now][i]])
         dfs(l[now][i],x);
}

int main()
{
   int n,m,s=0,o=0,ans=1;
   bool f=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
         num[i]=++s;
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         memset(hash,0,sizeof(hash));
         dfs(i,++o);
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         f^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
            ans=1LL*ans*mi(mat[i][i],p-2);
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (f)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],mat[601][601],num[601];
bool hash[601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

void dfs(int now,int x)
{
   hash[now]=1;
   if (num[now])
      mat[x][num[now]]=1;
   for (int i=1;i<=l[now][0];i++)
      if (!hash[l[now][i]])
         dfs(l[now][i],x);
}

int main()
{
   int n,m,s=0,o=0,ans=1;
   bool f=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
         num[i]=++s;
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         memset(hash,0,sizeof(hash));
         dfs(i,++o);
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         f^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2);
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (f)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],mat[601][601],num[601];
bool hash[601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

void dfs(int now,int x)
{
   hash[now]=1;
   if (num[now])
      mat[x][num[now]]=1;
   for (int i=1;i<=l[now][0];i++)
      if (!hash[l[now][i]])
         dfs(l[now][i],x);
}

int main()
{
   int n,m,s=0,o=0,ans=1;
   bool f=0,ff=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      if (n>10&&ff)
         printf("%d %d\n",a,b);
      if (a==5&&b==13)
         ff=1;
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
         num[i]=++s;
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         memset(hash,0,sizeof(hash));
         dfs(i,++o);
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         f^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2);
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (f)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#define zero(a) (abs(a)<eps)
#define lowbit(a) ((a)&(-(a)))
#define abs(a) ((a)>0?(a):(-(a)))
#define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y1))
#define dj(x1,y1,x2,y2) ((x1)*(x2)+(y1)*(y2))
#define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1)))
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;

int l[601][601],du[601],d[601],mat[601][601],f[601][601];
int p;

int mi(int a,int b)
{
   if (!b)
      return 1;
   int t=mi(a,b>>1);
   t=1LL*t*t%p;
   if (b&1)
      t=1LL*t*a%p;
   return t;
}

int main()
{
   int n,m,s=0,o=0,ans=1,st=0,en=0;
   bool flag=0;
   cin>>n>>m>>p;
   for (int i=1;i<=m;i++)
   {
      int a,b;
      scanf("%d%d",&a,&b);
      l[a][++l[a][0]]=b;
      du[b]++;
   }
   for (int i=1;i<=n;i++)
      if (!du[i])
      {
         d[++en]=i;
         f[i][++o]=1;
      }
   while (st<=en)
   {
      int now=d[st++];
      for (int i=1;i<=l[now][0];i++)
      {
         for (int j=1;j<=o;j++)
            f[l[now][i]][j]+=f[now][j];
         if (!(--du[l[now][i]]))
            d[++en]=l[now][i];
      }
   }
   for (int i=1;i<=n;i++)
      if (!l[i][0])
      {
         s++;
         for (int j=1;j<=o;j++)
            mat[s][j]=f[i][j];
      }
   for (int i=1;i<=s;i++)
   {
      if (!mat[i][i])
      {
         int j;
         for (j=i+1;j<=s&&!mat[i][j];j++);
         if (j>s)
         {
            ans=0;
            goto out;
         }
         for (int k=1;k<=s;k++)
            swap(mat[k][i],mat[k][j]);
         flag^=1;
      }
      for (int j=i+1;j<=s;j++)
         if (mat[j][i])
         {
            ans=1LL*ans*mi(mat[i][i],p-2);
            for (int k=s;k>=i;k--)
               mat[j][k]=((1LL*mat[j][k]*mat[i][i]-1LL*mat[i][k]*mat[j][i])%p+p)%p;
         }
   }
   for (int i=1;i<=s;i++)
      ans=1LL*ans*mat[i][i]%p;
   if (flag)
      ans=p-ans;
   out:
   cout<<ans<<endl;
   return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define N 610
#define M 220000
using namespace std;
int n,m,mo,f[N],chu[N],ru[N],next[M],e[M],head[N],num,be[N],a[N][N],i,x,y,len,ans,j,k;
int dfs(int x){
	if(f[x]!=-1)return f[x];
	f[x]=0;
	for(int i=head[x];i;i=next[i])f[x]=(f[x]+dfs(e[i]))%mo;
	return f[x];
}
void work(int s){
	int l,x,i,k;
	++num;
	memset(f,255,sizeof(f));
	f[s]=1;
	l=0;
	for(i=1;i<=n;++i)if(!chu[i])
		a[num][++l]=dfs(i);
}
long long pow(long long x,int y){
	long long res=1;
	while(y){
		if(y&1)res=res*x%mo;
		y/=2;
		x=x*x%mo;
	}
	return res;
}
int main(){
	scanf("%d%d%d",&n,&m,&mo);
	for(i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		ru[y]++;
		chu[x]++;
		next[++len]=head[y]; head[y]=len; e[len]=x;
	}
	ans=1;
	for(i=1;i<=n;++i)if(!ru[i])work(i);
	for(i=1;i<=num;++i){
		for(j=i;j<=num;++j)if(a[j][i])break;
		if(j>num)return printf("%d\n",0),0;
		if(j!=i){
			for(k=1;k<=num;++k)swap(a[i][k],a[j][k]);
			ans*=-1;
		}
		for(j=i+1;j<=num;++j)if(a[j][i]){
			for(k=num;k>=i;--k)a[j][k]=((long long)a[j][k]*a[i][i]-(long long)a[i][k]*a[j][i])%mo;
			ans=pow(a[i][i],mo-2)*ans%mo;
		}
		ans=1ll*ans*a[i][i]%mo;
	}
	printf("%d\n",(ans+mo)%mo);
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define N 610
#define M 220000
using namespace std;
int n,m,mo,f[N],chu[N],ru[N],next[M],e[M],head[N],num,be[N],a[N][N],i,x,y,len,ans,j,k;
int dfs(int x){
	if(f[x]!=-1)return f[x];
	f[x]=0;
	for(int i=head[x];i;i=next[i])f[x]=(f[x]+dfs(e[i]))%mo;
	return f[x];
}
void work(int s){
	int l,x,i,k;
	++num;
	memset(f,255,sizeof(f));
	f[s]=1;
	l=0;
	for(i=1;i<=n;++i)if(!chu[i])
		a[num][++l]=dfs(i);
}
long long pow(long long x,int y){
	long long res=1;
	while(y){
		if(y&1)res=res*x%mo;
		y/=2;
		x=x*x%mo;
	}
	return res;
}
int main(){
	scanf("%d%d%d",&n,&m,&mo);
	for(i=1;i<=m;++i){
		scanf("%d%d",&x,&y);
		ru[y]++;
		chu[x]++;
		next[++len]=head[y]; head[y]=len; e[len]=x;
	}
	ans=1;
	for(i=1;i<=n;++i)if(!ru[i])work(i);
	for(i=1;i<=num;++i){
		for(j=i;j<=num;++j)if(a[j][i])break;
		if(j>num)return printf("%d\n",0),0;
		if(j!=i){
			for(k=1;k<=num;++k)swap(a[i][k],a[j][k]);
			ans*=-1;
		}
		for(j=i+1;j<=num;++j)if(a[j][i]){
			for(k=num;k>=i;--k)a[j][k]=((long long)a[j][k]*a[i][i]-(long long)a[i][k]*a[j][i])%mo;
			ans=pow(a[i][i],mo-1)*ans%mo;
		}
		ans=1ll*ans*a[i][i]%mo;
	}
	printf("%d\n",(ans+mo)%mo);
}


#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>

using namespace std;

typedef long long int ll;

ll modulo;

ll eleva(ll b,ll e)
{
  if (e==0) return 1;
  if (e%2==0) return eleva(b*b%modulo,e/2);
  return b*eleva(b*b%modulo,e/2)%modulo;
}

ll inverso(ll x)
{
  return eleva(x,modulo-2);
}

ll caminos[601][601];

int n,m;
vector<int> g[601];
int in[601];
int out[601];
int vistos[601];

vector<int> lista1;
vector<int> lista2;
ll matriz[601][601];
int k;

void escribe()
{
  for (int i=0;i<k;i++) {
    for (int j=0;j<k;j++)
      cout<<matriz[i][j]<<",";
    cout<<endl;
  }
}

int main()
{
  cin>>n>>m>>modulo;
  for (int i=0;i<m;i++) {
    int u,v;
    cin>>u>>v;
    g[u].push_back(v);
    out[u]++;
    in[v]++;
  }
  for (int uu=1;uu<=n;uu++) {
    for (int v=1;v<=n;v++)
      vistos[v]=0;
    caminos[uu][uu]=1;
    queue<int> q;
    q.push(uu);
    while (not q.empty()) {
      int u=q.front();
      q.pop();
      vector<int> &ar=g[u];
      for (int i=0;i<int(ar.size());i++) {
	int v=ar[i];
	vistos[v]++;
	caminos[uu][v]+=caminos[uu][u];
	caminos[uu][v]%=modulo;
	if (vistos[v]==in[v])
	  q.push(v);
      }
    }
  }
  for (int u=1;u<=n;u++) {
    if (in[u]==0) lista1.push_back(u);
    if (out[u]==0) lista2.push_back(u);
  }
  k=int(lista1.size());
  for (int i=0;i<k;i++)
    for (int j=0;j<k;j++)
      matriz[i][j]=caminos[lista1[i]][lista2[j]];

  //escribe();

  ll sol=1;
  ll signo=1;
  for (int i=0;i<k;i++) {
    {
      int ii=i;
      while (ii<k and matriz[ii][i]==0) ii++;
      if (ii==k) {
	cout<<0<<endl;
	exit(0);
      }
      if (ii>i) {
	for (int j=i;j<k;j++)
	  swap(matriz[i][j],matriz[ii][j]);
	signo*=-1;
      }
    }
    for (int ii=i+1;ii<k;ii++) {
      if (matriz[ii][i]) {
	ll factor=(-matriz[ii][i]*inverso(matriz[i][i]))%modulo;
	for (int j=i;j<k;j++)
	  matriz[ii][j]=(matriz[ii][j]+factor*matriz[i][j])%modulo;
      }
    }
    sol=(sol*matriz[i][i])%modulo;
    //escribe();
  }
  sol=((signo*sol%modulo)+modulo)%modulo;
  cout<<sol<<endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>

using namespace std;

typedef long long int ll;

ll modulo;

ll eleva(ll b,ll e)
{
  if (e==0) return 1;
  if (e%2==0) return eleva(b*b%modulo,e/2);
  return b*eleva(b*b%modulo,e/2)%modulo;
}

ll inverso(ll x)
{
  return eleva(x,modulo-2);
}

ll caminos[601][601];

int n,m;
vector<int> g[601];
int in[601];
int out[601];
int vistos[601];

vector<int> lista1;
vector<int> lista2;
ll matriz[601][601];
int k;

void escribe()
{
  for (int i=0;i<k;i++) {
    for (int j=0;j<k;j++)
      cout<<matriz[i][j]<<",";
    cout<<endl;
  }
}

int main()
{
  cin>>n>>m>>modulo;
  for (int i=0;i<m;i++) {
    int u,v;
    cin>>u>>v;
    g[u].push_back(v);
    out[u]++;
    in[v]++;
  }
  for (int uu=1;uu<=n;uu++) {
    for (int v=1;v<=n;v++)
      vistos[v]=0;
    caminos[uu][uu]=1;
    queue<int> q;
    q.push(uu);
    while (not q.empty()) {
      int u=q.front();
      q.pop();
      vector<int> &ar=g[u];
      for (int i=0;i<int(ar.size());i++) {
	int v=ar[i];
	vistos[v]++;
	caminos[uu][v]+=caminos[uu][u];
	caminos[uu][v]%=modulo;
	if (vistos[v]==in[v])
	  q.push(v);
      }
    }
  }
  for (int u=1;u<=n;u++) {
    if (in[u]==0) lista1.push_back(u);
    if (out[u]==0) lista2.push_back(u);
  }
  k=int(lista1.size());
  for (int i=0;i<k;i++)
    for (int j=0;j<k;j++)
      matriz[i][j]=caminos[lista1[i]][lista2[j]];

  //escribe();

  ll sol=1;
  ll signo=1;
  for (int i=0;i<k;i++) {
    {
      int ii=i;
      while (ii<k and matriz[ii][i]==0) ii++;
      if (ii==k) {
	cout<<0<<endl;
	exit(0);
      }
      if (ii>i) {
	for (int j=i;j<k;j++)
	  swap(matriz[i][j],matriz[ii][j]);
	signo*=-1;
      }
    }
    for (int ii=i+1;ii<k;ii++) {
      ll factor=(-matriz[ii][i]*inverso(matriz[i][i]))%modulo;
      for (int j=i;j<k;j++)
	matriz[ii][j]=(matriz[ii][j]+factor*matriz[i][j])%modulo;
    }
    sol=(sol*matriz[i][i])%modulo;
    //escribe();
  }
  sol=((signo*sol%modulo)+modulo)%modulo;
  cout<<sol<<endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>

using namespace std;

typedef long long int ll;

ll modulo;

ll eleva(ll b,ll e)
{
  if (e==0) return 1;
  if (e%2==0) return eleva(b*b%modulo,e/2);
  return b*eleva(b*b%modulo,e/2)%modulo;
}

ll inverso(ll x)
{
  return eleva(x,modulo-2);
}

ll caminos[601][601];

int n,m;
vector<int> g[601];
int in[601];
int out[601];
int vistos[601];

vector<int> lista1;
vector<int> lista2;
ll matriz[601][601];
int k;

void escribe()
{
  for (int i=0;i<k;i++) {
    for (int j=0;j<k;j++)
      cout<<matriz[i][j]<<",";
    cout<<endl;
  }
}

int main()
{
  cin>>n>>m>>modulo;
  for (int i=0;i<m;i++) {
    int u,v;
    cin>>u>>v;
    g[u].push_back(v);
    out[u]++;
    in[v]++;
  }
  queue<int> q;
  for (int u=1;u<=n;u++) {
    if (in[u]==0) {
      lista1.push_back(u);
      q.push(u);
      caminos[u][u]=1;
    }
    if (out[u]==0) lista2.push_back(u);
  }
  while (not q.empty()) {
    int u=q.front();
    q.pop();
    vector<int> &ar=g[u];
    for (int i=0;i<int(ar.size());i++) {
      int v=ar[i];
      vistos[v]++;
      for (int j=0;j<int(lista1.size());j++) {
	int uu=lista1[j];
	caminos[uu][v]+=caminos[uu][u];
	caminos[uu][v]%=modulo;
      }
      if (vistos[v]==in[v])
	q.push(v);
    }
  }
  k=int(lista1.size());
  for (int i=0;i<k;i++)
    for (int j=0;j<k;j++)
      matriz[i][j]=caminos[lista1[i]][lista2[j]];

  //escribe();

  ll sol=1;
  ll signo=1;
  for (int i=0;i<k;i++) {
    {
      int ii=i;
      while (ii<k and matriz[ii][i]==0) ii++;
      if (ii==k) {
	cout<<0<<endl;
	exit(0);
      }
      if (ii>i) {
	for (int j=i;j<k;j++)
	  swap(matriz[i][j],matriz[ii][j]);
	signo*=-1;
      }
    }
    for (int ii=i+1;ii<k;ii++) {
      if (matriz[ii][i]) {
	ll factor=(-matriz[ii][i]*inverso(matriz[i][i]))%modulo;
	for (int j=i;j<k;j++)
	  matriz[ii][j]=(matriz[ii][j]+factor*matriz[i][j])%modulo;
      }
    }
    sol=(sol*matriz[i][i])%modulo;
    //escribe();
  }
  sol=((signo*sol%modulo)+modulo)%modulo;
  cout<<sol<<endl;
}


#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
int P;

int N;
vector <int> graph[610]; // edge_from
int indeg[610],outdeg[610];
vector <int> source,sink;
int dp[610];

int dfs(int x){
    int i;

    if(dp[x] != -1) return dp[x];

    int ans = 0;
    REP(i,graph[x].size()){
        ans += dfs(graph[x][i]);
        if(ans >= P) ans -= P;
    }

    return dp[x] = ans;
}

int D;
ll a[310][310];

ll power(ll x, ll n){
    if(n == 0) return 1;
    ll y = power(x,n/2);
    y = y * y % P;
    if(n%2 == 1) y = y * x % P;
    return y;
}

ll func(void){
    int i,j,k;

/*  REP(i,D){
        REP(j,D) cout << a[i][j] << ' ';
        cout << endl;
    }
*/

    bool neg = false;

    REP(j,D){
        for(i=j;i<D;i++) if(a[i][j] != 0) break;
        if(i == D) return 0;
        if(i != j){
            neg = !neg;
            REP(k,D) swap(a[i][k],a[j][k]);
        }

        for(i=j+1;i<D;i++){
            ll coef = (P - a[i][j]) * power(a[j][j],P-2) % P;
            for(k=j;k<D;k++) a[i][k] = (a[i][k] + a[j][k] * coef) % P;
        }
    }

    ll ans = (neg ? (P - 1) : 1);
    REP(i,D) ans = ans * a[i][i] % P;
    return ans;
}

int main(void){
    int M,x,y,i,j;

    scanf("%d%d%d",&N,&M,&P);
    REP(i,M){
        scanf("%d%d",&x,&y);
        x--; y--;
        indeg[y]++; outdeg[x]++;
        graph[y].push_back(x);
    }

    REP(i,N){
        if(indeg[i] > 0 && outdeg[i] == 0) sink.push_back(i);
        if(indeg[i] == 0 && outdeg[i] > 0) source.push_back(i);
    }

    D = sink.size();
    REP(i,D){
        REP(j,N) dp[j] = -1;
        dp[source[i]] = 1;
        REP(j,D) a[i][j] = dfs(sink[j]);
    }

    ll ans = func();

    bool neg = false;
    REP(i,N) if(indeg[i] == 0 && outdeg[i] == 0){
        int cnt1 = 0, cnt2 = 0;
        REP(j,D) if(sink[j] < i) cnt1++;
        REP(j,D) if(source[j] < i) cnt2++;
        if(cnt1 % 2 != cnt2 % 2) neg = !neg;
    }
    if(neg) ans = (P - ans) % P;

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = 2 * ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	r[n + m + 1] = n + m + 1;
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == n + m + 1)
		{
			ans[l[i]]++;
			continue;
		}
		if (pos[r[i]] - pos[i] < pos[i] - pos[l[i]])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	r[n + m] = n + m;
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == n + m + 1)
		{
			ans[l[i]]++;
			continue;
		}
		if (r[i] - i < i - l[i])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	r[n + m + 1] = n + m + 1;
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == n + m + 1)
		{
			ans[l[i]]++;
			continue;
		}
		if (r[i] - i < i - l[i])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == 0)
		{
			ans[l[i]]++;
			continue;
		}
		if (r[i] - i < i - l[i])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == n + m + 1)
		{
			ans[l[i]]++;
			continue;
		}
		if (r[i] - i < i - l[i])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)

const int N = ((int)1e5) + 5;

int n,m;
int pos[N];
bool ist[N];
int l[N];
int r[N];
int ans[N];

int main ()
{
	scanf("%d %d",&n,&m);
	r[n + m + 1] = n + m + 1;
	for (int i = 1; i <= n + m; i++)
	{
		scanf("%d",&pos[i]);
	}
	for (int i = 1; i <= n + m; i++)
	{
		int x;
		scanf("%d",&x);
		ist[i] = (x == 1);
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			l[i] = i;
		else
			l[i] = l[i - 1];
	}
	for (int i = n + m; i >= 1; i--)
	{
		if (ist[i])
			r[i] = i;
		else
			r[i] = r[i + 1];
	}
	for (int i = 1; i <= n + m; i++)
	{
		if (ist[i])
			continue;
		if (l[i] == 0)
		{
			ans[r[i]]++;
			continue;
		}
		if (r[i] == n + m + 1)
		{
			ans[l[i]]++;
			continue;
		}
		if (pos[r[i]] - pos[i] < pos[i] - pos[l[i]])
			ans[r[i]]++;
		else
			ans[l[i]]++;
	}
	for (int i = 1; i <= n + m; i++)
		if (ist[i])
			printf("%d ",ans[i]);
}


#include <iostream>
#include<vector>
#include<iterator>
using namespace std;

int main()
{
    long long int n,m,g=0;
    cin>>n>>m;
    vector<long long int>v1;
    vector<pair<long long int,long long int> >v2;
    vector<long long int>::iterator it1;
    vector<pair<long long int,long long int> >::iterator it2;
    vector<pair<long long int,long long int> >::iterator it3;

    for(long long int i=0;i<n+m;i++){
        long long int a;
        cin>>a;
        v1.push_back(a);
    }
    it1=v1.begin();
    for(long long int i=0;i<n+m;i++){
        long long int a;
        cin>>a;
        if(a==1){
            v2.push_back(make_pair(*(it1),0));
        }
        it1++;
    }
    it1=v1.begin();
    it2=v2.begin();
    it3=v2.begin();
    it3++;
    //cout<<*(it1)<<it2->first<<it3->first<<endl;
    while(it1!=v1.end()){
        if(g==0){
            //cout<<*(it1)<<it2->first<<it3->first<<endl;
            if(*(it1)<=(it2->first+it3->first)/2){
            //    cout<<"hey"<<endl;
                it2->second++;
            }
            else{
          //      cout<<"arre"<<endl;
                it2++;
                it3++;
            }
        }

        if(it3==v2.end()){
        //    cout<<"oohho"<<endl;
            g=1;
            it2->second++;
        }
        it1++;
    }
    it2=v2.begin();
    while(it2!=v2.end()){
        if((it2->second)>0)
            cout<<(it2->second)-1<<" ";
        else{
            cout<<it2->second<<" ";
        }
        it2++;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,m;
    cin>>n>>m;
    long long int a[n+m],t[m],r[n],ans[m];
    //map<int,int>m;
    for(long long int i=0;i<n+m;i++){
        cin>>a[i];
        if(i<m){
            ans[i]=0;
        }
    }
    long long int l=0,ri=1,j=0,k=0;
    for(long long int i=0;i<n+m;i++){
        long long int b;
        cin>>b;
        if(b){
            t[j]=a[i];
            j++;
        }
        else{
            r[k]=a[i];
            k++;
        }
    }
    if(m==1){
        cout<<n<<endl;
        return 0;
    }
    /*for(int i=0;i<n;i++){
        cout<<r[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<m;i++){
        cout<<t[i]<<" ";
    }*/
    //cout<<endl;
    for(long long int i=0;i<n;i++){
        //cout<<r[i]<<t[l]<<t[ri]<<endl;
        if(r[i]>t[ri]){
            while(r[i]>t[ri]&&ri<m){
                l++;
                ri++;
            }
            //cout<<ri<<endl;
            if(ri>=m){
                //cout<<i<<endl;
                //cout<<"hey"<<endl;
                ans[m-1]+=n-i;
                break;
            }
        }
        if(abs(t[l]-r[i])<=abs(t[ri]-r[i])){
            //cout<<"l"<<endl;
            ans[l]++;
        }
        if(abs(t[l]-r[i])>abs(t[ri]-r[i])){
            //cout<<"r"<<endl;
            ans[ri]++;
        }

    }
    for(long long int i=0;i<m;i++){
        cout<<ans[i]<<" ";
    }
}


#include <iostream>
#include<vector>
#include<iterator>
using namespace std;

int main()
{
    long long int n,m,g=0;
    cin>>n>>m;
    vector<long long int>v1;
    vector<pair<long long int,long long int> >v2;
    vector<long long int>::iterator it1;
    vector<pair<long long int,long long int> >::iterator it2;
    vector<pair<long long int,long long int> >::iterator it3;

    for(long long int i=0;i<n+m;i++){
        long long int a;
        cin>>a;
        v1.push_back(a);
    }
    it1=v1.begin();
    for(long long int i=0;i<n+m;i++){
        long long int a;
        cin>>a;
        if(a==1){
            v2.push_back(make_pair(*(it1),0));
        }
        it1++;
    }
    it1=v1.begin();
    it2=v2.begin();
    it3=v2.begin();
    it3++;
    if(it3==v2.end()){
        g=1;
    }
    //cout<<*(it1)<<it2->first<<it3->first<<endl;
    while(it1!=v1.end()){
        if(g==0){
            //cout<<*(it1)<<it2->first<<it3->first<<endl;
            if(*(it1)<=(it2->first+it3->first)/2){
            //    cout<<"hey"<<endl;
                it2->second++;
            }
            else{
          //      cout<<"arre"<<endl;
                it2++;
                it3++;
            }
        }

        if(it3==v2.end()){
        //    cout<<"oohho"<<endl;
            g=1;
            it2->second++;
        }
        it1++;
    }
    it2=v2.begin();
    while(it2!=v2.end()){
        if((it2->second)>0){
            cout<<(it2->second)-1<<" ";
        }
        else{
            cout<<it2->second<<" ";
        }
        it2++;
    }
}


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

int main()
{
    long long int r,t;
    cin>>r>>t;
    long long int P[r+t],m[r+t],T[t],R[r];
    long long int t1[t];
    long long int i,j,k;
    unsigned long long int l,u;
    j=0;k=0;
    for(i=0;i<(r+t);i++){
        cin>>P[i];
    }
    for(i=0;i<(r+t);i++){
        cin>>m[i];
        if(i<t){
            t1[i]=0;
        }
        if(m[i]==1){
            T[j]=P[i];
            j++;
        }
        else{
            R[k]=P[i];
            k++;
        }
    }

    for(i=0;i<r;i++){
            l=1000000000;
        for(j=0;j<t;j++){
            u=l;
            l=abs(T[j]-R[i]);
            //cout<<u<< "  "<<l<<endl;
            if(l>=u){
                t1[j-1]++;
                break;
            }
            if(j==t-1){
                t1[j]++;
            }
        }
    }
    for(i=0;i<t;i++){
        cout<<t1[i]<< " ";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,m;
    cin>>n>>m;
    long long int a[n+m],t[m],r[n],ans[m];
    //map<int,int>m;
    for(long long int i=0;i<n+m;i++){
        cin>>a[i];
        if(i<m){
            ans[i]=0;
        }
    }
    long long int l=0,ri=1,j=0,k=0;
    for(long long int i=0;i<n+m;i++){
        long long int b;
        cin>>b;
        if(b){
            t[j]=a[i];
            j++;
        }
        else{
            r[k]=a[i];
            k++;
        }
    }
    if(m==1){
        cout<<n<<endl;
        return 0;
    }
    /*for(int i=0;i<n;i++){
        cout<<r[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<m;i++){
        cout<<t[i]<<" ";
    }*/
    //cout<<endl;
    for(long long int i=0;i<n;i++){
        //cout<<r[i]<<t[ri]<<endl;
        if(r[i]>t[ri]){
            while(r[i]>t[ri]){
                l++;
                ri++;
            }
            //cout<<ri<<endl;
            if(ri>=m){
                //cout<<i<<endl;
                //cout<<"hey"<<endl;
                ans[ri-1]+=n-i;
                break;
            }
        }
        else if(abs(t[l]-r[i])<=abs(t[ri]-r[i])){
            ans[l]++;
        }
        else if(abs(t[l]-r[i])>abs(t[ri]-r[i])){
            ans[ri]++;
        }

    }
    for(long long int i=0;i<m;i++){
        cout<<ans[i]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,m;
    cin>>n>>m;
    long long int a[n+m],t[m],r[n],ans[m];
    //map<int,int>m;
    for(long long int i=0;i<n+m;i++){
        cin>>a[i];
        if(i<m){
            ans[i]=0;
        }
    }
    long long int l=0,ri=1,j=0,k=0;
    for(long long int i=0;i<n+m;i++){
        long long int b;
        cin>>b;
        if(b){
            t[j]=a[i];
            j++;
        }
        else{
            r[k]=a[i];
            k++;
        }
    }
    if(m==1){
        cout<<n<<endl;
        return 0;
    }
    /*for(int i=0;i<n;i++){
        cout<<r[i]<<" ";
    }
    cout<<endl;
    for(int i=0;i<m;i++){
        cout<<t[i]<<" ";
    }*/
    //cout<<endl;
    for(long long int i=0;i<n;i++){
        //cout<<r[i]<<t[ri]<<endl;
        if(r[i]>t[ri]){
            while(r[i]>t[ri]&&ri<m){
                l++;
                ri++;
            }
            //cout<<ri<<endl;
            if(ri>=m){
                //cout<<i<<endl;
                //cout<<"hey"<<endl;
                ans[m-1]+=n-i;
                break;
            }
        }
        else if(abs(t[l]-r[i])<=abs(t[ri]-r[i])){
            ans[l]++;
        }
        else if(abs(t[l]-r[i])>abs(t[ri]-r[i])){
            ans[ri]++;
        }

    }
    for(long long int i=0;i<m;i++){
        cout<<ans[i]<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100005
#define MOD 1000000007
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef vector<int> vi;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	int n, m;
	cin>>n>>m;
	int a[n+m];
	int d[n];
	for(int i=0;i<n+m;i++){
		cin>>a[i];
	}
	for(int i=0;i<n+m;i++){
		cin>>d[i];
	}

	set<int> driv;
	int cnt=0;
	mii ans;

	for(int i=0;i<n+m;i++){
		if(d[i]){
			driv.insert(a[i]);
		}
	}

	for(int i=0;i<n+m;i++){
		if(!d[i]){
			set<int>::iterator bef = driv.upper_bound(a[i]);
			bef--;
			set<int>::iterator aft = bef;
			bef++;
			int drivaft;
			if(bef!=driv.begin())
				drivaft = *aft;
			int drivbef = *bef;

//			cout<<a[i]<<" goes to ("<<drivaft<<" "<<drivbef<<endl;
			if(bef==driv.begin() || (bef!=driv.end() && abs(a[i]-drivaft)<abs(a[i]-drivbef))){
//				cout<<drivbef<<endl;
				ans[drivbef]++;
			}
			else{
//				cout<<drivaft<<endl;
				ans[drivaft]++;
			}
		}
	}
	for(int i=0;i<n+m;i++){
		if(d[i])
			cout<<ans[a[i]]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100005
#define MOD 1000000007
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef vector<int> vi;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	ll n, m;
	cin>>n>>m;
	ll a[n+m+1];
	ll d[n+m+1];
	for(int i=0;i<n+m;i++){
		cin>>a[i];
	}
	for(int i=0;i<n+m;i++){
		cin>>d[i];
	}
	set<int> driv;
	mii ans;

	for(int i=0;i<n+m;i++){
		if(d[i]){
//			cout<<a[i]<<" ";
			driv.insert(a[i]);
		}
	}
//	cout<<endl;

	for(int i=0;i<n+m;i++){
		if(!d[i]){
			set<int>::iterator bef = driv.upper_bound(a[i]);
			bef--;
			set<int>::iterator aft = bef;
			bef++;
			int drivaft;
			if(bef!=driv.begin())
				drivaft = *aft;
			int drivbef = *bef;

//			cout<<a[i]<<" goes to ("<<drivaft<<" "<<drivbef<<endl;
			if(bef==driv.begin() || (bef!=driv.end() && abs(a[i]-drivaft)<abs(a[i]-drivbef))){
//				cout<<drivbef<<endl;
				ans[drivbef]++;
			}
			else{
//				cout<<drivbef<<" ";
//				cout<<drivaft<<endl;
				ans[drivaft]++;
			}
		}
	}
	for(int i=0;i<n+m;i++){
		if(d[i])
			cout<<ans[a[i]]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100005
#define MOD 1000000007
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef vector<int> vi;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	int n, m;
	cin>>n>>m;
	int a[n+m];
	int d[n];
	for(int i=0;i<n+m;i++){
		cin>>a[i];
	}
	for(int i=0;i<n+m;i++){
		cin>>d[i];
	}

	set<int> driv;
	int cnt=0;
	mii ans;

	for(int i=0;i<n+m;i++){
		if(d[i]){
			driv.insert(a[i]);
		}
	}

	for(int i=0;i<n+m;i++){
		if(!d[i]){
			set<int>::iterator bef = driv.upper_bound(a[i]);
			bef--;
			set<int>::iterator aft = bef;
			bef++;
			int drivaft;
			if(bef!=driv.begin())
				drivaft = *aft;
			int drivbef = *bef;

//			cout<<a[i]<<" goes to ("<<drivaft<<" "<<drivbef<<endl;
			if(bef==driv.begin() || (bef!=driv.end() && abs(a[i]-drivaft)<=abs(a[i]-drivbef))){
//				cout<<drivbef<<endl;
				ans[drivbef]++;
			}
			else{
//				cout<<drivaft<<endl;
				ans[drivaft]++;
			}
		}
	}
	for(int i=0;i<n+m;i++){
		if(d[i])
			cout<<ans[a[i]]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100005
#define MOD 1000000007
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef vector<int> vi;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	ll n, m;
	cin>>n>>m;
	ll a[n+m+1];
	int d[n+m+1];
	for(int i=0;i<n+m;i++){
		cin>>a[i];
	}
	for(int i=0;i<n+m;i++){
		cin>>d[i];
	}
	set<int> driv;
	mii ans;

	for(int i=0;i<n+m;i++){
		if(d[i]){
//			cout<<a[i]<<" ";
			driv.insert(a[i]);
		}
	}
//	cout<<endl;

	for(int i=0;i<n+m;i++){
		if(!d[i]){
			set<int>::iterator bef = driv.upper_bound(a[i]);
			bef--;
			set<int>::iterator aft = bef;
			bef++;
			int drivaft;
			int drivbef = *bef;
			if(bef!=driv.begin())
				drivaft = *aft;
			else{
				ans[drivbef]++;
				continue;
			}

//			cout<<a[i]<<" goes to ("<<drivaft<<" "<<drivbef<<endl;
			if((bef!=driv.end() && abs(a[i]-drivaft)>abs(a[i]-drivbef))){
//				cout<<drivbef<<endl;
				ans[drivbef]++;
			}
			else{
//				cout<<drivbef<<" ";
//				cout<<drivaft<<endl;
				ans[drivaft]++;
			}
		}
	}
	for(int i=0;i<n+m;i++){
		if(d[i])
			cout<<ans[a[i]]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100005
#define MOD 1000000007
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef map<int, int> mii;
typedef vector<int> vi;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	ll n, m;
	cin>>n>>m;
	ll a[n+m+1];
	int d[n+m+1];
	for(int i=0;i<n+m;i++){
		cin>>a[i];
	}
	for(int i=0;i<n+m;i++){
		cin>>d[i];
	}
	set<int> driv;
	mii ans;

	for(int i=0;i<n+m;i++){
		if(d[i]){
//			cout<<a[i]<<" ";
			driv.insert(a[i]);
		}
	}
//	cout<<endl;

	for(int i=0;i<n+m;i++){
		if(!d[i]){
			set<int>::iterator bef = driv.upper_bound(a[i]);
			if(bef==driv.begin()){
				ans[(*bef)]++;
				continue;
			}
			bef--;
			set<int>::iterator aft = bef;
			bef++;
			int drivaft;
			int drivbef = *bef;
			drivaft = *aft;

//			cout<<a[i]<<" goes to ("<<drivaft<<" "<<drivbef<<endl;
			if((bef!=driv.end() && abs(a[i]-drivaft)>abs(a[i]-drivbef))){
//				cout<<drivbef<<endl;
				ans[drivbef]++;
			}
			else{
//				cout<<drivbef<<" ";
//				cout<<drivaft<<endl;
				ans[drivaft]++;
			}
		}
	}
	for(int i=0;i<n+m;i++){
		if(d[i])
			cout<<ans[a[i]]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int i=0; i<n; i++)
ll n,x,y,z,c,c1,c2,k,k1,t,l,m,arr[100005],arr1[100005],arr2[100005];

int main()
{
    ios;
    cin>>n>>m;
    for(int i=0; i<n+m; i++)cin>>arr[i];
    for(int i=0; i<n+m; i++)
    {
        cin>>x;
        if(x)arr1[c1++]=arr[i];
        else arr2[c2++]=arr[i];
    }
    int j=0;
    for(int i=0; i<m-1; i++)
    {
        c=0;
        for(; j<n; j++)
        {
            if(abs(arr1[i]-arr2[j])<=abs(arr1[i+1]-arr2[j]))c++;
            else break;
        }
        cout<<c<<' ';
        k+=c;
    }
    cout<<n-k;

    return 0;
}

/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int i=0; i<n; i++)
ll n,x,y,z,c,c1,c2,k,k1,t,l,m,arr[100005],arr1[100005],arr2[100005];

int main()
{
    ios;
    cin>>n>>m;
    for(int i=0; i<n+m; i++)cin>>arr[i];
    for(int i=0; i<n+m; i++)
    {
        cin>>x;
        if(x)arr1[c1++]=arr[i];//m
        else arr2[c2++]=arr[i];
    }
    sort(arr1,arr1+m);
    sort(arr2,arr2+n);
    for(int i=0; i<m-1; i++)
    {
        x=arr1[i+1]-arr1[i];
        y=upper_bound(arr2,arr2+n,x)-arr2;
        cout<<y-c<<' ';
        c=y;
    }
    cout<<n-c<<endl;

    return 0;
}

/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int i=0; i<n; i++)
ll n,x,y,z,c,c1,c2,k,k1,t,l,m,arr[500005],arr1[500005],arr2[500005];

int main()
{
    ios;
    cin>>n>>m;
    for(int i=0; i<n+m; i++)cin>>arr[i];
    for(int i=0; i<n+m; i++)
    {
        cin>>x;
        if(x)arr1[c1++]=arr[i];
        else arr2[c2++]=arr[i];
    }
    int j=0;
    for(int i=0; i<m-1; i++)
    {
        c=0;
        if(j==n)
        {
            cout<<0<<' ';
            continue;
        }
        for(; j<n; j++)
        {
            if(abs(arr1[i]-arr2[j])<=abs(arr1[i+1]-arr2[j]))c++;
            else break;
        }
        cout<<c<<' ';
        k+=c;
    }
    cout<<n-k;

    return 0;
}

/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int i=0; i<n; i++)
ll n,x,y,z,c,c1,c2,k,k1,t,l,m,arr[100005],arr1[100005],arr2[100005];

int main()
{
    ios;
    cin>>n>>m;
    for(int i=0; i<n+m; i++)cin>>arr[i];
    for(int i=0; i<n+m; i++)
    {
        cin>>x;
        if(x)arr1[c1++]=arr[i];
        else arr2[c2++]=arr[i];
    }
    for(int i=0; i<m-1; i++)
    {
        x=arr1[i+1]-arr1[i];
        y=lower_bound(arr2,arr2+n,x)-arr2;
        cout<<y-c<<' ';
        c=y;
    }
    cout<<n-c<<endl;

    return 0;
}

/**

**/


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define mm(o,k) memset(o,k,sizeof o)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Sort(v) sort(v.begin(),v.end())
#define rSort(v) sort(v.rbegin(),v.rend())
#define LB(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define UB(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define all(v) v.begin(),v.end()
#define FX(n) fixed<<setprecision(n)
#define F first
#define S second
#define pb push_back
#define fr(i,a,b)	for(int i=0; i<n; i++)
ll n,x,y,z,c,c1,c2,k,k1,t,l,m,arr[100005],arr1[100005],arr2[100005];

int main()
{
    ios;
    cin>>n>>m;
    for(int i=0; i<n+m; i++)cin>>arr[i];
    for(int i=0; i<n+m; i++)
    {
        cin>>x;
        if(x)arr1[c1++]=arr[i];
        else arr2[c2++]=arr[i];
    }
    int j=0;
    for(int i=0; i<m-1; i++)
    {
        c=0;
        if(j==n)
        {
            cout<<0<<' ';
            continue;
        }
        for(; j<n; j++)
        {
            if(abs(arr1[i]-arr2[j])<=abs(arr1[i+1]-arr2[j]))c++;
            else break;
        }
        cout<<c<<' ';
        k+=c;
    }
    cout<<n-k;

    return 0;
}

/**

**/


#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 2 * 1e5 + 10;
int pep[maxn];
int dri[maxn];
int main()
{
    int n, m;
    while(cin>>n>>m){
        for(int i = 0; i < m + n; i++){
            cin>>pep[i];
        }
        int cnt = 0;
        for(int i = 0; i < m + n; i++){
            int t;
            cin>>t;
            if(t){
                dri[cnt++] = i;
            }
        }
        int pos = 0;
        for(int i = 0; i < m - 1; i++){
            int ans = 0;
            int mid = (pep[dri[i]] + pep[dri[i + 1]])/2;
            //cout<<endl<<endl<<mid<<endl<<endl;
            for(; pos < dri[i + 1]; pos++)
            {
                if(pos == dri[i]) continue;
                if(pep[pos] < pep[dri[i]] || pep[pos] <= mid)
                {
                    ans++;
                }
                if(pep[pos] > mid) break;
            }
            cout<<ans;
            if(i != m - 1) cout<<" ";
        }
        int ans = 0;
        for(; pos < m + n; pos++){
            if(pep[pos] < pep[dri[m - 1]] || pep[pos] - pep[dri[m - 1]] > 0){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 2 * 1e5 + 10;
int pep[maxn];
int dri[maxn];
int main()
{
    int n, m;
    while(cin>>n>>m){
        for(int i = 0; i < m + n; i++){
            cin>>pep[i];
        }
        int cnt = 0;
        for(int i = 0; i < m + n; i++){
            int t;
            cin>>t;
            if(t){
                dri[cnt++] = i;
            }
        }
        int pos = 0;
        for(int i = 0; i < m - 1; i++){
            int ans = 0;
            int mid = (pep[dri[i]] + pep[dri[i + 1]])/2;
            for(; pos < dri[i + 1]; pos++)
            {
                if(pep[pos] < pep[dri[i]] || pep[pos] - pep[dri[i]] >= mid)
                {
                    ans++;
                }
                if(pep[pos] > mid) break;
            }
            cout<<ans;
            if(i != m - 1) cout<<" ";
        }
        int ans = 0;
        for(; pos < m + n; pos++){
            if(pep[pos] < pep[dri[m - 1]] || pep[pos] - pep[dri[m - 1]] > 0){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 2 * 1e5 + 10;
int pep[maxn];
int dri[maxn];
int main()
{
    int n, m;
    while(cin>>n>>m){
        for(int i = 0; i < m + n; i++){
            cin>>pep[i];
        }
        int cnt = 0;
        for(int i = 0; i < m + n; i++){
            int t;
            cin>>t;
            if(t){
                dri[cnt++] = i;
            }
        }
        int pos = 0;
        for(int i = 0; i < m - 1; i++){
            int ans = 0;
            int mid = (pep[dri[i]] + pep[dri[i + 1]])/2;
            //cout<<endl<<endl<<mid<<endl<<endl;
            for(; pos < dri[i + 1]; pos++)
            {
                if(pos == dri[i]) continue;
                if(pep[pos] < pep[dri[i]] || pep[pos] - pep[dri[i]] <= mid)
                {
                    ans++;
                }
                if(pep[pos] > mid) break;
            }
            cout<<ans;
            if(i != m - 1) cout<<" ";
        }
        int ans = 0;
        for(; pos < m + n; pos++){
            if(pep[pos] < pep[dri[m - 1]] || pep[pos] - pep[dri[m - 1]] > 0){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
const int maxn = 2 * 1e5 + 10;
int pep[maxn];
int dri[maxn];
int main()
{
    int n, m;
    while(cin>>n>>m){
        for(int i = 0; i < m + n; i++){
            cin>>pep[i];
        }
        int cnt = 0;
        for(int i = 0; i < m + n; i++){
            int t;
            cin>>t;
            if(t){
                dri[cnt++] = i;
            }
        }
        int pos = 0;
        for(int i = 0; i < m - 1; i++){
            int ans = 0;
            int mid = (pep[dri[i]] + pep[dri[i + 1]])/2;
            //cout<<endl<<endl<<mid<<endl<<endl;
            for(; pos < dri[i + 1]; pos++)
            {
                if(pep[pos] < pep[dri[i]] || pep[pos] - pep[dri[i]] <= mid)
                {
                    ans++;
                }
                if(pep[pos] > mid) break;
            }
            cout<<ans;
            if(i != m - 1) cout<<" ";
        }
        int ans = 0;
        for(; pos < m + n; pos++){
            if(pep[pos] < pep[dri[m - 1]] || pep[pos] - pep[dri[m - 1]] > 0){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()

using namespace std;

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

const int N=100003;

int n, m;

int x[N+N], ans[N+N];
vector<int> taxi;
bool isTaxi[N+N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0; i<n+m; ++i) cin>>x[i];
    for(int i=0; i<n+m; ++i) {
        cin>>isTaxi[i];
        if(isTaxi[i]) taxi.push_back(i);
    }
    int minn, idx, tt;
    for(int i=0; i<n+m; ++i) {
        if(isTaxi[i]) continue;
        minn=(int)(1e9)+100;
        for(auto j:taxi) {
            tt=abs(x[j]-x[i]);
            if(minn>tt) {
                minn=tt;
                idx=j;
            }
            else if(minn==tt) idx=min(idx, j);
        }
        ans[idx]++;
    }
    for(auto i:taxi) cout<<ans[i]<<" ";
    cout<<endl;
    //cerr<<"Time: "<<clock()/(CLOCKS_PER_SEC*1.0)<<"s"<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()

using namespace std;

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

const int N=100003;

int n, m;
bool fl;

int x[N+N], ans[N+N];
vector<int> taxi, notTaxi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0; i<n+m; ++i) cin>>x[i];
    for(int i=0; i<n+m; ++i) {
        cin>>fl;
        if(fl) taxi.push_back(x[i]);
        else notTaxi.push_back(x[i]);
    }
    int idx=0;
    for(int i:notTaxi) {
        while(idx<m-1 && abs(i-taxi[idx])>abs(i-taxi[idx+1])) idx++;
        ans[idx]++;
    }
    for(int i=0; i<m; ++i) cout<<ans[i]<<" ";
    cout<<endl;
    //cerr<<"Time: "<<clock()/(CLOCKS_PER_SEC*1.0)<<"s"<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()

using namespace std;

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

const int N=100003;

int n, m;

int x[N+N], ans[N+N];
vector<int> taxi, taxiValue;
bool isTaxi[N+N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0; i<n+m; ++i) cin>>x[i];
    for(int i=0; i<n+m; ++i) {
        cin>>isTaxi[i];
        if(isTaxi[i]) taxi.push_back(i), taxiValue.push_back(x[i]);
    }
    taxiValue.push_back((int)(1e9)+1);
    taxiValue.push_back((int)(-1e9)+1);
    sort(all(taxiValue));
    int mid, a1, a2;
    for(int i=0; i<n+m; ++i) {
        if(isTaxi[i]) continue;
        mid=lower_bound(all(taxiValue), x[i])-taxiValue.begin();
        a1=abs(taxiValue[mid]-x[i]);a2=abs(taxiValue[mid-1]-x[i]);
        if(a1>=a2) ans[mid-1]++;
        else ans[mid]++;
    }
    for(int i=1; i<=m; ++i) cout<<ans[i]<<" ";
    cout<<endl;
    //cerr<<"Time: "<<clock()/(CLOCKS_PER_SEC*1.0)<<"s"<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define endl '\n'
#define ff first
#define ss second
#define all(abcc) (abcc).begin(), (abcc).end()

using namespace std;

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

const int N=100003;

int n, m;

int x[N+N], ans[N+N];
vector<int> taxi, taxiValue;
bool isTaxi[N+N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0; i<n+m; ++i) cin>>x[i];
    taxi.push_back(-1);
    for(int i=0; i<n+m; ++i) {
        cin>>isTaxi[i];
        if(isTaxi[i]) taxi.push_back(i), taxiValue.push_back(x[i]);
    }
    taxi.push_back(-1);
    taxiValue.push_back((int)(1e9)+1);
    taxiValue.push_back((int)(-1e9)+1);
    sort(all(taxiValue));
    int mid, a1, a2;
    for(int i=0; i<n+m; ++i) {
        if(isTaxi[i]) continue;
        mid=lower_bound(all(taxiValue), x[i])-taxiValue.begin();
        a1=abs(taxiValue[mid]-x[i]);a2=abs(taxiValue[mid-1]-x[i]);
        if(a1>=a2) ans[mid-1]++;
        else ans[mid]++;
    }
    for(int i=1; i<=m; ++i) cout<<ans[i]<<" ";
    cout<<endl;
    //cerr<<"Time: "<<clock()/(CLOCKS_PER_SEC*1.0)<<"s"<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[1005], d[1005], r[1005], ans=0, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		bool y;
		cin >> y;
		if (y)d[c++] = x[i];
		else r[k++] = x[i];
	}
	k = 0;
	for (int  i = 0; i < m; i++)
	{
		while (k<n&&(i==m-1||abs(d[i]-r[k])<=abs(d[i+1]-r[k])))
		{
			ans++;
			k++;
		}
		cout << ans << " ";
		ans = 0;
	}

#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[1005], y[1005], d[1005], r[1005], ans[1005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	sort(d, d + m);
	sort(r, r + n);
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
			if (r[i] > d[m - 1]) {
				ans[m - 1]++; i++;
			}
			else if (r[i] > d[j] && r[i] < d[j + 1]) {
			if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
				ans[j]++; i++;
			}
			else { ans[j + 1]++; i++; }
			}
			else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[200005], y[100005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	sort(d, d + m);
	sort(r, r + n);
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
			if (r[i] > d[m - 1]) {
				ans[m - 1]++; i++;
			}
			else if (r[i] > d[j] && r[i] < d[j + 1]) {
			if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
				ans[j]++; i++;
			}
			else { ans[j + 1]++; i++; }
			}
			else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[100005], y[100005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
			if (r[i] > d[m - 1]) {
				ans[m - 1]++; i++;
			}
			else if (r[i] > d[j] && r[i] < d[j + 1]) {
			if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
				ans[j]++; i++;
			}
			else { ans[j + 1]++; i++; }
			}
			else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	int n, m, x[1005], y[1005], d[1005], r[1005], ans[1005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;

	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	d[c] = 10000000;
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
					if (r[i] > d[j] && r[i] < d[j + 1]) {
						if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
							ans[j]++; i++;
						}
						else { ans[j + 1]++; i++; }
				}
					else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[100005], d[100005], r[100005], ans=0, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		bool y;
		cin >> y;
		if (y)d[c++] = x[i];
		else r[k++] = x[i];
	}
	if (m == 1)cout << n;
	else {
		k = 0;
		for (int  i = 0; i < m; i++)
		{
			while (k<n&&(i==m-1||abs(d[i]-r[k])<=abs(d[i+1]-r[k])))
			{
				ans++;
				k++;
			}
			cout << ans << " ";
			ans = 0;
		}

	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	int n, m, x[100005], y[100005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;

	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	if (m == 1)cout << n;
	else {
		for (int i = 0; i < n; i++)
		{
			if (r[i] < d[0])ans[0]++;
			else if (r[i]>d[m - 1])ans[m - 1]++;
			else {
				for (int j = 0; j < m - 1; j++)
				{
					if (r[i] > d[j] && r[i] < d[j + 1]) {
						if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
							ans[j]++; break;
						}
						else { ans[j + 1]++; break; }

					}
				}
			}
		}

	for (int i = 0; i < m; i++)
	{
		cout << ans[i] << " ";
	}}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	int n, m, x[100005], y[100005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	d[c] = 10000000;
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
					if (r[i] > d[j] && r[i] < d[j + 1]) {
						if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
							ans[j]++; i++;
						}
						else { ans[j + 1]++; i++; }
				}
					else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[200005], d[100005], r[100005], ans=0, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		bool y;
		cin >> y;
		if (y)d[c++] = x[i];
		else r[k++] = x[i];
	}
	k = 0;
	for (int  i = 0; i < m; i++)
	{
		while (k<n&&(i==m-1||abs(d[i]-r[k])<=abs(d[i+1]-r[k])))
		{
			ans++;
			k++;
		}
		cout << ans << " ";
		ans = 0;
	}

#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	int n, m, x[100005], y[1005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
			if (r[i] > d[m - 1]) {
				ans[m - 1]++; i++;
			}
			else if (r[i] > d[j] && r[i] < d[j + 1]) {
			if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
				ans[j]++; i++;
			}
			else { ans[j + 1]++; i++; }
			}
			else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[100005], y[100005], d[100005], r[100005], ans[100005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	sort(d, d + m);
	sort(r, r + n);
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
			if (r[i] > d[m - 1]) {
				ans[m - 1]++; i++;
			}
			else if (r[i] > d[j] && r[i] < d[j + 1]) {
			if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
				ans[j]++; i++;
			}
			else { ans[j + 1]++; i++; }
			}
			else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	lli  n, m, x[100005], d[100005], r[100005], ans=0, c = 0, k = 0;
	cin >> n >> m;
	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		bool y;
		cin >> y;
		if (y)d[c++] = x[i];
		else r[k++] = x[i];
	}
	k = 0;
	for (int  i = 0; i < m; i++)
	{
		while (k<n&&(i==m-1||abs(d[i]-r[k])<=abs(d[i+1]-r[k])))
		{
			ans++;
			k++;
		}
		cout << ans << " ";
		ans = 0;
	}

#if _DEBUG
	system("pause");
#endif
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<iomanip>
#include<cmath>
#include <utility>
#include <numeric>
#include<complex>
#include<sstream>
#include <functional>
#include<valarray>
#define ln cout<<endl;
#define vll vector<long long int>
#define vi vector<int>
#define vc vector<char>
#define vstr vector<string>
#define vb vector<bool>
#define sti set<int>
#define stc set<char>
#define sz size()
#define lli long long int
using namespace std;
lli prime(lli n) {
	if (n % 2 == 0 && n != 2 || n<2)
		return false;
	else {
		for (lli i = 3; i*i <= n; i += 2)
		{
			if (n%i == 0)
			{
				return false;
			}
		}
	}
	return true;
}
unsigned long long gcd(unsigned long long  n, unsigned  long long  m) {//g
	if (n%m == 0)
		return m;
	else return gcd(m, n%m);
}
lli lcm(lli n, lli m) {
	return n*m / gcd(n, m);
}
lli fact(lli n) {
	if (n == 1)return 1;
	else return n * fact(n - 1);
}
int sumdigit(int n) {
	int sum = 0;
	while (n)
	{
		sum += (n % 10);
		n /= 10;
	}
	return sum;
}
string tobinary(lli n)
{
	string s;
	while (n)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	reverse(s.begin(), s.end());
	return s;
}
/*template<class T> string tostring(T par)
{
stringstreem ss;
ss<<par;
return ss.str();
}*/
string tostring(double n) {
	double m = n;
	string x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
char tochar(int n) {
	int m = n;
	char x;
	stringstream ss;
	ss << m;
	ss >> x;
	return x;
}
int div(lli n)
{
	int c = 1;
	if (n == 1)return 1;
	if (n == 2) return 2;
	//if(prime(n))return 2;
	for (int i = 2; i <= int(sqrt(n)); i++)
	{
		if (n%i == 0)
			c++;
	}
	if (sqrt(n)*sqrt(n) == n)return c * 2 - 1;
	return c * 2;
}
int main()
{
	/*int  n, k,a, sum=0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
	cin >> a;
	if (i < k)sum += (a*(-1));
	}*/
	int n, m, x[1005], y[1005], d[1005], r[1005], ans[1005] = { 0 }, c = 0, k = 0;
	cin >> n >> m;

	for (int i = 0; i < n + m; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < n + m; i++)
	{
		cin >> y[i];
		if (y[i] == 1)d[c++] = x[i];
		else r[k++] = x[i];
	}
	d[c] = 10000000;
	if (m == 1)cout << n;
	else {
		for (int i = 0,j=0; i < n, j < m ;)
		{
					if (r[i] > d[j] && r[i] < d[j + 1]) {
						if (abs(r[i] - d[j]) <= abs(r[i] - d[j + 1])) {
							ans[j]++; i++;
						}
						else { ans[j + 1]++; i++; }
				}
					else j++;
			}

		for (int i = 0; i < m; i++)
		{
			cout << ans[i] << " ";
		}
	}
#if _DEBUG
	system("pause");
#endif
	return 0;
}