# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    int was = -1;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            was = i;
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H[H.size() - 1],line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            {
                pii P = {Q[Q[i][1]][1],Q[Q[i][1]][2]};
                if (Q[i][1] >= was)
                    t.erase(t.find(P));
                now.erase(now.find(P));
            }
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) > H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    int was = -1;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            was = i;
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H[H.size() - 1],line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            {
                pii P = {Q[Q[i][1]][1],Q[Q[i][1]][2]};
                if (Q[i][1] >= was)
                    t.erase(t.find(P));
                now.erase(now.find(P));
            }
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) < H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H.back(),line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            now.erase(now.find({Q[Q[i][1]][1],Q[Q[i][1]][2]}));
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) < H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H.back(),line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            now.erase(now.find({Q[Q[i][1]][1],Q[Q[i][1]][2]}));
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) > H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    line(void)
    {
        a = b = 0;
    }
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
const ll oo = (ll)(-3e18);
vector < line > t[1 << 22];
line * Hull[1 << 22];
int sz[1 << 22];
bool operator < (line A,line B)
{
    if (A.a != B.a) return A.a < B.a;
    return A.b < B.b;
}
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
ll get(int W,int V)
{
    if (!sz[W]) return oo;
    int l = 0,r = sz[W] - 1;
    while (l < r)
    {
        int m = (l + r) / 2;
        if (Hull[W][m].val(V) < Hull[W][m+1].val(V))
            l = m + 1;
        else
            r = m;
    }
    return Hull[W][l].val(V);
}
void update(int p,int u,int l,int r,line cnt,int node)
{
    if (l <= p && u <= r) t[node].push_back(cnt);
    else
    {
        int m = (p + u) / 2;
        if (l <= m) update(p,m,l,r,cnt,node << 1);
        if (m+1<=r) update(m+1,u,l,r,cnt,node << 1 | 1);
    }
}
void build(int p,int u,int node)
{
    vector < line > now = t[node];
    t[node].clear();
    sort(now.begin(),now.end());
    for (auto it : now)
    {
        int sz = t[node].size();
        while (sz >= 2 && inter(t[node][sz - 2],t[node][sz - 1],it)) t[node].pop_back(),--sz;
        t[node].push_back(it);
    }
    Hull[node] = new line[t[node].size() + 1];
    sz[node] = t[node].size();
    for (int i = 0;i < sz[node];++i)
        Hull[node][i] = t[node][i];
    t[node].clear();
    now.clear();
    if (p == u) return;
    int m = (p + u) / 2;
    build(p,m,node << 1);
    build(m+1,u,node << 1 | 1);
}
ll query(int p,int u,int v,int pos,int node)
{
    ll ans = get(node,v);
    if (p != u)
    {
        int m = (p + u) / 2;
        if (pos <= m) ans = max(ans,query(p,m,v,pos,node << 1));
        else ans = max(ans,query(m+1,u,v,pos,node << 1 | 1));
    }
    return ans;
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    static vi Q[1 << 20];
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = {op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = {op,v};
        }
    }
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 2)
        {
            int who = Q[i][1];
            was[who] = 1;
            update(1,n,who,i,line(Q[who][1],Q[who][2]),1);
        }
    for (int i = 1;i <= n;++i)
        if (!was[i] && Q[i][0] == 1)
            update(1,n,i,n,line(Q[i][1],Q[i][2]),1);
    build(1,n,1);
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 3)
        {
            const ll ans = query(1,n,Q[i][1],i,1);
            if (ans == oo)
                fo << "EMPTY SET\n";
            else
                fo << ans << '\n';
        }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 1500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    int was = -1;
    int sz = 0;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            was = i;
            now.clear();
            H.clear();
            sz = 0;
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (sz >= 2 && inter(H[sz - 2],H[sz - 1],line(it.x,it.y))) H.pop_back(),--sz;
                H.push_back(line(it.x,it.y));
                ++sz;
            }
        }
        if (Q[i][0] == 2)
            {
                pii P = {Q[Q[i][1]][1],Q[Q[i][1]][2]};
                if (Q[i][1] >= was)
                    t.erase(t.find(P));
                now.erase(now.find(P));
            }
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = sz - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) < H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
const ll oo = (ll)(-3e18);
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
bool operator < (line A,line B)
{
    if (A.a != B.a) return A.a < B.a;
    return A.b < B.b;
}
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
ll get(vector < line > H,int V)
{
    if (H.empty()) return oo;
    int l = 0,r = H.size() - 1;
    while (l < r)
    {
        int m = (l + r) / 2;
        if (H[m].val(V) < H[m+1].val(V))
            l = m + 1;
        else
            r = m;
    }
    return H[l].val(V);
}
vector < line > t[1 << 22];
void update(int p,int u,int l,int r,line cnt,int node)
{
    p2(mp(l,r));
    if (l > r) return ;
    if (l <= p && u <= r) t[node].push_back(cnt);
    else
    {
        int m = (p + u) / 2;
        if (l <= m) update(p,m,l,r,cnt,node << 1);
        if (m+1<=r) update(m+1,u,l,r,cnt,node << 1 | 1);
    }
}
void build(int p,int u,int node)
{
    vector < line > now = t[node];
    t[node].clear();
    sort(now.begin(),now.end());
    for (auto it : now)
    {
        int sz = t[node].size();
        while (sz >= 2 && inter(t[node][sz - 2],t[node][sz - 1],it)) t[node].pop_back(),--sz;
        t[node].push_back(it);
    }
    if (p == u) return;
    int m = (p + u) / 2;
    build(p,m,node << 1);
    build(m+1,u,node << 1 | 1);
}
ll query(int p,int u,int v,int pos,int node)
{
    ll ans = get(t[node],v);
    if (p != u)
    {
        int m = (p + u) / 2;
        if (pos <= m) ans = max(ans,query(p,m,v,pos,node << 1));
        else ans = max(ans,query(m+1,u,v,pos,node << 1 | 1));
    }
    return ans;
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    static vi Q[1 << 20];
    static int was[1 << 20];
    static int w[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = {op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = {op,v};
        }
        w[i] = w[i-1] + (Q[i][0] == 3);
    }
    for (int i = 1;i <= n;++i)
        cerr << w[i] << " \n"[i == n];
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 2)
        {
            int who = Q[i][1];
            was[who] = 1;
            update(1,w[n],w[who] + 1,w[i],line(Q[who][1],Q[who][2]),1);
        }
    for (int i = 1;i <= n;++i)
        if (!was[i] && Q[i][0] == 1)
            update(1,w[n],w[i] + 1,w[n],line(Q[i][1],Q[i][2]),1);
    build(1,w[n],1);
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 3)
        {
            const ll ans = query(1,w[n],Q[i][1],w[i],1);
            if (ans == oo)
                fo << "EMPTY SET\n";
            else
                fo << ans << '\n';
        }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) >= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    int was = -1;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            was = i;
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H[H.size() - 1],line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            {
                pii P = {Q[Q[i][1]][1],Q[Q[i][1]][2]};
                if (Q[i][1] >= was)
                    t.erase(t.find(P));
                now.erase(now.find(P));
            }
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) > H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
const ll oo = (ll)(-3e18);
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
bool operator < (line A,line B)
{
    if (A.a != B.a) return A.a < B.a;
    return A.b < B.b;
}
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
ll get(vector < line > H,int V)
{
    if (H.empty()) return oo;
    int l = 0,r = H.size() - 1;
    while (l < r)
    {
        int m = (l + r) / 2;
        if (H[m].val(V) < H[m+1].val(V))
            l = m + 1;
        else
            r = m;
    }
    return H[l].val(V);
}
vector < line > t[1 << 22];
void update(int p,int u,int l,int r,line cnt,int node)
{
    if (l <= p && u <= r) t[node].push_back(cnt);
    else
    {
        int m = (p + u) / 2;
        if (l <= m) update(p,m,l,r,cnt,node << 1);
        if (m+1<=r) update(m+1,u,l,r,cnt,node << 1 | 1);
    }
}
void build(int p,int u,int node)
{
    vector < line > now = t[node];
    t[node].clear();
    sort(now.begin(),now.end());
    for (auto it : now)
    {
        int sz = t[node].size();
        while (sz >= 2 && inter(t[node][sz - 2],t[node][sz - 1],it)) t[node].pop_back(),--sz;
        t[node].push_back(it);
    }
    if (p == u) return;
    int m = (p + u) / 2;
    build(p,m,node << 1);
    build(m+1,u,node << 1 | 1);
}
ll query(int p,int u,int v,int pos,int node)
{
    ll ans = get(t[node],v);
    if (p != u)
    {
        int m = (p + u) / 2;
        if (pos <= m) ans = max(ans,query(p,m,v,pos,node << 1));
        else ans = max(ans,query(m+1,u,v,pos,node << 1 | 1));
    }
    return ans;
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    static vi Q[1 << 20];
    static int was[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = {op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = {op,v};
        }
    }
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 2)
        {
            int who = Q[i][1];
            was[who] = 1;
            update(1,n,who,i,line(Q[who][1],Q[who][2]),1);
        }
    for (int i = 1;i <= n;++i)
        if (!was[i] && Q[i][0] == 1)
            update(1,n,i,n,line(Q[i][1],Q[i][2]),1);
    build(1,n,1);
    for (int i = 1;i <= n;++i)
        if (Q[i][0] == 3)
        {
            const ll ans = query(1,n,Q[i][1],i,1);
            if (ans == oo)
                fo << "EMPTY SET\n";
            else
                fo << ans << '\n';
        }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) <= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 1500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    int was = -1;
    int sz = 0;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            was = i;
            now.clear();
            H.clear();
            sz = 0;
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (sz >= 2 && inter(H[sz - 2],H[sz - 1],line(it.x,it.y))) H.pop_back(),--sz;
                H.push_back(line(it.x,it.y));
                ++sz;
            }
        }
        if (Q[i][0] == 2)
            {
                pii P = {Q[Q[i][1]][1],Q[Q[i][1]][2]};
                if (Q[i][1] >= was)
                    t.erase(t.find(P));
                now.erase(now.find(P));
            }
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = sz - 1;
            ll ans = -3e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) < H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
