#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(4e5)+7;
const int inf = int(1e9)+7;
int n , x[maxN] , a[maxN] , b[maxN] , L[maxN] , R[maxN];
vector<int> val , event[2 * maxN];
namespace sub1{
bool check(){
for (int i = 2 ; i <= n ; i++){
if (a[i] != a[i - 1] || b[i] != b[i - 1]) return 0;
}
return 1;
}
void solve(){
if (n == 1){
cout << "1 -1\n";
}
else{
cout << "2 " << 2 * (n - 1) << "\n";
}
}
}
namespace sub3{
bool check(){
return (n <= 300);
}
ii calc(ii x , ii y){
if (x.fi > y.fi) return x;
if (y.fi > x.fi) return y;
ii ans = {x.fi , -1};
if (x.se != -1 && y.se != -1) ans.se = x.se + y.se;
return ans;
}
void solve(){
ii ans = {0 , 0};
for (int i = 1 ; i <= n ; i++){
set<int> X , Y;
for (int j = i ; j <= n ; j++){
if (L[i] != L[j]){
if (sz(X) < 2) X.insert(R[j]);
}
if (R[i] != R[j]){
if (sz(Y) < 2) Y.insert(L[j]);
}
if (sz(X) == 0) ans = calc(ans , {j - i + 1 , -1});
if (sz(X) == 1) ans = calc(ans , {j - i + 1 , +1});
if (sz(Y) == 0) ans = calc(ans , {j - i + 1 , -1});
if (sz(Y) == 1) ans = calc(ans , {j - i + 1 , +1});
}
}
cout << ans.fi << " " << ans.se << "\n";
}
}
namespace sub4{
#define lef(id) id * 2
#define rig(id) id * 2 + 1
struct segtree_min{
int st[4 * maxN];
void init(){
for (int id = 1 ; id <= 4 * n ; id++) st[id] = +inf;
}
void update(int id , int l , int r , int p , int x){
if (l == r){
st[id] = x;
return;
}
int mid = (l + r) / 2;
if (p <= mid){
update(lef(id) , l , mid , p , x);
}
else{
update(rig(id) , mid + 1 , r , p , x);
}
st[id] = min(st[lef(id)] , st[rig(id)]);
}
int get(int id , int l , int r , int u , int v){
if (v < l || r < u) return +inf;
if (u <= l && r <= v) return st[id];
int mid = (l + r) / 2;
return min(get(lef(id) , l , mid , u , v) , get(rig(id) , mid + 1 , r , u , v));
}
} Min;
struct segtree_max{
int st[4 * maxN];
void init(){
for (int id = 1 ; id <= 4 * n ; id++) st[id] = -inf;
}
void update(int id , int l , int r , int p , int x){
if (l == r){
st[id] = x;
return;
}
int mid = (l + r) / 2;
if (p <= mid){
update(lef(id) , l , mid , p , x);
}
else{
update(rig(id) , mid + 1 , r , p , x);
}
st[id] = max(st[lef(id)] , st[rig(id)]);
}
int get(int id , int l , int r , int u , int v){
if (v < l || r < u) return -inf;
if (u <= l && r <= v) return st[id];
int mid = (l + r) / 2;
return max(get(lef(id) , l , mid , u , v) , get(rig(id) , mid + 1 , r , u , v));
}
} Max;
ii calc(ii x , ii y){
if (x.fi > y.fi) return x;
if (y.fi > x.fi) return y;
ii ans = {x.fi , -1};
if (x.se != -1 && y.se != -1) ans.se = x.se + y.se;
return ans;
}
ii ans = {0 , 0};
void prepare(){
for (int i = 1 ; i <= sz(val) ; i++) event[i].clear();
Min.init(); Max.init();
for (int i = 1 ; i <= n ; i++){
Min.update(1 , 1 , n , i , R[i]);
Max.update(1 , 1 , n , i , R[i]);
}
for (int i = 1 ; i <= n ; i++){
event[L[i]].push_back(i);
}
for (int i = 1 ; i <= sz(val) ; i++){
for (int j : event[i]){
Min.update(1 , 1 , n , j , +inf);
Max.update(1 , 1 , n , j , -inf);
}
for (int j : event[i]){
int lef = j , rig = n , pos = -1;
while (lef <= rig){
int mid = (lef + rig) / 2;
int x = Min.get(1 , 1 , n , j , mid);
int y = Max.get(1 , 1 , n , j , mid);
if (x == +inf || x == y){
pos = mid;
lef = mid + 1;
}
else{
rig = mid - 1;
}
}
int x = Min.get(1 , 1 , n , j , pos);
if (x == +inf){
ans = calc(ans , {pos - j + 1 , -1});
}
else{
ans = calc(ans , {pos - j + 1 , +1});
}
}
for (int j : event[i]){
Min.update(1 , 1 , n , j , R[j]);
Max.update(1 , 1 , n , j , R[j]);
}
}
}
void solve(){
prepare();
for (int i = 1 ; i <= n ; i++) swap(L[i] , R[i]);
prepare();
cout << ans.fi << " " << ans.se << "\n";
}
}
void solve(){
cin >> n;
for (int i = 1 ; i <= n ; i++){
cin >> x[i] >> a[i] >> b[i];
L[i] = x[i] - a[i];
R[i] = x[i] + b[i];
val.push_back(L[i]);
val.push_back(R[i]);
}
unq(val);
for (int i = 1 ; i <= n ; i++){
L[i] = lower_bound(all(val) , L[i]) - val.begin() + 1;
R[i] = lower_bound(all(val) , R[i]) - val.begin() + 1;
}
if (sub1::check()) return sub1::solve();
if (sub3::check()) return sub3::solve();
return sub4::solve();
}
#define name "ROADSIGNS"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gaW50KDRlNSkrNzsKY29uc3QgaW50IGluZiA9IGludCgxZTkpKzc7CgppbnQgbiAsIHhbbWF4Tl0gLCBhW21heE5dICwgYlttYXhOXSAsIExbbWF4Tl0gLCBSW21heE5dOwp2ZWN0b3I8aW50PiB2YWwgLCBldmVudFsyICogbWF4Tl07CgpuYW1lc3BhY2Ugc3ViMXsKICAgIGJvb2wgY2hlY2soKXsKICAgICAgICBmb3IgKGludCBpID0gMiA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgICAgIGlmIChhW2ldICE9IGFbaSAtIDFdIHx8IGJbaV0gIT0gYltpIC0gMV0pIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICByZXR1cm4gMTsKICAgIH0KCiAgICB2b2lkIHNvbHZlKCl7CiAgICAgICAgaWYgKG4gPT0gMSl7CiAgICAgICAgICAgIGNvdXQgPDwgIjEgLTFcbiI7CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIGNvdXQgPDwgIjIgIiA8PCAyICogKG4gLSAxKSA8PCAiXG4iOwogICAgICAgIH0KICAgIH0KfQoKbmFtZXNwYWNlIHN1YjN7CiAgICBib29sIGNoZWNrKCl7CiAgICAgICAgcmV0dXJuIChuIDw9IDMwMCk7CiAgICB9CgogICAgaWkgY2FsYyhpaSB4ICwgaWkgeSl7CiAgICAgICAgaWYgKHguZmkgPiB5LmZpKSByZXR1cm4geDsKICAgICAgICBpZiAoeS5maSA+IHguZmkpIHJldHVybiB5OwogICAgICAgIGlpIGFucyA9IHt4LmZpICwgLTF9OwogICAgICAgIGlmICh4LnNlICE9IC0xICYmIHkuc2UgIT0gLTEpIGFucy5zZSA9IHguc2UgKyB5LnNlOwogICAgICAgIHJldHVybiBhbnM7CiAgICB9CgogICAgdm9pZCBzb2x2ZSgpewogICAgICAgIGlpIGFucyA9IHswICwgMH07CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgICAgICBzZXQ8aW50PiBYICwgWTsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IGkgOyBqIDw9IG4gOyBqKyspewogICAgICAgICAgICAgICAgaWYgKExbaV0gIT0gTFtqXSl7CiAgICAgICAgICAgICAgICAgICAgaWYgKHN6KFgpIDwgMikgWC5pbnNlcnQoUltqXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoUltpXSAhPSBSW2pdKXsKICAgICAgICAgICAgICAgICAgICBpZiAoc3ooWSkgPCAyKSBZLmluc2VydChMW2pdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzeihYKSA9PSAwKSBhbnMgPSBjYWxjKGFucyAsIHtqIC0gaSArIDEgLCAtMX0pOwogICAgICAgICAgICAgICAgaWYgKHN6KFgpID09IDEpIGFucyA9IGNhbGMoYW5zICwge2ogLSBpICsgMSAsICsxfSk7CiAgICAgICAgICAgICAgICBpZiAoc3ooWSkgPT0gMCkgYW5zID0gY2FsYyhhbnMgLCB7aiAtIGkgKyAxICwgLTF9KTsKICAgICAgICAgICAgICAgIGlmIChzeihZKSA9PSAxKSBhbnMgPSBjYWxjKGFucyAsIHtqIC0gaSArIDEgLCArMX0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgYW5zLmZpIDw8ICIgIiA8PCBhbnMuc2UgPDwgIlxuIjsKICAgIH0KfQoKbmFtZXNwYWNlIHN1YjR7CiAgICAjZGVmaW5lIGxlZihpZCkgaWQgKiAyCiAgICAjZGVmaW5lIHJpZyhpZCkgaWQgKiAyICsgMQogICAgc3RydWN0IHNlZ3RyZWVfbWluewogICAgICAgIGludCBzdFs0ICogbWF4Tl07CgogICAgICAgIHZvaWQgaW5pdCgpewogICAgICAgICAgICBmb3IgKGludCBpZCA9IDEgOyBpZCA8PSA0ICogbiA7IGlkKyspIHN0W2lkXSA9ICtpbmY7CiAgICAgICAgfQoKICAgICAgICB2b2lkIHVwZGF0ZShpbnQgaWQgLCBpbnQgbCAsIGludCByICwgaW50IHAgLCBpbnQgeCl7CiAgICAgICAgICAgIGlmIChsID09IHIpewogICAgICAgICAgICAgICAgc3RbaWRdID0geDsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIGlmIChwIDw9IG1pZCl7CiAgICAgICAgICAgICAgICB1cGRhdGUobGVmKGlkKSAsIGwgLCBtaWQgLCBwICwgeCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIHVwZGF0ZShyaWcoaWQpICwgbWlkICsgMSAsIHIgLCBwICwgeCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc3RbaWRdID0gbWluKHN0W2xlZihpZCldICwgc3RbcmlnKGlkKV0pOwogICAgICAgIH0KCiAgICAgICAgaW50IGdldChpbnQgaWQgLCBpbnQgbCAsIGludCByICwgaW50IHUgLCBpbnQgdil7CiAgICAgICAgICAgIGlmICh2IDwgbCB8fCByIDwgdSkgcmV0dXJuICtpbmY7CiAgICAgICAgICAgIGlmICh1IDw9IGwgJiYgciA8PSB2KSByZXR1cm4gc3RbaWRdOwogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIHJldHVybiBtaW4oZ2V0KGxlZihpZCkgLCBsICwgbWlkICwgdSAsIHYpICwgZ2V0KHJpZyhpZCkgLCBtaWQgKyAxICwgciAsIHUgLCB2KSk7CiAgICAgICAgfQogICAgfSBNaW47CgogICAgc3RydWN0IHNlZ3RyZWVfbWF4ewogICAgICAgIGludCBzdFs0ICogbWF4Tl07CgogICAgICAgIHZvaWQgaW5pdCgpewogICAgICAgICAgICBmb3IgKGludCBpZCA9IDEgOyBpZCA8PSA0ICogbiA7IGlkKyspIHN0W2lkXSA9IC1pbmY7CiAgICAgICAgfQoKICAgICAgICB2b2lkIHVwZGF0ZShpbnQgaWQgLCBpbnQgbCAsIGludCByICwgaW50IHAgLCBpbnQgeCl7CiAgICAgICAgICAgIGlmIChsID09IHIpewogICAgICAgICAgICAgICAgc3RbaWRdID0geDsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIGlmIChwIDw9IG1pZCl7CiAgICAgICAgICAgICAgICB1cGRhdGUobGVmKGlkKSAsIGwgLCBtaWQgLCBwICwgeCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIHVwZGF0ZShyaWcoaWQpICwgbWlkICsgMSAsIHIgLCBwICwgeCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc3RbaWRdID0gbWF4KHN0W2xlZihpZCldICwgc3RbcmlnKGlkKV0pOwogICAgICAgIH0KCiAgICAgICAgaW50IGdldChpbnQgaWQgLCBpbnQgbCAsIGludCByICwgaW50IHUgLCBpbnQgdil7CiAgICAgICAgICAgIGlmICh2IDwgbCB8fCByIDwgdSkgcmV0dXJuIC1pbmY7CiAgICAgICAgICAgIGlmICh1IDw9IGwgJiYgciA8PSB2KSByZXR1cm4gc3RbaWRdOwogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIHJldHVybiBtYXgoZ2V0KGxlZihpZCkgLCBsICwgbWlkICwgdSAsIHYpICwgZ2V0KHJpZyhpZCkgLCBtaWQgKyAxICwgciAsIHUgLCB2KSk7CiAgICAgICAgfQogICAgfSBNYXg7CgogICAgaWkgY2FsYyhpaSB4ICwgaWkgeSl7CiAgICAgICAgaWYgKHguZmkgPiB5LmZpKSByZXR1cm4geDsKICAgICAgICBpZiAoeS5maSA+IHguZmkpIHJldHVybiB5OwogICAgICAgIGlpIGFucyA9IHt4LmZpICwgLTF9OwogICAgICAgIGlmICh4LnNlICE9IC0xICYmIHkuc2UgIT0gLTEpIGFucy5zZSA9IHguc2UgKyB5LnNlOwogICAgICAgIHJldHVybiBhbnM7CiAgICB9CgogICAgaWkgYW5zID0gezAgLCAwfTsKCiAgICB2b2lkIHByZXBhcmUoKXsKICAgICAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gc3oodmFsKSA7IGkrKykgZXZlbnRbaV0uY2xlYXIoKTsKICAgICAgICBNaW4uaW5pdCgpOyBNYXguaW5pdCgpOwogICAgICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKXsKICAgICAgICAgICAgTWluLnVwZGF0ZSgxICwgMSAsIG4gLCBpICwgUltpXSk7CiAgICAgICAgICAgIE1heC51cGRhdGUoMSAsIDEgLCBuICwgaSAsIFJbaV0pOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgICAgIGV2ZW50W0xbaV1dLnB1c2hfYmFjayhpKTsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IHN6KHZhbCkgOyBpKyspewogICAgICAgICAgICBmb3IgKGludCBqIDogZXZlbnRbaV0pewogICAgICAgICAgICAgICAgTWluLnVwZGF0ZSgxICwgMSAsIG4gLCBqICwgK2luZik7CiAgICAgICAgICAgICAgICBNYXgudXBkYXRlKDEgLCAxICwgbiAsIGogLCAtaW5mKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGludCBqIDogZXZlbnRbaV0pewogICAgICAgICAgICAgICAgaW50IGxlZiA9IGogLCByaWcgPSBuICwgcG9zID0gLTE7CiAgICAgICAgICAgICAgICB3aGlsZSAobGVmIDw9IHJpZyl7CiAgICAgICAgICAgICAgICAgICAgaW50IG1pZCA9IChsZWYgKyByaWcpIC8gMjsKICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IE1pbi5nZXQoMSAsIDEgLCBuICwgaiAsIG1pZCk7CiAgICAgICAgICAgICAgICAgICAgaW50IHkgPSBNYXguZ2V0KDEgLCAxICwgbiAsIGogLCBtaWQpOwogICAgICAgICAgICAgICAgICAgIGlmICh4ID09ICtpbmYgfHwgeCA9PSB5KXsKICAgICAgICAgICAgICAgICAgICAgICAgcG9zID0gbWlkOwogICAgICAgICAgICAgICAgICAgICAgICBsZWYgPSBtaWQgKyAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBlbHNlewogICAgICAgICAgICAgICAgICAgICAgICByaWcgPSBtaWQgLSAxOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGludCB4ID0gTWluLmdldCgxICwgMSAsIG4gLCBqICwgcG9zKTsKICAgICAgICAgICAgICAgIGlmICh4ID09ICtpbmYpewogICAgICAgICAgICAgICAgICAgIGFucyA9IGNhbGMoYW5zICwge3BvcyAtIGogKyAxICwgLTF9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICAgICAgYW5zID0gY2FsYyhhbnMgLCB7cG9zIC0gaiArIDEgLCArMX0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvciAoaW50IGogOiBldmVudFtpXSl7CiAgICAgICAgICAgICAgICBNaW4udXBkYXRlKDEgLCAxICwgbiAsIGogLCBSW2pdKTsKICAgICAgICAgICAgICAgIE1heC51cGRhdGUoMSAsIDEgLCBuICwgaiAsIFJbal0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIHZvaWQgc29sdmUoKXsKICAgICAgICBwcmVwYXJlKCk7CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspIHN3YXAoTFtpXSAsIFJbaV0pOwogICAgICAgIHByZXBhcmUoKTsKICAgICAgICBjb3V0IDw8IGFucy5maSA8PCAiICIgPDwgYW5zLnNlIDw8ICJcbiI7CiAgICB9Cn0KCnZvaWQgc29sdmUoKXsKICAgIGNpbiA+PiBuOwogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgIGNpbiA+PiB4W2ldID4+IGFbaV0gPj4gYltpXTsKICAgICAgICBMW2ldID0geFtpXSAtIGFbaV07CiAgICAgICAgUltpXSA9IHhbaV0gKyBiW2ldOwogICAgICAgIHZhbC5wdXNoX2JhY2soTFtpXSk7CiAgICAgICAgdmFsLnB1c2hfYmFjayhSW2ldKTsKICAgIH0KICAgIHVucSh2YWwpOwogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgIExbaV0gPSBsb3dlcl9ib3VuZChhbGwodmFsKSAsIExbaV0pIC0gdmFsLmJlZ2luKCkgKyAxOwogICAgICAgIFJbaV0gPSBsb3dlcl9ib3VuZChhbGwodmFsKSAsIFJbaV0pIC0gdmFsLmJlZ2luKCkgKyAxOwogICAgfQogICAgaWYgKHN1YjE6OmNoZWNrKCkpIHJldHVybiBzdWIxOjpzb2x2ZSgpOwogICAgaWYgKHN1YjM6OmNoZWNrKCkpIHJldHVybiBzdWIzOjpzb2x2ZSgpOwogICAgcmV0dXJuIHN1YjQ6OnNvbHZlKCk7Cn0KCiNkZWZpbmUgbmFtZSAiUk9BRFNJR05TIgoKaW50IG1haW4oKXsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgaWYgKGZvcGVuKG5hbWUiLklOUCIgLCAiciIpKXsKICAgICAgICBmcmVvcGVuKG5hbWUiLklOUCIgLCAiciIgLCBzdGRpbik7CiAgICAgICAgZnJlb3BlbihuYW1lIi5PVVQiICwgInciICwgc3Rkb3V0KTsKICAgIH0KICAgIGludCB0ID0gMTsgLy9jaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQo=