#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#define R register
#define ll long long
#define db double
#define sqr(_x) _x*_x
#define Cmax(_a,_b) (_a<_b?_a=_b,1:0)
#define Cmin(_a,_b) (_b<_a?_a=_b,1:0)
#define Max(_a,_b) (_a<_b?_b:_a)
#define Min(_a,_b) (_a<_b?_a:_b)
#define Abs(_x) (_x<0?-(_x):_x)
#define Mp(_a,_b) make_pair(_a,_b)
using namespace std;
namespace Dntcry
{
	inline int read()
	{
		R int a=0,b=1; R char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) (c=='-')?b=-1:0;
		for(;c>='0'&&c<='9';c=getchar()) a=(a<<1)+(a<<3)+c-'0';
		return a*b;
	}
	inline ll lread()
	{
		R ll a=0,b=1; R char c=getchar();
		for(;c<'0'||c>'9';c=getchar()) (c=='-')?b=-1:0;
		for(;c>='0'&&c<='9';c=getchar()) a=(a<<1)+(a<<3)+c-'0';
		return a*b;
	}
	const int Maxm=210010;
	int m,cnt=0,last[Maxm],col[Maxm];
	struct Edge
	{
		int v,next;
	}e[Maxm<<1];
	struct node
	{
		int val,name;
	}p[Maxm<<1];
	bool cmp(R node a,R node b)
	{
		return a.val<b.val;
	}
	void Add(R int u,R int v)
	{
		e[++cnt].v=v,e[cnt].next=last[u],last[u]=cnt;
		e[++cnt].v=u,e[cnt].next=last[v],last[v]=cnt;
	}
	void dfs(R int now,R int c)
	{
		if(col[now]!=-1) return ;
		col[now]=c;
		for(R int i=last[now];i;i=e[i].next)
			dfs(e[i].v,c^1);
	}
	int Main()
	{
		m=read();
		for(R int i=0,l,r;i<m;i++)
			{
				l=read(),r=read();
				Add(i<<1,i<<1|1);
				p[i<<1].val=l<<1,p[i<<1].name=i<<1;
				p[i<<1|1].val=r<<1|1,p[i<<1|1].name=i<<1|1;
			}
		sort(p,p+m*2,cmp);
		for(R int i=0;i<m;i++)
			{
				R int x=p[i<<1].name,y=p[i<<1|1].name;
				Add(x,y);
			}
		memset(col,-1,sizeof(col));
		for(R int i=0;i<m;i++)
			{
				if(col[i<<1]==-1) dfs(i<<1,0);
				printf("%d ",col[i<<1]);
			}
		return 0 ;
	}
}
int main()
{
	return Dntcry::Main();
}


/*
 * Author:  Yzcstc
 * Created Time:  2014/10/30 19:12:23
 * File Name: cf429.cpp
 */
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
vector<int> e[210000];
int col[210000], n;
pair<int, int> p[210000];
void dfs(int u, int color){
     if (col[u] != -1) return;
     col[u] = color;
     for (int i = 0; i < (int)e[u].size(); ++i)
          dfs(e[u][i], color^1);
}

void solve(){
     for (int i = 0; i <= n * 2; ++i) e[i].clear();
     int l, r;
     for (int i = 0; i < n; ++i){
          scanf("%d%d", &l, &r);
          e[i<<1].push_back(i<<1|1), e[i<<1|1].push_back(i<<1);
          p[i<<1] = make_pair(l<<1,i<<1), p[i<<1|1] = make_pair(r<<1|1, i<<1|1);
     }
     sort(p, p + 2*n);
     for (int i = 0; i < n; ++i){
          int x = p[i<<1].second, y = p[i<<1|1].second;
          e[x].push_back(y), e[y].push_back(x);
     }
     memset(col, -1, sizeof(col));
     for (int i = 0; i < n; ++i){
         if (col[i<<1] == -1) dfs(i<<1, 0);
         printf("%d ", col[i<<1]);
     }
}

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);
    while (scanf("%d", &n) != EOF){
        solve();
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 200010
using namespace std;

int n, m;

struct Edge {
    int to, next, id, F; bool ext;
} e[maxn * 4]; int c1, head[maxn];
inline void add_edge(int u, int v, int id, int F) {
    e[c1].to = v; e[c1].id = id; e[c1].F = F;
    e[c1].next = head[u]; head[u] = c1++;
}

int l[maxn], r[maxn], a[maxn], cnt;
void init_hash() {
    sort(a + 1, a + 2 * n + 1); cnt = unique(a + 1, a + 2 * n + 1) - a - 1;
    for (int i = 1; i <= n; ++i) {
        l[i] = lower_bound(a + 1, a + cnt + 1, l[i]) - a;
        r[i] = lower_bound(a + 1, a + cnt + 1, r[i]) - a;
    }
}

int du[maxn];

int ans[maxn]; bool vis[maxn];
void dfs(int u) {
    vis[u] = 1;
    for (int i = head[u]; ~i; i = e[i].next) {
        int v = e[i].to, id = e[i].id, F = e[i].F; bool &ext = e[i].ext;
        if (ext) continue ; e[i].ext = e[i ^ 1].ext = 1;
        ans[id] = F; dfs(v);
    }
}

int main() { memset(head, -1, sizeof head);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &l[i], &r[i]); ++r[i];
        a[i] = l[i]; a[i + n] = r[i];
    } init_hash();
    for (int i = 1; i <= n; ++i) {
        add_edge(l[i], r[i], i, 0);
        add_edge(r[i], l[i], i, 1);
        ++du[l[i]]; ++du[r[i]];
    } int la = 0;
    for (int i = 1; i <= cnt; ++i) {
        if (!(du[i] & 1)) continue ;
        if (la) add_edge(la, i, n + 1, 0), add_edge(i, la, n + 1, 0), la = 0;
        else la = i;
    }
    for (int i = 1; i <= cnt; ++i) if (!vis[i]) dfs(i);
    for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define maxn 100010
using namespace std;

int n, m;

struct Edge {
    int to, next, id, F; bool ext;
} e[maxn * 4]; int c1, head[maxn];
inline void add_edge(int u, int v, int id, int F) {
    e[c1].to = v; e[c1].id = id; e[c1].F = F;
    e[c1].next = head[u]; head[u] = c1++;
}

int l[maxn], r[maxn], a[maxn * 2], cnt;
void init_hash() {
    sort(a + 1, a + 2 * n + 1); cnt = unique(a + 1, a + 2 * n + 1) - a - 1;
    for (int i = 1; i <= n; ++i) {
        l[i] = lower_bound(a + 1, a + cnt + 1, l[i]) - a;
        r[i] = lower_bound(a + 1, a + cnt + 1, r[i]) - a;
    }
}

int du[maxn];

int ans[maxn]; bool vis[maxn];
void dfs(int u) {
    vis[u] = 1;
    for (int i = head[u]; ~i; i = e[i].next) {
        int v = e[i].to, id = e[i].id, F = e[i].F; bool &ext = e[i].ext;
        if (ext) continue ; e[i].ext = e[i ^ 1].ext = 1;
        ans[id] = F; dfs(v);
    }
}

int main() { memset(head, -1, sizeof head);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &l[i], &r[i]); ++r[i];
        a[i] = l[i]; a[i + n] = r[i];
    } init_hash();
    for (int i = 1; i <= n; ++i) {
        add_edge(l[i], r[i], i, 0);
        add_edge(r[i], l[i], i, 1);
        ++du[l[i]]; ++du[r[i]];
    } int la = 0;
    for (int i = 1; i <= cnt; ++i) {
        if (!(du[i] & 1)) continue ;
        if (la) add_edge(la, i, n + 1, 0), add_edge(i, la, n + 1, 0), la = 0;
        else la = i;
    }
    for (int i = 1; i <= cnt; ++i) if (!vis[i]) dfs(i);
    for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