struct line
{
    int a,b;
    ll val(int x)
    {
        return 1ll * a * x + b;
    }
    line(int a,int b) : a(a),b(b) {}
};
int inter(line A,line B,line C)
{
    return (B.b - C.b) * 1ll * (C.a - A.a) >= (A.b - C.b) * 1ll * (C.a - B.a);
}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    IOS;
    fi>>n;
    const int block = 500;
    static vi Q[1 << 20];
    for (int i = 1;i <= n;++i)
    {
        int op;
        fi>>op;
        if (op == 1)
        {
            int a,b;
            fi>>a>>b;
            Q[i] = vi{op,a,b};
        }
        else
        {
            int v;
            fi>>v;
            Q[i] = vi{op,v};
        }
    }
    multiset < pair < int , int > > t,now;
    vector < line > H;
    for (int i = 1;i <= n;++i)
    {
        if (i % block == 1)
        {
            now.clear();
            H.clear();
            for (int j = i;j <= min(n,i + block - 1);++j)
                if (Q[j][0] == 2)
                    {
                        pii P = pii{Q[Q[j][1]][1],Q[Q[j][1]][2]};
                        if (Q[j][1] < i)
                            t.erase(t.find(P)),now.insert(P);
                    }
            for (auto it : t)
            {
                while (H.size() >= 2 && inter(H[H.size() - 2],H[H.size() - 1],line(it.x,it.y))) H.pop_back();
                H.push_back(line(it.x,it.y));
            }
        }
        if (Q[i][0] == 2)
            now.erase(now.find({Q[Q[i][1]][1],Q[Q[i][1]][2]}));
        else
        if (Q[i][0] == 1)
        {
            t.insert({Q[i][1],Q[i][2]});
            now.insert({Q[i][1],Q[i][2]});
        }
        else
        {
            if (now.empty() && H.empty()) {fo << "EMPTY SET\n";continue;}
            const int V = Q[i][1];
            int l = 0,r = H.size() - 1;
            ll ans = -1e18;
            for (auto it : now)
                ans = max(ans,1ll * it.x * V + it.y);
            while (l < r)
            {
                int m = (l + r) / 2;
                if (H[m].val(V) > H[m+1].val(V))
                    l = m + 1;
                else
                    r = m;
            }
            if (!H.empty()) ans = max(ans,H[l].val(V));
            fo << ans << '\n';
        }
    }
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 87654321
#define IINF 1987654321987654321
#define MOD 1000000007

const int MAXN = 3e5 + 50;
vector<Pll> tree[4*MAXN];
void add(int x, int y, Pll p, int l, int r, int id) {
	if(x <= l && r <= y) {
		tree[id].push_back(p);
		return;
	}
	if(r < x || y < l) return;
	int mid = (l + r) / 2;
	add(x, y, p, l, mid, 2*id);
	add(x, y, p, mid+1, r, 2*id+1);
}

int q, n;
int tin[MAXN], tout[MAXN];
ll x[MAXN];
Pll line[MAXN];
void readInput() {
	scanf("%d", &q);
	repp(i, q) {
		int t; scanf("%d", &t);
		if(t == 1) {
			scanf("%lld%lld", &line[i].first, &line[i].second);
			tin[i] = n+1;
		} else if(t == 2) {
			int li; scanf("%d", &li);
			tout[li] = n;
		} else {
			scanf("%lld", &x[++n]);
		}
	}
	repp(i, q) {
		if(tin[i]) {
			if(!tout[i]) tout[i] = n;
			add(tin[i], tout[i], line[i], 1, n, 1);
		}
	}
}

inline bool ok(Pll &a, Pll &b, Pll &c) {
	return (a.second - c.second) * (b.first - a.first) > (a.second - b.second) * (c.first - a.first);
}

void findConvexHull(int l, int r, int id) {
	vector<Pll> hull;
	sort(tree[id].begin(), tree[id].end(), [&](const Pll &a, const Pll &b) {
		return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
	});
	ll sl = -IINF;
	for(auto &e : tree[id]) {
		if(e.first == sl) continue;
		sl = e.first;
		while((int)hull.size() >= 2 && !ok(hull[(int)hull.size()-2], hull.back(), e))
			hull.pop_back();
		hull.push_back(e);
	}
	tree[id] = hull;

	if(l < r) {
		int mid = (l + r) / 2;
		findConvexHull(l, mid, 2*id);
		findConvexHull(mid+1, r, 2*id+1);
	}
}

inline ll yval(ll x, Pll l) {
	return l.first * x + l.second;
}

ll solve(int p, int l, int r, int id) {
	if(p < l || r < p) return -IINF;
	ll mx = -IINF;
	int s = 0, e = (int)tree[id].size()-1;
	while(s < e) {
		int m = (s + e) / 2;
		if(yval(x[p], tree[id][m]) < yval(x[p], tree[id][m+1]))
			s = m+1;
		else
			e = m;
	}
	if(!tree[id].empty()) mx = max(mx, yval(x[p], tree[id][s]));
	if(l < r) {
		int mid = (l + r) / 2;
		mx = max(mx, solve(p, l, mid, 2*id));
		mx = max(mx, solve(p, mid+1, r, 2*id+1));
	}
	return mx;
}

