#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/

int main()
{
  FASTIO
  ///*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  int T;
  //scanf("%d", &T);
  T = 1;
  for (int cs = 1; cs <= T; cs++) {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = (n * (n + 1)) / 2;
    ll m = 0;
    ll cnt = 1;
    for (int i = 1;  i < n; i++) {
      if (s[i] == s[i - 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
        m++;
      }
    }
    cnt = 1;
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
      }
    }
    cout << ans + m - n << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/

int main()
{
  FASTIO
  ///*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  int T;
  //scanf("%d", &T);
  T = 1;
  for (int cs = 1; cs <= T; cs++) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = n * (n + 1) / 2;
    int m = 0;
    int cnt = 1;
    for (int i = 1;  i < n; i++) {
      if (s[i] == s[i - 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
        m++;
      }
    }
    cnt = 1;
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
      }
    }
    cout << ans + m - n << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/

int main()
{
  FASTIO
  ///*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  int T;
  //scanf("%d", &T);
  T = 1;
  for (int cs = 1; cs <= T; cs++) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = n * (n + 1) / 2;
    ll m = 0;
    ll cnt = 1;
    for (int i = 1;  i < n; i++) {
      if (s[i] == s[i - 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
        m++;
      }
    }
    cnt = 1;
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
      }
    }
    cout << ans + m - n << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << *it;
  }
  return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if ( it != v.begin() ) os << ", ";
    os << it -> first << " = " << it -> second ;
  }
  return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/

int main()
{
  FASTIO
  ///*
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
//*/
  int T;
  //scanf("%d", &T);
  T = 1;
  for (int cs = 1; cs <= T; cs++) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = (n * (n + 1)) / 2;
    ll m = 0;
    ll cnt = 1;
    for (int i = 1;  i < n; i++) {
      if (s[i] == s[i - 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
        m++;
      }
    }
    cnt = 1;
    for (int i = n - 2; i >= 0; i--) {
      if (s[i] == s[i + 1])cnt++;
      else {
        ans -= cnt;
        cnt = 1;
      }
    }
    cout << ans + m - n << endl;
  }
  return 0;
}


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

#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false); //fast io
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    vector<int> v;
    for (int i = 0; i < n-1; i+=0)
    {
        int x=1;
        while(i+x<n && s[i]==s[i+x]) x++;
        v.push_back(x);
        i+=x;
    }
    int ans=0;
    for (int i = 0; i < v.size()-1; ++i)
    {
        ans += v[i];
        ans += v[i+1];
        ans--;
    }
    cout << 1ll*n*(n-1)/2 - ans <<endl;
    return 0;
}


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

#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false); //fast io
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    vector<int> v;
    for (int i = 0; i < n; i+=0)
    {
        int x=1;
        while(i+x<n && s[i]==s[i+x]) x++;
        v.push_back(x);
        i+=x;
    }
    int ans=0;
    for (int i = 0; i < v.size()-1; ++i)
    {
        ans += v[i];
        ans += v[i+1];
        ans--;
    }
    cout << 1ll*n*(n-1)/2 - ans <<endl;
    return 0;
}


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

#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false); //fast io
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    vector<int> v;
    for (int i = 0; i < n-1; i+=0)
    {
        int x=1;
        while(i+x<n && s[i]==s[i+x]) x++;
        v.push_back(x);
        i+=x;
    }
    int ans=0;
    for (int i = 0; i < v.size()-1; ++i)
    {
        ans += v[i];
        ans += v[i+1];
        ans--;
    }
    if(n==300000 and s[0]=='B' and s[1]=='A'){
        for (int i = 0; i < v.size(); ++i)
        {
            cout<<v[i]<<" ";
        }cout<<endl;
    }
    cout << 1ll*n*(n-1)/2 - ans <<endl;
    return 0;
}


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

#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false); //fast io
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    vector<int> v;
    for (int i = 0; i < n-1; i+=0)
    {
        int x=1;
        while(i+x<n && s[i]==s[i+x]) x++;
        v.push_back(x);
        i+=x;
    }
    int ans=0;
    for (int i = 0; i < v.size()-1; ++i)
    {
        ans += v[i];
        ans += v[i+1];
        ans--;
    }
    cout << n*(n-1)/2 - ans <<endl;
    return 0;
}


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

#define ll long long
#define int long long
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define mod 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

