malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double power(float x, int y) {     float temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       if (y > 0)         return x * temp * temp;       else         return (temp * temp) / x;     }   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     ;     long long int ans = a[0];     long long int t = a[0];     for (long long int i = 1; i < n; i++) {       t += a[i];       ans = min(ans, t);     }     cout << abs(ans) << endl;   }   int main() {     long long int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int64_t calc(int64_t l, int64_t r, int64_t ln) {     if (ln < 2) return 1;     int64_t mx = max(l, r);     int64_t mn = min(l, r);     int64_t ans = (int64_t)pow(201, (ln - 2));     cout << ans << endl;     ans += (int64_t)pow((201 - mx + 1), (ln - 1));     cout << ans << endl;     int64_t to = 201 - mn;     int64_t fr = to - mx + mn + 1;     cout << fr <<     << to << endl;     ans += (to * (to + 1)) / 2;     ans -= (fr * (fr + 1)) / 2;     cout <<  ANS:   << l <<     << r <<     << ln <<   =   << ans << endl;     return ans;   }   int main() {     int n;     cin >> n;     int a[n + 2];     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i + 1]);     }     a[0] = 1;     a[n + 1] = 1;     n += 2;     int64_t *dp[2][201], ps[2][201];     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 201; ++j) {         dp[i][j] = (int64_t *)calloc(n, sizeof(int64_t));         ps[i][j] = 0;       }     }     dp[0][1][0] = 1;     ps[0][0] = dp[0][0][0];     ps[1][0] = dp[1][0][0];     for (int j = 1; j < 201; ++j) {       ps[0][j] = ps[0][j - 1] + dp[0][j][0];       ps[1][j] = ps[1][j - 1] + dp[1][j][0];       ps[0][j] %= 998244353;       ps[1][j] %= 998244353;     }     for (int i = 1; i < n; ++i) {       if (a[i] == -1) {         for (int j = 1; j < 201; ++j) {           dp[0][j][i] = ps[1][j - 1] + ps[0][j - 1];           dp[0][j][i] %= 998244353;           dp[1][j][i] = dp[0][j][i - 1] +                         ((ps[1][201 - 1] - ps[1][j - 1] + 998244353) % 998244353);           dp[1][j][i] %= 998244353;         }       } else {         dp[1][a[i]][i] = dp[0][a[i]][i - 1];         for (int j = a[i]; j < 201; ++j) {           dp[1][a[i]][i] += dp[1][j][i - 1];           dp[1][a[i]][i] %= 998244353;         }         dp[0][a[i]][i] = 0;         for (int j = 1; j < a[i]; ++j) {           dp[0][a[i]][i] += dp[0][j][i - 1] + dp[1][j][i - 1];           dp[0][a[i]][i] %= 998244353;         }       }       ps[0][0] = dp[0][0][i];       ps[1][0] = dp[1][0][i];       for (int j = 1; j < 201; ++j) {         ps[0][j] = ps[0][j - 1] + dp[0][j][i];         ps[1][j] = ps[1][j - 1] + dp[1][j][i];         ps[0][j] %= 998244353;         ps[1][j] %= 998244353;       }     }     int64_t ans = 0;     for (int i = 1; i < 201; ++i) {       ans += dp[0][i][n - 1];       ans %= 998244353;       ans += dp[1][i][n - 1];       ans %= 998244353;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-6;   int main() {     { ; };     int n;     scanf( %d , &n);     vector<pair<int, int> > V(n);     int totalW = 0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &V[i].first, &V[i].second);       totalW += V[i].first;     }     int res = ((1 << 30) - 1);     for (int maxH = 1; maxH <= 1000; maxH++) {       bool testOK = true;       int coda = n / 2;       int nowW = totalW;       vector<int> candidate;       for (int i = 0; i < n && testOK; i++) {         if (V[i].second > maxH) {           if (V[i].first > maxH)             testOK = false;           else {             if (coda == 0)               testOK = false;             else               nowW += V[i].second - V[i].first;             coda--;           }         } else {           if (V[i].first > V[i].second && V[i].first <= maxH) {             candidate.emplace_back(V[i].second - V[i].first);           }         }       }       if (testOK) {         sort((candidate).begin(), (candidate).end());         nowW += accumulate(             candidate.begin(),             candidate.begin() + min(((int)(candidate).size()), coda), 0);         res = min(res, nowW * maxH);       }     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   int findMaximalK(int n);   using namespace std;   int main() {     int n, b, p, x, y;     cin >> n >> b >> p;     y = n * p;     x = 0;     int remaining = n;     while (remaining > 1) {       int doingMatch = pow(2, findMaximalK(remaining));       x += doingMatch * b + doingMatch / 2;       int passToNextRound = remaining - doingMatch / 2;       remaining = passToNextRound;     }     cout << x <<     << y;   }   int findMaximalK(int n) {     int count = 0;     while (n > 1) {       n /= 2;       count++;     }     return count;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int M = 1e7 + 5;   const int N = 3e5 + 5;   struct node {     vector<int> h, c;     node() {       h.clear();       c.clear();     }     void read(int n) {       int ans;       for (int i = 0; i < n; i++) {         scanf( %d , &ans);         h.push_back(ans);       }       for (int i = 0; i < n; i++) {         scanf( %d , &ans);         c.push_back(ans);       }     }   };   vector<node> a;   int h[M];   LL c[M];   int tl[M], tr[M];   LL dp[M];   stack<int> sk;   void reads(int &n) {     int m, k, q;     LL mul;     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; i++) {       scanf( %d , &k);       node tmp;       tmp.read(k);       a.push_back(tmp);     }     scanf( %d , &q);     n = 0;     while (q--) {       scanf( %d%I64d , &k, &mul);       k--;       for (int i = 0; i < a[k].h.size(); i++) {         h[++n] = a[k].h[i];         c[n] = mul * a[k].c[i];       }     }   }   void make_tl(int n) {     for (int i = n; i >= 1; i--) {       while (!sk.empty() && h[sk.top()] <= sk.top() - i) {         tl[sk.top()] = i + 1;         sk.pop();       }       sk.push(i);     }     while (!sk.empty()) {       tl[sk.top()] = 1;       sk.pop();     }   }   void make_tr(int n) {     for (int i = 1; i <= n; i++) {       while (!sk.empty() && h[sk.top()] <= i - sk.top()) {         tr[sk.top()] = i - 1;         sk.pop();       }       sk.push(i);     }     while (!sk.empty()) {       tr[sk.top()] = n;       sk.pop();     }   }   int main() {     int n;     reads(n);     make_tl(n);     make_tr(n);     for (int i = 1; i <= n; i++) {       dp[i] = dp[tl[i] - 1] + c[i];       while (!sk.empty() && tr[sk.top()] < i) sk.pop();       if (!sk.empty()) dp[i] = min(dp[i], dp[sk.top() - 1] + c[sk.top()]);       if (sk.empty() || dp[sk.top() - 1] + c[sk.top()] > dp[i - 1] + c[i])         sk.push(i);     }     printf( %I64d n , dp[n]);     return 0;   }
#include <bits/stdc++.h>   long long Max(const long long x, const long long y) {     if (x > y) return x;     return y;   }   const long long mo = 1e9 + 7, M = 1005;   char s[M];   long long k, a[M], len, dp[M][M][2];   long long dfs(const long long pos, const long long dis, const bool pd,                 const bool lim) {     if (!pos) return pd;     if (!lim && ~dp[pos][dis][pd]) return dp[pos][dis][pd];     long long res = 0, up = lim ? a[pos] : 9;     for (long long i = 0; i <= up; ++i)       if (i != 4 && i != 7)         res = (res + dfs(pos - 1, Max(dis - 1, 0), pd, lim && i == up)) % mo;       else         res = (res + dfs(pos - 1, k, dis || pd, lim && i == up)) % mo;     if (!lim) dp[pos][dis][pd] = res;     return res;   }   long long check() {     long long last = 0x3f3f3f3f;     for (long long i = len; i; --i)       if (a[i] == 4 || a[i] == 7) {         if (last - i <= k) return 1;         last = i;       }     return 0;   }   signed main() {     memset(dp, -1, sizeof dp);     long long T;     scanf( %lld%lld , &T, &k);     while (T--) {       scanf( %s , s);       len = strlen(s);       for (long long i = 0; i < len; ++i) a[len - i] = s[i] ^ 48;       long long ans = (dfs(len, 0, 0, 1) - check() + mo) % mo;       scanf( %s , s);       len = strlen(s);       for (long long i = 0; i < len; ++i) a[len - i] = s[i] ^ 48;       ans = (dfs(len, 0, 0, 1) - ans + mo) % mo;       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   template <class Class>   void Print(Class instance) {     std::cout << instance << std::endl;   }   void Print() { std::cout << std::endl; }   int main() {     std::ios_base::sync_with_stdio(false);     size_t n;     std::cin >> n;     std::vector<int> time(n + 1);     std::vector<int> paid(n + 1);     size_t hour_pointer = 0;     size_t day_pointer = 0;     int hour_paid = 0;     int day_paid = 0;     for (size_t index = 1; index < n + 1; ++index) {       std::cin >> time[index];       while (time[hour_pointer] + 90 <= time[index]) {         hour_paid -= paid[hour_pointer];         ++hour_pointer;       }       while (time[day_pointer] + 1440 <= time[index]) {         day_paid -= paid[day_pointer];         ++day_pointer;       }       paid[index] = std::min({20, 50 - hour_paid, 120 - day_paid});       hour_paid += paid[index];       day_paid += paid[index];       Print(paid[index]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   multiset<int> s1;   struct node {     char s;     int a1;   } p1[int(1e6 + 50)];   char s[50];   int main() {     int n, a;     while (~scanf( %d , &n)) {       int cnt = 0;       s1.clear();       for (int i = 0; i < n; i++) {         scanf( %s , s);         if (s[0] !=  r ) {           scanf( %d , &a);           if (s[0] ==  i ) {             s1.insert(a);             p1[cnt].s =  i ;             p1[cnt++].a1 = a;           } else if (s[0] ==  g ) {             while (!s1.empty() && (*s1.begin()) < a) {               s1.erase(s1.begin());               p1[cnt++].s =  r ;             }             if (s1.empty() || (!s1.empty() && (*s1.begin()) > a)) {               s1.insert(a);               p1[cnt].s =  i ;               p1[cnt++].a1 = a;             }             p1[cnt].s =  g ;             p1[cnt++].a1 = a;           }         } else {           if (!s1.empty()) {             s1.erase(s1.begin());           } else {             p1[cnt].s =  i ;             p1[cnt++].a1 = 0;           }           p1[cnt++].s =  r ;         }       }       printf( %d n , cnt);       for (int i = 0; i < cnt; i++) {         if (p1[i].s ==  i ) {           printf( insert %d n , p1[i].a1);         } else if (p1[i].s ==  g ) {           printf( getMin %d n , p1[i].a1);         } else if (p1[i].s ==  r ) {           printf( removeMin n );         }       }       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vll = vector<long long>;   using vvll = vector<vll>;   using vpii = vector<pair<int, int> >;   using vpll = vector<pair<long long, long long> >;   using vld = vector<long double>;   using vb = vector<bool>;   const int inf = (int)1e9 + 7;   const long long llinf = (long long)1e18 + 7;   void solve() {     long long n;     cin >> n;     vll a[n];     for (long long i = 0; i < n; i++) {       long long ki;       cin >> ki;       for (long long j = 0; j < ki; j++) {         long long x;         cin >> x;         a[i].push_back(x);       }       sort(a[i].begin(), a[i].end());     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long l, r;       l = (i - 1 + n) % n;       r = (i + 1 + n) % n;       for (long long j = 1; j <= (a[i].size()) - 1; j++) {         ans += (upper_bound(a[r].begin(), a[r].end(), a[i][j]) -                     upper_bound(a[r].begin(), a[r].end(), a[i][j - 1]) !=                 upper_bound(a[l].begin(), a[l].end(), a[i][j]) -                     upper_bound(a[l].begin(), a[l].end(), a[i][j - 1]));       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int ttt = 1;     while (ttt--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> yarr(51, 0);     vector<int> xarr(51, 0);     int q = 4 * n + 1;     vector<pair<int, int>> trav;     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       trav.push_back(make_pair(x, y));       xarr[x]++;       yarr[y]++;     }     int maxy = 0;     int maxx = 0;     int minx = 1000, miny = 1000;     int indexx = 0, indexy = 0;     for (int i = 0; i < 51; i++) {       if (yarr[i] >= n && i > maxy) {         maxy = i;       }       if (xarr[i] >= n && i > maxx) {         maxx = i;       }       if (yarr[i] >= n && i < miny) {         miny = i;       }       if (xarr[i] >= n && i < minx) {         minx = i;       }     }     for (int i = 0; i < trav.size(); i++) {       if (trav[i].first == minx && trav[i].second >= miny &&           trav[i].second <= maxy)         continue;       if (trav[i].first == maxx && trav[i].second >= miny &&           trav[i].second <= maxy)         continue;       if (trav[i].second == miny && trav[i].first >= minx &&           trav[i].first <= maxx)         continue;       if (trav[i].second == maxy && trav[i].first >= minx &&           trav[i].first <= maxx)         continue;       cout << trav[i].first <<     << trav[i].second <<   n ;       break;     }   }
#include <bits/stdc++.h>   using namespace std;   long long s[10], m[10];   const long long md = 1e9 + 7;   string str;   int n;   vector<int> v[100010];   int main() {     for (int i = 0; i <= 9; i++) {       m[i] = 10;       s[i] = i;     }     cin >> str;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       v[i].push_back(st[0] -  0 );       for (int j = 3; j < st.size(); j++) v[i].push_back(st[j] -  0 );     }     for (int i = n; i >= 1; i--) {       int cur = v[i][0];       long long mm = 1, ss = 0;       for (int j = 1; j < v[i].size(); j++) {         ss = (ss * m[v[i][j]]) % md;         mm = (mm * m[v[i][j]]) % md;         ss += s[v[i][j]];         if (ss >= md) ss -= md;       }       s[cur] = ss;       m[cur] = mm;     }     long long ans = 0;     for (int i = 0; i < str.size(); i++) {       ans = (ans * m[str[i] -  0 ]) % md;       ans += s[str[i] -  0 ];       if (ans >= md) ans -= md;     }     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int MAXN = 600010;   set<int> g[MAXN];   int n, t, m, k;   int visited[MAXN];   void dfs(int i) {     visited[i] = 1;     for (auto x : g[i])       if (!visited[x]) dfs(x);     return;   }   int main() {     cin >> n;     pair<int, int> a[n];     for (long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second;     sort(a, a + n);     int res = 0;     set<pair<int, pair<int, int> > > s;     for (long long i = 0; i < n; i++) {       auto x =           s.lower_bound({a[i].first, {-((long long)1e15), -((long long)1e15)}});       while (x != s.begin()) {         s.erase(s.begin());       }       auto it =           s.upper_bound({a[i].second, {-((long long)1e15), -((long long)1e15)}});       x = s.begin();       while (x != it) {         g[i].insert(x->second.second);         g[x->second.second].insert(i);         res++;         if (res >= n) {           cout <<  NO                 <<   n ;           return 0;         }         x++;       }       s.insert({a[i].second, {a[i].first, i}});     }     dfs(0);     for (long long i = 0; i < n; i++) {       if (!visited[i]) {         cout <<  NO ;         return 0;       }     }     if (res == n - 1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a, b, c;   vector<pair<int, int> > v[200005], e[200005];   int p[200005];   int fin(int x) {     if (p[x] != x) p[x] = fin(p[x]);     return p[x];   }   void onion(int x, int y) {     if (fin(x) == fin(y)) return;     p[fin(y)] = fin(x);   }   priority_queue<pair<long long, pair<int, int> > > q;   int lca[200005][25], maxi[200005][25];   int depth[200005];   long long sum = 0;   long long cen[200005];   void dfs(int node, int prev) {     for (auto it : e[node]) {       if (it.first == prev) continue;       depth[it.first] = depth[node] + 1;       lca[it.first][0] = node;       maxi[it.first][0] = it.second;       dfs(it.first, node);     }   }   int plz(int x, int y) {     if (depth[x] < depth[y]) swap(x, y);     int res = 0;     for (int i = 20; i >= 0; i--) {       if (depth[x] - (1 << i) >= depth[y]) {         res = max(res, maxi[x][i]);         x = lca[x][i];       }     }     if (x == y) return res;     for (int i = 20; i >= 0; i--) {       if (lca[x][i] != lca[y][i]) {         res = max(res, maxi[x][i]);         res = max(res, maxi[y][i]);         x = lca[x][i];         y = lca[y][i];       }     }     res = max(res, maxi[x][0]);     res = max(res, maxi[y][0]);     return res;   }   pair<int, int> rr[200005];   map<pair<int, int>, int> mapa;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; m >= i; i++) {       scanf( %d%d%d , &a, &b, &c);       rr[i] = {a, b};       cen[i] = c;       v[a].push_back({b, c});       v[b].push_back({a, c});       q.push({-c, {a, b}});     }     for (int i = 1; n >= i; i++) p[i] = i;     while (!q.empty()) {       int cost = -q.top().first;       int u = q.top().second.first;       int uu = q.top().second.second;       q.pop();       if (fin(u) == fin(uu)) continue;       onion(u, uu);       e[u].push_back({uu, cost});       e[uu].push_back({u, cost});       mapa[{u, uu}] = 1;       sum += cost;     }     dfs(1, -1);     for (int j = 1; 20 >= j; j++)       for (int i = 1; n >= i; i++) {         lca[i][j] = lca[lca[i][j - 1]][j - 1];         maxi[i][j] = max(maxi[i][j - 1], maxi[lca[i][j - 1]][j - 1]);       }     int qq;     qq = m;     for (int i = 1; m >= i; i++) {       int a = rr[i].first;       int b = rr[i].second;       if (mapa[{a, b}] == 1) {         printf( %lld n , sum);         continue;       }       long long wynik = 1LL * sum + cen[i] - plz(a, b);       printf( %lld n , wynik);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   const int INF = 0x3f3f3f3f;   int d[MAXN], e[MAXN];   int main() {     memset(d, INF, sizeof d);     memset(e, INF, sizeof e);     int n;     cin >> n;     string s;     cin >> s;     int at = INF;     for (int i = 0; i < n; i++) {       if (s[i] ==  R )         at = 0;       else if (s[i] ==  L )         at = INF;       d[i] = at;       if (at < INF) at++;     }     at = INF;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  R )         at = INF;       else if (s[i] ==  L )         at = 0;       e[i] = at;       if (at < INF) at++;     }     int cont = 0;     for (int i = 0; i < n; i++) {       if (d[i] == e[i]) cont++;     }     cout << cont << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline void Rd(int &res) {     char c;     res = 0;     while (c = getchar(), c <  0 )       ;     do {       res = (res << 1) + (res << 3) + (c ^ 48);     } while (c = getchar(), c >=  0 );   }   const int S = 200;   long long n, s, ans;   int work(long long x) {     int rs = 0;     while (x) {       rs += x % 10;       x /= 10;     }     return rs;   }   int main() {     cin >> n >> s;     for (int i = 1; i <= n && i <= S; i++) {       int sum = work(i);       if (abs(sum - i) >= s) ans++;     }     if (n > S) {       ans += max((long long)0, n - (s + S) + 1);       if (s < S) {         for (long long i = S + 1; i < s + S && i <= n; i++) {           int sum = work(i);           if (abs(sum - i) >= s) ans++;         }       } else {         for (long long i = s; i < s + S && i <= n; i++) {           int sum = work(i);           if (abs(sum - i) >= s) ans++;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, i, fuck = 0;     scanf( %lld , &a);     scanf( %lld , &b);     scanf( %lld , &c);     for (i = a; i >= 1; i--) {       if ((2 * i) <= b && (4 * i) <= c) {         fuck = 1;         break;       }     }     if (fuck == 0)       printf( 0 n );     else       printf( %lld  , i + 2 * i + 4 * i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long pw[1020304], iv[1020304];   unsigned long long h[1020304], f[1020304];   int check(int l, int r) {     unsigned long long p1 = (h[r] + 1000000007 -                              h[l - 1] * pw[r - l + 1] % 1000000007) %                             1000000007,                        p2 = (f[r] + 1000000007 - f[l - 1]) * iv[l - 1] %                             1000000007;     return p1 == p2;   }   int n, d;   char s[1020304];   bool dfs(int i, bool w) {     if (i == 4) {       int z = i;     }     if (i > n && w) cout << s + 1 << endl;     if (i > n) return w;     char t = s[i];     for (char c = (w) ?  a  : s[i]; c <=  z ; c++) {       if (i >= d)         if (check(i - d + 2, i - 1) && s[i - d + 1] == c) continue;       if (i > d)         if (check(i - d + 1, i - 1) && s[i - d] == c) continue;       h[i] = (h[i - 1] * 10007 + c) % 1000000007;       f[i] = (f[i - 1] + pw[i - 1] * c) % 1000000007;       s[i] = c;       if (dfs(i + 1, c > t || w)) return true;     }     s[i] = t;     return false;   }   int main() {     unsigned long long t = 1;     pw[0] = iv[0] = 1;     for (int i = 1; i <= 400000; ++i)       pw[i] = pw[i - 1] * 10007 % 1000000007,       iv[i] = iv[i - 1] * 820925358 % 1000000007;     cin >> d;     scanf( %s , s + 1);     n = strlen(s + 1);     if (d == 1) {       puts( Impossible );       return 0;     }     if (!dfs(1, 0)) {       puts( Impossible );       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 150000;   const int L = 19;   vector<int> edges[N];   long long x[N], y[N];   int anc[N][L], tin[N], tout[N], s[N], moment;   void dfs(int x, int last) {     tin[x] = ++moment;     anc[x][0] = last;     for (int i = 1; i < L; i++) anc[x][i] = anc[anc[x][i - 1]][i - 1];     for (int i = 0; i < edges[x].size(); i++)       if (edges[x][i] != last) dfs(edges[x][i], x);     tout[x] = ++moment;   }   long long coef(int i, int j, int k) {     long long a = y[i] - y[j], b = x[j] - x[i], c = x[i] * y[j] - x[j] * y[i];     return (a * x[k] + b * y[k] + c);   }   bool father(int x, int y) { return (tin[x] <= tin[y] && tout[y] <= tout[x]); }   int lca(int a, int b) {     if (father(a, b)) return a;     if (father(b, a)) return b;     for (int i = L - 1; i >= 0; i--)       if (!father(anc[a][i], b)) a = anc[a][i];     return anc[a][0];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d %I64d , &x[i], &y[i]);     int cnt = 1;     s[cnt] = n;     for (int i = n - 1; i >= 1; i--) {       s[++cnt] = i;       while (cnt > 2 && coef(s[cnt], s[cnt - 2], s[cnt - 1]) < 0)         swap(s[cnt - 1], s[cnt]), cnt--;       edges[s[cnt]].push_back(s[cnt - 1]);       edges[s[cnt - 1]].push_back(s[cnt]);     }     moment = 0, dfs(n, n);     int quests;     scanf( %d , &quests);     for (int i = 1; i <= quests; i++) {       int x, y;       scanf( %d %d , &x, &y);       printf( %d  , lca(x, y));     }     return 0;   }