#include using namespace std; //template int size(const T &x) { return x.size(); } #define rep(i,a,b) for (auto i=(a); i<(b); ++i) #define iter(it,c) for (auto it = (c).begin(); it != (c).end(); ++it) typedef pair ii; typedef vector vi; typedef vector vii; typedef vector vvi; typedef long long ll; const int INF = 2147483647; vector adj, all_adj; vi color; bool check_bipartite(int at) { iter(it,all_adj[at]) { if (color[*it] == -1) { color[*it] = 1-color[at]; if (!check_bipartite(*it)) { return false; } } if (color[at] == color[*it]) { return false; } } return true; } int other_color(int c1) { int c2 = 0; if (c2 == c1) c2++; if (c2 == c1) assert(false); return c2; } int other_color(int c1, int c2) { int c3 = 0; if (c3 == c1 || c3 == c2) c3++; if (c3 == c1 || c3 == c2) c3++; if (c3 == c1 || c3 == c2) assert(false); return c3; } int n; void doit(int at, int idx) { if (idx == -1) { if (color[at] == -1) { color[at] = 0; } if (at+1 < n && color[at+1] == -1) { doit(at+1, (int)adj[at+1].size()-1); } return; } int nxt = adj[at][idx]; if (color[at] == -1) { color[at] = other_color(color[nxt]); } bool done = true; if (color[nxt] == -1) { color[nxt] = adj[nxt].empty() ? other_color(color[at]) : other_color(color[at], color[adj[nxt].back()]); done = false; } doit(at, idx-1); if (!done) { doit(nxt, (int)adj[nxt].size()-1); } } int main() { ios_base::sync_with_stdio(false); cin >> n; adj.resize(n); all_adj.resize(n); stack S; rep(i,0,n) { int fire, hire; cin >> fire >> hire; while (fire) { ii other = S.top(); S.pop(); int mn = min(fire, other.second); assert(mn > 0); adj[other.first].push_back(i); all_adj[i].push_back(other.first); all_adj[other.first].push_back(i); if (mn < other.second) { S.push(ii(other.first, other.second - mn)); } fire -= mn; } if (hire > 0) { S.push(ii(i, hire)); } } bool bipartite = true; color.assign(n, -1); rep(i,0,n) { if (color[i] == -1) { color[i] = 0; if (!check_bipartite(i)) { bipartite = false; break; } } } if (!bipartite) { color.assign(n, -1); doit(0, (int)adj[0].size()-1); } int mx = 0; rep(i,0,n) mx = max(mx, color[i]); cout << mx+1 << endl; rep(i,0,n) { if (i != 0) cout << " "; cout << color[i]+1; } cout << endl; return 0; }