<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

253. Theodore Roosevelt
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



Danger! Sudden attack on Russia! These are Americans "again", but this time they are serious. Giant aircraft-carrier "Theodore Roosevelt" is entering the Baltic Sea. At one o'clock American aircraft launched from the carrier bombed Petrozavodsk.
At three o'clock we detected the location of "Theodore Roosevelt". In a moment Russian fighters Mig-29 took off into the night air to inflict the crushing strike against the carrier. Using top secret military satellite "Raduga-1" we detected the exact region where the carrier was located - the convex polygon. The fighters launched M rockets and ground forces detected the coordinates of their explosions.
You are an indispensable engineer of Russian military forces, and you were waken up by the phone call at four o'clock. They command you to arrive to headquarters for the most important task - detect whether "Theodore Roosevelt" was destroyed or not! You are given all information: the coordinates of vertices of the region polygon and the coordinates of the explosions.
It was computed that at least K rockets should have hit the detected region to destroy the carrier. Commander ordered you to complete the work till five o'clock, so you must hurry.

Input
The first line of input contains three integers N, M and K (3<=N<=10^5, 0<=K<=M<=10^5). The following N lines contain coordinates of polygon vertices in counter-clockwise order. And then last M lines contain coordinates of rockets explosions. Is is guaranteed that all coordinates are integer numbers not exceeding 10^9 by their absolute value.

Output
Output "YES" (without quotes) if "Theodore Roosevelt" was destroyed, or "NO" (without quotes) in the other case.

Sample test(s)

Input
5 4 2
1 -1
1 2
0 4
-1 2
-1 -1
-2 -1
1 -1
0 1
2 3

Output
YES
Author:	Dmitry Filippov (DEF)
Resource:	Petrozavodsk Summer Training Sessions 2004
Date:	August 25, 2004

<|response|>
1. Abridged problem statement  
Given a convex polygon of N vertices in counter-clockwise order, and M query points, determine how many query points lie inside or on the boundary of the polygon. If at least K points are inside or on the polygon, output “YES”, otherwise “NO”. Constraints: 3 ≤ N ≤ 10^5, 0 ≤ K ≤ M ≤ 10^5, coordinates are integers with absolute value ≤ 10^9.

2. Key observations  
- A general point-in-polygon test is O(N) per query, too slow for N, M up to 10^5.  
- For a **convex** polygon, we can answer each query in O(log N) by "fan-triangulating" from one fixed vertex.  
- Choose one polygon vertex P0 (e.g. the lexicographically minimum (x,y)). The other vertices, in CCW order around P0, form a fan of triangles (P0, Pi, Pi+1).  
- To test a point Q:  
  1. Quickly reject if Q is strictly to the right of ray P0→P1 or strictly to the left of ray P0→P_{N−1}.  
  2. Otherwise binary-search to find the wedge [P0, P_i, P_{i+1}] that could contain Q.  
  3. Finally check with cross products that Q lies inside or on triangle (P0, P_i, P_{i+1}).

3. Full solution approach  
Step A. Read N, M, K. Read polygon vertices in CCW order. Read M query points.  
Step B. Find the lexicographically smallest vertex P0 among the N points. Rotate the vertex array so that P0 becomes the first element; call the rest fan[0…N−2] in CCW order.  
Step C. Define orientation (cross product) function orient(A,B,C) = sign of (B−A)×(C−A); it is +1 if A→B→C makes a CCW turn, −1 if CW, 0 if collinear.  
Step D. For each query Q:  
  1. If orient(P0, fan[0], Q) < 0, Q is to the right of P0→fan[0], reject.  
     If orient(P0, fan[N−2], Q) > 0, Q is to the left of P0→fan[N−2], reject.  
  2. Otherwise binary-search on fan[]:  
     - Let L=0, R=N−2. While R−L>1, set mid=(L+R)/2.  
     - If orient(P0, fan[mid], Q) ≥ 0, set L=mid; else set R=mid.  
     After the loop, Q lies between rays P0→fan[L] and P0→fan[R].  
  3. Check if Q is inside triangle (P0, fan[L], fan[R]) by testing orient(fan[L], fan[R], Q) ≥ 0. If so, count it as inside or on boundary.  
Step E. If the total count ≥ K, print “YES”, else “NO”.

Time complexity: O(N + M log N). Memory: O(N + M).

4. C++ implementation with detailed comments  
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// A point with integer coordinates
struct Point {
    ll x, y;
};

// Compute cross product (B - A) × (C - A)
ll cross(const Point &A, const Point &B, const Point &C) {
    // (Bx - Ax)*(Cy - Ay) - (By - Ay)*(Cx - Ax)
    return (B.x - A.x) * (C.y - A.y)
         - (B.y - A.y) * (C.x - A.x);
}