int main() {
	readInput();
	findConvexHull(1, n, 1);
	repp(i, n) {
		ll val = solve(i, 1, n, 1);
		if(val == -IINF) printf("EMPTY SET\n");
		else printf("%lld\n", val);
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 87654321
#define IINF 1987654321987654321
#define MOD 1000000007

const int MAXN = 3e5 + 50;
vector<Pll> tree[4*MAXN];
void add(int x, int y, Pll p, int l, int r, int id) {
	if(x <= l && r <= y) {
		tree[id].push_back(p);
		return;
	}
	if(r < x || y < l) return;
	int mid = (l + r) / 2;
	add(x, y, p, l, mid, 2*id);
	add(x, y, p, mid+1, r, 2*id+1);
}

int q, n;
int tin[MAXN], tout[MAXN];
ll x[MAXN];
Pll line[MAXN];
bool isEmpty[MAXN];
void readInput() {
	scanf("%d", &q);
	int cnt = 0;
	repp(i, q) {
		int t; scanf("%d", &t);
		if(t == 1) {
			scanf("%lld%lld", &line[i].first, &line[i].second);
			tin[i] = n+1;
			cnt++;
		} else if(t == 2) {
			int li; scanf("%d", &li);
			tout[li] = n;
			cnt--;
		} else {
			scanf("%lld", &x[++n]);
			if(cnt == 0) isEmpty[n] = true;
		}
	}
	repp(i, q) {
		if(tin[i]) {
			if(!tout[i]) tout[i] = n;
			add(tin[i], tout[i], line[i], 1, n, 1);
		}
	}
}

inline bool ok(Pll &a, Pll &b, Pll &c) {
	return (a.second - c.second) * (b.first - a.first) >= (a.second - b.second) * (c.first - a.first);
}

void findConvexHull(int l, int r, int id) {
	vector<Pll> hull;
	sort(tree[id].begin(), tree[id].end(), [&](const Pll &a, const Pll &b) {
		return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
	});
	ll sl = -IINF;
	for(auto &e : tree[id]) {
		if(e.first == sl) continue;
		sl = e.first;
		while((int)hull.size() >= 2 && !ok(hull[(int)hull.size()-2], hull.back(), e))
			hull.pop_back();
		hull.push_back(e);
	}
	tree[id] = hull;

	if(l < r) {
		int mid = (l + r) / 2;
		findConvexHull(l, mid, 2*id);
		findConvexHull(mid+1, r, 2*id+1);
	}
}

inline ll yval(ll x, Pll l) {
	return l.first * x + l.second;
}

ll solve(int p, int l, int r, int id) {
	if(p < l || r < p) return -IINF;
	ll mx = -IINF;
	int s = 0, e = (int)tree[id].size()-1;
	while(s < e) {
		int m = (s + e) / 2;
		if(yval(x[p], tree[id][m]) < yval(x[p], tree[id][m+1]))
			s = m+1;
		else
			e = m;
	}
	if(!tree[id].empty()) mx = max(mx, yval(x[p], tree[id][s]));
	if(l < r) {
		int mid = (l + r) / 2;
		mx = max(mx, solve(p, l, mid, 2*id));
		mx = max(mx, solve(p, mid+1, r, 2*id+1));
	}
	return mx;
}

int main() {
	readInput();
	findConvexHull(1, n, 1);
	repp(i, n) {
		if(isEmpty[i]) printf("EMPTY SET\n");
		else printf("%lld\n", solve(i, 1, n, 1));
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;

#define rep(pos, len) for(int pos=0;pos<len;pos++)
#define repp(pos, len) for(int pos=1;pos<=len;pos++)

#define INF 87654321
#define IINF 1987654321987654321
#define MOD 1000000007

const int MAXN = 3e5 + 50;
vector<Pll> tree[4*MAXN];
void add(int x, int y, Pll p, int l, int r, int id) {
	if(x <= l && r <= y) {
		tree[id].push_back(p);
		return;
	}
	if(r < x || y < l) return;
	int mid = (l + r) / 2;
	add(x, y, p, l, mid, 2*id);
	add(x, y, p, mid+1, r, 2*id+1);
}

int q, n;
int tin[MAXN], tout[MAXN];
ll x[MAXN];
Pll line[MAXN];
bool isEmpty[MAXN];
void readInput() {
	scanf("%d", &q);
	int cnt = 0;
	repp(i, q) {
		int t; scanf("%d", &t);
		if(t == 1) {
			scanf("%lld%lld", &line[i].first, &line[i].second);
			tin[i] = n+1;
			cnt++;
		} else if(t == 2) {
			int li; scanf("%d", &li);
			tout[li] = n;
			cnt--;
		} else {
			scanf("%lld", &x[++n]);
			if(cnt == 0) isEmpty[n] = true;
		}
	}
	repp(i, q) {
		if(tin[i]) {
			if(!tout[i]) tout[i] = n;
			if(tin[i] <= tout[i]) add(tin[i], tout[i], line[i], 1, n, 1);
		}
	}
}

inline bool ok(Pll &a, Pll &b, Pll &c) {
	return (b.first - a.first) * (c.second - b.second) <= (b.first - c.first) * (a.second - b.second);
}

void findConvexHull(int l, int r, int id) {
	vector<Pll> hull;
	sort(tree[id].begin(), tree[id].end(), [&](const Pll &a, const Pll &b) {
		return make_pair(a.first, -a.second) < make_pair(b.first, -b.second);
	});
	ll sl = -IINF;
	for(auto &e : tree[id]) {
		if(e.first == sl) continue;
		sl = e.first;
		while((int)hull.size() >= 2 && !ok(hull[(int)hull.size()-2], hull.back(), e))
			hull.pop_back();
		hull.push_back(e);
	}
	tree[id] = hull;

	if(l < r) {
		int mid = (l + r) / 2;
		findConvexHull(l, mid, 2*id);
		findConvexHull(mid+1, r, 2*id+1);
	}
}

inline ll yval(ll x, Pll l) {
	return l.first * x + l.second;
}

ll solve(int p, int l, int r, int id) {
	if(p < l || r < p) return -IINF;
	ll mx = -IINF;
	int s = 0, e = (int)tree[id].size()-1;
	while(s < e) {
		int m = (s + e) / 2;
		if(yval(x[p], tree[id][m]) < yval(x[p], tree[id][m+1]))
			s = m+1;
		else
			e = m;
	}
	if(!tree[id].empty()) mx = max(mx, yval(x[p], tree[id][s]));
	if(l < r) {
		int mid = (l + r) / 2;
		if(p <= mid) mx = max(mx, solve(p, l, mid, 2*id));
		else mx = max(mx, solve(p, mid+1, r, 2*id+1));
	}
	return mx;
}

int main() {
	readInput();
	findConvexHull(1, n, 1);
	repp(i, n) {
		if(isEmpty[i]) printf("EMPTY SET\n");
		else printf("%lld\n", solve(i, 1, n, 1));
	}
}


#include<bits/stdc++.h>
#define TP int
#define Max 88888
using namespace std;
inline TP read(){
    char c=getchar();
    TP x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f)x=-x;return x;
}
inline double readdouble(){
    char c=getchar();
    double x=0;
    bool f=0;
    while(!isdigit(c))f^=!(c^45),c=getchar();
    while(isdigit(c))x=x*10+(c^48),c=getchar();
    if(!(c^46)){
        double t=1;c=getchar();
        while(isdigit(c))t/=10,x+=t*(c^48),c=getchar();
    }if(f)x=-x;return x;
}
inline bool blank(char c){return !(c&&c^9&&c^10&&c^13&&c^32);}
inline void readstr(char *s){
    char c=getchar();
    while(blank(c))c=getchar();
    while(!blank(c))*s++=c,c=getchar();*s=0;
}
inline bool isendl(char c){return !(c&&c^10&&c^13);}
inline void getstr(char *s){
    char c=getchar();
    while(isendl(c))c=getchar();
    while(!isendl(c))*s++=c,c=getchar();*s=0;
}
int a[Max],x[Max],n=read();
bool flag=false;
int main(){
	for(int i=0;i<n;i++){
		a[i]=read();
		x[i]=read();
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i]){
					flag=true;
					break;
				}
			}
		}
	}
	if(flag==true){
		puts("YES");
	}
	else if(flag==false){
		puts("NO");
	}
    return 0;
}


#include<cstdio>
using namespace std;
int n,x[1010],d[1010];
int a[1010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&d[i]);
		a[i]=x[i]+d[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(x[i]==a[j]&&a[i]==x[j])
			{
				printf("YES");
				return 0;
			}
		}
	}
	printf("NO");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x[101],d[101];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i]>>d[i];
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
			{
				cout<<"YES";return 0;
			 }
		}
	}
	cout<<"NO";
	return 0;
}