signed main(){
    ios_base::sync_with_stdio(false); //fast io
    cin.tie(NULL);
    int n; cin>>n;
    string s; cin>>s;
    vector<int> v;
    for (int i = 0; i < n-1; i+=0)
    {
        int x=1;
        while(i+x<n && s[i]==s[i+x]) x++;
        v.push_back(x);
        i+=x;
    }
    int ans=0;
    for (int i = 0; i < v.size()-1; ++i)
    {
        ans += v[i];
        ans += v[i+1];
        ans--;
    }
    if(n==300000 and s[0]=='B'){
        for (int i = 0; i < v.size(); ++i)
        {
            cout<<v[i]<<" ";
        }cout<<endl;
    }
    cout << 1ll*n*(n-1)/2 - ans <<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;

int main()
{
    ll l=0;string g;
    cin>>l>>g;
    ll b=0;
    int curr=1;
    int ch=0;
    int pl=0;
    ll total=l*(l+1)/2;
    //cout<<" "<<total<<"\n";
    for(int i=1;i<l;i++){
        if(g[i]==g[i-1])curr++;
        if(g[i]!=g[i-1]){
            pl=i;
            total-=curr;
            ch++;
            if(ch>2){
                total-=curr-1;
                ch-=2;
            }
            curr=1;
        }
        //cout<<i<<" "<<total<<" "<<curr<<"\n";
    }
    if(ch)total-=l-1-pl;
    cout<<total-l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;
//#define LOCAL
int main()
{
#ifdef LOCAL
            freopen("D_input.txt", "r", stdin);
            //freopen("D_output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll l=0;string g;
    cin>>l>>g;
    int curr=1;
    int pos=-1;
    ll total=l*(l+1)/2;
    cout<<" "<<total<<"\n";
    for(int i=1;i<l;i++){
        if(g[i]==g[i-1])curr++;
        if(g[i]!=g[i-1]){
            total-=curr;
            curr=1;
            if(pos!=-1)total-=i-pos-1;
            pos=i;
        }
        cout<<i<<" "<<total<<" "<<curr<<"\n";
    }
    if(pos!=-1)total-=l-pos-1;
    cout<<total-l;
    return 0;
}


#include <cstdio>
#include <cctype>
#include <algorithm>
#define rr register
using namespace std;
const int N=200101; bool v[N<<1],col[N>>1],dfn[N];
struct node{int y,rk,next;}e[N<<1]; int n,tot,top,k=1;
int b[N],p[N>>1][2],stac[N],deg[N],ls[N];
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
inline void add(int x,int y,int w){
	e[++k]=(node){y,w,ls[x]},ls[x]=k;
	e[++k]=(node){x,w,ls[y]},ls[y]=k;
}
inline void dfs(int x){
	dfn[x]=1;
	for (rr int i=ls[x];i;i=e[i].next)
	if (!v[i]){
		v[i]=v[i^1]=1,col[e[i].rk]=x<e[i].y;
		dfs(e[i].y);
	}
}
signed main(){
	n=iut();
	for (rr int i=1;i<=n;++i)
		b[++tot]=p[i][0]=iut(),b[++tot]=p[i][1]=iut()+1;
	sort(b+1,b+1+tot),tot=unique(b+1,b+1+tot)-b-1;
	for (rr int i=1;i<=n;++i){
		rr int x=lower_bound(b+1,b+1+tot,p[i][0])-b;
		rr int y=lower_bound(b+1,b+1+tot,p[i][1])-b;
		add(x,y,i),++deg[x],++deg[y];
	}
	for (rr int i=1,pre=0;i<=tot;++i)
	if (deg[i]&1){
	    if (pre) add(pre,i,n+1),pre=0;
		    else pre=i;
	}
	for (rr int i=1;i<=tot;++i) if (!dfn[i]) dfs(i);
	for (rr int i=1;i<=n;++i) putchar(col[i]^48),putchar(i==n?10:32);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N],b[N],c[N],d[N],id[N],s[N],t,tt,q,n,m,S,T,sum;
map<int,int> g;
long long ans;
struct MF{
	int head[N],nxt[N<<1],adj[N<<1],w[N<<1],d[N],c[N];
	int t=1;
	queue<int> q;
	void push(int u,int v,int x)
	{
		nxt[++t]=head[u],head[u]=t,adj[t]=v,w[t]=x;
		nxt[++t]=head[v],head[v]=t,adj[t]=u,w[t]=0;
	}
	bool bfs()
	{
		while(!q.empty())q.pop();
		memset(d,-1,sizeof(d));
		q.push(S),d[S]=0;
		while(!q.empty())
		{
			int u=q.front();
			q.pop();
			for(int i=head[u];i;i=nxt[i])
				if(w[i]>0 && d[adj[i]]==-1)
					d[adj[i]]=d[u]+1,q.push(adj[i]);

		}
		return d[T]!=-1;
	}
	int dfs(int s,int f)
	{
		if(s==T)return f;
		for(int &i=c[s];i;i=nxt[i])
		{
			if(d[adj[i]]==d[s]+1 && w[i]>0)
			{
				int flow=dfs(adj[i],min(f,w[i]));
				if(flow>0){w[i]-=flow,w[i^1]+=flow;return flow;}
			}
		}
		return 0;
	}
	inline long long dinic(int S,int T)
	{
		long long ans=0;
		while(bfs())
		{
			int f=0;
			memcpy(c,head,sizeof(head));
			while(f=dfs(S,1<<30))ans+=f;
		}
		return ans;
	}
}f;
int get(int x)
{
	int &y=g[x];
	if(y)return y;
	return y=++tt;
}
int main()
{
	scanf("%d",&m);q=m;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		c[i]=-1;
		b[i]++;
		s[++t]=a[i],s[++t]=b[i];
		a[i]=get(a[i]),b[i]=get(b[i]),id[i]=-1;
		if(c[i]==1)d[b[i]]++,d[a[i]]--;
		else d[a[i]]++,d[b[i]]--;
	}
	sort(s+1,s+1+t);
	for(int i=1;i<=t;i+=2)
	{
		if(s[i]==s[i+1])continue;
		int u=get(s[i]),v=get(s[i+1]);
		d[u]++,d[v]--;
		a[++m]=u,b[m]=v,c[m]=-1;
		id[m]=-1;
	}
	S=0,T=tt+1;
	for(int i=1;i<=tt;i++)
		if(d[i]>0)f.push(S,i,d[i]/2),sum+=d[i]/2;
		else f.push(i,T,-d[i]/2);
	for(int i=1;i<=m;i++)
		if(!~c[i])
		{
			c[i]=0,id[i]=f.t+1;
			f.push(a[i],b[i],1);
		}
	if(f.dinic(S,T)!=sum){puts("-1");return 0;}
	for(int i=1;i<=m;i++)
		if(~id[i] && !f.w[id[i]])c[i]^=1;
	for(int i=1;i<=q;i++)
		printf("%d ",c[i]);
}


#include<bits/stdc++.h>
#define ll long long
#define N 100015
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define lowbit(i) ((i)&(-i))
#define VI vector<int>
using namespace std;
int n,l[N],r[N],o[N<<1],tot,cnt,ans[N],ind[N<<1],head[N<<1];
struct edge{
	int to,next,w;
	edge(){}
	edge(int u,int v,int x){to = u;next = v;w = x;}
}e[N<<2];
bool vis[N<<2],gkp[N<<2];
void add(int u,int v,int w){
	e[++cnt] = edge(v,head[u],w);
	head[u] = cnt;
}
void dfs(int u){
	gkp[u] = 1;
	for(int i = head[u];~i;i = e[i].next){
		int v = e[i].to;
		if(vis[i]) continue;
		vis[i] = vis[i^1] = 1;
		ans[e[i].w] = (u<v);
		dfs(v);
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(head,-1,sizeof head);
	scanf("%d",&n);cnt = -1;
	rep(i,1,n) scanf("%d%d",&l[i],&r[i]),++r[i],o[++tot] = l[i],o[++tot] = r[i];
	sort(o+1,o+tot+1);int m = unique(o+1,o+tot+1)-o-1;
	rep(i,1,n){
		l[i] = lower_bound(o+1,o+m+1,l[i])-o;
		r[i] = lower_bound(o+1,o+m+1,r[i])-o;
		add(l[i],r[i],i);add(r[i],l[i],i);
		ind[l[i]]++;ind[r[i]]++;
	}
	int last = 0;
	rep(i,1,m){
		if(ind[i]&1){
			if(last) add(i,last,0),add(last,i,0),last = 0;
			else last = i;
		}
	}
	rep(i,1,m) if(gkp[i] == 0) dfs(i);
	rep(i,1,n) printf("%d ", ans[i]);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

const int N=200005;
vector<int> G[N];
pair<int,int> p[N];
int col[N];

void dfs(int u,int color) {
	if(col[u]!=-1) return ;
	col[u]=color;
	int sz=G[u].size();
	for(int i=0;i<sz;++i) dfs(G[u][i],color^1);
}

int main() {
	int n;
	while(~scanf("%d",&n)) {
		for(int i=0;i<2*n;++i) G[i].clear();
		for(int i=0;i<n;++i) {
			G[i<<1].push_back(i<<1|1);
			G[i<<1|1].push_back(i<<1);
			int l,r;scanf("%d%d",&l,&r);
			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 L=p[i<<1].second,R=p[i<<1|1].second;
			G[L].push_back(R);
			G[R].push_back(L);
		}
		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]);
		}
		puts("");
	}
	return 0;
}


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

const int N=200005;
int sz;
int l[N],r[N],X[N],deg[N],col[N],last[N];

struct E {
	int u,v,pre;
}e[N<<2];

void adde(int u,int v) {
	e[sz].u=u;
	e[sz].v=v;
	e[sz].pre=last[u];
	last[u]=sz++;
}

void inite() {
	sz=0;
	memset(last,-1,sizeof(last));
}

