func_code_string: #include <bits/stdc++.h>   using namespace std;   const int block_size = 320;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 7;   const long double eps = 1e-9;   const double PI = atan(1) * 4;   template <typename T>   inline int sign(const T &a) {     if (a < 0) return -1;     if (a > 0) return 1;     return 0;   }   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T, typename S>   inline bool upmin(T &a, const S &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T &a, const S &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   inline void in(T &x) {     x = 0;     T f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   long long twop(int x) { return 1LL << x; }   template <typename T>   T MOD(T a, T m) {     a %= m;     if (a < 0) a += m;     return a;   }   template <typename T>   T inverse(T a, T m) {     a = MOD(a, m);     if (a <= 1) return a;     return MOD((1 - inverse(m, a) * m) / a, m);   }   template <typename A, typename B>   inline void in(A &x, B &y) {     in(x);     in(y);   }   template <typename A, typename B, typename C>   inline void in(A &x, B &y, C &z) {     in(x);     in(y);     in(z);   }   template <typename A, typename B, typename C, typename D>   inline void in(A &x, B &y, C &z, D &d) {     in(x);     in(y);     in(z);     in(d);   }   template <typename T>   T sqr(T x) {     return x * x;   }   long long gcd(long long a, long long b) {     while (b != 0) {       a %= b;       swap(a, b);     }     return a;   }   long long fast(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) {         b--;         ans = ans * a % mod;       } else {         a = a * a % mod;         b /= 2;       }     }     return ans % mod;   }   pair<long long, long long> operator-(const pair<long long, long long> &a,                                        const pair<long long, long long> &b) {     return make_pair(a.first - b.first, a.second - b.second);   }   long long cp(pair<long long, long long> o, pair<long long, long long> a,                pair<long long, long long> b) {     a = a - o;     b = b - o;     return a.first * b.second - a.second * b.first;   }   pair<long long, long long> process(pair<long long, long long> diff) {     long long g = abs(gcd(diff.first, diff.second));     diff.first /= g;     diff.second /= g;     return diff;   }   template <int maxn, typename NUM>   struct BIT {     NUM s[maxn];     void init() { memset(s, 0, sizeof(s)); }     BIT() { init(); }     void update(int a, NUM value) {       a++;       while (a < maxn) {         s[a] += value;         a += ((a) & (-(a)));       }     }     NUM query(int a) {       NUM ans = 0;       a++;       while (a) {         ans += s[a];         a -= ((a) & (-(a)));       }       return ans;     }     NUM query(int a, int b) {       if (b < a) return 0;       return query(b) - query(a - 1);     }   };   BIT<300010, long long> bit;   namespace SOLVE {   vector<vector<pair<long long, long long>>> vec;   bool cmp(const pair<pair<long long, long long>, long long> &a,            const pair<pair<long long, long long>, long long> &b) {     return a.first.second < b.first.second;   }   long long ans[300010];   void main() {     int n;     in(n);     vec.resize(n + 1);     for (long long i = 1; i < n + 1; i++) {       int c;       in(c);       vector<pair<long long, long long>> v;       for (long long j = 0; j < c; j++) {         pair<long long, long long> x;         in(x.first, x.second);         v.push_back(x);       }       v.push_back(v[0]);       for (long long j = 1; j < c + 1; j++) {         vec[i].push_back(process(v[j] - v[j - 1]));       }     }     int q;     in(q);     vector<pair<pair<long long, long long>, long long>> query(q);     for (long long i = 0; i < q; i++) {       in(query[i].first.first, query[i].first.second);       query[i].second = i;     }     sort(begin(query), end(query), cmp);     int cur = 0;     map<pair<long long, long long>, int> occ;     for (auto q : query) {       while (cur < q.first.second) {         ++cur;         for (auto v : vec[cur]) {           bit.update(occ[v], -1);           bit.update(cur, 1);           occ[v] = cur;         }       }       ans[q.second] = bit.query(q.first.first, q.first.second);     }     {};     for (long long i = 0; i < q; i++) cout << ans[i] << endl;   }   }  // namespace SOLVE   signed main() {     int t = 1;     while (t--) {       SOLVE::main();     }     return 0;   }   