#include<iostream>
#include<cstdio>
#include<alogathram>
using namespace std;
int x[1205],d[1205];
int main()
{
    int n;
    cin>>n;
    bool flag=false;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>d[i];
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(x[i]+d[i]==x[j]&&x[i]==x[j]+d[j])
                flag=true;
        }
    }
    if(flag)
    {
    	cout<<"YES";
    	return 0;
	}
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,f=0,x[10000],d[10000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	  cin>>x[i]>>d[i];
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=n;j++)
	    if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
		  {f=1;break;}
	if(f==1)cout<<"YES";
	else cout<<"NO";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int i,j,a[1001],x[1001],n;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i]>>x[i];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
				{
					cout<<"YES";
					return 0;
				}
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
struct luotuo{
    int x,d;
}lt[105];
bool cmp(const luotuo a,const luotuo b){
    return a.x<b.x;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&lt[i].x,&lt[i].d);
    }
    sort(lt+1,lt+n+1,cmp);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if((lt[i].x+lt[i].d==lt[j].x)&&(lt[j].x+lt[j].d==lt[i].x)){
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[20001];
	memset(a,0,sizeof(a));
	for (int i=0;i<n;i++)
	{
		int temp;
		cin>>temp;
		temp+=10000;
		cin>>a[temp];
	}
	for (int i=0;i<20001;i++)
		if (a[i])
		{
			if (i+a[i]>10000||i+a[i]<-10000)continue;
			if (a[i+a[i]]==-a[i])
			{
				cout<<"YES";
				return 0;
			}
		}
	cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e2+5;
int x[MAXN],d[MAXN];
int main(){
    int n;
    scanf ("%d",&n);
    for (int i=0;i<n;i++)
        scanf ("%d%d",x+i,d+i);
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (x[i]+d[i]==x[j]&&x[j]+d[j]==x[i]){
                printf ("YES")
                return 0;
            }
    printf ("NO");
    return 0;
}


#include<iostream>
using namespace std;
struct wdnmd
{
	int wz,jl;
	bool ok;
};
int main()
{
	int n;
	cin>>n;
	wdnmd a[n];
	for(int i=0;i<n;i++)
	cin>>a[i].wz>>a[i].jl;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		if(a[i].wz+a[i].jl==a[j].wz)
		{
			if(a[j].wz+a[j].jl==a[i].wz)
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;

}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,a[111111],b[111111];
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i])
	{
	cout<<"YES";
	return 0;
	}
	cout<<"NO";
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n;
int x[1000],d,b;
int main(){
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x[i]>>d;
		b=x[i]+d;
		for(j=1;j<i;j++){
			if(b==x[j]){
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define N 110
using namespace std;
int n, flag = 0;
struct Node {
	int x, d;
}c[N];
bool cmp(Node a, Node b) {
	return a.x < b.x;
}
int main()
{
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> c[i].x >> c[i].d;
	sort(c + 1, c + n + 1, cmp);
	for(int i = 1; i <= n; ++i) {
		if(c[i].d > 0) {
			int j = i + 1;
			while(j <= n && c[j].x < c[i].x + c[i].d) {
				j++;
			}
			if(j <= n && c[j].x + c[j].d == c[i].x) {
				flag = 1;
				break;
			}
		}
	}
	if(flag)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


#include<iostream>

using namespace std;

int a[100],b[100];
int main(){
	int i,j,n,x,d,k=0,t=0;
	cin>>n;
	for( i=0;i<n;i++){
		cin>>a[i]>>b[i];

	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			if(a[i]+b[i]==a[j]&&a[i]==a[j]+b[j]){
				cout<<"Yes";
				return 0;
			}
	}
	cout<"No";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,j,n;
    cin>>n;
    int a[n],b[n];
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    for(i=0;i<n;i++)
        for(j=0;j<n;j++){
            if(i==j)continue;
            if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i]){cout<<"YES"<<endl;return 0;}
        }
        cout<<"NO"<<endl;
        return 0;
}


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

int a[10005],b[10005];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	bool flag=false;
	for(int i=1;i<n;i++) {
		for(int j=i+1;j<=n;j++) {
			if(a[i]+b[i]==a[j] && a[i]==a[j]+b[j]) flag=true;
		}
	}
	if(flag) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include <iostream>
using namespace std;
struct lt{
	int x;
	int d;
	int q;
	int h;
};
int main(){
	int i,j,n;
	cin>>n;
	lt a[n+1];
	for(i=1;i<=n;i++){
		cin>>a[i].x>>a[i].d;
		a[i].q=a[i].x-a[i].d;
		a[i].h=a[i].x+a[i].d;
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if((a[i].h==a[j].q)||(a[i].q==a[j].h)){
				cout<<"NO";
				return 0;
			}
		}
	}
	cout<<"YES";
	return 0;
}


#include <iostream>//头文件
using namespace std;//名字空间
int a[10000],x[10000];//定义两个数组
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>x[i];
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        if(i!=j)
        {
            if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[103],f[103];
int main ()
{
	int n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	 cin>>a[i]>>f[i];
	for(i=1;i<=n;i++)
	  for(j=1;j<=n;j++)
	{
		if(a[i]!=a[j])
		if(a[i]+f[i]==a[j] && a[j]+f[j]==a[i])
		{
			cout<<"YES";return 0;
		}
	}
	cout<<"NO";

	return 0;
}


#include<iostream>
using namespace std;
bool f[20001],f1;
int main()
{
    int n,a[101],b[101],i;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        f[b[i]]=1;
    }
    for(i=1;i<=n;i++)
    {
        if(f[a[i]+b[i]])
            f1=1;
    }
    if(!f1)
        cout<<"NO";
    else
        cout<<"YES";
    return 0;
}


#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin>>n;
	int a[n],x[n];
	for(int i=0;i<n;i++)
	cin>>a[i]>>x[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				{if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
				cout<<"yes";
				return; 0}
			}
		}
	}
	cout<<"no";
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<ctime>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#define ll long long
using namespace std;
int a[10001],x[10001];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>x[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
    	    if(i!=j)
    	    {
    	        if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
    	        {
    	            printf("YES");
					return 20030711;
   		        }
    	    }
    	}
    }
    printf("NO");
    return 0;
}


#include<iostream>
using namespace std;
int a[101];
int b,c,i,x,s=0;
int main(){
	cin>>x;
	for(i=1;i<=x;i++){
		cin>>b>>c;
		a[b+c]++;
	}
	for(i=1;i<=101;i++){
		if(a[i]>1){
			s++;
		}
	}
	if(s>0){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}


#include<bits/stdc++.h>
using namespace std;
int a[105],b[105];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j&&a[i]+b[i]==a[j]&&a[j]+b[j]==a[i])
			{
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int x1,d1,x2,d2;
    scanf("%d%d%d%d",&x1,&d1,&x2,&d2);
    if((x1+d1)==x2&&(x2+d2)==x1){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    double x,a,b,c,d;
    cin>>x>>a>>b>>c>>d;
    x*x>=(a-c)*(a-c)+(b-d)*(b-d)?cout<<"YES":cout<<"NO";
}


#include <iostream>

using namespace std;

int a[100010], b[100010];

int main() {
	int n; cin >> n;
	for (register int i = 0; i < n; i ++)
		cin >> a[i] >> b[i];
	for (register int i = 0; i < n; i ++)
		for (register int j = 0; j < n; j ++)
			if (i != j && a[i] + b[i]  == j && i == a[j] + b[j]) {
				cout << "YES" << endl;
				return 0;
			}
	cout << "NO" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int x[1010];
int d[1010];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i]>>d[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)
			{
				if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
				{
					cout<<"YES";
					return 0;
				}
			}
	cout<<"NO";
    return 0;
}


#include<iostream>
using namespace std;
int a[1000],b[1000];
int main()
{
    int n;
    cin>>n;
    bool f=0;
    for(int i=1;i<=n;i++){cin>>a[i]>>b[i];}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j!=i){
                if(a[i]+b[i]==a[j]){
                    f=1;
                }
            }
        }
    }
    if(f){
        cout<<"YES";
        else
        cout<<"NO";
        return 0;
    }
}


#include <bits/stdc++.h>

using namespace std;

int a[10000],b[10000],xsh=0;

int main()
{
	int n;
	cin>>n;

	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
	}

	for(int j=1;j<=n;j++)
	{
		for(int i=j+1;i<=n;i++)
		{
			if(b[j]+a[j]==a[i] && b[i]+a[i]==a[j]) xsh++;
		}
	}

	if(xsh==0) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin>>n;
	int a[n],x[n];
	for(int i=0;i<n;i++)
	cin>>a[i]>>x[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
				{cout<<"yes";
				return 0;}
			}
		}
	}
	cout<<"no";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10001]={0},b[10001]={0};
int main()
{
	int x,y,i,n,j,k;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	for(i=1;i<=n;i++)
	x=a[i]+b[i];
	y=a[i];
	for(j=1;j<=n;j++)
	if (x==a[j])
	{
		cout<<"YES";
		return 0;
	}
	else
	    cout<<"NO";
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<cstring>
#include<string>
using namespace std;
int a[105],d[105];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&a[i],&d[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]+d[i]==a[j]&&a[j]+d[j]==a[i]){
                printf("YES\n");
                return 0;
            }
		}
	}
	printf("NO\n");
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n,x[10001],d[10001],i,j,ans=0;
    cin>>n;
    for(i=1;i<=n;i++){
    cin>>x[i];
    cin>>d[i];
    }
    for(i=1;i<=n;i++){
    for(j=1;j<=n;j++)
    {
        if(i!=j){
    if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
    {
        ans++;
    }
    }
    }
    }
    if(ans>0) cout<<"YES";
    else cout<<"NO";
    return 0;


#include<bits/stdc++.h>
using namespace std;
struct ele
{
	int x, d;
};
int n;
ele k[101];
bool bo = 0;
int main(){
	memset(k, 0, sizeof(k));
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &k[i].x, &k[i].d);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j < i; j++)
			if (k[i].x + k[i].d == k[j].x && k[j].x + k[j].d == k[i].x) bo = 1;
	if (bo) printf("YES\n");
	else printf("NO\n");
	return 0;
}


#include<iostream>

using namespace std;

int a[100],b[100];
int main(){
	int i,j,n,x,d,k=0,t=0;
	cin>>n;
	for( i=0;i<n;i++){
		cin>>a[i]>>b[i];

	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			if(a[i]+b[i]==a[j]&&a[i]==a[j]+b[j]){
				cout<<"Yes";
				return 0;
			}
	}
	cout<<"No";
	return 0;
}


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