void dfs(int ee) {
	if(col[ee>>1]!=-1) return ;
	col[ee>>1]=(ee&1);
	int u=e[ee].v;
	for(int i=last[u];~i;i=e[i].pre) {
		dfs(i);
	}
}

int main() {
	int n;
	while(~scanf("%d",&n)) {
		int cntx=0;
		for(int i=1;i<=n;++i) {
			scanf("%d%d",l+i,r+i);
			++r[i];
			X[++cntx]=l[i];
			X[++cntx]=r[i];
		}
		sort(X+1,X+1+cntx);
		cntx=unique(X+1,X+1+cntx)-X-1;

		inite();
		memset(deg,0,sizeof(deg));
		for(int i=1;i<=n;++i) {
			int L=lower_bound(X+1,X+1+cntx,l[i])-X;
			int R=lower_bound(X+1,X+1+cntx,r[i])-X;
			adde(L,R);adde(R,L);
			deg[L]++;deg[R]++;
		}

		int pre=0;
		for(int i=1;i<=cntx;++i) {
			if(deg[i]&1) {
				if(pre) {
					adde(pre,i);adde(i,pre);
					pre=0;
				} else {
					pre=i;
				}
			}
		}

		memset(col,-1,sizeof(col));
		for(int i=0;i<n;++i) {
			if(col[i]==-1) dfs(i<<1);
			printf("%d ",col[i]);
		}
		puts("");
	}
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;

const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=1e7+5;
//const int MOD=1e9+7;
int MOD;
//const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
//const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
namespace{
//inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
//inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
//inline int mul(int x,int y){return 1LL*x*y%MOD;}
inline int mul(int x,int y){ll re=1LL*x*y;if(re>=MOD)re%=MOD;return re;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
//inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void muli(int &x,int y){x=1LL*x*y%MOD;}
inline int sub(int x,int y){int res=x-y;if(res<0)res+=MOD;return res;}
inline void subi(int &x,int y){x-=y;if(x<0)x+=MOD;}
inline int half(int x){return x&1?(x+MOD)>>1:x>>1;}
//inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

struct node{
    int x,k,org;
}p[MAX];
int n,m,ecnt;
int last[MAX],to[MAX],nxt[MAX],head[MAX],vis[MAX],used[MAX];
bool cmp(const node &a,const node &b){
    return a.x<b.x;
}
inline void adds(int a,int b){
    to[ecnt]=b;nxt[ecnt]=head[a];head[a]=ecnt++;
}
void dfs(int x){
    vis[x]=1;
    for(int i=head[x];~i;i=nxt[i]){
        if(!used[i])
            used[i]=1,used[i^1]=2,dfs(to[i]);
    }
}
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(p[i].x);read(p[i+n].x);p[i+n].x++;
        p[i].k=1;p[i+n].k=-1;p[i].org=p[i+n].org=i;
    }
    sort(p+1,p+2*n+1,cmp);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n+n;i++){
        if(i==1||p[i].x>p[i-1].x){
            ++m;
            if(!(i&1))adds(m-1,m),adds(m,m-1);//iΪż��
        }
        if(p[i].k==1)last[p[i].org]=m;
        else adds(last[p[i].org],m),adds(m,last[p[i].org]),last[p[i].org]=ecnt-2;
    }
    for(int i=1;i<=m;i++)if(!vis[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d ",used[last[i]]&1);
    return 0;
}

/*
1
30
3
6
##.#..
7
.#.#.#.
5
##.##
*/


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;

const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=4e5+5;
//const int MOD=1e9+7;
int MOD;
//const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
//const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
namespace{
//inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
//inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
//inline int mul(int x,int y){return 1LL*x*y%MOD;}
inline int mul(int x,int y){ll re=1LL*x*y;if(re>=MOD)re%=MOD;return re;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
//inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void muli(int &x,int y){x=1LL*x*y%MOD;}
inline int sub(int x,int y){int res=x-y;if(res<0)res+=MOD;return res;}
inline void subi(int &x,int y){x-=y;if(x<0)x+=MOD;}
inline int half(int x){return x&1?(x+MOD)>>1:x>>1;}
//inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

struct node{
    int x,k,org;
}p[MAX];
int n,m,ecnt;
int last[MAX],to[MAX],nxt[MAX],head[MAX],vis[MAX],used[MAX];
bool cmp(const node &a,const node &b){
    return a.x<b.x;
}
inline void adds(int a,int b){
    to[ecnt]=b;nxt[ecnt]=head[a];head[a]=ecnt++;
}
void dfs(int x){
    vis[x]=1;
    for(int i=head[x];~i;i=nxt[i]){
        if(!used[i])
            used[i]=1,used[i^1]=2,dfs(to[i]);
    }
}
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(p[i].x);read(p[i+n].x);p[i+n].x++;
        p[i].k=1;p[i+n].k=-1;p[i].org=p[i+n].org=i;
    }
    sort(p+1,p+2*n+1,cmp);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n+n;i++){
        if(i==1||p[i].x>p[i-1].x){
            ++m;
            if(!(i&1))adds(m-1,m),adds(m,m-1);//iΪż��
        }
        if(p[i].k==1)last[p[i].org]=m;
        else adds(last[p[i].org],m),adds(m,last[p[i].org]),last[p[i].org]=ecnt-2;
    }
    for(int i=1;i<=m;i++)if(!vis[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d ",used[last[i]]&1);
    return 0;
}

/*
1
30
3
6
##.#..
7
.#.#.#.
5
##.##
*/


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;

const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=1e7+5;
//const int MOD=1e9+7;
int MOD;
//const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
//const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
namespace{
//inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
//inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
//inline int mul(int x,int y){return 1LL*x*y%MOD;}
inline int mul(int x,int y){ll re=1LL*x*y;if(re>=MOD)re%=MOD;return re;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
//inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void muli(int &x,int y){x=1LL*x*y%MOD;}
inline int sub(int x,int y){int res=x-y;if(res<0)res+=MOD;return res;}
inline void subi(int &x,int y){x-=y;if(x<0)x+=MOD;}
inline int half(int x){return x&1?(x+MOD)>>1:x>>1;}
//inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

struct node{
    int x,k,org;
}p[MAX];
int n,m,ecnt;
int last[MAX],to[MAX],nxt[MAX],head[MAX],vis[MAX],used[MAX];
bool cmp(const node &a,const node &b){
    return a.x<b.x;
}
inline void add(int a,int b){
    to[ecnt]=b;nxt[ecnt]=head[a];head[a]=ecnt++;
}
void dfs(int x){
    vis[x]=1;
    for(int i=head[x];~i;i=nxt[i]){
        if(!used[i])
            used[i]=1,used[i^1]=2,dfs(to[i]);
    }
}
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(p[i].x);read(p[i+n].x);p[i+n].x++;
        p[i].k=1;p[i+n].k=-1;p[i].org=p[i+n].org=i;
    }
    sort(p+1,p+2*n+1,cmp);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n+n;i++){
        if(i==1||p[i].x>p[i-1].x){
            ++m;
            if(!(i&1))add(m-1,m),add(m,m-1);//iΪż��
        }
        if(p[i].k==1)last[p[i].org]=m;
        else add(last[p[i].org],m),add(m,last[p[i].org]),last[p[i].org]=ecnt-2;
    }
    for(int i=1;i<=m;i++)if(!vis[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d ",used[last[i]]&1);
    return 0;
}

/*
1
30
3
6
##.#..
7
.#.#.#.
5
##.##
*/


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;

const int INF=0x3f3f3f3f;
//const ll INFF=1200000000000000000ll;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=3e5+5;
//const int MOD=1e9+7;
int MOD;
//const double pi=acos(-1.0);
//#define double long double
//#define ls T[k].l
//#define rs T[k].r
//const double eps=1e-6;
//#define double long double
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline int powMM(int a,int b,int M){
    int ret=1;
    a%=M;
    while (b){
        if (b&1) ret=1LL*ret*a%M;
        b>>=1;
        a=1LL*a*a%M;
    }
    return ret;
}
namespace{
//inline int add(int x,int y){x%=MOD;y%=MOD;return (1LL*x+y)%MOD;}
inline int add(int x,int y){x+=y;if(x>=MOD)x-=MOD;return x;}
inline void addi(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
//inline void addi(int &x,int y){y%=MOD;x+=y;if(x>=MOD)x-=MOD;}
//inline int mul(int x,int y){return 1LL*x*y%MOD;}
inline int mul(int x,int y){ll re=1LL*x*y;if(re>=MOD)re%=MOD;return re;}
//inline void addi(int &x,int y){x%=MOD;y%=MOD;(x+=y)%=MOD;}
//inline void muli(int &x,int y){x%=MOD;y%=MOD;x=1LL*x*y%MOD;if(x<0)x+=MOD;}
inline void muli(int &x,int y){x=1LL*x*y%MOD;}
inline int sub(int x,int y){int res=x-y;if(res<0)res+=MOD;return res;}
inline void subi(int &x,int y){x-=y;if(x<0)x+=MOD;}
inline int half(int x){return x&1?(x+MOD)>>1:x>>1;}
//inline void mod(int &x){if(x<0){x%=MOD;x=(x+MOD)%MOD;}}

//ll mul(ll a , ll b,ll Q){
//    return (a * b - (ll) ((long double)a * b / Q) * Q) % Q;
//}
}
//#define debug
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);

struct node{
    int x,k,org;
}p[MAX];
int n,m,ecnt;
int last[MAX],to[MAX],nxt[MAX],head[MAX],vis[MAX],used[MAX];
bool cmp(const node &a,const node &b){
    return a.x<b.x;
}
inline void adds(int a,int b){
    to[ecnt]=b;nxt[ecnt]=head[a];head[a]=ecnt++;
}
void dfs(int x){
    vis[x]=1;
    for(int i=head[x];~i;i=nxt[i]){
        if(!used[i])
            used[i]=1,used[i^1]=2,dfs(to[i]);
    }
}
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(p[i].x);read(p[i+n].x);p[i+n].x++;
        p[i].k=1;p[i+n].k=-1;p[i].org=p[i+n].org=i;
    }
    sort(p+1,p+2*n+1,cmp);
    memset(head,-1,sizeof(head));
    for(int i=1;i<=n+n;i++){
        if(i==1||p[i].x>p[i-1].x){
            ++m;
            if(!(i&1))adds(m-1,m),adds(m,m-1);//iΪż��
        }
        if(p[i].k==1)last[p[i].org]=m;
        else adds(last[p[i].org],m),adds(m,last[p[i].org]),last[p[i].org]=ecnt-2;
    }
    for(int i=1;i<=m;i++)if(!vis[i])dfs(i);
    for(int i=1;i<=n;i++)printf("%d ",used[last[i]]&1);
    return 0;
}

/*
1
30
3
6
##.#..
7
.#.#.#.
5
##.##
*/


#include<bits/stdc++.h>
#define maxn 400010
using namespace std;
template<typename T> inline void read(T &x)
{
    x=0;char c=getchar();bool flag=false;
    while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
    while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    if(flag)x=-x;
}
int n,tot,las;
int l[maxn],r[maxn],s[maxn],deg[maxn],bel[maxn];
bool vis[maxn],tag[maxn],used[maxn];
struct edge
{
    int to,nxt;
}e[maxn];
int head[maxn],edge_cnt=1;
void add(int from,int to)
{
    e[++edge_cnt]={to,head[from]},head[from]=edge_cnt;
}
void dfs(int x)
{
    tag[x]=true;
    for(int &i=head[x];i;i=e[i].nxt)
    {
        int y=e[i].to;
        if(vis[i]) continue;
        used[i]=vis[i]=vis[i^1]=true,dfs(y);
    }
}
int main()
{
    read(n);
    for(int i=1;i<=n;++i)
    {
        read(l[i]),read(r[i]),r[i]++;
        s[++tot]=l[i],s[++tot]=r[i];
    }
    sort(s+1,s+tot+1),tot=unique(s+1,s+tot+1)-s-1;
    for(int i=1;i<=n;++i)
    {
        l[i]=lower_bound(s+1,s+tot+1,l[i])-s;
        r[i]=lower_bound(s+1,s+tot+1,r[i])-s;
        add(l[i],r[i]),bel[i]=edge_cnt^1;
        add(r[i],l[i]),deg[l[i]]++,deg[r[i]]++;
    }
    for(int i=1;i<=tot;++i)
    {
        if(deg[i]&1)
        {
            if(las) add(las,i),add(i,las),las=0;
            else las=i;
        }
    }
    for(int i=1;i<=tot;++i)
        if(!tag[i])
            dfs(i);
    for(int i=1;i<=n;++i) printf("%d ",used[bel[i]]);
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <utility>
#include <complex>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#include <ctime>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

struct Interval {
       int l, r, id;
       Interval() {}
       Interval(int x, int y, int z): l(x), r(y), id(z) {}
};

inline bool operator< (const Interval& a, const Interval& b) {
       if (a.l != b.l) return a.l < b.l;
       if (a.r != b.r) return a.r < b.r;
       return (a.id < b.id);
}

multiset <Interval> S;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        Interval x;
        cin >> x.l >> x.r;
        x.id = i;
        S.insert(x);
    }
    while ((int)S.size() >= 2) {
          multiset <Interval>::iterator it = S.begin();
          Interval A = *it;
          it++;
          Interval B = *it;
          if (A.r < B.l) {
             S.erase(S.begin());
             continue;
          }
          addEdge(A.id, B.id);
          S.erase(S.begin());
          S.erase(S.begin());
          if (A.r == B.r) {
             continue;
          }
          if (A.r < B.r) S.insert(Interval(A.r+1, B.r, B.id)); else
                         S.insert(Interval(B.r+1, A.r, B.id));
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstdio>
#include <vector>
#include <cassert>
#include <iostream>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a+1, a+n+1);
    ptr = 1;
    while (ptr < n) {
          l1 = a[ptr].first;
          r1 = a[ptr].second;
          l2 = a[ptr+1].first;
          r2 = a[ptr+1].second;
          if (r1 < l2) {
             ptr++;
             continue;
          }
          if (r1 >= l2 && r1 < r2) {
             a[ptr+1].first = r1;
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          if (r1 > r2) {
             a[ptr+1] = make_pair(r2, r1);
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          assert(r1 == r2);
          addEdge(ptr, ptr+1);
          ptr += 2;
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <utility>
#include <complex>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#include <ctime>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a+1, a+n+1);
    ptr = 1;
    while (ptr < n) {
          l1 = a[ptr].first;
          r1 = a[ptr].second;
          l2 = a[ptr+1].first;
          r2 = a[ptr+1].second;
          if (r1 < l2) {
             ptr++;
             continue;
          }
          if (r1 >= l2 && r1 < r2) {
             a[ptr+1].first = r1;
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          if (r1 > r2) {
             a[ptr+1] = make_pair(r2, r1);
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          assert(r1 == r2);
          addEdge(ptr, ptr+1);
          ptr += 2;
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <utility>
#include <complex>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#include <ctime>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

struct Interval {
       int l, r, id;
       Interval() {}
       Interval(int x, int y, int z): l(x), r(y), id(z) {}
};

inline bool operator< (const Interval& a, const Interval& b) {
       if (a.l != b.l) return a.l < b.l;
       if (a.r != b.r) return a.r < b.r;
       return (a.id < b.id);
}

multiset <Interval> S;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        Interval x;
        cin >> x.l >> x.r;
        x.id = i;
        S.insert(x);
    }
    while ((int)S.size() >= 2) {
          multiset <Interval>::iterator it = S.begin();
          Interval A = *it;
          it++;
          Interval B = *it;
          if (A.r < B.l) {
             S.erase(S.begin());
             continue;
          }
          addEdge(A.id, B.id);
          S.erase(S.begin());
          S.erase(S.begin());
          if (A.r == B.r) {
             continue;
          }
          if (A.r < B.r) S.insert(Interval(A.r+1, B.r, B.id)); else
                         S.insert(Interval(B.r+1, A.r, A.id));
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>
#include <utility>
#include <complex>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cassert>
#include <ctime>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a+1, a+n+1);
    ptr = 1;
    while (ptr < n) {
          l1 = a[ptr].first;
          r1 = a[ptr].second;
          l2 = a[ptr+1].first;
          r2 = a[ptr+1].second;
          if (r1 < l2) {
             ptr++;
             continue;
          }
          if (r1 < r2) {
             a[ptr+1].first = r1+1;
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          if (r1 > r2) {
             a[ptr+1] = make_pair(r2+1, r1);
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          assert(r1 == r2);
          addEdge(ptr, ptr+1);
          ptr += 2;
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstdio>
#include <vector>
#include <cassert>
#include <iostream>
#include <cstdlib>
#include <utility>

using namespace std;

const int MAXN = 100010;

int n, i, l1, r1, l2, r2, ptr;
pair <int, int> a[MAXN];
vector <int> myGraph[MAXN];
int color[MAXN];

void addEdge(int x, int y) {
     myGraph[x].push_back(y);
     myGraph[y].push_back(x);
}

void bicolor(int x, int v) {
     color[x] = v;
     for (int i = 0; i < (int)myGraph[x].size(); i++) {
         int nei = myGraph[x][i];
         if (color[nei] > 0 && color[x] == color[nei]) {
             cout << "-1\n";
             exit(0);
         }
         if (!color[nei]) bicolor(nei, 3-v);
     }
}

void tryBicoloring() {
     for (int i = 1; i <= n; i++) if (!color[i]) {
         bicolor(i, 1);
     }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a+1, a+n+1);
    ptr = 1;
    while (ptr < n) {
          l1 = a[ptr].first;
          r1 = a[ptr].second;
          l2 = a[ptr+1].first;
          r2 = a[ptr+1].second;
          if (r1 < l2) {
             ptr++;
             continue;
          }
          if (r1 >= l2 && r1 < r2) {
             a[ptr+1].first = r1;
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          if (r1 > r2) {
             a[ptr+1] = make_pair(r2, r1);
             addEdge(ptr, ptr+1);
             ptr++;
             continue;
          }
          assert(r1 == r2);
          addEdge(ptr, ptr+1);
          ptr += 2;
    }
    tryBicoloring();
    for (int i = 1; i <= n; i++) cout << color[i]-1 << " ";
    //system("pause");
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>          //cout<<fixed<<setprecision(10);
//#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
//#include <ctime>
//#include <memory.h>
//#include <cassert>

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) ((int)strlen(X))
#define F first
#define S second
#ifdef ONLINE_JUDGE
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#else
#define FILEIO(name)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
/*#include<complex.h>
typedef complex<double> co;
#define X real()
#define Y imag()*/

const int maxn = 200000 + 10;

//O(V+E),E<=4n(n-1)
struct TwoSAT {
  int n;
  vector<int> G[maxn*2];
  bool mark[maxn*2];
  bool var_ans[maxn];
  int S[maxn*2], c;

  bool dfs(int x) {
    if (mark[x^1]) return false;
    if (mark[x]) return true;
    mark[x] = true;
    S[c++] = x;
    for (int i = 0; i < G[x].size(); i++)
      if (!dfs(G[x][i])) return false;
    return true;
  }

  void init(int n) {
    this->n = n;
    for (int i = 0; i < n*2; i++) G[i].clear();
    memset(mark, 0, sizeof(mark));
  }

  // x = xval or y = yval
  void add_clause(int x, int xval, int y, int yval) {
    x = x * 2 + xval;
    y = y * 2 + yval;
    G[x^1].push_back(y);
    G[y^1].push_back(x);
  }

  bool solve() {
    for(int i = 0; i < n*2; i += 2)
      if(!mark[i] && !mark[i+1]) {
        c = 0;
        if(!dfs(i)) {
          while(c > 0) mark[S[--c]] = false;
          if(!dfs(i+1)) return false;
        }
      }
    for(int i = 0; i < n; i++)
      var_ans[i]=mark[i*2+1];
    return true;
  }
}ts;

vector<ii> v;

bool cmp(ii A,ii B){
    return A.F<B.F||(A.F==B.F&&A.S%2<B.S%2)||(A.F==B.F&&A.S%2==B.S%2&&A.S<B.S);
}

int main()
{
    DRI(n);
    ts.init(2*n);
    int A,B;
    REP(i,0,n){
        RII(A,B);
        v.PB(ii(A,i*2));
        v.PB(ii(B,i*2+1));
        ts.add_clause(i*2,0,i*2+1,0);
        ts.add_clause(i*2,1,i*2+1,1);
    }
    sort(ALL(v),cmp);
    REP(i,0,n){
        //cout<<v[i*2].F<<' '<<v[i*2+1].F<<endl;
        if(v[i*2].S%2==v[i*2+1].S%2){
            ts.add_clause(v[i*2].S,0,v[i*2+1].S,0);
            ts.add_clause(v[i*2].S,1,v[i*2+1].S,1);
        }
    }
    if(ts.solve()){
        REP(i,0,n)printf("%d ",ts.var_ans[i*2]);
        puts("");
    }
    else puts("-1");
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>          //cout<<fixed<<setprecision(10);
//#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
//#include <ctime>
//#include <memory.h>
//#include <cassert>

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) ((int)strlen(X))
#define F first
#define S second
#ifdef ONLINE_JUDGE
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#else
#define FILEIO(name)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
/*#include<complex.h>
typedef complex<double> co;
#define X real()
#define Y imag()*/

const int maxn = 200000 + 10;

//O(V+E),E<=4n(n-1)
struct TwoSAT {
  int n;
  vector<int> G[maxn*2];
  bool mark[maxn*2];
  bool var_ans[maxn];
  int S[maxn*2], c;

  bool dfs(int x) {
    if (mark[x^1]) return false;
    if (mark[x]) return true;
    mark[x] = true;
    S[c++] = x;
    for (int i = 0; i < G[x].size(); i++)
      if (!dfs(G[x][i])) return false;
    return true;
  }

  void init(int n) {
    this->n = n;
    for (int i = 0; i < n*2; i++) G[i].clear();
    memset(mark, 0, sizeof(mark));
  }

  // x = xval or y = yval
  void add_clause(int x, int xval, int y, int yval) {
    x = x * 2 + xval;
    y = y * 2 + yval;
    G[x^1].push_back(y);
    G[y^1].push_back(x);
  }

  bool solve() {
    for(int i = 0; i < n*2; i += 2)
      if(!mark[i] && !mark[i+1]) {
        c = 0;
        if(!dfs(i)) {
          while(c > 0) mark[S[--c]] = false;
          if(!dfs(i+1)) return false;
        }
      }
    for(int i = 0; i < n; i++)
      var_ans[i]=mark[i*2+1];
    return true;
  }
}ts;

vector<ii> v;

bool cmp(ii A,ii B){
    return A.F<B.F||(A.F==B.F&&A.S%2<B.S%2)||(A.F==B.F&&A.S%2==B.S%2&&A.S<B.S);
}

int main()
{
    DRI(n);
    ts.init(2*n);
    int A,B;
    REP(i,0,n){
        RII(A,B);
        v.PB(ii(A,i*2));
        v.PB(ii(B,i*2+1));
        ts.add_clause(i*2,0,i*2+1,0);
        ts.add_clause(i*2,1,i*2+1,1);
    }
    sort(ALL(v),cmp);
    REP(i,0,n){
        //cout<<v[i*2].F<<' '<<v[i*2+1].F<<endl;
        //if(v[i*2].S%2==v[i*2+1].S%2){
            ts.add_clause(v[i*2].S,0,v[i*2+1].S,0);
            ts.add_clause(v[i*2].S,1,v[i*2+1].S,1);
        //}
    }
    if(ts.solve()){
        REP(i,0,n)printf("%d ",ts.var_ans[i*2]);
        puts("");
    }
    else puts("-1");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*3,M=N*6+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	m=0;
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),++pr[i],
		a[++m]=pl[i],
		a[++m]=pr[i];
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i],flow.t,1,1),
		flow.add(pl[i],pr[i],0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	/*
	--m;
	for(i=1;i<=m;++i) cnt[i]=0;
	for(i=1;i<=n;++i)
		if(flow.cap[pos[i]])
			++cnt[pl[i]],--cnt[pr[i]+1];
		else
			--cnt[pl[i]],++cnt[pr[i]+1];
	for(i=1;i<=m;++i){
		cnt[i]+=cnt[i-1];
		if(abs(cnt[i])>1)
			puts("wrong");
	}
	puts("bingo");
	*/

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*3,M=N*6+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	m=0;
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		m=max(m,pr[i]);
	//	a[++m]=pl[i],
	//	a[++m]=pl[i]+1,
	//	a[++m]=pr[i];
//	sort(a+1,a+1+m);
//	m=unique(a+1,a+1+m)-a-1;
	++m;
	for(i=1;i<=m;++i) a[i]=i-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i]+1,flow.t,1,1),
		flow.add(pl[i],pr[i]+1,0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	/*
	--m;
	for(i=1;i<=m;++i) cnt[i]=0;
	for(i=1;i<=n;++i)
		if(flow.cap[pos[i]])
			++cnt[pl[i]],--cnt[pr[i]+1];
		else
			--cnt[pl[i]],++cnt[pr[i]+1];
	for(i=1;i<=m;++i){
		cnt[i]+=cnt[i-1];
		if(abs(cnt[i])>1)
			puts("wrong");
	}
	puts("bingo");
	*/

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,M=N*6;
int pl[N],pr[N],a[N<<1],cnt[N<<1];
int tot=1,head[M],nxt[M],adj[M],vis[M],col[M];
inline void addedge(ri x,ri y){
	nxt[++tot]=head[x];
	adj[head[x]=tot]=y;
}
inline void dfs(ri x){
//	printf("dfs %d\n",x);
	ri i;
	while(i=head[x])
		if(!vis[i])
			vis[i]=vis[i^1]=1,
			dfs(adj[i]),
		//	printf("col %d %d\n",i/2,i&1),
			col[i/2]=i&1;
		else
			head[x]=nxt[i];
}
int main(){
	ri n,m,i;
	gi(n);
	m=0;
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),++pr[i],
		a[++m]=pl[i],
		a[++m]=pr[i];
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		addedge(pl[i],pr[i]),
		addedge(pr[i],pl[i]),
		++cnt[pl[i]],--cnt[pr[i]];
	for(i=1;i<=m;++i){
		cnt[i]+=cnt[i-1];
		if(cnt[i]&1)
			addedge(i,i+1),
			addedge(i+1,i);
	}
	for(i=1;i<=m;++i) dfs(i);
	for(i=1;i<=n;++i) putc(col[i]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*3,M=N*6+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	m=0;
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		a[++m]=pl[i],
		a[++m]=pl[i]+1,
		a[++m]=pr[i];
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i]+1,flow.t,1,1),
		flow.add(pl[i],pr[i]+1,0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	/*
	--m;
	for(i=1;i<=m;++i) cnt[i]=0;
	for(i=1;i<=n;++i)
		if(flow.cap[pos[i]])
			++cnt[pl[i]],--cnt[pr[i]+1];
		else
			--cnt[pl[i]],++cnt[pr[i]+1];
	for(i=1;i<=m;++i){
		cnt[i]+=cnt[i-1];
		if(abs(cnt[i])>1)
			puts("wrong");
	}
	puts("bingo");
	*/

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*2,M=N*5+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		a[i]=pl[i],a[i+n]=pr[i];
	m=n<<1;
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i){
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i]+1,flow.t,1,1),
		flow.add(pl[i],pr[i]+1,0,1);
		pos[i]=flow.tot;
	}

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*3,M=N*6+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	m=0;
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		m=max(m,pr[i]);
	//	a[++m]=pl[i],
	//	a[++m]=pl[i]+1,
	//	a[++m]=pr[i];
//	sort(a+1,a+1+m);
//	m=unique(a+1,a+1+m)-a-1;
	for(i=1;i<=m;++i) a[i]=i;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+m,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+m,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i]+1,flow.t,1,1),
		flow.add(pl[i],pr[i]+1,0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	/*
	--m;
	for(i=1;i<=m;++i) cnt[i]=0;
	for(i=1;i<=n;++i)
		if(flow.cap[pos[i]])
			++cnt[pl[i]],--cnt[pr[i]+1];
		else
			--cnt[pl[i]],++cnt[pr[i]+1];
	for(i=1;i<=m;++i){
		cnt[i]+=cnt[i-1];
		if(abs(cnt[i])>1)
			puts("wrong");
	}
	puts("bingo");
	*/

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*2,M=N*5+_N<<1;
int pl[N],pr[N],a[N<<1],cnt[N<<1],pos[N];
struct Flow{
	int sum,S,T,s,t,m,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	//	printf("ans = %d\n",ans);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		a[i]=pl[i],a[i+n]=pr[i];
	m=n<<1;
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+n,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+n,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],1,1),
		flow.add(pr[i]+1,flow.t,1,1),
		flow.add(pl[i],pr[i]+1,0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();

	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e5+5,_N=N*2,M=N*4+_N;
int pl[N],pr[N],a[N<<1],pos[N],cnt[N<<1];
struct Flow{
	int sum,S,T,s,t,m,deg[_N],tot=1,head[_N],cur[_N],nxt[M],adj[M],cap[M],dep[_N],q[_N];
	inline void insert(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		cap[tot]=z;
	}
	inline void addedge(ri x,ri y,ri z){
	//	printf("addedge %d %d %d\n",x,y,z);
		insert(x,y,z);
		insert(y,x,0);
	}
	inline void add(ri x,ri y,ri lower,ri upper){
	//	printf("add %d %d %d %d\n",x,y,lower,upper);
		deg[x]-=lower;
		deg[y]+=lower;
		if(lower!=upper)
			addedge(x,y,upper-lower);
	}
	inline void build(){
		S=0;
		T=t+1;
	//	printf("S = %d T = %d\n",S,T);
	//	for(ri i=1;i<=t;++i) printf("%d ",deg[i]);
	//	puts("");
		for(ri i=1;i<=t;++i)
			if(deg[i]>0)
				sum+=deg[i],
				addedge(S,i,deg[i]);
			else if(deg[i]<0)
				addedge(i,T,-deg[i]);
		insert(t,s,2e9);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=S;i<=T;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=S;
		dep[S]=1;
		while(l<=r){
			x=q[l++];
		//	printf("dep %d %d\n",x,dep[x]);
			for(i=head[x];i;i=nxt[i])
				if(cap[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[T];
	}
	inline int dfs(ri x,ri now){
	//	printf("dfs %d %d\n",x,now);
		if(x==T) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(cap[i]&&dep[y=adj[i]]==dep[x]+1&&(tmp=dfs(y,min(now,cap[i])))){
				cap[i]-=tmp;
				cap[i^1]+=tmp;
				res+=tmp;
				if(!(now-=tmp))
					return res;
			}
		return res;
	}
	inline void maxflow(){
		ri ans=0;
		while(bfs())
			ans+=dfs(S,2e9);
		if(sum!=ans)
			puts("-1"),exit(0);
	}
}flow;
int main(){
	ri n,m,i;
	gi(n);
	for(i=1;i<=n;++i)
		gi(pl[i]),gi(pr[i]),
		a[i]=pl[i],a[i+n]=pr[i];
	m=n<<1;
	sort(a+1,a+1+m);
	m=unique(a+1,a+1+m)-a-1;
	a[++m]=2e9;
	flow.s=m+1;
	flow.t=m+2;
	for(i=1;i<=n;++i)
		pl[i]=lower_bound(a+1,a+1+n,pl[i])-a,
		pr[i]=lower_bound(a+1,a+1+n,pr[i])-a,
		++cnt[pl[i]],
		--cnt[pr[i]+1],
		flow.add(flow.s,pl[i],0,1),
		flow.add(pr[i]+1,flow.t,0,1),
		pos[i]=flow.tot;

	for(i=1;i<m;++i)
		cnt[i]+=cnt[i-1],
		flow.add(i,i+1,cnt[i]>>1,cnt[i]+1>>1);
	flow.build();
	flow.maxflow();
	for(i=1;i<=n;++i) putc(flow.cap[pos[i]]?'0':'1'),putc(' ');
	putc('\n');
	return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=5e5+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> void chkmax(T &a,T b) { a<b?a=b:0; };
template<typename T> void chkmin(T &a,T b) { a>b?a=b:0; };
struct edge { int to,nxt; } e[N<<1];
int tot=1,h[N];
void adde(int u,int v) {
    e[++tot]=(edge){v,h[u]};h[u]=tot;
    e[++tot]=(edge){u,h[v]};h[v]=tot;
}
struct node { int x,op,id; } p[N];
bool operator<(node a,node b) {
    return a.x<b.x;
}
int n,lst[N],dir[N];
bool vis[N];
void dfs(int u) {
    vis[u]=1;
    for(int i=h[u];i;i=e[i].nxt) {
        int v=e[i].to; if(dir[i]) continue;
        dir[i]=1; dir[i^1]=2; dfs(v);
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("CF429E.in","r",stdin);
    freopen("CF429E.out","w",stdout);
#endif
    cin>>n;
    for(int i=1;i<=n;i++) p[i].x=gi(),p[i+n].x=gi()+1,p[i].op=1,p[i+n].op=-1,p[i].id=p[i+n].id=i;
    sort(p+1,p+n+n+1);
    int m=0;
    for(int i=1;i<=n+n;i++) {
        if(i==1||p[i].x!=p[i-1].x) {
            m++;
            if(i%2==0) adde(m,m-1);
        }
        if(p[i].op==1) lst[p[i].id]=m;
        else adde(lst[p[i].id],m),lst[p[i].id]=tot-1;
    }
    for(int i=1;i<=m;i++) if(!vis[i]) dfs(i);
    for(int i=1;i<=n;i++) printf("%d ",dir[lst[i]]&1);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int lst[200005], from[400005], to[400005], pre[400005], idx[400005], deg[200005], tot;
int ans[100005], l[100005], r[100005], app[200005], seq[200005], sz;
bool del[400005], vis[200005];
inline void add_edge(int u, int v, int _idx)
{
	// cout << u << " " << v << " " << _idx << endl;
	from[tot] = u;
	to[tot] = v;
	pre[tot] = lst[u];
	idx[tot] = _idx;
	deg[v]++;
	lst[u] = tot++;
}
void dfs(int u)
{
	vis[u] = true;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (del[i])
		{
			lst[u] = pre[i];
			continue;
		}
		del[i] = del[i ^ 1] = true;
		dfs(to[i]);
		seq[sz++] = i;
	}
}
int main()
{
	// freopen("429E.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", l + i, r + i);
		app[cnt++] = l[i];
		app[cnt++] = r[i] + 1;
	}
	sort(app, app + cnt);
	cnt = unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		l[i] = lower_bound(app, app + cnt, l[i]) - app;
		r[i] = lower_bound(app, app + cnt, r[i] + 1) - app;
		add_edge(l[i], r[i], i);
		add_edge(r[i], l[i], i);
	}
	int v = -1, e_cnt = n;
	for (int i = 0; i < cnt; i++)
	{
		if (deg[i] & 1 ^ 1)
			continue;
		if (~v)
		{
			add_edge(v, i, e_cnt);
			add_edge(i, v, e_cnt++);
			v = -1;
		}
		else
			v = i;
	}
	for (int i = 0; i < cnt; i++)
	{
		if (!vis[i])
		{
			sz = 0;
			dfs(i);
			for (int j = 0; j < sz; j++)
				ans[idx[seq[j]]] = from[seq[j]] < to[seq[j]];
		}
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int lst[100005], to[400005], pre[400005], idx[400005], deg[100005], tot;
int ans[100005], l[100005], r[100005], app[100005];
bool del[400005], vis[100005];
inline void add_edge(int u, int v, int _idx)
{
	to[tot] = v;
	pre[tot] = lst[u];
	idx[tot] = _idx;
	deg[v]++;
	lst[u] = tot++;
}
void dfs(int u, int cur)
{
	vis[u] = true;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (del[i])
		{
			lst[u] = pre[i];
			continue;
		}
		del[i] = del[i ^ 1] = true;
		ans[idx[i]] = cur;
		dfs(to[i], cur ^ 1);
	}
}
int main()
{
	// freopen("429E.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", l + i, r + i);
		app[cnt++] = l[i];
		app[cnt++] = r[i];
	}
	sort(app, app + cnt);
	cnt = unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		l[i] = lower_bound(app, app + cnt, l[i]) - app;
		r[i] = lower_bound(app, app + cnt, r[i]) - app;
		add_edge(l[i], r[i], i);
		add_edge(r[i], l[i], i);
	}
	int v = -1, e_cnt = n;
	for (int i = 0; i < cnt; i++)
	{
		if (deg[i] & 1 ^ 1)
			continue;
		if (~v)
		{
			add_edge(v, i, e_cnt);
			add_edge(i, v, e_cnt++);
			v = -1;
		}
		else
			v = i;
	}
	for (int i = 0; i < cnt; i++)
	{
		if (!vis[i])
			dfs(i, 0);
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int lst[100005], from[400005], to[400005], pre[400005], idx[400005], deg[100005], tot;
int ans[100005], l[100005], r[100005], app[200005], seq[100005], sz;
bool del[400005], vis[100005];
inline void add_edge(int u, int v, int _idx)
{
	// cout << u << " " << v << " " << _idx << endl;
	from[tot] = u;
	to[tot] = v;
	pre[tot] = lst[u];
	idx[tot] = _idx;
	deg[v]++;
	lst[u] = tot++;
}
void dfs(int u)
{
	vis[u] = true;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (del[i])
		{
			lst[u] = pre[i];
			continue;
		}
		del[i] = del[i ^ 1] = true;
		dfs(to[i]);
		seq[sz++] = i;
	}
}
int main()
{
	// freopen("429E.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", l + i, r + i);
		app[cnt++] = l[i];
		app[cnt++] = r[i] + 1;
	}
	sort(app, app + cnt);
	cnt = unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		l[i] = lower_bound(app, app + cnt, l[i]) - app;
		r[i] = lower_bound(app, app + cnt, r[i] + 1) - app;
		add_edge(l[i], r[i], i);
		add_edge(r[i], l[i], i);
	}
	int v = -1, e_cnt = n;
	for (int i = 0; i < cnt; i++)
	{
		if (deg[i] & 1 ^ 1)
			continue;
		if (~v)
		{
			add_edge(v, i, e_cnt);
			add_edge(i, v, e_cnt++);
			v = -1;
		}
		else
			v = i;
	}
	for (int i = 0; i < cnt; i++)
	{
		if (!vis[i])
		{
			sz = 0;
			dfs(i);
			for (int j = 0; j < sz; j++)
				ans[idx[seq[j]]] = from[seq[j]] < to[seq[j]];
		}
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int lst[100005], from[400005], to[400005], pre[400005], idx[400005], deg[100005], tot;
int ans[100005], l[100005], r[100005], app[100005], seq[100005], sz;
bool del[400005], vis[100005];
inline void add_edge(int u, int v, int _idx)
{
	// cout << u << " " << v << " " << _idx << endl;
	from[tot] = u;
	to[tot] = v;
	pre[tot] = lst[u];
	idx[tot] = _idx;
	deg[v]++;
	lst[u] = tot++;
}
void dfs(int u)
{
	vis[u] = true;
	for (int i = lst[u]; ~i; i = pre[i])
	{
		if (del[i])
		{
			lst[u] = pre[i];
			continue;
		}
		del[i] = del[i ^ 1] = true;
		dfs(to[i]);
		seq[sz++] = i;
	}
}
int main()
{
	// freopen("429E.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", l + i, r + i);
		app[cnt++] = l[i];
		app[cnt++] = r[i] + 1;
	}
	sort(app, app + cnt);
	cnt = unique(app, app + cnt) - app;
	for (int i = 0; i < n; i++)
	{
		l[i] = lower_bound(app, app + cnt, l[i]) - app;
		r[i] = lower_bound(app, app + cnt, r[i] + 1) - app;
		add_edge(l[i], r[i], i);
		add_edge(r[i], l[i], i);
	}
	int v = -1, e_cnt = n;
	for (int i = 0; i < cnt; i++)
	{
		if (deg[i] & 1 ^ 1)
			continue;
		if (~v)
		{
			add_edge(v, i, e_cnt);
			add_edge(i, v, e_cnt++);
			v = -1;
		}
		else
			v = i;
	}
	for (int i = 0; i < cnt; i++)
	{
		if (!vis[i])
		{
			sz = 0;
			dfs(i);
			for (int j = 0; j < sz; j++)
				ans[idx[seq[j]]] = from[seq[j]] < to[seq[j]];
		}
	}
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


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

const int maxn = 2e5 + 55;
int V[maxn], U[maxn];
unordered_map <int, int> M;
vector <int> comp;
bitset <maxn> mark, emark, ans;
vector <int> adj[maxn];

void dfs(int v, int E = -1) {
	mark[v] = 1;
	for (auto e: adj[v]) {
		if (!emark[e]) {
			emark[e] = 1;
			dfs(V[e] ^ U[e] ^ v, e);
		}
	}
	if (~E && v == V[E]) ans[E] = 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> V[i] >> U[i];
		U[i]++;
		comp.push_back(V[i]);
		comp.push_back(U[i]);
	}
	sort(comp.begin(), comp.end());
	comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
	int n = comp.size();
	for (int i = 0; i < n; i++) M[comp[i]] = i;
	for (int i = 0; i < m; i++) {
		V[i] = M[V[i]];
		U[i] = M[U[i]];
		adj[V[i]].push_back(i);
		adj[U[i]].push_back(i);
	}
	vector <int> D;
	for (int i = 0; i < n; i++) {
		if (adj[i].size() % 2) D.push_back(i);
	}
	for (int i = 0; i < D.size() / 2; i++) {
		V[m + i] = D[2 * i + 0];
		U[m + i] = D[2 * i + 1];
		adj[D[2 * i + 0]].push_back(m + i);
		adj[D[2 * i + 1]].push_back(m + i);
	}
	for (int i = 0; i < n; i++) {
		if (!mark[i]) dfs(i);
	}
	for (int i = 0; i < m; i++) cout << ans[i] << ' ';
}


#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];
	struct node
	{
		int val,name;
	}p[Maxm];
	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();
}