#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point(int a = 0, int b = 0) : x(a), y(b) {}
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
  bool operator<(const Point &p) const {
    return x < p.x || (x == p.x && y < p.y);
  }
};
long long Cross(const Point &u, const Point &v) {
  return (long long)u.x * v.y - (long long)u.y * v.x;
}
long long Dot(const Point &u, const Point &v) {
  return (long long)u.x * v.x + (long long)u.y * v.y;
}
multiset<Point> st1, st2;
multiset<Point>::iterator it1, it2;
int n;
Point tp[4];
void init() {
  sort(tp, tp + 3);
  st1.clear();
  st2.clear();
  st1.insert(tp[0]);
  st1.insert(tp[2]);
  st2.insert(tp[0]);
  st2.insert(tp[2]);
  if (Cross(tp[1] - tp[0], tp[2] - tp[0]) > 0) {
    st1.insert(tp[1]);
  } else
    st2.insert(tp[1]);
}
bool IsPointOnSeg(const Point &u, const Point &v, const Point &p) {
  if (Cross(u - p, v - p) == 0 && Dot(u - p, v - p) <= 0) return 1;
  return 0;
}
int IsInDownConvexHull(const Point &u) {
  if (st1.count(u) > 0) return 1;
  it2 = it1 = st1.upper_bound(u);
  if (it1 == st1.begin()) return 0;
  if (it1 == st1.end()) return 0;
  it2--;
  long long k = Cross((*it2) - u, (*it1) - u);
  if (k >= 0)
    return 1;
  else
    return 0;
}
int IsInUpConvexHull(const Point &u) {
  if (st2.count(u) > 0) return 1;
  it2 = it1 = st2.upper_bound(u);
  if (it1 == st2.end()) return 0;
  if (it1 == st2.begin()) return 0;
  it2--;
  long long k = Cross((*it2) - u, (*it1) - u);
  if (k <= 0)
    return 1;
  else
    return 0;
}
multiset<Point>::iterator findPre(multiset<Point> &st, const Point &u) {
  multiset<Point>::iterator it;
  it = st.lower_bound(u);
  if (it == st.begin()) return st.end();
  it--;
  return it;
}
multiset<Point>::iterator findNext(multiset<Point> &st, const Point &u) {
  multiset<Point>::iterator it;
  it = st.upper_bound(u);
  return it;
}
void Insert(const Point &u) {
  int tmp2 = IsInUpConvexHull(u), tmp1 = IsInDownConvexHull(u);
  if (tmp1 && tmp2) return;
  if (tmp1 == 0) {
    while (1) {
      it1 = findNext(st1, u);
      if (it1 == st1.end()) break;
      it2 = findNext(st1, *it1);
      if (it2 == st1.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        st1.erase(*it1);
      } else
        break;
    }
    while (1) {
      it1 = findPre(st1, u);
      if (it1 == st1.end()) break;
      it2 = findPre(st1, *it1);
      if (it2 == st1.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        st1.erase(*it1);
      } else
        break;
    }
    st1.insert(u);
  }
  if (tmp2 == 0) {
    while (1) {
      it1 = findNext(st2, u);
      if (it1 == st2.end()) break;
      it2 = findNext(st2, *it1);
      if (it2 == st2.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        st2.erase(*it1);
      } else
        break;
    }
    while (1) {
      it1 = findPre(st2, u);
      if (it1 == st2.end()) break;
      it2 = findPre(st2, *it1);
      if (it2 == st2.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        st2.erase(*it1);
      } else
        break;
    }
    st2.insert(u);
  }
}
void Insert1(const Point &u) {
  int tmp1 = IsInUpConvexHull(u), tmp2 = IsInDownConvexHull(u);
  if (tmp1 && tmp2) return;
  it1 = it2 = st1.upper_bound(u);
  if (it1 == st1.end()) {
    it1--;
    it1--;
    it2--;
    while (1) {
      long long k = Cross((*it2) - u, (*it1) - u);
      if (k >= 0) {
        Point t = *it2;
        it2--;
        st1.erase(t);
        if (it1 == st1.begin()) break;
        it1--;
      } else
        break;
    }
    st1.insert(u);
    it1 = it2 = st2.end();
    it1--;
    it1--;
    it2--;
    while (1) {
      long long k = Cross((*it2) - u, (*it1) - u);
      if (k <= 0) {
        Point t = *it2;
        it2--;
        st2.erase(t);
        if (it1 == st2.begin()) break;
        it1--;
      } else
        break;
    }
    st2.insert(u);
    return;
  }
  if (it1 == st1.begin()) {
    it2++;
    while (it2 != st1.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st1.erase(t);
      } else
        break;
    }
    st1.insert(u);
    it1 = it2 = st2.begin();
    it2++;
    while (it2 != st2.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st2.erase(t);
      } else
        break;
    }
    st2.insert(u);
    return;
  }
  if (tmp1 == 0) {
    it2 = it1 = st2.upper_bound(u);
    it2++;
    while (it2 != st2.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st2.erase(t);
      } else
        break;
    }
    st2.insert(u);
    it2 = it1 = st2.lower_bound(u);
    it1--;
    if (it1 != st2.begin()) {
      it1--;
      it2--;
      while (1) {
        long long k = Cross((*it2) - u, (*it1) - u);
        if (k <= 0) {
          Point t = *it2;
          it2--;
          st2.erase(t);
          if (it1 == st2.begin()) break;
          it1--;
        } else
          break;
      }
    }
  } else if (tmp2 == 0) {
    it2 = it1 = st1.upper_bound(u);
    it2++;
    while (it2 != st1.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st1.erase(t);
      } else
        break;
    }
    st1.insert(u);
    it2 = it1 = st1.lower_bound(u);
    it1--;
    if (it1 != st1.begin()) {
      it1--;
      it2--;
      while (1) {
        long long k = Cross((*it2) - (*it1), u - (*it1));
        if (k <= 0) {
          Point t = *it2;
          it2--;
          st1.erase(t);
          if (it1 == st1.begin()) break;
          it1--;
        } else
          break;
      }
    }
  }
}
void solve() {
  init();
  for (int i = 3; i < n; i++) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    if (t == 1) {
      Insert(Point(x, y));
    } else {
      int t1 = IsInUpConvexHull(Point(x, y));
      int t2 = IsInDownConvexHull(Point(x, y));
      if ((t1 && t2))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
int main() {
  while (~scanf("%d", &n)) {
    st1.clear();
    st2.clear();
    for (int i = 0; i < 3; i++) {
      int t, x, y;
      scanf("%d%d%d", &t, &x, &y);
      tp[i] = Point(x, y);
    }
    solve();
  }
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

Once a walrus professor Plato asked his programming students to perform the following practical task. 

The students had to implement such a data structure that would support a convex hull on some set of points S. The input to the program had q queries of two types: 

1. Add a point with coordinates (x, y) into the set S. Note that in this case the convex hull of S could have changed, and could have remained the same. 

2. Say whether a point with coordinates (x, y) belongs to an area limited by the convex hull, including the border. 

All the students coped with the task. What about you?

Input

The first line contains an integer q (4 ≤ q ≤ 105). 

Then follow q lines in the following way: "t x y", where t is the query type (1 or 2), and (x, y) are the coordinates of the point ( - 106 ≤ x, y ≤ 106, x and y are integers). 

There is at least one query of type 2.

It is guaranteed that the three queries of the first type follow first and the points given in the queries form a non-degenerative triangle. Also all the points added in S are distinct.

Output

For each query of the second type print one string containing "YES", if the point lies inside the convex hull or on its border. Otherwise, print "NO".

Examples

Input

8
1 0 0
1 2 0
1 2 2
2 1 0
1 0 2
2 1 1
2 2 1
2 20 -1


Output

YES
YES
YES
NO

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
  Point(int a = 0, int b = 0) : x(a), y(b) {}
  Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
  bool operator<(const Point &p) const {
    return x < p.x || (x == p.x && y < p.y);
  }
};
long long Cross(const Point &u, const Point &v) {
  return (long long)u.x * v.y - (long long)u.y * v.x;
}
long long Dot(const Point &u, const Point &v) {
  return (long long)u.x * v.x + (long long)u.y * v.y;
}
multiset<Point> st1, st2;
multiset<Point>::iterator it1, it2;
int n;
Point tp[4];
void init() {
  sort(tp, tp + 3);
  st1.clear();
  st2.clear();
  st1.insert(tp[0]);
  st1.insert(tp[2]);
  st2.insert(tp[0]);
  st2.insert(tp[2]);
  if (Cross(tp[1] - tp[0], tp[2] - tp[0]) > 0) {
    st1.insert(tp[1]);
  } else
    st2.insert(tp[1]);
}
bool IsPointOnSeg(const Point &u, const Point &v, const Point &p) {
  if (Cross(u - p, v - p) == 0 && Dot(u - p, v - p) <= 0) return 1;
  return 0;
}
int IsInDownConvexHull(const Point &u) {
  if (st1.count(u) > 0) return 1;
  it2 = it1 = st1.upper_bound(u);
  if (it1 == st1.begin()) return 0;
  if (it1 == st1.end()) return 0;
  it2--;
  long long k = Cross((*it2) - u, (*it1) - u);
  if (k >= 0)
    return 1;
  else
    return 0;
}
int IsInUpConvexHull(const Point &u) {
  if (st2.count(u) > 0) return 1;
  it2 = it1 = st2.upper_bound(u);
  if (it1 == st2.end()) return 0;
  if (it1 == st2.begin()) return 0;
  it2--;
  long long k = Cross((*it2) - u, (*it1) - u);
  if (k <= 0)
    return 1;
  else
    return 0;
}
multiset<Point>::iterator findPre(multiset<Point> &st, const Point &u) {
  multiset<Point>::iterator it;
  it = st.lower_bound(u);
  if (it == st.begin()) return st.end();
  it--;
  return it;
}
multiset<Point>::iterator findNext(multiset<Point> &st, const Point &u) {
  multiset<Point>::iterator it;
  it = st.upper_bound(u);
  return it;
}
void Insert(const Point &u) {
  int tmp2 = IsInUpConvexHull(u), tmp1 = IsInDownConvexHull(u);
  if (tmp1 && tmp2) return;
  if (tmp1 == 0) {
    while (1) {
      it1 = findNext(st1, u);
      if (it1 == st1.end()) break;
      it2 = findNext(st1, *it1);
      if (it2 == st1.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        st1.erase(*it1);
      } else
        break;
    }
    while (1) {
      it1 = findPre(st1, u);
      if (it1 == st1.end()) break;
      it2 = findPre(st1, *it1);
      if (it2 == st1.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        st1.erase(*it1);
      } else
        break;
    }
    st1.insert(u);
  }
  if (tmp2 == 0) {
    while (1) {
      it1 = findNext(st2, u);
      if (it1 == st2.end()) break;
      it2 = findNext(st2, *it1);
      if (it2 == st2.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        st2.erase(*it1);
      } else
        break;
    }
    while (1) {
      it1 = findPre(st2, u);
      if (it1 == st2.end()) break;
      it2 = findPre(st2, *it1);
      if (it2 == st2.end()) break;
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        st2.erase(*it1);
      } else
        break;
    }
    st2.insert(u);
  }
}
void Insert1(const Point &u) {
  int tmp1 = IsInUpConvexHull(u), tmp2 = IsInDownConvexHull(u);
  if (tmp1 && tmp2) return;
  it1 = it2 = st1.upper_bound(u);
  if (it1 == st1.end()) {
    it1--;
    it1--;
    it2--;
    while (1) {
      long long k = Cross((*it2) - u, (*it1) - u);
      if (k >= 0) {
        Point t = *it2;
        it2--;
        st1.erase(t);
        if (it1 == st1.begin()) break;
        it1--;
      } else
        break;
    }
    st1.insert(u);
    it1 = it2 = st2.end();
    it1--;
    it1--;
    it2--;
    while (1) {
      long long k = Cross((*it2) - u, (*it1) - u);
      if (k <= 0) {
        Point t = *it2;
        it2--;
        st2.erase(t);
        if (it1 == st2.begin()) break;
        it1--;
      } else
        break;
    }
    st2.insert(u);
    return;
  }
  if (it1 == st1.begin()) {
    it2++;
    while (it2 != st1.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st1.erase(t);
      } else
        break;
    }
    st1.insert(u);
    it1 = it2 = st2.begin();
    it2++;
    while (it2 != st2.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st2.erase(t);
      } else
        break;
    }
    st2.insert(u);
    return;
  }
  if (tmp1 == 0) {
    it2 = it1 = st2.upper_bound(u);
    it2++;
    while (it2 != st2.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k >= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st2.erase(t);
      } else
        break;
    }
    st2.insert(u);
    it2 = it1 = st2.lower_bound(u);
    it1--;
    if (it1 != st2.begin()) {
      it1--;
      it2--;
      while (1) {
        long long k = Cross((*it2) - u, (*it1) - u);
        if (k <= 0) {
          Point t = *it2;
          it2--;
          st2.erase(t);
          if (it1 == st2.begin()) break;
          it1--;
        } else
          break;
      }
    }
  } else if (tmp2 == 0) {
    it2 = it1 = st1.upper_bound(u);
    it2++;
    while (it2 != st1.end()) {
      long long k = Cross((*it1) - u, (*it2) - u);
      if (k <= 0) {
        Point t = *it1;
        it1++;
        it2++;
        st1.erase(t);
      } else
        break;
    }
    st1.insert(u);
    it2 = it1 = st1.lower_bound(u);
    it1--;
    if (it1 != st1.begin()) {
      it1--;
      it2--;
      while (1) {
        long long k = Cross((*it2) - (*it1), u - (*it1));
        if (k <= 0) {
          Point t = *it2;
          it2--;
          st1.erase(t);
          if (it1 == st1.begin()) break;
          it1--;
        } else
          break;
      }
    }
  }
}
void solve() {
  init();
  for (int i = 3; i < n; i++) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    if (t == 1) {
      Insert(Point(x, y));
    } else {
      int t1 = IsInUpConvexHull(Point(x, y));
      int t2 = IsInDownConvexHull(Point(x, y));
      if ((t1 && t2))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
}
int main() {
  while (~scanf("%d", &n)) {
    st1.clear();
    st2.clear();
    for (int i = 0; i < 3; i++) {
      int t, x, y;
      scanf("%d%d%d", &t, &x, &y);
      tp[i] = Point(x, y);
    }
    solve();
  }
  return 0;
}

```