// Returns true if point Q lies inside or on triangle A-B-C.
// Assumes triangle is oriented CCW or CW; we allow boundary.
bool pointInTriangle(const Point &A, const Point &B, const Point &C, const Point &Q) {
    // Compute three orientations
    ll c1 = cross(A, B, Q);
    ll c2 = cross(B, C, Q);
    ll c3 = cross(C, A, Q);
    // Q is inside or on boundary if all are non-negative
    // or all are non-positive
    bool nonNeg = (c1 >= 0 && c2 >= 0 && c3 >= 0);
    bool nonPos = (c1 <= 0 && c2 <= 0 && c3 <= 0);
    return nonNeg || nonPos;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, M, K;
    cin >> N >> M >> K;

    vector<Point> poly(N);
    for(int i = 0; i < N; i++){
        cin >> poly[i].x >> poly[i].y;
    }

    // Read queries
    vector<Point> queries(M);
    for(int i = 0; i < M; i++){
        cin >> queries[i].x >> queries[i].y;
    }

    // Find index of lexicographically smallest vertex
    int idx0 = 0;
    for(int i = 1; i < N; i++){
        if (poly[i].x < poly[idx0].x ||
           (poly[i].x == poly[idx0].x && poly[i].y < poly[idx0].y)) {
            idx0 = i;
        }
    }

    // Rotate polygon so that idx0 becomes 0
    vector<Point> pts(N);
    for(int i = 0; i < N; i++){
        pts[i] = poly[(idx0 + i) % N];
    }
    // pts[0] is base P0; fan[0..N-2] are the other vertices
    Point P0 = pts[0];
    vector<Point> fan(N - 1);
    for(int i = 1; i < N; i++){
        fan[i - 1] = pts[i];
    }

    int insideCount = 0;
    // Process each query
    for(auto &Q : queries) {
        // Quick reject against the outer wedges
        if (cross(P0, fan[0], Q) < 0) continue;
        if (cross(P0, fan[N-2], Q) > 0) continue;

        // Binary search to find sector
        int L = 0, R = N - 2;
        while (R - L > 1) {
            int mid = (L + R) >> 1;
            if (cross(P0, fan[mid], Q) >= 0) {
                L = mid;
            } else {
                R = mid;
            }
        }
        // Now test if Q is inside triangle (P0, fan[L], fan[R])
        if (pointInTriangle(P0, fan[L], fan[R], Q)) {
            insideCount++;
        }
    }

    // Check if we have at least K inside points
    cout << (insideCount >= K ? "YES\n" : "NO\n");
    return 0;
}
```

5. Python implementation with detailed comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    it = iter(data)
    N = int(next(it))
    M = int(next(it))
    K = int(next(it))

    # Read polygon vertices
    poly = []
    for _ in range(N):
        x = int(next(it)); y = int(next(it))
        poly.append((x, y))

    # Read query points
    queries = []
    for _ in range(M):
        x = int(next(it)); y = int(next(it))
        queries.append((x, y))

    # Find lexicographically smallest vertex
    idx0 = min(range(N), key=lambda i: (poly[i][0], poly[i][1]))
    # Rotate so that idx0 is first
    pts = poly[idx0:] + poly[:idx0]
    P0 = pts[0]
    fan = pts[1:]    # list of N-1 points in CCW around P0

    # Cross product (B - A) × (C - A)
    def cross(A, B, C):
        return (B[0] - A[0]) * (C[1] - A[1]) - \
               (B[1] - A[1]) * (C[0] - A[0])

    # Check if Q in triangle A-B-C (including boundary)
    def in_triangle(A, B, C, Q):
        c1 = cross(A, B, Q)
        c2 = cross(B, C, Q)
        c3 = cross(C, A, Q)
        # all non-negative or all non-positive
        return (c1 >= 0 and c2 >= 0 and c3 >= 0) or \
               (c1 <= 0 and c2 <= 0 and c3 <= 0)

    cnt = 0
    for Q in queries:
        # Quick reject against the first and last rays
        if cross(P0, fan[0], Q) < 0:
            continue
        if cross(P0, fan[-1], Q) > 0:
            continue

        # Binary search to find wedge [P0, fan[L], fan[R]]
        L, R = 0, len(fan) - 1
        while R - L > 1:
            mid = (L + R) // 2
            if cross(P0, fan[mid], Q) >= 0:
                L = mid
            else:
                R = mid

        # Final triangle test
        if in_triangle(P0, fan[L], fan[R], Q):
            cnt += 1

    # Output result
    print("YES" if cnt >= K else "NO")

if __name__ == "__main__":
    main()
```