#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define lowbit(x) ((x) & -(x)) #define lson l,mid,id<<1 #define rson mid+1,r,id<<1|1 #define ls id<<1 #define rs id<<1|1 #define MID(l,r) ((l)+(((r)-(l))>>1)) #define fi first #define se second #define mk make_pair #define mt make_tuple #define pb push_back #define epb emplace_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() using LL = long long; //using LL = __int64; using pii = pair; using pdd = pair; using pLL = pair; const int INF = 0x3f3f3f3f; const LL LINF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; const int e5 = 100000; // 1e5 const int e6 = 1000000; //1e6; const int MOD_1e9 = 1000000007; //1e9 + 7 const int MOD_998 = 998244353; const int MOD = MOD_1e9; template< typename T = int > inline T read() { char c = '\0'; bool f = false; T x = 0; while(c < '0' || '9' < c) {if(c == '-') f = true; c = getchar();} while('0' <= c && c <= '9') {x = (x << 1) + (x << 3) + (c & 0xf); c = getchar();} if(f) return -x; return x; } template< typename T > inline void read(T &x) {x = read();} template< typename T, typename ...Args > inline void read(T &x, Args &...args) {read(x); read(args...);} template< typename T > inline void get_min(T &x, T y) {if(y < x) x = y;} template< typename T > inline void get_max(T &x, T y) {if(x < y) x = y;} template< typename X, typename Y > inline void depair(X &x, Y &y, const pair &pr) {x = pr.fi; y = pr.se;} template< typename T > inline void get_unique(vector &vec) {sort(all(vec)); vec.erase(unique(all(vec)), vec.end());} inline int sig(double x) {return x < -eps ? -1 : eps < x;} LL fp(LL a, LL n, LL mod = MOD) { if(n < 0) a = fp(a, mod - 2, mod), n = -n; LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res; } template< int mod > struct Mint { int x; Mint():x(0) {} Mint(int _x): x(_x) {if(x < 0 || x >= mod) x %= mod; if(x < 0) x += mod;} Mint(LL _x) {if(_x < 0 || _x >= mod) _x %= mod; if(_x < 0) _x += mod; x = _x;} Mint operator - () const {return Mint(mod - x);} Mint operator + (const Mint &rhs) const {return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x);} Mint operator - (const Mint &rhs) const {return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x);} Mint operator * (const Mint &rhs) const {return Mint((LL)x * rhs.x % mod);} Mint operator / (const Mint &rhs) const {return Mint((LL)x * fp(rhs.x, -1, mod) % mod);} bool operator == (const Mint &rhs) const {return x == rhs.x;} bool operator != (const Mint &rhs) const {return x != rhs.x;} Mint &operator += (const Mint &rhs) {x += rhs.x; if(x >= mod) x -= mod; return *this;} Mint &operator -= (const Mint &rhs) {x -= rhs.x; if(x < 0) x += mod; return *this;} Mint &operator *= (const Mint &rhs) {x = (LL)x * rhs.x % mod; return *this;} Mint &operator /= (const Mint &rhs) {x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this;} friend ostream &operator << (ostream &out, const Mint &rhs) {return out << to_string(rhs.x);} Mint inv() {return Mint(fp(x, -1, mod));} Mint pow(int k) {return Mint(fp(x, k, mod));} Mint pow(const Mint &t) {return Mint(fp(x, t.x, mod));} }; const int maxn = (int) 2e5 + 20; const int maxm = (int) 2e6 + 20; struct Point { LL x, y; Point() {} Point(LL _x, LL _y): x(_x), y(_y) {} Point operator - (const Point &t) const {return Point{x - t.x, y - t.y};} int operator ^ (const Point &t) const {return x * t.y - y * t.x;} bool operator < (const Point &t) const {return x < t.x || (x == t.x && y < t.y);} bool operator == (const Point &t) const {return x == t.x && y == t.y;} }; void work() { int n; while(cin >>n) { vector p(n); for(int i = 0; i < n; i++) { int x, y; read(x, y); p[i] = Point(x, y); } int m; read(m); vector g(m); for(int i = 0; i < m; i++) { int x, y; read(x, y); g[i] = Point(x, y); } auto go = [](vector g, vector p) -> int { get_unique(g); get_unique(p); if(g.size() == 1) { if(p.size() == 1 && p.front() == g.front()) return 1; return -1; } if(p.size() == 1) { for(auto &x : g) if(x == p.front()) return 1; } vector> ck(g.size(), vector(g.size())); for(int i = 0; i < g.size(); i++) for(int j = 0; j < g.size(); j++) { if(i == j) { ck[i][j] = 0; } else { bool f = 1; for(auto &x : p) { if(((g[j] - g[i]) ^ (x - g[i])) < 0) { f = 0; break; } } ck[i][j] = f; } } vector> dp(g.size(), vector(g.size())), dp2(dp); for(int i = 0; i < g.size() - 1; i++) { dp[i][i] = 1; for(int j = i + 1; j < g.size(); j++) { dp[i][j] = INF; for(int k = i; k < j; k++) { if(ck[k][j]) get_min(dp[i][j], dp[i][k] + 1); } } } for(int i = g.size() - 1; i > 0; i--) { dp2[i][i] = 1; for(int j = i - 1; j >= 0; j--) { dp2[i][j] = INF; for(int k = i; k > j; k--) { if(ck[k][j]) get_min(dp2[i][j], dp2[i][k] + 1); } } } int res = INF; for(int i = 0; i < g.size() - 1; i++) for(int j = i + 1; j < g.size(); j++) { int w = dp[i][j] + dp2[j][i] - 2; if(w == 2) { bool f = 1; for(auto &x : p) { if(x.x < g[i].x || g[j].x < x.x) { f = 0; break; } } if(f) get_min(res, w); } else { get_min(res, w); } } if(res >= INF) res = -1; return res; }; int ans = go(g, p); if(ans == -1) { cout <<"ToT" <