int n;
int a[101],b[101];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(int i=1;i<n;i++)
	    for(int j=i+1;j<=n;j++)if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i]){cout<<"YES"<<endl;return 0;}
	cout<<"NO"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct node {
	int x,d;
} a[105];
int n,ans,x,d;
bool cmp(node a,node b) {
	return a.x < b.x;
}
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i].x >> a[i].d;
	sort(a + 1,a + n + 1,cmp);
	for(int i = 1; i < n; i++)
		for(int j = i + 1; j <= n; j++)
			if(a[i].x + a[i].d == a[j].x && a[j].x + a[j].d == a[i].x) {
				cout << "YES";
				return 0;
			}
	cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x[105],d[105];
int main()
{
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>d[i];
	}
	for(int i=1;i<=n;i++)
	{
		int a=x[i]+d[i];
		int b=x[a]+d[a];
		if(b==x[i])
		{
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,i,j;
struct qqq{
	int a,b;
}q[105];
int main(){
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>q[i].a>>q[i].b;
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			if(q[i].a+q[i].b==q[j].a&&q[j].a+q[j].b==q[i].a){
				cout<<"YES"<<endl;
				return 0;
		}
	cout<<"NO"<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[101],b[101];
	bool flag=false;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(b[i]*b[j]<0)
			{
				if(b[i]>0&&b[j]<0&&a[i]<=a[j])
				{
					if(a[i]+b[i]>=a[j]&&a[j]+b[j]<=a[i])
					{
						flag=true;
						break;
					}
				}
				else if(b[i]<0&&b[j]>0&&a[i]>=a[j])
				{
					if(a[i]+b[i]<=a[j]&&a[j]+b[j]>=a[i])
					{
						flag=true;
						break;
					}
				}
			}
		}
		if(flag==true) break;
	}
	if(flag==false) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b[1000000],c[100000];
int main()
{
	cin>>a;
	for(int i=0;i<=a;i++)
	{
		cin>>b[i]>>c[i];
		if(b[i]+c[i]>=b[i+1])
		{

		cout<<"YES";
		break;
	}
		else
		{
			i++;
		}
		while(i<=a)
		{
			cout<<"NO";
		}
	}

	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int a[10000];
	int b[10000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < n; i++)
	{
		int num = a[i] + b[i];
		int x = a[i];
		for (int j = 0; j < n; j++)
		{
			if (num == a[j])
			{
				if (a[j] + b[j] == x)
				{
					cout << "YES";
					return 0;
				}
			}
		}
	}
	cout << "NO";
}


#include<bits/stdc++.h>

using namespace std;

int n,d[20010],x[10010];

void init()
{
	cin>>n;

	for(int i=0;i<n;i++)
	{
		cin>>x[i];

		cin>>d[i];
	}
		for(int i=0;i<n;i++)
		{

			for(int j=0;j<n;j++)

			if(i!=j)
			{
				if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
				{
					cout<<"YES";
				}
				else cout<<"NO";
			}
		}

}

int main(void)
{
	init();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int pos[10010],tu[10010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&pos[i],&tu[i]);
    }
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;i++)
	if(i!=j)
	{
		if(pos[i]+tu[i]==pos[j]&&pos[j]+tu[j]==pos[i])
	    {
		    printf("YES");
		    return 0;
	    }
	}
	printf("NO");
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <windows.h>
#include <cstring>
#include <bits/stdc++.h>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <fstream>
#include <climits>
#include <clocale>
#include <cstdlib>
#include <bitset>
#include <ctime>
#include <cerrno>
#include <complex>
#include <deque>
#include <map>
#include <ios>
#include <functional>
#include <limits>
#include <limits>
#include <list>
#include <iomanip>
#include <iosfwd>
#include <istream>
#include <ostream>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <utility>
#include <cwchar>
#include <cwctype>
//#include <fenv.h>
//#include <cinttypes>
//#include <cstdint>
//#include <ctgmath>
using namespace std;
int main()
{
	int n,a = 0;
	int x[10001],d[10001];
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
	{
		scanf("%d%d",&x[i],&d[i]);
	}
	for(int i = 1;i < n;i++)
	{
		for(int j = 1;j <= n;j++)
		{
			if(i != j)
			{
				if(x[i] + d[i] == x[j] && x[j] + d[j] == x[i])
				{
					printf("YES");
					return 0;
				}
			}
		}
	}
	printf("NO");
	return 0;
}


