#include <bits/stdc++.h>
#define endl '\n'
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
using namespace std;
template<class T, class T2> inline int chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline int chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const int MAXN = (int)1e5 + 42;
/// Benq 2-Sat and scc
template<int SZ> struct scc {
vector<int> adj[SZ], radj[SZ], todo, allComp;
int N, comp[SZ];
bitset<SZ> visit;
void clear(int n)
{
for(int i = 0; i < n; i++)
adj[i].clear(), radj[i].clear();
allComp.clear();
todo.clear();
}
void clear_2()
{
allComp.clear();
todo.clear();
}
void dfs(int v) {
visit[v] = 1;
for (int w: adj[v]) if (!visit[w]) dfs(w);
todo.pb(v);
}
void dfs2(int v, int val) {
comp[v] = val;
for (int w: radj[v]) if (comp[w] == -1) dfs2(w,val);
}
void addEdge(int a, int b) { adj[a].pb(b), radj[b].pb(a); }
void genSCC() {
F0R(i,N) comp[i] = -1, visit[i] = 0;
F0R(i,N) if (!visit[i]) dfs(i);
reverse(ALL(todo)); // toposort
for (int i: todo) if (comp[i] == -1) dfs2(i,i), allComp.pb(i);
}
};
template<int SZ> struct twosat {
scc<2*SZ> S;
int N;
void SetTrue(int x) { S.addEdge(x^1,x); }
void NotBoth1(int x, int y)
{
S.addEdge(x, y^1);
S.addEdge(y, x^1);
}
void SetBothSame(int x, int y)
{
//cout << "SAME" << x / 2 << " " << y / 2 << endl;
S.addEdge(x, y);
S.addEdge(y, x);
S.addEdge(x ^ 1, y ^ 1);
S.addEdge(y ^ 1, x ^ 1);
}
int tmp[2*SZ];
bitset<SZ> ans;
void init(int n)
{
S.clear(2 * n);
N = n;
for(int i = 0; i < SZ; i++)
tmp[2 * i] = tmp[2 * i + 1] = 0, ans[i] = 0;
}
void clear_sat()
{
S.clear_2();
for(int i = 0; i < SZ; i++)
tmp[2 * i] = tmp[2 * i + 1] = 0, ans[i] = 0;
}
bool solve() {
S.N = 2*N; S.genSCC();
for (int i = 0; i < 2*N; i += 2) if (S.comp[i] == S.comp[i^1]) return 0;
reverse(ALL(S.allComp));
for (int i: S.allComp) if (tmp[i] == 0)
tmp[i] = 1, tmp[S.comp[i^1]] = -1;
F0R(i,N) if (tmp[S.comp[2*i]] == 1) ans[i] = 1;
return 1;
}
};
int n, X[MAXN], Y[MAXN];
map<int, vector<pair<int, int> > > on_x;
map<int, vector<pair<int, int> > > on_y;
vector<pair<pair<int, int>, int> > Vec;
int read_int();
void read()
{
n = read_int();
for(int i = 0; i < n; i++)
{
int x, y;
x = read_int();
y = read_int();
X[i] = x;
Y[i] = y;
on_x[x].push_back({y, i});
on_y[y].push_back({x, i});
Vec.push_back({{x, y}, i});
}
}
twosat<MAXN> sat2;
set<pair<int, int> > st;
bool simple_check(int64_t d)
{
sat2.init(n);
for(auto X: on_x)
{
// currently looking at |
int last = -2 * d - 42, il = -1;
for(auto it: X.second)
{
if((int64_t)it.first - last <= d)
{
sat2.SetTrue(it.second * 2);
sat2.SetTrue(il * 2);
}
else if((int64_t)it.first - last <= 2 * d)
sat2.NotBoth1(it.second * 2 + 1, il * 2 + 1);
last = it.first;
il = it.second;
}
}
for(auto X: on_y)
{
// currently looking at -
int last = -2 * d - 42, il = -1;
for(auto it: X.second)
{
if((int64_t)it.first - last <= d)
{
sat2.SetTrue(it.second * 2 + 1);
sat2.SetTrue(il * 2 + 1);
}
else if((int64_t)it.first - last <= 2 * d)
sat2.NotBoth1(it.second * 2, il * 2);
last = it.first;
il = it.second;
}
}
return sat2.solve();
}
bool check(int d)
{
if(!simple_check(d)) return false;
sat2.clear_sat();
int p_l = 0;
st.clear();
for(int i = 0; i < n; i++)
{
while(Vec[i].first.first - Vec[p_l].first.first > d) st.erase({Vec[p_l].first.second, Vec[p_l].second}), p_l++;
int y = Vec[i].first.second, idx = Vec[i].second;
auto R = st.lower_bound({y, MAXN});
if(R != st.end() && R->first - y <= d)
sat2.SetBothSame(R->second * 2, idx * 2);
if(R != st.begin())
{
R--;
if(y - R->first <= d)
sat2.SetBothSame(R->second * 2, idx * 2);
}
if(i != n - 1 && Vec[i].first.first != Vec[i + 1].first.first)
{
if(Vec[i + 1].first.first - Vec[i].first.first > d) st.clear(), p_l = i + 1;
else for(int j = i; j >= 0 && Vec[j].first.first == Vec[i].first.first; j--)
st.insert({Vec[j].first.second, Vec[j].second});
}
}
return sat2.solve();
}
void solve()
{
for(auto &it: on_x)
sort(ALL(it.second));
for(auto &it: on_y)
sort(ALL(it.second));
sort(ALL(Vec));
if(check((int)1e9 + 42))
{
cout << -1 << endl;
for(int i = 0; i < n; i++)
cout << (sat2.ans[i] ? '-' : '|');
return;
}
int low = 0, high = (int)1e9, mid, ret = 0;
/*for(int i = 0; high - (1 << i) >= low; i++)
if(!check(high - (1 << i))) high -= (1 << i);
else
{
ret = high - (1 << i);
low = high - (1 << i) + 1;
break;
}*/
for(int i = 0; i < n; i++)
{
int vert = (int)1e9, hor = (int)1e9;
{
auto &V = on_x[X[i]];
auto L = U_B(ALL(V), make_pair(Y[i], i)) - V.begin();
if(L != SZ(V))
chkmin(vert, V[L].first - Y[i]);
L -= 2;
if(L >= 0)
chkmin(vert, Y[i] - V[L].first);
}
{
auto &V = on_y[Y[i]];
auto L = U_B(ALL(V), make_pair(X[i], i)) - V.begin();
if(L != SZ(V))
chkmin(hor, V[L].first - X[i]);
L -= 2;
if(L >= 0)
chkmin(hor, X[i] - V[L].first);
}
chkmin(high, max(hor, vert));
}
while(low <= high)
{
mid = (low + high) >> 1;
if(check(mid))
ret = mid, low = mid + 1;
else
high = mid - 1;
}
check(ret);
cout << ret << endl;
for(int i = 0; i < n; i++)
cout << (sat2.ans[i] ? '-' : '|');
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
const int maxl = 100000;
char buff[maxl];
int ret_int, pos_buff = 0;
void next_char() { if(++pos_buff == maxl) fread(buff, 1, maxl, stdin), pos_buff = 0; }
int read_int()
{
ret_int = 0;
for(; buff[pos_buff] < '0' || buff[pos_buff] > '9'; next_char());
for(; buff[pos_buff] >= '0' && buff[pos_buff] <= '9'; next_char())
ret_int = ret_int * 10 + buff[pos_buff] - '0';
return ret_int;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgovLyNwcmFnbWEgR0NDIG9wdGltaXplICgiTzMiKQovLyNwcmFnbWEgR0NDIHRhcmdldCAoInNzZTQiKQoKI2RlZmluZSBTWih4KSAoKGludCl4LnNpemUoKSkKI2RlZmluZSBBTEwoVikgVi5iZWdpbigpLCBWLmVuZCgpCiNkZWZpbmUgTF9CIGxvd2VyX2JvdW5kCiNkZWZpbmUgVV9CIHVwcGVyX2JvdW5kCiNkZWZpbmUgcGIgcHVzaF9iYWNrCgojZGVmaW5lIEZPUihpLCBhLCBiKSBmb3IgKGludCBpPWE7IGk8KGIpOyBpKyspCiNkZWZpbmUgRjBSKGksIGEpIGZvciAoaW50IGk9MDsgaTwoYSk7IGkrKykKI2RlZmluZSBGT1JkKGksYSxiKSBmb3IgKGludCBpID0gKGIpLTE7IGkgPj0gYTsgaS0tKQojZGVmaW5lIEYwUmQoaSxhKSBmb3IgKGludCBpID0gKGEpLTE7IGkgPj0gMDsgaS0tKQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdGVtcGxhdGU8Y2xhc3MgVCwgY2xhc3MgVDI+IGlubGluZSBpbnQgY2hrbWF4KFQgJngsIGNvbnN0IFQyICZ5KSB7IHJldHVybiB4IDwgeSA/IHggPSB5LCAxIDogMDsgfQp0ZW1wbGF0ZTxjbGFzcyBULCBjbGFzc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