p124.ans2
======================
INSIDE

=================
p124.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<pair<pair<int, int>, pair<int, int>>> segments;
pair<int, int> tgt;

void read() {
    cin >> n;
    segments.resize(n);
    cin >> segments;
    cin >> tgt;
}


void solve() {
    int cnt = 0;
    for(int i = 0; i < (int)segments.size(); i++) {
        auto [p1, p2] = segments[i];
        auto [x1, y1] = p1;
        auto [x2, y2] = p2;

        if(x1 == x2 && tgt.second >= min(y1, y2) && tgt.second <= max(y1, y2) &&
           tgt.first == x1) {
            cout << "BORDER" << endl;
            return;
        }

        if(y1 == y2 && tgt.second == y1 && min(x1, x2) <= tgt.first &&
           tgt.first <= max(x1, x2)) {
            cout << "BORDER" << endl;
            return;
        }

        if(y1 == y2 && tgt.second < y1 && min(x1, x2) < tgt.first &&
           tgt.first <= max(x1, x2)) {
            cnt++;
        }
    }

    if(cnt % 2 == 0) {
        cout << "OUTSIDE" << endl;
    } else {
        cout << "INSIDE" << endl;
    }
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
p124.in1
======================
4
0 0 0 3
3 3 3 0
0 3 3 3
3 0 0 0
2 2

=================
p124.ans1
======================
INSIDE

=================
statement.txt
======================
124. Broken line

time limit per test: 0.25 sec.
memory limit per test: 4096 KB


There is a closed broken line on a plane with sides parallel to coordinate axes, without self-crossings and self-contacts. The broken line consists of K segments. You have to determine, whether a given point with coordinates (X0,Y0) is inside this closed broken line, outside or belongs to the broken line.


Input

The first line contains integer K (4 Ј K Ј 10000) - the number of broken line segments. Each of the following N lines contains coordinates of the beginning and end points of the segments (4 integer xi1,yi1,xi2,yi2; all numbers in a range from -10000 up to 10000 inclusive). Number separate by a space. The segments are given in random order. Last line contains 2 integers X0 and Y0 - the coordinates of the given point delimited by a space. (Numbers X0, Y0 in a range from -10000 up to 10000 inclusive).


Output

The first line should contain:

INSIDE - if the point is inside closed broken line,

OUTSIDE - if the point is outside,

BORDER - if the point belongs to broken line.



Sample Input

4
0 0 0 3
3 3 3 0
0 3 3 3
3 0 0 0
2 2
Sample Output

INSIDE
Author	: Alex Y. Suslov, Sergey V. Mironov
Resource	: 5th Southern Subregional Contest. Saratov 2002
Date	: 2002-10-10

=================
p124.in2
======================
5
0 0 0 2
0 2 2 2
2 2 2 1
2 1 2 0
2 0 0 0
1 1

=================