#include<iostream>
using namespace std;
int a[1000],b[1000];
int main()
{
    int n;
    cin>>n;
    bool f=0;
    for(int i=1;i<=n;i++){cin>>a[i]>>b[i];}
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j!=i){
                if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i]){
                    f=1;
                }
            }
        }
    }
    if(f)
        cout<<"YES";
    else
        cout<<"NO";
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int a[100001],b[100001],t;
int main(){
	int n;
	cin>>n;
	int i,j;
	for(i=1;i<=n;i++)
		cin>>a[i]>>b[i];
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
		if(i!=j)
        {
            if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i])
            {
                cout<<"YES";
                return 0;
            }
        }
		}
	}

		 cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    int x[n+1],d[n+1];
    for(int i=1;i<=n;i++){
    	cin>>x[i]>>d[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j&&x[i]+d[i]==x[j]&&x[j]+d[j]==x[i]){
				cout<<"YES";
				return 0;
			}
	cout<<"NO";
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    int a[1001]={0},b[1001]={0};
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i]>>b[i];
    for(int i=1;i<=n;i++)
    {
    	int num=a[i]+b[i];
    	int place=a[i];
    	for(int j=1;j<=n;j++)
    	{
    		if(num==a[j])
    		{
    			if(a[j]+b[j]==place)
    			{
    				cout<<"YES";
    				return 0;
    			}
    		}
    	}
    }
    cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int camel[n],spit[n];
	for(int i=0;i<n;i++)
	{
		cin>>camel[i]>>spit[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i!=j)
			{
				if((camel[i]+spit[i]==camel[j])&&(camel[j]+spit[j]==camel[i]))
				{
					cout<<"YES";
					return 0;
				}
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int n;bool pla[110];
int dd[110];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,d;
		scanf("%d%d",&x,&d);
		pla[x]=1;
		dd[x]=d;
	}
	for(int i=1;i<=n;i++)
	{
		if(i+dd[i]>n||i+dd[i]<1)continue;
		if(pla[i+dd[i]]==1&&i+dd[i]+dd[i+dd[i]]==i)
		{
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout<<"YES";
    return 0;
}


#include <iostream>
using namespace std;
int a[10005],x[10005];
int main(){
    int n,i,j;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i]>>x[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++)
        if(i!=j){
            if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i]){
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<int,int>a;
int x[105],y[105];
int main()
{
    int n,i,t;
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>x[i]>>y[i];
        a[x[i]]=1;
    }
    for(i=1;i<=n;++i)
    {
        t=x[i]+y[i];
        if(a.find(t)!=a.end()) {cout<<"YES"; return 0;}
    }
    cout<<"NO";
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;
int n;
struct luotuo{
  int x;
  int d;
}lt[105];
bool cmp(const luotuo a,const luotuo b)
{return(a.x<b.x);
}
int main()
{cin>>n;
 for(int i=1;i<=n;i++)
   cin>>lt[i].x>>lt[i].d;
 sort(lt+1,lt+n+1,cmp);
 for(int i=1;i<=n;i++){
   for(int j=i+1;j<=n;j++){
     if((lt[i].x+lt[i].d==lt[j].x) && (lt[j].x+lt[j].d==lt[i].x)){
       cout<<"YES"<<endl;
     }
   }
 }
 cout<<"NO"<<endl;
 return 0;
}


#include<iostream>
using namespace std;

struct Camel {
    int x, d;

    bool operator == (const Camel& c) const {
        return x + d == c.x || c.x + c.d == x;
    }
};

Camel c[105];

int main() {
    int n;

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> c[i].x >> c[i].d;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(i != j && c[i] == c[j]) {
                cout << "YES" << endl;

                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a,b,x[105],y[105];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>x[i]>>y[i];
	for(int i=1;i<=n;++i){
		a=x[i]+y[i];
		for(int j=1;j<=n;++j){
			if (a==x[j])b=x[j]+y[j];
		}
		if (b==x[i]){cout<<"YES"<<endl;return 0;}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >>n;
	int a[n+2],b[n+2],c[n+2];
	a[0]=b[0]=c[0]=a[n+1]=b[n+1]=c[n+1]=-2147483647;
	for (int i=1;i<=n;i++)
	{
		cin >>a[i]>>b[i];
		c[i]=a[i]+b[i];
	}
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
		{
			if (c[j]>c[i]){
				swap(c[j],c[i]);
				swap(b[j],b[i]);
				swap(a[j],a[i]);
			}
		}
	bool flag=false;
	for (int i=1;i<=n;i++)
		if (c[i]==a[i+1]||c[i]==a[i-1])
			flag=true;
	if (flag==true)
		cout <<"YES"<<endl;
	else
		cout <<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
using namespace std;
int n,sum=0,x[10005],d[20005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>d[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
					sum++;
				if(sum==2)
				{
					cout<<"YES";
					return 0;
				}
			}
		}
	cout<<"NO";
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
int a[10005],b[10005];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(a[i]+b[i]==a[j]&&a[j]+b[j]==a[i])
				{
					cout<<"YES";
					return 0;
				}
			}
		}
	}
	cout<<"NO";
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
map<int,int>a;
int x[105],y[105];
int main()
{
    int n,i,t,ans=0;
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>x[i]>>y[i];
        a[x[i]]=1;
    }
    for(i=1;i<=n;++i)
    {
        t=x[i]+y[i];
        if(a.find(t)!=a.end()) ans++;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
int x[101],d[101];
int main()
{
	cin >> n;
	for (int i = 1;i <= n;i++)
	    cin >> x[i] >> d[i];
	for (int i = 1;i <= n;i++)
	    for (int j = 1;j <= n;j++)
	        if (i != j && i + d[i] == j && j + d[j] == i)
	        {
	        	cout << "YES";
	        	return 0;
			}
	cout << "NO";
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[10000],x[10000];
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i]>>x[i];
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        if(i!=j)
        {
            if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include <iostream>
using namespace std;

int a[1200], b[1200];
int main()
{
	int n;
	cin >> n;
	bool flag = false;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (a[i] + b[i] == a[j] && a[i] == a[j] + b[j])
				flag = 1;
		}
	}
	if (flag)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool flag[10100];
int place[10100];
int jl[10100];
int num[10100];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>place[i]>>jl[i];
		num[place[i]]=i;
		flag[place[i]]=true;
	}
	for(int i=1;i<=n;i++)
	{
		int x=place[i]+jl[i];
		//cout<<x<<endl;
		if(flag[x]==false)
		continue;
		//cout<<jl[i]<<endl;
		if(jl[i]<0)
		{
			if(jl[num[x]]<0||jl[num[x]]!=abs(jl[i]))
			continue;
			cout<<"YES"<<endl;
			return 0;
		}
		else
		{
			//cout<<jl[num[x]]<<"     当I="<<x<<endl;
			if(jl[num[x]]>0||abs(jl[num[x]])!=jl[i])
			continue;
			cout<<"YES"<<endl;
			return 0;
		}
	}
	cout<<"NO"<<endl;
	return 0;
}
/*
2
0 5
5 -5
*/


#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
int a[100000],d[100000],s,c,p1,p2;
int n,m,i,x,y,t,j;
double z,sum;
int main()
{         cin>>n;
     for(i=0;i<n;i++){
         cin>>a[i]>>d[i];
     }
     for(i=0;i<n-1;i++){
         if(a[i]+d[i]==a[i+1]&&a[i+1]+d[i+1]==a[i]&&a[i]!=a[i+1]){cout<<"YES"<<endl;return 0;}
     }
       cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[1200],b[1200];
int main(){
    int n;
    cin>>n;
    bool flag=0;
    for (int i=1;i<=n;i++) cin>>a[i]>>b[i];
    for (int i=1;i<n;i++){
        for (int j=i+1;j<=n;j++){
            if (a[i]+b[i]==a[j] and a[i]==a[j]+b[j])
                flag=1;
        }
    }
    if (flag==1) cout<<"YES";
    else cout<<"NO";
    return 0;
}


#include<iostream>
using namespace std;
long long a[101],d[101],n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>d[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        	if(i!=j)
				if(a[i]+d[i]==a[j]&&a[j]+d[j]==a[i])
            	{
                	cout<<"YES";return 0;
            	}
    cout<<"NO";return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int d[1000005],x[1000005],n;
    cin<<n;
    for(int i=1;i<=n;i++)
       cin<<x[i]<<d[i];
//{
    for(int i=1;i<=n;i++)
         for(int j=i;j<=n;j++)
         {
             if(i==j)continue;
if(a[j]+d[j]==a[i]&&a[i]+d[i]==a[j])
{
    cout>>"YES";
    return 0;
}
         }
         cout>>"NO";
}


#include<bits/stdc++.h>
using namespace std;
int a[10010],x[10010];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]>>x[i];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        if(i!=j&&a[i]+x[i]==a[j]&&a[j]+x[j]==a[i])
        {
            cout<<"YES";
            return 0;
        }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,x[105],d[105];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i]>>d[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j&&x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
			{
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e2+5;
int x[MAXN],d[MAXN];
int main(){
    int n;
    scanf ("%d",&n);
    for (int i=0;i<n;i++)
        scanf ("%d%d",x+i,d+i);
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (x[i]+d[i]==x[j]&&x[j]+d[j]==x[i]){
                printf ("YES");
                return 0;
            }
    printf ("NO");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct camel
{
    int p,range;
}c[101];
int n,i,j,x;
int main()
{
    cin >> n;
    while(n--)
    {
        x++;
        cin >> c[x].p >> c[x].range;
    }
    for(i=1;i<=x;i++)
    {
        for(j=i+1;j<=x;j++)
        {
            if(c[i].p+c[i].range==c[j].p&&c[i].range==-c[j].range)
            {
                printf("YES");
                return 0;
            }
        }
    }
    printf("NO");
}


#include <iostream>
using namespace std;
int main() {
	int n, a[10001], b[10001];
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= n; j++) {
			if(i != j) {
				if(a[i] + b[i] == a[j] && a[j] + b[j] == a[i]) {
					cout << "YES"  << endl;
					return 0;
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x[105],d[105];
int main(){
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> x[i] >> d[i];
    }
    for(int i=1;i<=n;i++){
        int a=x[i]+d[i],b=INT_MAX/2;
        for(int j=1;j<=n;j++){
            if(a==x[j]){
                b=x[j]+d[j];
            }
        }
        if(b==x[i]){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
int pos[100010],tu[10010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&pos[i],&tu[i]);
    }
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;i++)
	if(i!=j)
	{
		if(pos[i]+tu[i]==pos[j]&&pos[j]+tu[j]==pos[i])
	{
		printf("YES");
		return 0;
	}
	}
	else printf("NO");
	return 0;
}


#include"bits/stdc++.h"
using namespace std;
int n,x[111],y[111];

int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d%d",&x[i],&y[i]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i!=j){
				if(x[i]+y[i]==x[j]&&x[j]+y[j]==x[i]){
					cout<<"YES"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include <stdio.h>
#define N 110
int x[N],d[N];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d %d",&x[i],&d[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
            {
                printf("YES\n");
                return 0;
            }
    printf("NO\n");
}


#include<bits/stdc++.h>

using namespace std;

int a[100],b[100];
int main(){
	int j,n,x,d,k=0,t=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];

	}
	for(int i=0;i<n;i++){
		for(j=0;j<n;j++)
			if(a[i]+b[i]==a[j]&&a[i]==a[j]+b[j]){
				cout<<"Yes";
				return 0;
			}
	}
	cout<"No";
	return 0;
}


#include<iostream>
using namespace std;
int a[1000001],b[1000001];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j++)
		{
			if((a[i]+b[i])==a[j]&&(a[j]+b[j])==a[i])
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
#include<algorithm>
#include <hash_map>
using namespace std;
using namespace __gnu_cxx;

int main(){
	int n;cin>>n;
	int *l=new int[n];
	hash_map<int,int> IH;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		l[i]=a;
		IH[a]=a+b;
	}
	for(int i=0;i<n;i++){
		if(IH[IH[l[i]]]==l[i])
		{
			cout<<"YES";
			return 0;
		}

	}
	cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int a[103];
map<int,int>mp;
int main()
{
    int n;
    cin>>n;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>x;
        mp[a[i]]=x;
    }
    for(int i=0;i<n;i++)
    {
        int e=a[i]+mp[a[i]];
        if(e>=0&&e<n)
        {
            if(e+mp[e]==a[i])
            {
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    //system("pause");
}


#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000],b[1000];
int c[1000];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a[i]>>b[i];
		c[i]=a[i]+b[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(c[j]==a[i]&&c[i]==a[j]&&i!=j){
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include<stdio.h>
struct node
{
    int x,d;
}t[101],a[101];
void u(int L,int R)
{
    int l,r,mid;
    l=L;
    r=R;
    mid=(l+r)/2;
    int m=mid;
    int i=0;
    while(l<=m&&m+1<=r)
    {
        if(t[l].x>t[m].x)a[i++]=t[m++];
        else a[i++]=t[l++];
    }
    while(l<=mid)a[i++]=t[l++];
    while(m<=r)a[i++]=t[m++];
    int g,j=0;
    for(g=L;g<+R;g++)
    {
        t[g]=a[j++];
    }
}
void s(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)/2;
    s(l,mid);
    s(mid+1,r);
    u(l,r);
}
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&t[i].x,&t[i].d);
    }
    s(0,n);
    /*for(i=0;i<n;i++)
    {
        printf("%d %d\n",t[i].x,t[i].d);
    }*/
    int flag=0;
    for(i=0;i<n;i++)
    {int j;
        for( j=i+1;j<n;j++)
        {
            if((t[i].x+t[i].d==t[j].x)&&(t[j].x+t[j].d==t[i].x))flag=1;
        }
    }
    if(flag)printf("YES\n");
    else printf("NO\n");
}


#include <iostream>
using namespace std;
int main()
{
	int a[10000], x[10000];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> x[i];
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
			if (i != j)
			{
				if ((a[i] + x[i] )>= a[j] && (a[j] + x[j]) >= a[i])
				{
					cout << "YES"<<endl;
					return 0;
				}
			}
	}
	cout << "NO"<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n;
int sum=0;
struct node{
	int x,d,zb;
}a[10001];
bool cmp(node a1,node b1)
{
	return a1.x<b1.x;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].d;
		a[i].zb=a[i].x+a[i].d;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(a[i].zb==a[j].x && a[j].zb==a[i].x)
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,x[100001],d[100001];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>d[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)
				if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
					cout<<"YES";
	cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int camel[n][2];
	for(int i=0;i<n;i++)
	{
		cin>>camel[i][0]>>camel[i][1];
	}
	for(int i=0;i<n;i++)
	{
		if(((camel[i][0]+camel[i][1])>=abs(camel[i][0]-camel[i+1][0]))&&((camel[i+1][0]+camel[i+1][1])>=abs(camel[i+1][0]-camel[i][0])))
		{
			cout<<"NO";return 0;
		}
		else
		{
			cout<<"YES";return 0;
		}
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define repeat(i,a,b) for(i=a;i<=b;i++)
int a[10001],b[10001];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	bool flag=false;
	repeat(i,1,n)
	{
		scanf("%d%d",&a[i],&b[i]);
	}
	for (i=1;i<n;i++)
	{
		for (j=i+1;j<=n;j++)//这样就不会有两只重复的骆驼了
		{
			if (a[i]+b[i]==a[j] && a[i]==a[j]+b[j])//看能不能互相都能吐出口水往另一只骆驼上喷，所以是&&
				flag=true;//如果能就为真
		}
	}
	if(flag)
		cout<<"YES";
	else
		cout<<"NO";
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,x[100001],d[100001];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>d[i];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j)
			{
				if(x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
					cout<<"YES";
				else cout<<"NO";
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[10000],x[10000];
int main(){
    int n,i,j;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i]>>x[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(i!=j){
                if(a[i]+x[i]==a[j]&&a[j]+x[j]==a[i]){
                    cout<<"YES";
                    return 0;
                }
            }
        }
    }
    cout<<"NO";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,x[105],d[105];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>d[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i!=j&&x[i]+d[i]==x[j]&&x[j]+d[j]==x[i])
			{
				cout<<"YES";
				return 0;
			}
		}
	}
	cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
LL a[10000], x[10000], n;
int main()
{
    scanf("%lld", &n);
    for(int i = 1; i <= n;i ++)
        scanf("%lld%lld", &a[i], &x[i]);
    for(int i = 1; i <= n;i ++)
    {
        for(int j = 1; j <= n;j ++)
        if(i != j)
        {
            if(a[i] + x[i] == a[j] && a[j] + x[j] == a[i])
            {
                printf("YES")
                return 0;
            }
        }
    }
    printf("NO");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4+4;
struct Node {
    int idx, len;
} node[maxn];
int main() {
    bool flag;
    int n, idx, len;
    cin >> n;
    flag = false;
    for (int i = 0; i < n; i++) { cin >> node[i].idx >> node[i].len; }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            if (node[i].idx <= abs(node[j].len + node[j].idx) && node[j].idx <= abs(node[i].len + node[i].idx)) {
                if ((node[i].len > 0 && node[j].len < 0) || (node[i].len < 0 && node[j].len > 0)) {
                    cout << "YES" << endl;
                    flag = true;
                    break;
                }
            }
            else { continue; }
        }
        if (flag == true) { break; }
    }
    if (!flag) { cout << "NO" << endl; }
    return 0;
}
/*
dsadasdasdsadad
31232143254354543
sd
s
d
sad
as*/


import java.io.*;
import java.util.*;

public class Codeforces {
	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt(), m = in.nextInt();
		char[][] a = new char[n][m];
		for (int i = 0; i < n; i++) {
			a[i] = in.next().toCharArray();
		}
		int[][] l = new int[n][m], r = new int[n][m];
		for (int i = 0; i < n; i++) {
			int last = 0;
			for (int j = m - 1; j >= 0; j--) {
				if (a[i][j] == '1') {
					last = j - m;
					break;
				}
			}
			if (last == 0) {
				out.println(-1);
				return;
			}
			for (int j = 0; j < m; j++) {
				if (a[i][j] == '1') {
					last = j;
				}
				l[i][j] = last;
			}
			for (int j = 0; j < m; j++) {
				if (a[i][j] == '1') {
					last = m + j;
					break;
				}
			}
			for (int j = m - 1; j >= 0; j--) {
				if (a[i][j] == '1') {
					last = j;
				}
				r[i][j] = last;
			}
		}
		int ans = -1;
		for (int j = 0; j < m; j++) {
			int cur = 0;
			for (int i = 0; i < n; i++) {
				cur += Math.min(j - l[i][j], r[i][j] - j);
			}
			if (ans == -1 || cur < ans) {
				ans = cur;
			}
		}
		out.println(ans);
	}

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));

		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {

				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Codeforces().run();
	}
}


