1. Abridged Problem Statement  
Given K axis-aligned segments that form a simple closed polygon (no self-intersections), determine for a query point (X₀, Y₀) whether it lies strictly inside the polygon, strictly outside it, or exactly on one of its segments (border).

2. Detailed Editorial  

Overview  
We want a classic “point-in-polygon” test specialized to axis-aligned edges. We’ll also detect if the point lies on any segment.

Approach  
Use a ray-casting (crossing number) method with a vertical ray shooting upward from the point. Count how many edges the ray crosses; odd → inside, even → outside. But before counting, check border cases.

Steps  
1) Read all K segments and the query point (X₀, Y₀).  
2) Border check:  
   - For each vertical segment (x₁=x₂): if X₀ = x₁ and Y₀ between y₁ and y₂ (inclusive), output BORDER.  
   - For each horizontal segment (y₁=y₂): if Y₀ = y₁ and X₀ between x₁ and x₂ (inclusive), output BORDER.  
3) Crossing count: cast a ray from (X₀, Y₀) straight up (increasing Y).  
   - Only horizontal segments can be intersected by a vertical ray.  
   - For each horizontal segment at y = Y₁: if Y₁ > Y₀ (above the point) and X₀ lies strictly between its endpoints on the left side or exactly at the right endpoint, count one intersection.  
     * We use the rule “min(x₁,x₂) < X₀ ≤ max(x₁,x₂)” to handle vertex cases correctly and avoid double-counting shared endpoints.  
4) If the total intersections count is odd → INSIDE; else → OUTSIDE.

Time Complexity  
O(K), scanning each segment a constant number of times. Memory O(K).

3. C++ Solution with Detailed Comments  

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

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

    int K;
    cin >> K;

    // Store each segment as ((x1,y1),(x2,y2))
    vector<array<int,4>> segs(K);
    for(int i = 0; i < K; i++) {
        cin >> segs[i][0]  // x1
            >> segs[i][1]  // y1
            >> segs[i][2]  // x2
            >> segs[i][3]; // y2
    }

    int X0, Y0;
    cin >> X0 >> Y0;

    // 1) Check if point is on any segment → BORDER
    for(auto &s : segs) {
        int x1 = s[0], y1 = s[1], x2 = s[2], y2 = s[3];
        if (x1 == x2) {
            // Vertical segment at x = x1
            if (X0 == x1 &&
                min(y1, y2) <= Y0 && Y0 <= max(y1, y2)) {
                cout << "BORDER\n";
                return 0;
            }
        }
        else {
            // Horizontal segment at y = y1(==y2)
            if (Y0 == y1 &&
                min(x1, x2) <= X0 && X0 <= max(x1, x2)) {
                cout << "BORDER\n";
                return 0;
            }
        }
    }

    // 2) Ray cast upward and count crossings with horizontal segments
    int crossings = 0;
    for(auto &s : segs) {
        int x1 = s[0], y1 = s[1], x2 = s[2], y2 = s[3];

        // Only horizontal segments (y1 == y2) can cross a vertical ray
        if (y1 == y2) {
            int y = y1;
            // Segment must lie strictly above the point
            if (y > Y0) {
                int xl = min(x1, x2);
                int xr = max(x1, x2);
                // Count if X0 is in (xl, xr] to handle endpoint rules
                if (xl < X0 && X0 <= xr) {
                    crossings++;
                }
            }
        }
    }

    // 3) Odd → inside, Even → outside
    cout << (crossings % 2 ? "INSIDE\n" : "OUTSIDE\n");
    return 0;
}
```

4. Python Solution with Detailed Comments  

```python
def main():
    import sys
    data = sys.stdin.read().strip().split()
    it = iter(data)

    # Read number of segments
    K = int(next(it))
    segments = []
    for _ in range(K):
        x1 = int(next(it)); y1 = int(next(it))
        x2 = int(next(it)); y2 = int(next(it))
        segments.append((x1, y1, x2, y2))

    # Read query point
    X0 = int(next(it)); Y0 = int(next(it))

    # 1) Border check
    for x1, y1, x2, y2 in segments:
        if x1 == x2:
            # vertical segment
            if X0 == x1 and min(y1,y2) <= Y0 <= max(y1,y2):
                print("BORDER")
                return
        else:
            # horizontal segment
            if Y0 == y1 and min(x1,x2) <= X0 <= max(x1,x2):
                print("BORDER")
                return

    # 2) Ray cast upward: count intersections with horizontal segments
    crossings = 0
    for x1, y1, x2, y2 in segments:
        if y1 == y2:  # horizontal
            y = y1
            # Only consider segments strictly above the point
            if y > Y0:
                xl, xr = sorted((x1, x2))
                # Use (xl, xr] to avoid double count at shared vertices
                if xl < X0 <= xr:
                    crossings += 1

    # 3) Odd → INSIDE; Even → OUTSIDE
    print("INSIDE" if crossings % 2 else "OUTSIDE")

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

5. Compressed Editorial  
Shoot a vertical ray upward from the point. First check if the point lies exactly on any segment → BORDER. Otherwise, for each horizontal edge above the point whose x-span contains the point (using `(min_x < X0 ≤ max_x)` to handle vertices), increment a crossing counter. If the count is odd → INSIDE, else → OUTSIDE. This runs in O(K).