typedef int ll;
typedef double db;
const ll N=1e6+10;
ll n,m,ans[N],vis[N];
vector<ll>A[N];
struct node{
	int x,y;
	node(int X=0,int Y=0):x(X),y(Y){}
	bool operator <(const node&res)const{
		return x==res.x?y<res.y:x<res.x;
	}
};
set<node>S;
inline void dfs(ll x,ll y){
	if (vis[x]>-1) return;else vis[x]=y;
	for (unsigned i=0;i<A[x].size();++i) dfs(A[x][i],!y);
}
int main(){
	scanf("%d",&n);
	for (ll i=0,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		A[i*2].push_back(i*2+1);
		A[i*2+1].push_back(i*2);
		S.insert(node(x*2,i*2));
		S.insert(node(y*2+1,i*2+1));
	}
	set<node>::iterator it=S.begin();
	for (ll i=0;i<n;++i){
		ll l=it->y;++it;
		ll r=it->y;++it;
		A[l].push_back(r);
		A[r].push_back(l);
	}
	memset(vis,-1,sizeof vis);
	for (ll i=0;i<n;++i) if (vis[i*2]<0) dfs(i*2,0);
	for (ll i=0;i<n;++i) printf("%d ",vis[i*2]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef int ll;
typedef double db;
const ll N=1e5+10;
ll n,m,ans[N],t[N*2],T[N*2];
struct node{
	ll l,r,id;
	bool operator <(const node &res)const{
		return l==res.l?r>res.r:l<res.l;
	}
}a[N];
inline ll query(ll x){
	ll y=0;
	for (;x;x-=x&-x) y+=T[x];
	return y;
}
inline void add(ll x,ll y){
	for (;x<=m;x+=x&-x) T[x]+=y;
}
int main(){
	scanf("%d",&n);
	t[++m]=1e9;
	for (ll i=1;i<=n;++i) scanf("%d%d",&a[i].l,&a[i].r),t[++m]=a[i].l,t[++m]=a[i].r,a[i].id=i;
	sort(a+1,a+1+n);
	sort(t+1,t+1+m);
	m=unique(t+1,t+1+m)-t-1;
	for (ll i=1,l,r;i<=n;++i){
		l=lower_bound(t+1,t+1+m,a[i].l)-t;
		r=lower_bound(t+1,t+1+m,a[i].r)-t;
		if (query(l)<1){
			ans[a[i].id]=1;
			add(l,1);
			add(r+1,-1);
		}else{
			ans[a[i].id]=0;
			add(l,-1);
			add(r+1,1);
		}
	}
	for (ll i=1;i<=n;++i) printf("%d ",ans[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
typedef int ll;
typedef double db;
const ll N=1e5+10;
ll n,m,ans[N],cnt,vis[N];
vector<ll>A[N];
struct node{
	int x,y;
	node(int X=0,int Y=0):x(X),y(Y){}
	bool operator <(const node&res)const{
		return x==res.x?y<res.y:x<res.x;
	}
};
set<node>S;
inline void dfs(ll x,ll y){
	if (vis[x]>-1) return;else vis[x]=y;
	for (unsigned i=0;i<A[x].size();++i) dfs(A[x][i],!y);
}
int main(){
	scanf("%d",&n);
	cnt=n*2;
	for (ll i=0,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		S.insert(node(x*2,i*2));
		S.insert(node(y*2+1,i*2+1));
	}
	set<node>::iterator it=S.begin();
	for (ll i=0;i<n;++i) {
		ll l=it->y;++it;
		ll r=it->y;++it;
		A[l].push_back(r);
		A[r].push_back(l);
	}
	memset(vis,-1,sizeof vis);
	for (ll i=0;i<n;++i) if (vis[i*2]<0) dfs(i*2,0);
	for (ll i=0;i<n;++i) printf("%d ",vis[i*2]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef int ll;
typedef double db;
const ll N=1e5+10;
ll n,m,ans[N],t[N*2],T[N*2];
struct node{
	ll l,r,id;
	bool operator <(const node &res)const{
		return l==res.l?r<res.r:l<res.l;
	}
}a[N];
inline ll query(ll x){
	ll y=0;
	for (;x;x-=x&-x) y+=T[x];
	return y;
}
inline void add(ll x,ll y){
	for (;x<=m;x+=x&-x) T[x]+=y;
}
int main(){
	scanf("%d",&n);
	t[++m]=1e9;
	for (ll i=1;i<=n;++i) scanf("%d%d",&a[i].l,&a[i].r),t[++m]=a[i].l,t[++m]=a[i].r,a[i].id=i;
	sort(a+1,a+1+n);
	sort(t+1,t+1+m);
	m=unique(t+1,t+1+m)-t-1;
	for (ll i=1,l,r;i<=n;++i){
		l=lower_bound(t+1,t+1+m,a[i].l)-t;
		r=lower_bound(t+1,t+1+m,a[i].r)-t;
		if (query(l)<1){
			ans[a[i].id]=1;
			add(l,1);
			add(r+1,-1);
		}else{
			ans[a[i].id]=0;
			add(l,-1);
			add(r+1,1);
		}
	}
	for (ll i=1;i<=n;++i) printf("%d ",ans[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
using namespace std;
typedef int ll;
typedef double db;
const ll N=1e5+10;
ll n,m,ans[N],vis[N];
vector<ll>A[N];
struct node{
	int x,y;
	node(int X=0,int Y=0):x(X),y(Y){}
	bool operator <(const node&res)const{
		return x==res.x?y<res.y:x<res.x;
	}
};
set<node>S;
inline void dfs(ll x,ll y){
	if (vis[x]>-1) return;else vis[x]=y;
	for (unsigned i=0;i<A[x].size();++i) dfs(A[x][i],!y);
}
int main(){
	scanf("%d",&n);
	for (ll i=0,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		A[i*2].push_back(i*2+1);
		A[i*2+1].push_back(i*2);
		S.insert(node(x*2,i*2));
		S.insert(node(y*2+1,i*2+1));
	}
	set<node>::iterator it=S.begin();
	for (ll i=0;i<n;++i){
		ll l=it->y;++it;
		ll r=it->y;++it;
		A[l].push_back(r);
		A[r].push_back(l);
	}
	memset(vis,-1,sizeof vis);
	for (ll i=0;i<n;++i) if (vis[i*2]<0) dfs(i*2,0);
	for (ll i=0;i<n;++i) printf("%d ",vis[i*2]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<bitset>
#include<iomanip>
using namespace std;
#define ri register int
#define il inline
#define pb push_back
#define LL long long
#define pairint pair<int,int>
#define fi first
#define se second
#define mp make_pair

namespace i207M
{

template<class T>il void in(T &x)
{
    x=0; bool f=0; char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=1;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
    if(f) x=-x;
}

#define N 200005
int n;
int nl[N],nr[N],ui[N],cu;
int v[N<<1],nx[N<<1];
int head[N],cnte=1;
int du[N];
il void adde(int uu,int vv)
{
//	printf("E %d %d\n",uu,vv);
	++du[uu];
	v[++cnte]=vv,nx[cnte]=head[uu],head[uu]=cnte;
}
int use[N];
int ans[N];
bool vis[N];
void dfs(int x)
{
//	printf("%d\n",x);
	vis[x]=1;
	for(ri &i=head[x];i;i=nx[i])
		if(!use[i>>1])
		{
			ans[i>>1]=(v[i]<x);
			use[i>>1]=1;
//			printf("V %d\n",v[i]);
			dfs(v[i]);
		}
}
int getn(int x)
{
	return lower_bound(ui+1,ui+1+cu,x)-ui;
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif
	in(n);
	for(ri i=1;i<=n;++i) in(nl[i]),in(nr[i]),++nr[i],ui[++cu]=nl[i],ui[++cu]=nr[i];
	sort(ui+1,ui+1+cu);
	cu=unique(ui+1,ui+1+cu)-ui-1;
	for(ri i=1;i<=n;++i)
	{
		int l=getn(nl[i]),r=getn(nr[i]);
		adde(l,r),adde(r,l);
	}
	int lst=-1;
	for(ri i=1;i<=cu;++i)
		if(du[i]&1)
		{
			if(lst!=-1) adde(lst,i),adde(i,lst),lst=-1;
			else lst=i;
		}
	dfs(1);
	for(ri i=1;i<=cu;++i) if(!vis[i]) dfs(i);
	for(ri i=1;i<=n;++i) printf("%d ",ans[i]);
    return 0;
}

}

int main()
{
    i207M::main();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<bitset>
#include<iomanip>
using namespace std;
#define ri register int
#define il inline
#define pb push_back
#define LL long long
#define pairint pair<int,int>
#define fi first
#define se second
#define mp make_pair

namespace i207M
{

template<class T>il void in(T &x)
{
    x=0; bool f=0; char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=1;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
    if(f) x=-x;
}

#define N 200005
int n;
int nl[N],nr[N],ui[N],cu;
int v[N<<1],nx[N<<1];
int head[N],cnte=1;
int du[N];
il void adde(int uu,int vv)
{
//	printf("E %d %d\n",uu,vv);
	++du[uu];
	v[++cnte]=vv,nx[cnte]=head[uu],head[uu]=cnte;
}
int use[N];
int ans[N];
void dfs(int x)
{
//	printf("%d\n",x);
	for(ri &i=head[x];i;i=nx[i])
		if(!use[i>>1])
		{
			ans[i>>1]=(v[i]<x);
			use[i>>1]=1;
//			printf("V %d\n",v[i]);
			dfs(v[i]);
		}
}
int getn(int x)
{
	return lower_bound(ui+1,ui+1+cu,x)-ui;
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif
	in(n);
	for(ri i=1;i<=n;++i) in(nl[i]),in(nr[i]),++nr[i],ui[++cu]=nl[i],ui[++cu]=nr[i];
	sort(ui+1,ui+1+cu);
	cu=unique(ui+1,ui+1+cu)-ui-1;
	for(ri i=1;i<=n;++i)
	{
		int l=getn(nl[i]),r=getn(nr[i]);
		adde(l,r),adde(r,l);
	}
	int lst=-1;
	for(ri i=1;i<=cu;++i)
		if(du[i]&1)
		{
			if(lst!=-1) adde(lst,i),adde(i,lst),lst=-1;
			else lst=i;
		}
	dfs(1);
	for(ri i=1;i<=n;++i) printf("%d ",ans[i]);
    return 0;
}

}

int main()
{
    i207M::main();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<cstring>
#include<string>
#include<bitset>
#include<iomanip>
using namespace std;
#define ri register int
#define il inline
#define pb push_back
#define LL long long
#define pairint pair<int,int>
#define fi first
#define se second
#define mp make_pair

namespace i207M
{

template<class T>il void in(T &x)
{
    x=0; bool f=0; char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=1;
        c=getchar();
    }
    while(c>='0'&&c<='9') x=x*10+(c^'0'),c=getchar();
    if(f) x=-x;
}

#define N 200005
int n;
int nl[N],nr[N],ui[N],cu;
int v[N<<1],nx[N<<1];
int head[N],cnte=1;
int du[N];
il void adde(int uu,int vv)
{
	++du[uu],++du[vv];
	v[++cnte]=vv,nx[cnte]=head[uu],head[uu]=cnte;
}
int use[N];
int ans[N];
void dfs(int x)
{
	for(ri &i=head[x];i;i=nx[i])
		if(!use[i>>1])
		{
			ans[i>>1]=(v[i]<x);
			use[i>>1]=1;
			dfs(v[i]);
		}
}
int getn(int x)
{
	return lower_bound(ui+1,ui+1+cu,x)-ui;
}
signed main()
{
#ifdef M207
	freopen("in.in","r",stdin);
//	freopen("out.out","w",stdout);
#endif
	in(n);
	for(ri i=1;i<=n;++i) in(nl[i]),in(nr[i]),ui[++cu]=nl[i],ui[++cu]=nr[i];
	sort(ui+1,ui+1+cu);
	cu=unique(ui+1,ui+1+cu)-ui-1;
	for(ri i=1;i<=n;++i)
	{
		int l=getn(nl[i]),r=getn(nr[i]);
		adde(l,r),adde(r,l);
	}
	int lst=-1;
	for(ri i=1;i<=cu;++i)
		if(du[i]&1)
		{
			if(lst!=-1) adde(lst,i),adde(i,lst);
			else lst=i;
		}
	dfs(1);
	for(ri i=1;i<=n;++i) printf("%d ",ans[i]);
    return 0;
}

}

int main()
{
    i207M::main();
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define M 1000005
using namespace std;
int n,L[M],R[M],b[M],D[M],nxt[M],head[M],to[M],Stack[M],tot;
int ans[M];
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void Write(int x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
void add(int u,int v){nxt[++tot]=head[u];head[u]=tot;to[tot]=v;return;}
void DFS(int x,int col){
	for (register int i=head[x];i;i=nxt[i])
		if (ans[(i+1)>>1]==-1) ans[(i+1)>>1]=(i&1)^1,DFS(to[i],col^1);
	Stack[++Stack[0]]=x;return;
}
int main(){
	n=read();
	for (register int i=1;i<=n;i++) b[++b[0]]=L[i]=read(),b[++b[0]]=R[i]=read()+1;
	sort(b+1,b+1+b[0]);b[0]=unique(b+1,b+1+b[0])-(b+1);
	for (register int i=1;i<=n;i++) L[i]=lower_bound(b+1,b+1+b[0],L[i])-b,R[i]=lower_bound(b+1,b+1+b[0],R[i])-b;
	for (register int i=1;i<=n;i++)
		add(L[i],R[i]),add(R[i],L[i]),++D[L[i]],--D[R[i]];
	for (register int i=1;i<b[0];i++)
		if ((D[i]+=D[i-1])&1) add(i,i+1),add(i+1,i);
	for (register int i=1;i<=(tot>>1);i++) ans[i]=-1;
	for (register int i=1;i<=b[0];i++) DFS(i,0);
	for (register int i=1;i<=n;i++) Write(ans[i]),putchar(' ');
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define M 1000005
using namespace std;
int n,L[M],R[M],b[M],D[M],nxt[M],head[M],to[M],Stack[M],tot;
int ans[M];
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
void Write(int x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
void add(int u,int v){nxt[++tot]=head[u];head[u]=tot;to[tot]=v;return;}
void DFS(int x,int col){
	for (register int &i=head[x];i;i=nxt[i])
		if (ans[(i+1)>>1]==-1) ans[(i+1)>>1]=(i&1)^1,DFS(to[i],col^1);
	Stack[++Stack[0]]=x;return;
}
int main(){
	n=read();
	for (register int i=1;i<=n;i++) b[++b[0]]=L[i]=read(),b[++b[0]]=R[i]=read()+1;
	sort(b+1,b+1+b[0]);b[0]=unique(b+1,b+1+b[0])-(b+1);
	for (register int i=1;i<=n;i++) L[i]=lower_bound(b+1,b+1+b[0],L[i])-b,R[i]=lower_bound(b+1,b+1+b[0],R[i])-b;
	for (register int i=1;i<=n;i++)
		add(L[i],R[i]),add(R[i],L[i]),++D[L[i]],--D[R[i]];
	for (register int i=1;i<b[0];i++)
		if ((D[i]+=D[i-1])&1) add(i,i+1),add(i+1,i);
	for (register int i=1;i<=(tot>>1);i++) ans[i]=-1;
	for (register int i=1;i<=b[0];i++) DFS(i,0);
	for (register int i=1;i<=n;i++) Write(ans[i]),putchar(' ');
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <deque>
#define ll long long
#define db double
using namespace std;
inline int read(){
    int SUM=0,ff=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
      if(ch=='-')
        ff=-1;
      ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
      SUM=(SUM<<3)+(SUM<<1)+(ch^48);
      ch=getchar();
    }
    return SUM*ff;
}
const int N=200010;
struct edge{
    int nxt,to;
}e[N<<2];
int h[N],cnte=1;
inline void addedge(int u,int v){
    e[++cnte]=(edge){h[u],v},h[u]=cnte;
}
multimap <int,int> mp;
int n,ans[N];
inline void paint(int u,int col){
    if(ans[u]!=-1){
      if(ans[u]!=col){
        puts("-1");
        exit(0);
      }
      else{
        return;
      }
    }
    ans[u]=col;
    for(int i=h[u];i;i=e[i].nxt){
       int v=e[i].to;
       paint(v,col^1);
    }
}
int main(){
    //freopen("CF429E Points and Segments.in","r",stdin);
    //freopen("CF429E Points and Segments.out","w",stdout);
    n=read();
    for(int i=0;i<n;i++){
       int l=read(),r=read();
       addedge(i<<1,i<<1|1);
       addedge(i<<1|1,i<<1);
       mp.insert(make_pair(l<<1,i<<1));
       mp.insert(make_pair(r<<1|1,i<<1|1));
    }
    multimap <int,int>:: iterator it=mp.begin();
    for(int i=0;i<n;i++){
       int l=it->second;it++;
       int r=it->second;it++;
       addedge(l,r),addedge(r,l);
    }
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<n;i++)
       if(ans[i<<1]==-1)
         paint(i<<1,0);
    for(int i=0;i<n;i++)
       printf("%d ",ans[i<<1]);
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <deque>
#define ll long long
#define db double
using namespace std;
inline int read(){
    int SUM=0,ff=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
      if(ch=='-')
        ff=-1;
      ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
      SUM=(SUM<<3)+(SUM<<1)+(ch^48);
      ch=getchar();
    }
    return SUM*ff;
}
const int N=200010;
struct edge{
    int nxt,to;
}e[N<<2];
int h[N],cnte=1;
inline void addedge(int u,int v){
    e[++cnte]=(edge){h[u],v},h[u]=cnte;
}
multimap <int,int> mp;
int n,ans[N];
inline void paint(int u,int col){
    if(ans[u]!=-1) return;
    ans[u]=col;
    for(int i=h[u];i;i=e[i].nxt){
       int v=e[i].to;
       paint(v,col^1);
    }
}
int main(){
    //freopen("CF429E Points and Segments.in","r",stdin);
    //freopen("CF429E Points and Segments.out","w",stdout);
    n=read();
    for(int i=0;i<n;i++){
       int l=read(),r=read();
       addedge(i<<1,i<<1|1);
       addedge(i<<1|1,i<<1);
       mp.insert(make_pair(l<<1,i<<1));
       mp.insert(make_pair(r<<1|1,i<<1|1));
    }
    multimap <int,int>:: iterator it=mp.begin();
    for(int i=0;i<n;i++){
       int l=it->second;it++;
       int r=it->second;it++;
       addedge(l,r),addedge(r,l);
    }
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<n;i++)
       if(ans[i<<1]==-1)
         paint(i<<1,0);
    for(int i=0;i<n;i++)
       printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <deque>
#define ll long long
#define db double
using namespace std;
inline int read(){
    int SUM=0,ff=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
      if(ch=='-')
        ff=-1;
      ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
      SUM=(SUM<<3)+(SUM<<1)+(ch^48);
      ch=getchar();
    }
    return SUM*ff;
}
const int N=100010;
struct edge{
    int nxt,to;
}e[N<<2];
int h[N],cnte=1;
inline void addedge(int u,int v){
    e[++cnte]=(edge){h[u],v},h[u]=cnte;
}
struct segment{
    int l,r,id;
    inline friend bool operator < (segment a1,segment a2){
        return a1.r==a2.r ? a1.l<a2.l : a1.r<a2.r;
    }
}s[N];
int n,ans[N];
inline void paint(int u,int col){
    if(ans[u]!=-1){
      if(ans[u]!=col){
        puts("-1");
        exit(0);
      }
      else{
        return;
      }
    }
    ans[u]=col;
    for(int i=h[u];i;i=e[i].nxt){
       int v=e[i].to;
       paint(v,col^1);
    }
}
int main(){
    //freopen("CF429E Points and Segments.in","r",stdin);
    //freopen("CF429E Points and Segments.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++){
       ans[i]=-1;
       s[i].l=read(),s[i].r=read();
       s[i].id=i;
    }
    sort(s+1,s+n+1);
    for(int i=2;i<=n;i++){
       if(s[i].l<=s[i-1].r){
         addedge(s[i].id,s[i-1].id);
         addedge(s[i-1].id,s[i].id);
       }
    }
    for(int i=1;i<=n;i++)
       if(ans[i]==-1)
         paint(i,0);
    for(int i=1;i<=n;i++)
       printf("%d ",ans[i]);
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <deque>
#define ll long long
#define db double
using namespace std;
inline int read(){
    int SUM=0,ff=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
      if(ch=='-')
        ff=-1;
      ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
      SUM=(SUM<<3)+(SUM<<1)+(ch^48);
      ch=getchar();
    }
    return SUM*ff;
}
const int N=200010;
struct edge{
    int nxt,to;
}e[N<<2];
int h[N],cnte=1;
inline void addedge(int u,int v){
    e[++cnte]=(edge){h[u],v},h[u]=cnte;
}
multimap <int,int> mp;
int n,ans[N];
inline void paint(int u,int col){
    if(ans[u]!=-1){
      if(ans[u]!=col){
        puts("-1");
        exit(0);
      }
      else{
        return;
      }
    }
    ans[u]=col;
    for(int i=h[u];i;i=e[i].nxt){
       int v=e[i].to;
       paint(v,col^1);
    }
}
int main(){
    //freopen("CF429E Points and Segments.in","r",stdin);
    //freopen("CF429E Points and Segments.out","w",stdout);
    n=read();
    for(int i=0;i<n;i++){
       int l=read(),r=read();
       addedge(i<<1,i<<1|1);
       addedge(i<<1|1,i<<1);
       mp.insert(make_pair(l<<1,i<<1));
       mp.insert(make_pair(r<<1|1,i<<1|1));
    }
    multimap <int,int>:: iterator it=mp.begin();
    for(int i=0;i<n;i++){
       int l=it->second;it++;
       int r=it->second;it++;
       addedge(l,r),addedge(r,l);
    }
    memset(ans,-1,sizeof(ans));
    for(int i=0;i<n;i++)
       if(ans[i<<1]==-1)
         paint(i<<1,0);
    for(int i=0;i<n;i++)
       printf("%d ",ans[i]);
    return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

inline int in() {int x; scanf("%d",&x); return x;}
#define debug(x) cerr << #x << '=' << (x) << endl
#define FOR(i,j,k) for(int i=j;i<k;++i)
#define bpc __builtin_popcount
#define blz __builtin_clz
#define btz __builtin_ctz
#define Size(x) ((int)(x).size())
#define endl '\n'
#define boost ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define pb push_back

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

const int INF = 1e9 + 10;
const ll LINF = 1000ll*1000*1000*1000*1000*1000 + 100;
const int MN = 5e5 + 10;

int L[MN] , R[MN];
int n,m;
int dv[MN];
int tmp[MN],col[MN];
bool mk[MN];
vector<int>adj[MN];
int sz;

void dfs(int s)
{
	for(;dv[s]<Size(adj[s]);++dv[s]){
		int v = adj[s][dv[s]];
		if(mk[v]) continue;
		mk[v] = true;
		if(s == L[v]){
			col[v] = 0;
			dfs(R[v]);
		}else{
			col[v] = 1;
			dfs(L[v]);
		}
	}
}

void input()
{
	cin >> n;
	m = n;
	for(int i=0;i<n;++i){
		cin >> L[i] >> R[i];
		L[i]*=2 , R[i] = 2*R[i]+1;
		tmp[sz++] = L[i] , tmp[sz++] = R[i];
	}
	sort(tmp , tmp+sz);
	sz = unique(tmp , tmp+sz) - tmp;
	for(int i=0;i<n;++i){
		L[i] = lower_bound(tmp , tmp+sz , L[i]) - tmp;
		R[i] = lower_bound(tmp , tmp+sz , R[i]) - tmp;
		adj[L[i]].pb(i) , adj[R[i]].pb(i);
	}
	bool flag = false;
	int lst;
	for(int i=0;i<sz;++i){
		if(Size(adj[i])%2 == 0) continue;
		if(flag){
			L[m] = lst , R[m] = i;
			adj[lst].pb(m) , adj[i].pb(m);
			++m;
			flag = false;
		}else flag = true , lst = i;
	}
}

void solve()
{
	for(int i=0;i<sz;++i)
		if(dv[i] < Size(adj[i])) dfs(i);
	for(int i=0;i<n;++i) cout << col[i] << ' ';
	cout << endl;
}

int main()
{
	boost;
	input();
	solve();
	return 0;
}


// In the name of God
// Code by: mrMaster

#include <bits/stdc++.h>

using namespace std;

inline int in() {int x; scanf("%d",&x); return x;}
#define debug(x) cerr << #x << '=' << (x) << endl
#define FOR(i,j,k) for(int i=j;i<k;++i)
#define bpc __builtin_popcount
#define blz __builtin_clz
#define btz __builtin_ctz
#define Size(x) ((int)(x).size())
#define endl '\n'
#define boost ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define pb push_back

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

const int INF = 1e9 + 10;
const ll LINF = 1000ll*1000*1000*1000*1000*1000 + 100;
const int MN = 1e5 + 10;

int L[4*MN] , R[4*MN];
int n,m;
int dv[3*MN];
int tmp[4*MN],col[4*MN];
bool mk[4*MN];
vector<int>adj[3*MN];

void dfs(int s)
{
	for(;dv[s]<Size(adj[s]);++dv[s]){
		int v = adj[s][dv[s]];
		if(mk[v]) continue;
		mk[v] = true;
		if(s == L[v]){
			col[v] = 0;
			dfs(R[v]);
		}else{
			col[v] = 1;
			dfs(L[v]);
		}
	}
}

void input()
{
	cin >> n;
	m = n;
	int sz = 0;
	for(int i=0;i<n;++i){
		cin >> L[i] >> R[i];
		L[i]*=2 , R[i] = 2*R[i]+1;
		tmp[sz++] = L[i] , tmp[sz++] = R[i];
	}
	sort(tmp , tmp+sz);
	sz = unique(tmp , tmp+sz) - tmp;
	for(int i=0;i<n;++i){
		L[i] = lower_bound(tmp , tmp+sz , L[i]) - tmp;
		R[i] = lower_bound(tmp , tmp+sz , R[i]) - tmp;
		adj[L[i]].pb(i) , adj[R[i]].pb(i);
	}
	bool flag = false;
	int lst;
	for(int i=0;i<sz;++i){
		if(Size(adj[i])%2 == 0) continue;
		if(flag){
			L[m] = lst , R[m] = i;
			adj[lst].pb(m) , adj[i].pb(m);
			++m;
			flag = false;
		}else flag = true , lst = i;
	}
}

void solve()
{
	for(int i=0;i<n;++i)
		if(dv[i] < Size(adj[i])) dfs(i);
	for(int i=0;i<n;++i) cout << col[i] << ' ';
	cout << endl;
}

int main()
{
	boost;
	input();
	solve();
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

struct edge{
  int u,v,next;
}G[N<<1];
int head[N],inum=1;

inline void add(int u,int v,int p){
  G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int deg[N];
int dir[N],vst[N];
#define V G[p].v
inline void dfs(int u){
  vst[u]=1;
  for (int p=head[u];p;p=G[p].next)
    if (dir[p>>1]==-1){
      dir[p>>1]=p&1;
      dfs(V);
    }
}

int sx[N],icnt;
inline int Bin(int x){
  return lower_bound(sx+1,sx+icnt+1,x)-sx;
}

int n,root;
int s[N],t[N];

int main(){
  read(n);
  for (int i=1;i<=n;i++)
    read(s[i]),read(t[i]),t[i]++,sx[++icnt]=s[i],sx[++icnt]=t[i];
  sort(sx+1,sx+icnt+1);
  icnt=unique(sx+1,sx+icnt+1)-sx-1;
  for (int i=1;i<=n;i++){
    s[i]=Bin(s[i]),t[i]=Bin(t[i]);
    add(s[i],t[i],++inum); add(t[i],s[i],++inum);
    deg[s[i]]++; deg[t[i]]++;
  }
  int last=0;
  for (int i=1;i<=icnt;i++)
    if (deg[i]&1)
      if (last)
	add(last,i,++inum),add(i,last,++inum),last=0;
      else
	last=i;
  for (int i=1;i<=(inum>>1);i++) dir[i]=-1;
  for (int i=1;i<=n;i++)
    if (!vst[i])
      dfs(i);
  for (int i=1;i<=n;i++)
    printf("%d ",dir[i]^1);
  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

struct edge{
  int u,v,next;
}G[N<<2];
int head[N],inum=1;

inline void add(int u,int v,int p){
  G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int deg[N];
int dir[N],vst[N];
#define V G[p].v
inline void dfs(int u){
  vst[u]=1;
  for (int p=head[u];p;p=G[p].next)
    if (dir[p>>1]==-1){
      dir[p>>1]=p&1;
      dfs(V);
    }
}

int sx[N],icnt;
inline int Bin(int x){
  return lower_bound(sx+1,sx+icnt+1,x)-sx;
}

int n,root;
int s[N],t[N];

int main(){
  read(n);
  for (int i=1;i<=n;i++)
    read(s[i]),read(t[i]),t[i]++,sx[++icnt]=s[i],sx[++icnt]=t[i];
  sort(sx+1,sx+icnt+1);
  icnt=unique(sx+1,sx+icnt+1)-sx-1;
  for (int i=1;i<=n;i++){
    s[i]=Bin(s[i]),t[i]=Bin(t[i]);
    add(s[i],t[i],++inum); add(t[i],s[i],++inum);
    deg[s[i]]++; deg[t[i]]++;
  }
  int last=0;
  for (int i=1;i<=icnt;i++)
    if (deg[i]&1)
      if (last)
	add(last,i,++inum),add(i,last,++inum),last=0;
      else
	last=i;
  for (int i=1;i<=(inum>>1);i++) dir[i]=-1;
  for (int i=1;i<=n;i++)
    if (!vst[i])
      dfs(i);
  for (int i=1;i<=n;i++)
    printf("%d ",dir[i]^1);
  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

struct edge{
  int u,v,next;
}G[N<<2];
int head[N],inum=1;

inline void add(int u,int v,int p){
  G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int deg[N];
int dir[N<<2],vst[N];
#define V G[p].v
inline void dfs(int u){
  vst[u]=1;
  for (int p=head[u];p;p=G[p].next)
    if (dir[p>>1]==-1){
      dir[p>>1]=p&1;
      dfs(V);
    }
}

int sx[N],icnt;
inline int Bin(int x){
  return lower_bound(sx+1,sx+icnt+1,x)-sx;
}

int n,root;
int s[N],t[N];

int main(){
  read(n);
  for (int i=1;i<=n;i++)
    read(s[i]),read(t[i]),t[i]++,sx[++icnt]=s[i],sx[++icnt]=t[i];
  sort(sx+1,sx+icnt+1);
  icnt=unique(sx+1,sx+icnt+1)-sx-1;
  for (int i=1;i<=n;i++){
    s[i]=Bin(s[i]),t[i]=Bin(t[i]);
    add(s[i],t[i],++inum); add(t[i],s[i],++inum);
    deg[s[i]]++; deg[t[i]]++;
  }
  int last=0;
  for (int i=1;i<=icnt;i++)
    if (deg[i]&1){
      if (last)
	add(last,i,++inum),add(i,last,++inum),last=0;
      else
	last=i;
    }
  for (int i=1;i<=(inum>>1);i++) dir[i]=-1;
  for (int i=1;i<=icnt;i++)
    if (!vst[i])
      dfs(i);
  for (int i=1;i<=n;i++)
    printf("%d ",dir[i]^1);
  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

struct edge{
  int u,v,next;
}G[N<<2];
int head[N],inum=1;

inline void add(int u,int v,int p){
  G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int deg[N];
int dir[N<<2],vst[N];
#define V G[p].v
inline void dfs(int u){
  vst[u]=1;
  for (int p=head[u];p;p=G[p].next)
    if (dir[p>>1]==-1){
      dir[p>>1]=p&1;
      dfs(V);
    }
}

int sx[N],icnt;
inline int Bin(int x){
  return lower_bound(sx+1,sx+icnt+1,x)-sx;
}

int n,root;
int s[N],t[N];

int main(){
  read(n);
  for (int i=1;i<=n;i++)
    read(s[i]),read(t[i]),t[i]++,sx[++icnt]=s[i],sx[++icnt]=t[i];
  sort(sx+1,sx+icnt+1);
  icnt=unique(sx+1,sx+icnt+1)-sx-1;
  for (int i=1;i<=n;i++){
    s[i]=Bin(s[i]),t[i]=Bin(t[i]);
    add(s[i],t[i],++inum); add(t[i],s[i],++inum);
    deg[s[i]]++; deg[t[i]]++;
  }
  int last=0;
  for (int i=1;i<=icnt;i++)
    if (deg[i]&1){
      if (last)
	add(last,i,++inum),add(i,last,++inum),last=0;
      else
	last=i;
    }
  for (int i=1;i<=(inum>>1);i++) dir[i]=-1;
  for (int i=1;i<=n;i++)
    if (!vst[i])
      dfs(i);
  for (int i=1;i<=n;i++)
    printf("%d ",dir[i]^1);
  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[400001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
void dfs(int u)
{
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		head[u]=i;
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=v.size();i++)
		dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
int vis[200001];
void dfs(int u)
{
	vis[u]=1;
	for(int i=head[u];i!=-1;i=e[i].nxt)
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
void dfs(int u)
{
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		head[u]=i;
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=v.size();i++)
		dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
void dfs(int u)
{
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		head[u]=i;
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=n;i++)
		dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
void dfs(int u)
{
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		head[u]=i;
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=n*2;i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=n;i++)
		dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[400001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
void dfs(int u)
{
	for(int i=head[u];i!=-1;i=e[i].nxt)
	{
		head[u]=i;
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=n;i++)
		dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<stack>
using namespace std;
struct edge
{
	int to,nxt,w;
}e[200001];
int edge_num=-1;
int head[200001];
void add(int u,int v)
{
	e[++edge_num].nxt=head[u];
	e[edge_num].to=v;
	head[u]=edge_num;
}
void add_edge(int u,int v)
{
	add(u,v);
	add(v,u);
}

struct node
{
	int l,r;
}q[200001];
int in[200001];
int vis[200001];
void dfs(int u)
{
	vis[u]=1;
	for(int i=head[u];i!=-1;i=e[i].nxt)
		if(e[i].w==0)
		{
			e[i].w=1,e[i^1].w=2;
			dfs(e[i].to);
		}
}
int main()
{
	memset(head,-1,sizeof(head));
	int n;
	scanf("%d",&n);
	vector<int> v;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].r++;
		v.push_back(q[i].l);
		v.push_back(q[i].r);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	for(int i=1;i<=n;i++)
	{
		q[i].l=lower_bound(v.begin(),v.end(),q[i].l)-v.begin()+1;
		q[i].r=lower_bound(v.begin(),v.end(),q[i].r)-v.begin()+1;
		add_edge(q[i].l,q[i].r);
		in[q[i].l]++;
		in[q[i].r]++;
	}

	vector<int>v1;
	for(int i=1;i<=v.size();i++)
		if(in[i]%2==1)
			v1.push_back(i);
	for(int i=0;i<v1.size();i+=2)
		add_edge(v1[i],v1[i+1]);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	for(int i=0;i<2*n;i++)
	{
		if(e[i].w==1)
			printf("%d ",i%2);
	}
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <ctime>
#include <iomanip>
#include <cstring>

#define SZ(x) ((int)x.size())
#define X first
#define Y second
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int N = 1e5 + 100;
const int E = 2e5 + 100;
int n;
int l[N], r[N];
vector <int> x;
vector <int> g[N];
vector <int> tour;

int to[E], mark[E], ecnt;
int from[E], c[E];

void add(int u, int v){
	from[ecnt] = u, to[ecnt] = v;
	g[u].push_back(ecnt);
	g[v].push_back(ecnt);
	ecnt ++;
}

void dfs(int v){
	while(SZ(g[v])){
		int id = g[v].back();
		g[v].pop_back();
		int u = from[id] + to[id] - v;
		if(!mark[id]){
			mark[id] = true;
			dfs(u);
			if(u < v)
				c[id] = 1;
			else
				c[id] = 0;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> l[i] >> r[i]; r[i] ++;
		x.PB(l[i]);
		x.PB(r[i]);
	}
	sort(x.begin(), x.end());
	x.resize(unique(x.begin(), x.end()) - x.begin());
	for(int i = 0; i < n; ++i){
		l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();
		r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();
		add(l[i], r[i]);
	}
	int lst = -1;
	for(int i = 0; i < 2 * n; ++i){
		if(SZ(g[i]) & 1){
			if(lst == -1) lst = i;
			else{
				add(lst, i);
				lst = -1;
			}
		}
	}
	for (int i = 0; i < 2 * n; i++)
		if (!g[i].empty())
			dfs(i);
	for (int i = 0; i < n; i++)
		cout << c[i] << " ";
	cout << endl;
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <ctime>
#include <iomanip>
#include <cstring>

#define SZ(x) ((int)x.size())
#define X first
#define Y second
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int N = 2e5 + 100;
const int E = 2e5 + 100;
int n;
int l[N], r[N];
vector <int> x;
vector <int> g[N];
vector <int> tour;

int to[E], mark[E], ecnt;
int from[E], c[E];

void add(int u, int v){
	from[ecnt] = u, to[ecnt] = v;
	g[u].push_back(ecnt);
	g[v].push_back(ecnt);
	ecnt ++;
}

void dfs(int v){
	while(SZ(g[v])){
		int id = g[v].back();
		g[v].pop_back();
		int u = from[id] + to[id] - v;
		if(!mark[id]){
			mark[id] = true;
			dfs(u);
			if(u < v)
				c[id] = 1;
			else
				c[id] = 0;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> l[i] >> r[i]; r[i] ++;
		x.PB(l[i]);
		x.PB(r[i]);
	}
	sort(x.begin(), x.end());
	x.resize(unique(x.begin(), x.end()) - x.begin());
	for(int i = 0; i < n; ++i){
		l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();
		r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();
		add(l[i], r[i]);
	}
	int lst = -1;
	for(int i = 0; i < 2 * n; ++i){
		if(SZ(g[i]) & 1){
			if(lst == -1) lst = i;
			else{
				add(lst, i);
				lst = -1;
			}
		}
	}
	for (int i = 0; i < 2 * n; i++)
		if (!g[i].empty())
			dfs(i);
	for (int i = 0; i < n; i++)
		cout << c[i] << " ";
	cout << endl;
	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <ctime>
#include <iomanip>
#include <cstring>

#define SZ(x) ((int)x.size())
#define X first
#define Y second
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;

const int N = 1e5 + 100;
const int E = 2e5 + 100;
int n;
int l[N], r[N];
vector <int> x;
vector <int> g[N];
vector <int> tour;

int to[E], mark[E], ecnt;
int from[E], c[E];
void add(int u, int v){
	from[ecnt] = u, to[ecnt] = v;
	g[u].push_back(ecnt);
	g[v].push_back(ecnt++);
}

void dfs(int v){
	while(SZ(g[v])){
		int id = g[v].back();
		g[v].pop_back();
		int u = from[id] + to[id] - v;
		if (!mark[id])
		{
			dfs(u);
			if (u < v)
				c[id] = 1;
			else
				c[id] = 0;
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> l[i] >> r[i]; r[i] ++;
		x.PB(l[i]);
		x.PB(r[i]);
	}
	sort(x.begin(), x.end());
	x.resize(unique(x.begin(), x.end()) - x.begin());
	for(int i = 0; i < n; ++i){
		l[i] = lower_bound(x.begin(), x.end(), l[i]) - x.begin();
		r[i] = lower_bound(x.begin(), x.end(), r[i]) - x.begin();
		add(l[i], r[i]);
	}
	int lst = -1;
	for(int i = 0; i < 2 * n; ++i){
		if(SZ(g[i]) & 1){
			if(lst == -1) lst = i;
			else{
				add(lst, i);
				lst = -1;
			}
		}
	}
	for (int i = 0; i < 2 * n; i++)
		dfs(i);
	for (int i = 0; i < n; i++)
		cout << c[i] << " ";
	cout << endl;
	return 0;
}


//sobskdrbhvk
#include <bits/stdc++.h>

using namespace std;

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

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 4e5 + 85 - 69;
bool mark[maxn],
	 emark[maxn],
	 ans[maxn];
int frm[maxn],
	too[maxn],
	n;
set<pair<pii, int> > s;
vector<int> adj[maxn],
	tour,
	all;

int idof(int x){
	return lower_bound(all(all), x) - all.begin();
}

void dfs(int u){
	mark[u] = true;
	while(sz(adj[u])){
		int e = adj[u].back();
		adj[u].pop_back();
		if(emark[e]) continue;
		emark[e] = true;
		dfs(frm[e] + too[e] - u);
	}
	tour.PB(u);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> frm[i] >> too[i], too[i]++;
		all.PB(frm[i]);
		all.PB(too[i]);
	}
	sort(all(all));
	for(int i = 0; i < n; i++){
		frm[i] = idof(frm[i]);
		too[i] = idof(too[i]);
		s.insert(MP(MP(frm[i], too[i]), i));
		adj[frm[i]].PB(i);
		adj[too[i]].PB(i);
	}
	int lst = -1, oecnt = 0;
	for(int i = 0; i < sz(all); i++){
		if(sz(adj[i]) & 1){
			if(lst == -1)
				lst = i;
			else{
				int id = n + oecnt;
				frm[id] = lst, too[id] = i;
				adj[lst].PB(id);
				adj[i].PB(id);
				s.insert(MP(MP(frm[id], too[id]), id));
				oecnt++, lst = -1;
			}
		}
	}
	for(int ii = 0; ii < sz(all); ii++) if(!mark[ii]){
		tour.clear();
		dfs(ii);
		for(int i = 0; i + 1 < sz(tour); i++){
			int u = tour[i],
				v = tour[i + 1];
			auto it = s.lower_bound(MP(MP(min(v, u), max(v, u)), -1));
			ans[it->R] = u < v;
			s.erase(it);
		}
	}
	for(int i = 0; i < n; i++)
		cout << ans[i] << ' ';
	cout << '\n';
	return 0;
}


//sobskdrbhvk
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 2e5;
int l[maxn],
	r[maxn],
	ans[maxn],
	pos[maxn],
	n;
vector<int> all;
vector<pii> adj[maxn];

void dfs(int v){
	for(int &i = pos[v]; i < sz(adj[v]); i++) if(!ans[adj[v][i].R]){
		ans[adj[v][i].R] = 1 + (v < adj[v][i].L);
		dfs(adj[v][i].L);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		l[i]--, r[i]++;
		all.PB(l[i]);
		all.PB(r[i]);
	}
	sort(all(all));
	all.resize(unique(all(all)) - all.begin());
	for(int i = 0; i < n; i++){
		l[i] = lower_bound(all(all), l[i]) - all.begin();
		r[i] = lower_bound(all(all), r[i]) - all.begin();
		adj[l[i]].PB({r[i], i});
		adj[r[i]].PB({l[i], i});
	}
	for(int i = 0; i + 1 < sz(all); i++){
		if(sz(adj[i]) & 1){
			adj[i].PB({i + 1, n});
			adj[i + 1].PB({i, n});
		}
	}
	for(int i = 0; i < sz(all); i++)
		dfs(i);
	for(int i = 0; i < n; i++)
		cout << ans[i] - 1 << ' ';
	cout << endl;
	return 0;
}


//sobskdrbhvk
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 2e5;
int l[maxn],
	r[maxn],
	ans[maxn],
	pos[maxn],
	n;
vector<int> all;
vector<pii> adj[maxn];

void dfs(int v){
	for(int &i = pos[v]; i < sz(adj[v]); i++) if(!ans[adj[v][i].R]){
		ans[adj[v][i].R] = 1 + (v < adj[v][i].L);
		dfs(adj[v][i].L);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		all.PB(l[i]);
		all.PB(r[i]);
	}
	sort(all(all));
	all.resize(unique(all(all)) - all.begin());
	for(int i = 0; i < n; i++){
		l[i] = lower_bound(all(all), l[i]) - all.begin();
		r[i] = lower_bound(all(all), r[i]) - all.begin();
		adj[l[i]].PB({r[i], i});
		adj[r[i]].PB({l[i], i});
	}
	for(int i = 0; i + 1 < sz(all); i++){
		if(sz(adj[i]) & 1){
			adj[i].PB({i + 1, n});
			adj[i + 1].PB({i, n});
		}
	}
	for(int i = 0; i < sz(all); i++)
		dfs(i);
	for(int i = 0; i < n; i++)
		cout << ans[i] - 1 << ' ';
	cout << endl;
	return 0;
}


//sobskdrbhvk
#include <bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 2e5;
int l[maxn],
	r[maxn],
	ans[maxn],
	pos[maxn],
	n;
vector<int> all;
vector<pii> adj[maxn];

void dfs(int v){
	for(int &i = pos[v]; i < sz(adj[v]); i++) if(!ans[adj[v][i].R]){
		ans[adj[v][i].R] = 1 + (v < adj[v][i].L);
		dfs(adj[v][i].L);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> l[i] >> r[i];
		r[i]++;
		all.PB(l[i]);
		all.PB(r[i]);
	}
	sort(all(all));
	all.resize(unique(all(all)) - all.begin());
	for(int i = 0; i < n; i++){
		l[i] = lower_bound(all(all), l[i]) - all.begin();
		r[i] = lower_bound(all(all), r[i]) - all.begin();
		adj[l[i]].PB({r[i], i});
		adj[r[i]].PB({l[i], i});
	}
	for(int i = 0; i + 1 < sz(all); i++){
		if(sz(adj[i]) & 1){
			adj[i].PB({i + 1, n});
			adj[i + 1].PB({i, n});
		}
	}
	for(int i = 0; i < sz(all); i++)
		dfs(i);
	for(int i = 0; i < n; i++)
		cout << ans[i] - 1 << ' ';
	cout << endl;
	return 0;
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n;
int al[MAXN], ar[MAXN];
int ke, la[MAXN];
int dir[MAXN];
int deg[MAXN];
int ei[MAXN*2];
bool vis[MAXN];

void init ();
void input ();
void work ();

void dfs ( int now );

int main()
{
	init();
	input();
	work();
}

void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &al[i], &ar[i] );
}

void work ()
{
	// main work

	lpi ( i, 1, n ) al[i] = al[i] << 1, ar[i] = ar[i] << 1 | 1;

	map < int, int > mp;
	int kc = 0;
	lpi ( i, 1, n ) mp[al[i]] = 0, mp[ar[i]] = 0;
	for ( auto &x : mp ) x.second = ++kc;
	lpi ( i, 1, n ) al[i] = mp[al[i]], ar[i] = mp[ar[i]];

	INIT ( la, -1 );
	lpi ( i, 1, n ){
		edge[ke].setd ( al[i], ar[i], la[al[i]] );
		ei[ke] = i;
		la[al[i]] = ke++;
		edge[ke].setd ( ar[i], al[i], la[ar[i]] );
		ei[ke] = i;
		la[ar[i]] = ke++;
		++deg[al[i]], ++deg[ar[i]];
	}

	int pre = -1;
	lpi ( i, 1, kc ){
		if ( deg[i] & 1 ){
			if ( pre == -1 ) pre = i;
			else{
				edge[ke].setd ( pre, i, la[pre] );
				la[pre] = ke++;
				edge[ke].setd ( i, pre, la[i] );
				la[i] = ke++;
				pre = -1;
			}
		}
	}

//	lp ( i, 0, ke ) cerr << edge[i].u << " " << edge[i].v << endl;

	lpi ( i, 1, n ) if ( ~la[i] ) dfs ( i );

	lpi ( i, 1, n ) printf ( "%d ", dir[i] );
	putchar ( '\n' );
}

void dfs ( int now )
{
	for ( int i = la[now]; ~i; i = la[now] ){
		la[now] = edge[i].last;
		if ( !vis[i>>1] ){
			vis[i>>1] = true;
			dfs ( edge[i].v );
			dir[ei[i]] = ( edge[i].v < edge[i].u  ) ? 1 : 0;
		}
	}
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n;
int al[MAXN], ar[MAXN];
int ke, la[MAXN];
int dir[MAXN];
int deg[MAXN];
int ei[MAXN*2];
bool vis[MAXN];

void init ();
void input ();
void work ();

void dfs ( int now );

int main()
{
	init();
	input();
	work();
}

void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &al[i], &ar[i] );
}

void work ()
{
	// main work

	lpi ( i, 1, n ) al[i] = al[i] << 1, ar[i] = ar[i] << 1 | 1;

	map < int, int > mp;
	int kc = 0;
	lpi ( i, 1, n ) mp[al[i]] = 0, mp[ar[i]] = 0;
	for ( auto &x : mp ) x.second = ++kc;
	lpi ( i, 1, n ) al[i] = mp[al[i]], ar[i] = mp[ar[i]];

	INIT ( la, -1 );
	lpi ( i, 1, n ){
		edge[ke].setd ( al[i], ar[i], la[al[i]] );
		ei[ke] = i;
		la[al[i]] = ke++;
		edge[ke].setd ( ar[i], al[i], la[ar[i]] );
		ei[ke] = i;
		la[ar[i]] = ke++;
		++deg[al[i]], ++deg[ar[i]];
	}

	int pre = -1;
	lpi ( i, 1, kc ){
		if ( deg[i] & 1 ){
			if ( pre == -1 ) pre = i;
			else{
				edge[ke].setd ( pre, i, la[pre] );
				la[pre] = ke++;
				edge[ke].setd ( i, pre, la[i] );
				la[i] = ke++;
				pre = -1;
			}
		}
	}

//	lp ( i, 0, ke ) cerr << edge[i].u << " " << edge[i].v << endl;

	lpi ( i, 1, kc ) if ( ~la[i] ) dfs ( i );

	lpi ( i, 1, n ) printf ( "%d ", dir[i] );
	putchar ( '\n' );
}

void dfs ( int now )
{
	for ( int i = la[now]; ~i; i = la[now] ){
		la[now] = edge[i].last;
		if ( !vis[i>>1] ){
			vis[i>>1] = true;
			dfs ( edge[i].v );
			dir[ei[i]] = ( edge[i].v < edge[i].u  ) ? 1 : 0;
		}
	}
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n;
int al[MAXN], ar[MAXN];
int ke, la[MAXN];
int dir[MAXN];
int deg[MAXN];
int ei[MAXN*2];
bool vis[MAXN];

void init ();
void input ();
void work ();

void dfs ( int now );

int main()
{
	init();
	input();
	work();
}

void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &al[i], &ar[i] ), ++ar[i];
}

void work ()
{
	// main work

	map < int, int > mp;
	int kc = 0;
	lpi ( i, 1, n ) mp[al[i]] = 0, mp[ar[i]] = 0;
	for ( auto &x : mp ) x.second = ++kc;
	lpi ( i, 1, n ) al[i] = mp[al[i]], ar[i] = mp[ar[i]];

	INIT ( la, -1 );
	lpi ( i, 1, n ){
		edge[ke].setd ( al[i], ar[i], la[al[i]] );
		ei[ke] = i;
		la[al[i]] = ke++;
		edge[ke].setd ( ar[i], al[i], la[ar[i]] );
		ei[ke] = i;
		la[ar[i]] = ke++;
		++deg[al[i]], ++deg[ar[i]];
	}

	int pre = -1;
	lpi ( i, 1, kc ){
		if ( deg[i] & 1 ){
			if ( pre == -1 ) pre = i;
			else{
				edge[ke].setd ( pre, i, la[pre] );
				la[pre] = ke++;
				edge[ke].setd ( i, pre, la[i] );
				la[i] = ke++;
				pre = -1;
			}
		}
	}

//	lp ( i, 0, ke ) cerr << edge[i].u << " " << edge[i].v << endl;

	lpi ( i, 1, n ) if ( ~la[i] ) dfs ( i );

	lpi ( i, 1, n ) printf ( "%d ", dir[i] );
	putchar ( '\n' );
}

void dfs ( int now )
{
	for ( int i = la[now]; ~i; i = la[now] ){
		la[now] = edge[i].last;
		if ( !vis[i>>1] ){
			vis[i>>1] = true;
			dfs ( edge[i].v );
			dir[ei[i]] = ( edge[i].v < edge[i].u  ) ? 1 : 0;
		}
	}
}


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 200007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n;
int al[MAXN], ar[MAXN];
int ke, la[MAXN];
int dir[MAXN];
int deg[MAXN];
int ei[MAXN*2];
bool vis[MAXN];

void init ();
void input ();
void work ();

void dfs ( int now );

int main()
{
	init();
	input();
	work();
}

void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d%d", &al[i], &ar[i] ), ++ar[i];
}

void work ()
{
	// main work

	map < int, int > mp;
	int kc;
	lpi ( i, 1, n ) mp[al[i]] = 0, mp[ar[i]] = 0;
	for ( auto &x : mp ) x.second = ++kc;
	lpi ( i, 1, n ) al[i] = mp[al[i]], ar[i] = mp[ar[i]];

	INIT ( la, -1 );
	lpi ( i, 1, n ){
		edge[ke].setd ( al[i], ar[i], la[al[i]] );
		ei[ke] = i;
		la[al[i]] = ke++;
		edge[ke].setd ( ar[i], al[i], la[ar[i]] );
		ei[ke] = i;
		la[ar[i]] = ke++;
		++deg[al[i]], ++deg[ar[i]];
	}

	int pre = -1;
	lpi ( i, 1, kc ){
		if ( deg[i] & 1 ){
			if ( pre == -1 ) pre = i;
			else{
				edge[ke].setd ( pre, i, la[pre] );
				la[pre] = ke++;
				edge[ke].setd ( i, pre, la[i] );
				la[i] = ke++;
				pre = -1;
			}
		}
	}

//	lp ( i, 0, ke ) cerr << edge[i].u << " " << edge[i].v << endl;

	lpi ( i, 1, n ) if ( ~la[i] ) dfs ( i );

	lpi ( i, 1, n ) printf ( "%d ", dir[i] );
	putchar ( '\n' );
}

void dfs ( int now )
{
	for ( int i = la[now]; ~i; i = la[now] ){
		la[now] = edge[i].last;
		if ( !vis[i>>1] ){
			vis[i>>1] = true;
			dfs ( edge[i].v );
			dir[ei[i]] = ( edge[i].v < edge[i].u  ) ? 1 : 0;
		}
	}
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+10;
int n,l[N],r[N],B[N],cc,head[N],cnt,du[N];
int f[N],ans[N],top,vis[N],ed;
map<int,int> Map;
struct edge{int next,to,id;}a[N<<2];
void link(int x,int y,int id)
{
	a[++cnt]=(edge){head[x],y,id};
	du[y]++;head[x]=cnt;
}
void dfs(int x)
{
	for(int &i=head[x],nw;i;i=a[i].next)
		if(!vis[abs(a[i].id)])
			vis[abs(a[i].id)]=1,nw=a[i].id,dfs(a[i].to),ans[++top]=nw;
}
int main()
{
	cin>>n;ed=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		l[i]--;B[++cc]=l[i];B[++cc]=r[i];
	}
	sort(B+1,B+cc+1);
	cc=unique(B+1,B+cc+1)-B-1;
	for(int i=1;i<=cc;i++) Map[B[i]]=i;
	for(int i=1;i<=n;i++) l[i]=Map[l[i]],r[i]=Map[r[i]];
	for(int i=1;i<=n;i++) link(l[i],r[i],i),link(r[i],l[i],-i);
	for(int i=1,lst=0;i<=cc;i++)
		if(du[i]&1)
		{
			if(lst) link(lst,i,++ed),link(i,lst,-ed),lst=0;
			else lst=i;
		}
	for(int i=1;i<=cc;i++) dfs(i);
	for(int i=top;i>=1;i--)
		if(abs(ans[i])<=n) f[abs(ans[i])]=ans[i]>0;
	for(int i=1;i<=n;i++) printf("%d ",f[i]);
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+10;
int n,l[N],r[N],B[N],cc,head[N],cnt,du[N];
int f[N],ans[N],top,vis[N],ed;
map<int,int> Map;
struct edge{int next,to,id;}a[N];
void link(int x,int y,int id)
{
	a[++cnt]=(edge){head[x],y,id};
	du[y]++;head[x]=cnt;
}
void dfs(int x)
{
	for(int &i=head[x],nw;i;i=a[i].next)
		if(!vis[abs(a[i].id)])
			vis[abs(a[i].id)]=1,nw=a[i].id,dfs(a[i].to),ans[++top]=nw;
}
int main()
{
	cin>>n;ed=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		l[i]--;B[++cc]=l[i];B[++cc]=r[i];
	}
	sort(B+1,B+cc+1);
	cc=unique(B+1,B+cc+1)-B-1;
	for(int i=1;i<=cc;i++) Map[B[i]]=i;
	for(int i=1;i<=n;i++) l[i]=Map[l[i]],r[i]=Map[r[i]];
	for(int i=1;i<=n;i++) link(l[i],r[i],i),link(r[i],l[i],-i);
	for(int i=1,lst=0;i<=cc;i++)
		if(du[i]&1)
		{
			if(lst) link(lst,i,++ed),link(i,lst,-ed),lst=0;
			else lst=i;
		}
	for(int i=1;i<=cc;i++) dfs(i);
	for(int i=top;i>=1;i--)
		if(abs(ans[i]<=n)) f[abs(ans[i])]=ans[i]>0;
	for(int i=1;i<=n;i++) printf("%d ",f[i]);
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+10;
int n,l[N],r[N],B[N],cc,head[N],cnt,du[N];
int f[N],ans[N],top,vis[N],ed;
map<int,int> Map;
struct edge{int next,to,id;}a[N];
void link(int x,int y,int id)
{
	a[++cnt]=(edge){head[x],y,id};
	du[y]++;head[x]=cnt;
}
void dfs(int x)
{
	for(int &i=head[x],nw;i;i=a[i].next)
		if(!vis[abs(a[i].id)])
			vis[abs(a[i].id)]=1,nw=a[i].id,dfs(a[i].to),ans[++top]=nw;
}
int main()
{
	cin>>n;ed=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		l[i]--;B[++cc]=l[i];B[++cc]=r[i];
	}
	sort(B+1,B+cc+1);
	cc=unique(B+1,B+cc+1)-B-1;
	for(int i=1;i<=cc;i++) Map[B[i]]=i;
	for(int i=1;i<=n;i++) l[i]=Map[l[i]],r[i]=Map[r[i]];
	for(int i=1;i<=n;i++) link(l[i],r[i],i),link(r[i],l[i],-i);
	for(int i=1,lst=0;i<=cc;i++)
		if(du[i]&1)
		{
			if(lst) link(lst,i,++ed),link(i,lst,-ed),lst=0;
			else lst=i;
		}
	for(int i=1;i<=cc;i++) dfs(i);
	for(int i=top;i>=1;i--)
		if(abs(ans[i])<=n) f[abs(ans[i])]=ans[i]>0;
	for(int i=1;i<=n;i++) printf("%d ",f[i]);
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
const int N=2e5+10;
int n,l[N],r[N],B[N],cc,head[N],cnt,du[N];
int f[N],ans[N],top,vis[N],ed;
map<int,int> Map;
struct edge{int next,to,id;}a[N];
void link(int x,int y,int id)
{
	a[++cnt]=(edge){head[x],y,id};
	du[y]++;head[x]=cnt;
}
void dfs(int x)
{
	for(int &i=head[x],nw;i;i=a[i].next)
		if(!vis[abs(a[i].id)])
			vis[abs(a[i].id)]=1,nw=a[i].id,dfs(a[i].to),ans[++top]=nw;
}
int main()
{
	cin>>n;ed=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		l[i]++;r[i]++;B[++cc]=l[i];B[++cc]=r[i];
	}
	sort(B+1,B+cc+1);
	cc=unique(B+1,B+cc+1)-B-1;
	for(int i=1;i<=cc;i++) Map[B[i]]=i;
	for(int i=1;i<=n;i++) l[i]=Map[l[i]],r[i]=Map[r[i]];
	for(int i=1;i<=n;i++) link(l[i],r[i],i),link(r[i],l[i],-i);
	for(int i=1,lst=0;i<=cc;i++)
		if(du[i]&1)
		{
			if(lst) link(lst,i,++ed),link(i,lst,-ed),lst=0;
			else lst=i;
		}
	for(int i=1;i<=cc;i++) dfs(i);
	for(int i=top;i>=1;i--)
		if(abs(ans[i]<=n)) f[abs(ans[i])]=ans[i]>0;
	for(int i=1;i<=n;i++) printf("%d ",f[i]);
}


#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,m,a[N],hd[N],to[N],nx[N],id[N],du[N],tt=1;
void add(int u,int v,int d){
	nx[++tt]=hd[u]; to[hd[u]=tt]=v; id[tt]=d; du[v]++;
	//cout<<u<<" "<<v<<endl;
}
bool vs[N]; int ans[N],l[N],r[N];
void dfs(int x,int u){
	for(int e=hd[u];e;e=nx[e]) if(!vs[e]){
		int v=to[e]; if(du[v]&1 && v!=x) continue;
		du[u]--; du[v]--; ans[id[e]]=(u<v); vs[e]=vs[e^1]=1;
		if(v!=x) dfs(x,v);
		break;
	}
}
int main()
{
	srand(time(0));
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>m;
	for(int i=1;i<=m;i++) scanf("%d%d",&l[i],&r[i]),r[i]++,a[++n]=l[i],a[++n]=r[i];
	sort(a+1,a+n+1); n=unique(a+1,a+n+1)-a-1;
	for(int i=1;i<=m;i++){
		int u=lower_bound(a+1,a+n+1,l[i])-a,v=lower_bound(a+1,a+n+1,r[i])-a;
		add(u,v,i),add(v,u,i);
	}
	for(int i=1,j=0;i<=n;i++) if(du[i]&1){
		if(!j) j=i;
		else add(j,i,0),add(i,j,0),j=0;
	}
	for(int i=1;i<=n;i++) while(du[i]) dfs(i,i);
	for(int i=1;i<=m;i++) printf("%d ",ans[i]); puts("");
	return 0;
}
//hello


// tzl ak IOI!

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

const int N = 1e5 + 100;

int n;
vi g[N];

struct seg
{
	int l, r, id;
	seg(){}
	seg(int L, int R, int I): l(L), r(R), id(I){}

	bool operator < (const seg &a) const
	{
		return l == a.l ? (r == a.r ? id < a.id : r < a.r) : l < a.l;
	}
};

set<seg> all;
int col[N];

void TZL()
{
	scf(n);
	forn(i, 1, n)
	{
		int l, r; scf(l, r);
		all.insert(seg(l, r, i));
		col[i] = -1;
	}
	return;
}

void dfs(int u, int c = 0)
{
	col[u] = c;
	for(int v: g[u]) if(!~col[v]) dfs(v, c ^ 1);
	return;
}

void RANK1()
{
	while(SZ(all) > 1)
	{
		seg a = *all.begin(); all.erase(all.begin());
		seg b = *all.begin(); all.erase(all.begin());

#ifdef DEBUG
		printf("%d %d %d\t%d %d %d\n", a.l, a.r, a.id, b.l, b.r, b.id);
#endif

		if(a.r < b.l)
		{
			all.insert(b);
			continue;
		}

		g[a.id].pb(b.id); g[b.id].pb(a.id);

		if(a.r > b.r) all.insert(seg(b.r + 1, a.r, a.id));
		if(a.r < b.r) all.insert(seg(a.r + 1, b.r, b.id));
	}

	forn(i, 1, n)
	{
		if(!~col[i]) dfs(i);
		printf("%d ", col[i]);
	}
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}


// tzl ak IOI!

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

const int N = 1e5 + 100;

int n;
vi g[N];

struct seg
{
	int l, r, id;
	seg(){}
	seg(int L, int R, int I): l(L), r(R), id(I){}

	bool operator < (const seg &a) const
	{
		return l == a.l ? r < a.r : l < a.l;
	}
};

set<seg> all;
int col[N];

void TZL()
{
	scf(n);
	forn(i, 1, n)
	{
		int l, r; scf(l, r);
		all.insert(seg(l, r, i));
		col[i] = -1;
	}
	return;
}

void dfs(int u, int c = 0)
{
	col[u] = c;
	for(int v: g[u]) if(!~col[v]) dfs(v, c ^ 1);
	return;
}

void RANK1()
{
	while(SZ(all) > 1)
	{
		seg a = *all.begin(); all.erase(all.begin());
		seg b = *all.begin(); all.erase(all.begin());

		if(a.r < b.l)
		{
			all.insert(b);
			continue;
		}

		g[a.id].pb(b.id); g[b.id].pb(a.id);

		if(a.r > b.r) all.insert(seg(b.r + 1, a.r, a.id));
		if(a.r < b.r) all.insert(seg(a.r + 1, b.r, b.id));
	}

	forn(i, 1, n)
	{
		if(!~col[i]) dfs(i);
		printf("%d ", col[i]);
	}
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}


// tzl ak IOI!

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

const int N = 1e5 + 100;

int n, top;
int id[N], l[N], r[N], stk[N], col[N];
vi g[N];

void TZL()
{
	scf(n);
	forn(i, 1, n) scf(l[i], r[i]), id[i] = i;
	sort(id + 1, id + n + 1, [&](int a, int b){ return l[a] == l[b] ? r[a] < r[b] : l[a] < l[b]; });
	FILL(col, -1);
	return;
}

void dfs(int u, int c = 0)
{
	col[u] = c;
	for(int v: g[u]) if(!~col[v]) dfs(v, c ^ 1);
	return;
}

void RANK1()
{
	forn(i, 1, n)
	{
		if(!top){ stk[top++] = i; continue; }
		int jj = id[stk[top - 1]], ii = id[i];
		int lj = l[jj], rj = r[jj], li = l[ii], ri = r[ii];

		if(li > rj){ stk[top - 1] = i; continue; }

		g[jj].pb(ii); g[ii].pb(jj);
		if(ri == rj) top--;
		else if(ri > rj) stk[top - 1] = i;
	}

	forn(i, 1, n) if(col[i] < 0) dfs(i);
	forn(i, 1, n) printf("%d ", col[i]);
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}


// tzl ak IOI!

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

const int N = 1e5 + 100;

int n;
vi g[N];

struct seg
{
	int l, r, id;
	seg(){}
	seg(int L, int R, int I): l(L), r(R), id(I){}

	bool operator < (const seg &a) const
	{
		return l == a.l ? r < a.r : l < a.l;
	}
};

set<seg> all;
int col[N];

void TZL()
{
	scf(n);
	forn(i, 1, n)
	{
		int l, r; scf(l, r);
		all.insert(seg(l, r, i));
		col[i] = -1;
	}
	return;
}

void dfs(int u, int c = 0)
{
	col[u] = c;
	for(int v: g[u]) if(!~col[v]) dfs(v, c ^ 1);
	return;
}

void RANK1()
{
	while(SZ(all) > 1)
	{
		seg a = *all.begin(); all.erase(all.begin());
		seg b = *all.begin(); all.erase(all.begin());

		if(a.r < b.l)
		{
			all.insert(a);
			continue;
		}

		g[a.id].pb(b.id); g[b.id].pb(a.id);

		if(a.r > b.r) all.insert(seg(b.r + 1, a.r, a.id));
		if(a.r < b.r) all.insert(seg(a.r + 1, b.r, b.id));
	}

	forn(i, 1, n)
	{
		if(!~col[i]) dfs(i);
		printf("%d ", col[i]);
	}
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}


// tzl ak IOI!

#include<bits/stdc++.h>

#define HEAP priority_queue
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l); i <= (r); ++i)
#define nrof(i, r, l) for(int i = (r); i >= (l); --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}

template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }

template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }

template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

template <typename T>
void chkmax(T &x, const T &y){ if(y > x) x = y; return; }

template <typename T>
void chkmin(T &x, const T &y){ if(y < x) x = y; return; }

#ifdef ONLINE_JUDGE
#define debug(x,c) ;
#else
#define DEBUG
#define debug(x,c) cerr<<#x<<"="<<x<<c;
#endif

//---------------------------head----------------------------

const int N = 2e5 + 100;

int n;
int ans[N], id[N], x[N];
vi g[N];

void TZL()
{
	scf(n);
	forn(i, 1, n)
	{
		scf(x[i], x[i + n]);
		x[i + n]++;
		g[i].pb(i + n);
		g[i + n].pb(i);
		id[i] = i;
		id[i + n] = i + n;
	}

	sort(id + 1, id + n + n + 1, [&](int i, int j){ return x[i] < x[j]; });

	for(int i = 1; i <= n + n; i += 2)
	{
#ifdef DEBUG
		printf("%d %d\n", id[i], id[i + 1]);
#endif
		g[id[i]].pb(id[i + 1]);
		g[id[i + 1]].pb(id[i]);
	}
	return;
}

void dfs(int u, int c = 1)
{
	ans[u] = c;
	for(int v: g[u]) if(!ans[v]) dfs(v, 3 - c);
	return;
}

void RANK1()
{
	forn(i, 1, n)
	{
		if(!ans[i]) dfs(i);
		printf("%d ", ans[i] - 1);
	}
	return;
}

#define tzl int
#define ak main
#define IOI ()
tzl ak IOI
{
#undef tzl
#undef ak
#undef IOI

	TZL();
	RANK1();

#define tzl return
#define caisi 0
#define myy ;
	tzl caisi myy
#undef tzl
#undef caisi
#undef myy
}


#include<cstdio>
#include<algorithm>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define N 100010

using namespace std;

int n, m;
struct E{int x, o, i;} e[N<<1]; int cnt;
struct _E{int ed, o, i, ne;} _e[N<<3]; int in[N<<1], he[N<<1], en; bool vis[N<<3];
int path[N<<2], tot;
int ans[N];

bool cmp1(E a, E b) {
	return a.x < b.x;
}

bool cmp2(E a, E b) {
	return a.i == b.i? a.o < b.o: a.i < b.i;
}

void ins(int a, int b, int i) {
	//printf("%d %d %d\n", a, b, i);
	++in[a]; ++in[b];
	_e[++en].ed = b; _e[en].o = 0; _e[en].i = i; _e[en].ne = he[b]; he[b] = en;
	_e[++en].ed = b; _e[en].o = 1; _e[en].i = i; _e[en].ne = he[a]; he[a] = en;
}

void dfs(int u) {
	for(int &i = he[u]; i; i = _e[i].ne)
	if(!vis[i]) {
		vis[i] = vis[i^1] = 1;
		int j = _e[i].i;
		dfs(_e[i].ed);
		path[++tot] = i;
	}
}

int main() {
	int i, x, la = 0;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d", &x); e[++cnt] = (E){x, 0, i};
		scanf("%d", &x); e[++cnt] = (E){x+1, 1, i};
	}
	sort(e + 1, e + cnt + 1, cmp1);
	//rep(i, 1, cnt) printf("%d %d %d\n", e[i].x, e[i].o, e[i].i);
	rep(i, 1, cnt) {
		if(i == 1 || e[i].x != la) {++m; la = e[i].x;}
		e[i].x = m;
	}
	sort(e + 1, e + cnt + 1, cmp2);
	rep(i, 1, n) ins(e[(i<<1)-1].x, e[i<<1].x, e[i<<1].i);
	rep(i, 1, m)
	if(in[i] & 1) {
		if(!la) la = i; else {
			ins(la, i, 0);
			la = 0;
		}
	}

	rep(i, 1, m) dfs(i);
	rep(i, 1, tot) {
		x = path[i];
		ans[_e[x].i] = _e[x].o;
	}
	rep(i, 1, n) printf("%d ", ans[i]); puts("");
	return 0;
}


#include<cstdio>
#include<algorithm>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define N 100010

using namespace std;

int n, m;
struct E{int x, o, i;} e[N<<1]; int cnt;
struct _E{int ed, o, i, ne;} _e[N<<3]; int in[N<<1], he[N<<1], en = 1; bool vis[N<<3];
int path[N<<2], tot;
int ans[N];

bool cmp1(E a, E b) {
	return a.x < b.x;
}

bool cmp2(E a, E b) {
	return a.i == b.i? a.o < b.o: a.i < b.i;
}

void ins(int a, int b, int i) {
	//printf("%d %d %d\n", a, b, i);
	++in[a]; ++in[b];
	_e[++en].ed = b; _e[en].o = 0; _e[en].i = i; _e[en].ne = he[a]; he[a] = en;
	_e[++en].ed = a; _e[en].o = 1; _e[en].i = i; _e[en].ne = he[b]; he[b] = en;
}

void dfs(int u) {
	for(int &i = he[u]; i; i = _e[i].ne)
	if(!vis[i]) {
		vis[i] = vis[i^1] = 1;
		int j = i;
		//printf("%d %d %d %d\n", u, _e[j].ed, _e[j].i, _e[j].o);
		dfs(_e[i].ed);
		path[++tot] = j;
	}
}

int main() {
	int i, x, la;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d", &x); e[++cnt] = (E){x, 0, i};
		scanf("%d", &x); e[++cnt] = (E){x+1, 1, i};
	}
	sort(e + 1, e + cnt + 1, cmp1);
	rep(i, 1, cnt) {
		if(i == 1 || e[i].x != la) {++m; la = e[i].x;}
		e[i].x = m;
	}
	sort(e + 1, e + cnt + 1, cmp2);
	rep(i, 1, n) ins(e[(i<<1)-1].x, e[i<<1].x, e[i<<1].i);
	la = 0;
	rep(i, 1, m)
	if(in[i] & 1) {
		if(!la) la = i; else {
			ins(la, i, 0);
			la = 0;
		}
	}
	//rep(i, 2, en) printf("%d %d %d\n", _e[i].ed, _e[i].o, _e[i].i);

	rep(i, 1, m) dfs(i);
	rep(i, 1, tot) {
		x = path[i];
		//printf("%d %d\n", _e[x].i, _e[x].o);
		ans[_e[x].i] = _e[x].o;
	}// puts("");
	rep(i, 1, n) printf("%d ", ans[i]); puts("");
	return 0;
}


#include<cstdio>
#include<algorithm>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define N 100010

using namespace std;

int n, m;
struct E{int x, o, i;} e[N<<1]; int cnt;
struct _E{int ed, o, i, ne;} _e[N<<3]; int in[N<<1], he[N<<1], en = 1; bool vis[N<<3];
int path[N<<2], tot;
int ans[N];

bool cmp1(E a, E b) {
	return a.x < b.x;
}

bool cmp2(E a, E b) {
	return a.i == b.i? a.o < b.o: a.i < b.i;
}

void ins(int a, int b, int i) {
	//printf("%d %d %d\n", a, b, i);
	++in[a]; ++in[b];
	_e[++en].ed = b; _e[en].o = 0; _e[en].i = i; _e[en].ne = he[b]; he[a] = en;
	_e[++en].ed = a; _e[en].o = 1; _e[en].i = i; _e[en].ne = he[a]; he[b] = en;
}

void dfs(int u) {
	for(int &i = he[u]; i; i = _e[i].ne)
	if(!vis[i]) {
		vis[i] = vis[i^1] = 1;
		int j = i;
		dfs(_e[i].ed);
		path[++tot] = j;
	}
}

int main() {
	int i, x, la;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d", &x); e[++cnt] = (E){x, 0, i};
		scanf("%d", &x); e[++cnt] = (E){x+1, 1, i};
	}
	sort(e + 1, e + cnt + 1, cmp1);
	rep(i, 1, cnt) {
		if(i == 1 || e[i].x != la) {++m; la = e[i].x;}
		e[i].x = m;
	}
	sort(e + 1, e + cnt + 1, cmp2);
	rep(i, 1, n) ins(e[(i<<1)-1].x, e[i<<1].x, e[i<<1].i);
	//rep(i, 2, en) printf("%d %d %d\n", _e[i].ed, _e[i].o, _e[i].i);
	la = 0;
	rep(i, 1, m)
	if(in[i] & 1) {
		if(!la) la = i; else {
			ins(la, i, 0);
			la = 0;
		}
	}

	rep(i, 1, m) dfs(i);
	rep(i, 1, tot) {
		x = path[i];
		//printf("%d %d\n", _e[x].i, _e[x].o);
		ans[_e[x].i] = _e[x].o;
	}// puts("");
	rep(i, 1, n) printf("%d ", ans[i]); puts("");
	return 0;
}


#include<cstdio>
#include<algorithm>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define N 100010

using namespace std;

int n, m;
struct E{int x, o, i;} e[N<<1]; int cnt;
struct _E{int ed, o, i, ne;} _e[N<<3]; int in[N<<1], he[N<<1], en; bool vis[N<<3];
int path[N<<2], tot;
int ans[N];

bool cmp1(E a, E b) {
	return a.x < b.x;
}

bool cmp2(E a, E b) {
	return a.i == b.i? a.o < b.o: a.i < b.i;
}

void ins(int a, int b, int i) {
	//printf("%d %d %d\n", a, b, i);
	++in[a]; ++in[b];
	_e[++en].ed = b; _e[en].o = 0; _e[en].i = i; _e[en].ne = he[b]; he[b] = en;
	_e[++en].ed = b; _e[en].o = 1; _e[en].i = i; _e[en].ne = he[a]; he[a] = en;
}

void dfs(int u) {
	for(int &i = he[u]; i; i = _e[i].ne)
	if(!vis[i]) {
		vis[i] = vis[i^1] = 1;
		int j = _e[i].i;
		dfs(_e[i].ed);
		path[++tot] = i;
	}
}

int main() {
	int i, x, la = 0;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d", &x); e[++cnt] = (E){x, 0, i};
		scanf("%d", &x); e[++cnt] = (E){x+1, 1, i};
	}
	sort(e + 1, e + cnt + 1, cmp1);
	rep(i, 1, cnt) {
		if(i == 1 || e[i].x != e[i-1].x) ++m;
		e[i].x = m;
	}
	sort(e + 1, e + cnt + 1, cmp2);
	//rep(i, 1, cnt) printf("%d %d %d\n", e[i].x, e[i].o, e[i].i);
	rep(i, 1, n) ins(e[(i<<1)-1].x, e[i<<1].x, e[i<<1].i);
	rep(i, 1, m)
	if(in[i] & 1) {
		if(!la) la = i; else {
			ins(la, i, 0);
			la = 0;
		}
	}

	rep(i, 1, m) dfs(i);
	rep(i, 1, tot) {
		x = path[i];
		ans[_e[x].i] = _e[x].o;
	}
	rep(i, 1, n) printf("%d ", ans[i]); puts("");
	return 0;
}


#include<cstdio>
#include<algorithm>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define N 100010

using namespace std;

int n, m;
struct E{int x, o, i;} e[N<<1]; int cnt;
struct _E{int ed, o, i, ne;} _e[N<<3]; int in[N<<1], he[N<<1], en; bool vis[N<<3];
int path[N<<2], tot;
int ans[N];

bool cmp1(E a, E b) {
	return a.x < b.x;
}

bool cmp2(E a, E b) {
	return a.i == b.i? a.o < b.o: a.i < b.i;
}

void ins(int a, int b, int i) {
	//printf("%d %d %d\n", a, b, i);
	++in[a]; ++in[b];
	_e[++en].ed = b; _e[en].o = 0; _e[en].i = i; _e[en].ne = he[b]; he[b] = en;
	_e[++en].ed = b; _e[en].o = 1; _e[en].i = i; _e[en].ne = he[a]; he[a] = en;
}

void dfs(int u) {
	for(int &i = he[u]; i; i = _e[i].ne)
	if(!vis[i]) {
		vis[i] = vis[i^1] = 1;
		int j = _e[i].i;
		dfs(_e[i].ed);
		path[++tot] = i;
	}
}

int main() {
	int i, x, la;
	scanf("%d", &n);
	rep(i, 1, n) {
		scanf("%d", &x); e[++cnt] = (E){x, 0, i};
		scanf("%d", &x); e[++cnt] = (E){x+1, 1, i};
	}
	sort(e + 1, e + cnt + 1, cmp1);
	rep(i, 1, cnt) {
		if(i == 1 || e[i].x != la) {++m; la = e[i].x;}
		e[i].x = m;
	}
	sort(e + 1, e + cnt + 1, cmp2);
	//rep(i, 1, cnt) printf("%d %d %d\n", e[i].x, e[i].o, e[i].i);
	rep(i, 1, n) ins(e[(i<<1)-1].x, e[i<<1].x, e[i<<1].i);
	la = 0;
	rep(i, 1, m)
	if(in[i] & 1) {
		if(!la) la = i; else {
			ins(la, i, 0);
			la = 0;
		}
	}

	rep(i, 1, m) dfs(i);
	rep(i, 1, tot) {
		x = path[i];
		ans[_e[x].i] = _e[x].o;
	}
	rep(i, 1, n) printf("%d ", ans[i]); puts("");
	return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
vector <int> G[200005];
pair <int,int> p[200005];
void init()
{
    int l,r;
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&l,&r);
        p[i*2]=make_pair(l*2,i*2);
        p[i*2+1]=make_pair(r*2+1,i*2+1);
        G[i*2].push_back(i*2+1);
        G[i*2+1].push_back(i*2);
    }
    sort(p,p+2*n);
    for (int i = 0; i < 2*n-1; ++i)
    {
        int x = p[i].second, y = p[i+1].second;
        G[x].push_back(y), G[y].push_back(x);
    }
}
int col[100005];
void dfs(int u,int c)
{
    if(col[u]!=-1) return;
    col[u]=c;
    int m=G[u].size();
    for(int i=0;i<m;i++)
    {
        dfs(G[u][i],c^1);
    }
}
void compute()
{
    memset(col, -1, sizeof(col));
    for(int i=0;i<n;i++)
    {
        dfs(i<<1,0);
        printf("%d ",col[i<<1]);
    }
    cout<<endl;
}
int main()
{
    cin>>n;
    init();
    compute();
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
vector <int> G[200005];
pair <int,int> p[200005];
void init()
{
    int l,r;
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&l,&r);
        p[i*2]=make_pair(l*2,i*2);
        p[i*2+1]=make_pair(r*2+1,i*2+1);
        G[i*2].push_back(i*2+1);
        G[i*2+1].push_back(i*2);
    }
    sort(p,p+2*n);
    for (int i = 0; i < n; ++i){
        int x = p[i<<1].second, y = p[i<<1|1].second;
        G[x].push_back(y), G[y].push_back(x);
    }
}
int col[200005];
void dfs(int u,int c)
{
    if(col[u]!=-1) return;
    col[u]=c;
    int m=G[u].size();
    for(int i=0;i<m;i++)
    {
        dfs(G[u][i],c^1);
    }
}
void compute()
{
    memset(col, -1, sizeof(col));
    for(int i=0;i<n;++i)
    {
        dfs(i<<1,0);
        printf("%d ",col[i<<1]);
    }
    cout<<endl;
}
int main()
{
    cin>>n;
    init();
    compute();
    return 0;
}


/*
  * Author:  Yzcstc
  * Created Time:  2014/10/30 19:12:23
  * File Name: cf429.cpp
  */
 #include<cstdio>
 #include<iostream>
 #include<cstring>
 #include<cstdlib>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<map>
 #include<set>
 #include<vector>
 #include<queue>
 #include<stack>
 #include<ctime>
 using namespace std;
 vector<int> e[210000];
 int col[210000], n;
 pair<int, int> p[210000];
 void dfs(int u, int color){
      if (col[u] != -1) return;
      col[u] = color;
      for (int i = 0; i < (int)e[u].size(); ++i)
           dfs(e[u][i], color^1);
 }

 void solve(){
      for (int i = 0; i <= n * 2; ++i) e[i].clear();
      int l, r;
      for (int i = 0; i < n; ++i){
           scanf("%d%d", &l, &r);
           e[i<<1].push_back(i<<1|1), e[i<<1|1].push_back(i<<1);
           p[i<<1] = make_pair(l<<1,i<<1), p[i<<1|1] = make_pair(r<<1|1, i<<1|1);
      }
      sort(p, p + 2*n);
      for (int i = 0; i < n; ++i){
           int x = p[i<<1].second, y = p[i<<1|1].second;
           e[x].push_back(y), e[y].push_back(x);
      }
      memset(col, -1, sizeof(col));
      for (int i = 0; i < n; ++i){
          if (col[i<<1] == -1) dfs(i<<1, 0);
          printf("%d ", col[i<<1]);
      }
 }

 int main(){
 //    freopen("a.in", "r", stdin);
 //    freopen("a.out", "w", stdout);
     while (scanf("%d", &n) != EOF){
         solve();
     }
     return 0;
 }


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
vector <int> G[100005];
pair <int,int> p[200005];
void init()
{
    int l,r;
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&l,&r);
        p[i*2]=make_pair(l*2,i*2);
        p[i*2+1]=make_pair(r*2+1,i*2+1);
        G[i*2].push_back(i*2+1);
        G[i*2+1].push_back(i*2);
    }
    sort(p,p+2*n);
    for (int i = 0; i < n; ++i)
    {
        int x = p[i<<1].second, y = p[i<<1|1].second;
        G[x].push_back(y), G[y].push_back(x);
    }
}
int col[100005];
void dfs(int u,int c)
{
    if(col[u]!=-1) return;
    col[u]=c;
    int m=G[u].size();
    for(int i=0;i<m;i++)
    {
        dfs(G[u][i],c^1);
    }
}
void compute()
{
    memset(col, -1, sizeof(col));
    for(int i=0;i<n;i++)
    {
        dfs(i<<1,0);
        printf("%d ",col[i]);
    }
    cout<<endl;
}
int main()
{
    cin>>n;
    init();
    compute();
    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
vector <int> G[100005];
pair <int,int> p[200005];
void init()
{
    int l,r;
    for(int i=0; i<n; i++)
    {
        scanf("%d %d",&l,&r);
        p[i*2]=make_pair(l*2,i*2);
        p[i*2+1]=make_pair(r*2+1,i*2+1);
        G[i*2].push_back(i*2+1);
        G[i*2+1].push_back(i*2);
    }
    sort(p,p+2*n);
    for (int i = 0; i < n; ++i)
    {
        int x = p[i<<1].second, y = p[i<<1|1].second;
        G[x].push_back(y), G[y].push_back(x);
    }
}
int col[100005];
void dfs(int u,int c)
{
    if(col[u]!=-1) return;
    col[u]=c;
    int m=G[u].size();
    for(int i=0;i<m;i++)
    {
        dfs(G[u][i],c^1);
    }
}
void compute()
{
    memset(col, -1, sizeof(col));
    for(int i=0;i<n;i++)
    {
        dfs(i<<1,0);
        printf("%d ",col[i<<1]);
    }
    cout<<endl;
}
int main()
{
    cin>>n;
    init();
    compute();
    return 0;
}