import java.lang.*;
import java.math.BigInteger;
import java.io.*;
import java.util.*;

public class Solution implements Runnable{
    public static BufferedReader br;
    public static PrintWriter out;
    public static StringTokenizer stk;
    public static boolean isStream = true;

    public static void main(String[] args) throws IOException {
    	if (isStream) {
            br = new BufferedReader(new InputStreamReader(System.in));
        } else {
            br = new BufferedReader(new FileReader("in.txt"));
        }
        out = new PrintWriter(System.out);
        new Thread(new Solution()).start();
    }

    public void loadLine() {
        try {
            stk = new StringTokenizer(br.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String nextLine() {
        try {
            return br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

    public String nextWord() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return stk.nextToken();
    }

    public Integer nextInt() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Integer.valueOf(stk.nextToken());
    }

    public Long nextLong() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Long.valueOf(stk.nextToken());
    }

    public Double nextDouble() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Double.valueOf(stk.nextToken());
    }

    public Float nextFloat() {
        while (stk==null||!stk.hasMoreTokens()) loadLine();
        return Float.valueOf(stk.nextToken());
    }

    int dist(int a, int b, int m) {
    	int dist1 = b-a; if (dist1 < 0) dist1 += m;
    	int dist2 = a-b; if (dist2 < 0) dist2 += m;
    	return Math.min(dist1, dist2);
    }

    public void run() {
    	int n = nextInt();
    	int m = nextInt();
    	int[][] arr = new int[n][m];
    	for (int i = 0; i< n; i++) {
    		String s = nextLine();
    		for (int j = 0; j < m; j++) {
    			arr[i][j] = s.charAt(j)-'0';
    		}
    	}

    	int[] prev = new int[n]; Arrays.fill(prev, -1);
    	int[] next = new int[n]; Arrays.fill(next, -1);
    	for (int i = 0; i < n; i++) {
    		for (int j = m-1; j >= 0; j--) {
    			if (arr[i][j] == 1) {
    				prev[i] = j;
    				break;
    			}
    		}
    		for (int j = 0; j < m; j++) {
    			if (arr[i][j] == 1) {
    				next[i] = j;
    				break;
    			}
    		}
    	}

    	boolean f = true;
    	for (int i = 0; i < n; i++) {
    		if (next[i] == -1 || prev[i] == -1) {
    			f = false;
    			break;
    		}
    	}

    	int bAns = Integer.MAX_VALUE;
    	if (f) {
    		for (int j = 0; j < m; j++) {
	    		int ans = 0;
	    		for (int i = 0; i < n; i++) {
	    			int d1 = dist(j, next[i], m);
	    			int d2 = dist(j, prev[i], m);
	    			ans += Math.min(d1, d2);
	    			if (arr[i][j] == 1) {
	    				prev[i] = j;
	    				int k = 0;
	    				for (k = next[i]+1; k < m && arr[i][k] != 1; k++) {}
	    				if (k != m) {
	    					next[i] = k;
	    				} else {
	    					for (k = 0; k < m; k++) {
	    						if (arr[i][k] == 1) {
	    							next[i] = k;
	    							break;
	    						}
	    					}
	    					if (k == m) {
	    						next[i] = -1;
	    					}
	    				}
	    			}
	    		}
	    		bAns = Math.min(bAns, ans);
	    	}
    	}
    	if (bAns == Integer.MAX_VALUE) bAns = -1;
    	out.println(bAns);
    	out.flush();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solver {

    int[][] mas;
    int[]storageLeft;
    int[]storageRight;
    boolean isShift;
    int n;
    int m;

    public static void main(String[] Args) throws NumberFormatException, IOException {
        new Solver().Run();
    }

    PrintWriter pw;
    StringTokenizer Stok;
    BufferedReader br;

    public String nextToken() throws IOException {
        while (Stok == null || !Stok.hasMoreTokens()) {
            Stok = new StringTokenizer(br.readLine());
        }
        return Stok.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public int minShift(int i,int j) {
        int a=-1;
        int left,right;
        for (int j2=j; j2<(m+j); j2++) {
            a++;
            left=(2*j-j2+m)%m;
            right=(j2)%m;
            if (mas[i][left]==1 || mas[i][right]==1) {
                return a;
            }
        }
        return (-1);
    }

    public void Run() throws NumberFormatException, IOException {
        br=new BufferedReader(new InputStreamReader(System.in));
        pw=new PrintWriter(new OutputStreamWriter(System.out));
        n=nextInt();
        m=nextInt();
        mas=new int[n][m];
        storageLeft=new int[n];
        storageRight=new int[n];
        String s;

        for (int i=0; i<n; i++) {
            s=nextToken();
            isShift=false;
            for (int j=0;j<m;j++) {
                mas[i][j]=(byte)(s.charAt(j)-48);
                if (mas[i][j]==1) {
                    isShift=true;
                }
            }
            if (!isShift) {
                i=n;
            }
        }

        if (!isShift) {
            pw.println("-1");
        } else {
            long min=100000000;

            for (int j=0; j<m; j++) {
                long k=0;
                for (int i=0; i<n; i++) {
                    k=k+minShift(i,j);
                }
                min = Math.min(k, min);
            }
            pw.println(min);
        }

        pw.flush();
        pw.close();
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solver {

    int[][] mas;
    int[] storage;
    boolean isShift;
    int n;
    int m;

    public static void main(String[] Args) throws NumberFormatException, IOException {
        new Solver().Run();
    }

    PrintWriter pw;
    StringTokenizer Stok;
    BufferedReader br;

    public String nextToken() throws IOException {
        while (Stok == null || !Stok.hasMoreTokens()) {
            Stok = new StringTokenizer(br.readLine());
        }
        return Stok.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public int minShift(int i,int j) {
        int a=storage[i]-1;
        int left,right;
        for (int j2=j+storage[i]; j2<(m+j); j2++) {
            a++;
            left=(2*j-j2+m)%m;
            right=(j2)%m;
            if ((mas[i][left]==1)  || (mas[i][right]==1)) {
                storage[i] = Math.max(a-1, 0);
                return a;
            }
        }
        return (-1);
    }

    public void Run() throws NumberFormatException, IOException {
        br=new BufferedReader(new InputStreamReader(System.in));
        pw=new PrintWriter(new OutputStreamWriter(System.out));
        n=nextInt();
        m=nextInt();
        mas=new int[n][m];
        storage=new int[n];
        String s;

        for (int i=0; i<n; i++) {
            s=nextToken();
            isShift=false;
            for (int j=0;j<m;j++) {
                mas[i][j]=(byte)(s.charAt(j)-48);
                if (mas[i][j]==1) {
                    isShift=true;
                }
            }
            if (!isShift) {
                i=n;
            }
        }

        if (!isShift) {
            pw.println("-1");
        } else {
            long min=100000000;

            for (int j=0; j<m; j++) {
                long k=0;
                for (int i=0; i<n; i++) {
                    k=k+minShift(i,j);
                }
                min = Math.min(k, min);
            }
            pw.println(min);
        }

        pw.flush();
        pw.close();
    }

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int rowCount = in.readInt();
		int columnCount = in.readInt();
		char[][] table = IOUtils.readTable(in, rowCount, columnCount);
		int[][] minShift = new int[rowCount][columnCount];
		ArrayUtils.fill(minShift, Integer.MAX_VALUE / 2);
		for (int i = 0; i < rowCount; i++) {
			int current = Integer.MAX_VALUE / 2;
			for (int j = 0; j < columnCount; j++) {
				current++;
				if (table[i][j] == '1')
					current = 0;
				minShift[i][j] = Math.min(minShift[i][j], current);
			}
			if (current >= Integer.MAX_VALUE / 2) {
				out.printLine(-1);
				return;
			}
			for (int j = 0; j < columnCount; j++) {
				current++;
				if (table[i][j] == '1')
					current = 0;
				minShift[i][j] = Math.min(minShift[i][j], current);
			}
			current = Integer.MAX_VALUE / 2;
			for (int j = columnCount - 1; j >= 0; j--) {
				current++;
				if (table[i][j] == '1')
					current = 0;
				minShift[i][j] = Math.min(minShift[i][j], current);
			}
			for (int j = columnCount - 1; j >= 0; j--) {
				current++;
				if (table[i][j] == '1')
					current = 0;
				minShift[i][j] = Math.min(minShift[i][j], current);
			}
		}
		int answer = Integer.MAX_VALUE;
		for (int i = 0; i < columnCount; i++) {
			int current = 0;
			for (int j = 0; j < rowCount; j++)
				current += minShift[j][i];
			answer = Math.min(answer, current);
		}
		out.printLine(answer);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static char[] readCharArray(InputReader in, int size) {
		char[] array = new char[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readCharacter();
		return array;
	}

	public static char[][] readTable(InputReader in, int rowCount, int columnCount) {
		char[][] table = new char[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readCharArray(in, columnCount);
		return table;
	}

	}

class ArrayUtils {

	public static void fill(int[][] array, int value) {
		for (int[] row : array)
			Arrays.fill(row, value);
	}

	}


//package round141;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A implements Runnable {

    private void solve() throws NumberFormatException, IOException {
        int n = in.nextInt(); // 100
        int m = in.nextInt(); // 10000

        boolean table[][] = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            String row = in.next();
            for (int j = 0; j < m; j++) {
                table[i][j] = row.charAt(j) == '1';
            }
        }

        int firstOne[] = new int[n];
        int lastOne[] = new int[n];
        boolean foundZeroRow = false;
        for (int i = 0; i < n; i++) {
            firstOne[i] = -1;
            for (int j = 0; j < m; ++j) {
                if (table[i][j]) {
                    firstOne[i] = j;
                    break;
                }
            }
            if (firstOne[i] == -1) {
                foundZeroRow = true;
                break;
            }
            for (int j = m - 1; j >= 0; j--) {
                if (table[i][j]) {
                    lastOne[i] = j;
                    break;
                }
            }
        }

        if (foundZeroRow) {
            out.println(-1);
            return;
        }

        int[][] minDistance = new int[n][m];
        for (int i = 0; i < n; i++) {
            // Left
            int curDistance = m - lastOne[i];
            for (int j = 0; j < m; j++, curDistance++) {
                if (table[i][j])
                    curDistance = 0;
                minDistance[i][j] = curDistance;
            }
            // Right
            curDistance = firstOne[i] + 1;
            for (int j = m - 1; j >= 0; j--, curDistance++) {
                if (table[i][j])
                    curDistance = 0;
                minDistance[i][j] = Math.min(minDistance[i][j], curDistance);
            }
        }

        int totalMin = Integer.MAX_VALUE;
        for (int j = 0; j < m; j++) {
            int currentSum = 0;
            for (int i = 0; i < n; i++) {
                currentSum += minDistance[i][j];
            }
            totalMin = Math.min(totalMin, currentSum);
        }

        out.println(totalMin);
    }

    private FastScanner in;
    private PrintWriter out;

    @Override
    public void run() {
        in = new FastScanner(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        try {
            solve();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            out.close();
        }
    }

    private static class FastScanner
    {
        private final BufferedReader reader;
        private StringTokenizer tokens;

        public FastScanner(Reader rawReader) {
            reader = new BufferedReader(rawReader);
        }

        public boolean hasNext() throws IOException
        {
            while (tokens == null || !tokens.hasMoreTokens()) {
                String nextLine = reader.readLine();
                if (nextLine == null)
                    return false;
                tokens = new StringTokenizer(nextLine);
            }
            return true;
        }

        public String next() throws IOException {
            return hasNext() ? tokens.nextToken() : null;
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] args) {
        new A().run();
    }

}