malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int MAX = 30;   long long x, num;   long long a[40];   bool check(long long x) {     for (int i = 1; i < MAX; ++i) {       if (a[i] == x) return 1;     }     return 0;   }   vector<int> ans;   int main() {     long long x = 1;     for (int i = 1; i < MAX; ++i) {       x <<= 1;       a[i] = x - 1;     }     scanf( %lld , &x);     while (check(x) == 0) {       int i;       num++;       for (i = MAX - 1; i >= 0; --i) {         if (x >> i) break;       }       x ^= a[i + 1];       ans.push_back(i + 1);       if (check(x)) break;       num++;       x++;     }     printf( %d n , num);     for (auto i : ans) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:67108864 )   using namespace std;   vector<int> g[200000];   bool def[200000], del[200000];   int all[200000], good[200000], _good[200000];   int n, m, k;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) {       int t;       scanf( %d , &t);       def[t - 1] = true;     }     for (int i = 0; i < m; i++) {       int from, to;       scanf( %d%d , &from, &to);       from--, to--;       g[from].push_back(to);       g[to].push_back(from);       if (def[from]) good[to]--;       if (def[to]) good[from]--;       all[from]++, all[to]++;     }     memcpy(_good, good, sizeof good);     priority_queue<pair<double, int>, vector<pair<double, int>>,                    greater<pair<double, int>>>         q;     for (int i = 0; i < n; i++) {       good[i] += all[i];       if (!def[i]) q.push(make_pair((double)good[i] / all[i], i));     }     double best = -1;     while (!q.empty()) {       int v = q.top().second;       double ratio = q.top().first;       q.pop();       if (del[v]) continue;       del[v] = true;       best = max(best, ratio);       for (auto it = g[v].begin(); it != g[v].end(); it++) {         if (def[*it] || del[*it]) continue;         good[*it]--;         q.push(make_pair((double)good[*it] / all[*it], *it));       }     }     memset(del, false, sizeof del);     memcpy(good, _good, sizeof _good);     for (int i = 0; i < n; i++) {       good[i] += all[i];       if (!def[i]) q.push(make_pair((double)good[i] / all[i], i));     }     double cur = -1;     while (!q.empty()) {       int v = q.top().second;       double ratio = q.top().first;       q.pop();       if (del[v]) continue;       cur = max(cur, ratio);       if (cur == best) break;       del[v] = true;       for (auto it = g[v].begin(); it != g[v].end(); it++) {         if (def[*it] || del[*it]) continue;         good[*it]--;         q.push(make_pair((double)good[*it] / all[*it], *it));       }     }     int r = 0;     for (int i = 0; i < n; i++)       if (!(del[i] || def[i])) r++;     printf( %d n , r);     for (int i = 0; i < n; i++)       if (!(del[i] || def[i])) printf( %d  , i + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.14159265358979323846;   const long long mod = 1e9 + 7;   const long long N = 5e5;   const long long INF = 1e9 + 1;   long long n, m, ans;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       long long a, b;       cin >> a >> b;       ans = max(ans, a + b);     }     cout << max(ans, m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     long long int n;     cin >> n;     cout << 1 <<    ;     n--;     for (int i = 1; i <= 2; i++) {       if ((n - i) % 3 != 0) {         cout << i <<     << n - i;         break;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, sum, prv[100010], val[100010], a[100010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         val[i] = 1, sum = a[i];       else {         if (sum <= a[i]) {           val[i] = 1;           prv[i] = -1;           sum = a[i] - sum;         } else {           val[i] = -1;           prv[i] = 1;           sum -= a[i];         }       }     }     for (int i = 0; i < n - 1; i++) {       val[i + 1] *= prv[i];       prv[i + 1] *= prv[i];     }     for (int i = 0; i < n; i++) printf(val[i] == 1 ?  +  :  - );     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int next(int a) { return a < 2 ? 1 : (next(a - 2) + (a - 1) / 2); }   int main() {     long int N;     cin >> N;     long int ret = 1;     cout << (N + 1) / 2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, f = 0, ans = 0;       cin >> n;       long long a[n];       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n - 1; i++) {         if (a[i + 1] < a[i]) ans += (a[i] - a[i + 1]);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, h, x, m1 = 0, m2 = 0;     cin >> n >> h;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x > h) {         m1 += 2;       } else {         m2++;       }     }     cout << m1 + m2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 4, inf = 1e9 + 7;   vector<int> vec[N];   vector<pair<int, int> > qry[N];   int col[N], cnt[N], frq[N];   int vis[N], siz[N], Res[N];   void dfs(int u, int p) {     siz[u] = 1;     for (auto v : vec[u]) {       if (v == p) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   void Add(int u, int p) {     cnt[++frq[col[u]]]++;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Add(v, u);     }   }   void Rem(int u, int p) {     cnt[frq[col[u]]--]--;     for (auto v : vec[u]) {       if (v == p || vis[v]) continue;       Rem(v, u);     }   }   void DFS(int u, int p, bool first) {     int mx = -1, id = -1;     for (auto v : vec[u]) {       if (v == p) continue;       if (siz[v] > mx) mx = siz[v], id = v;     }     for (auto v : vec[u]) {       if (v == p || v == id) continue;       DFS(v, u, 1);     }     if (id != -1) DFS(id, u, 0), vis[id] = 1;     Add(u, p);     for (auto x : qry[u]) Res[x.second] = cnt[x.first];     if (id != -1) vis[id] = 0;     if (first) Rem(u, p);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> col[i];     int m = n - 1;     while (m--) {       int u, v;       cin >> u >> v;       vec[u].push_back(v);       vec[v].push_back(u);     }     dfs(1, 1);     for (int i = 1; i <= q; i++) {       int v, k;       cin >> v >> k;       qry[v].push_back(make_pair(k, i));     }     DFS(1, 1, 0);     for (int i = 1; i <= q; i++) cout << Res[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000 * 1000 * 1000;   struct rib {     long long b, u, c, f;     size_t back;   };   void add_rib(vector<vector<rib> >& g, long long a, long long b, long long u,                long long c) {     rib r1 = {b, u, c, 0, g[b].size()};     rib r2 = {a, 0, -c, 0, g[a].size()};     g[a].push_back(r1);     g[b].push_back(r2);   }   namespace k {   long long n, m, k, c, d;   }   vector<long long> vr[55];   long long lr[50];   int main() {     long long n = 6001, m, k = INF;     vector<vector<rib> > g(n);     long long s, t;     cin >> k::n >> k::m >> k::k >> k::c >> (k::d);     long long tim = 100;     for (int i = 1; i < k::k + 1; i++) {       cin >> lr[i];       add_rib(g, 0, lr[i], 1, 0);     }     for (int j = 0; j < tim - 1; j++) {       for (int i = 2; i < k::n + 1; i++)         add_rib(g, j * 50 + i, (j + 1) * 50 + i, 50, k::c);     }     for (int j = 1; j < tim; j++) {       add_rib(g, j * 50 + 1, 1, 50, 0);     }     for (int i = 0; i < k::m; i++) {       long long x, y;       cin >> x >> y;       vr[x].push_back(y);       vr[y].push_back(x);       for (int j = 0; j < tim - 1; j++) {         for (int l = 0; l < 50; l++) {           add_rib(g, j * 50 + x, (j + 1) * 50 + y, 1,                   (k::c) + (k::d) * ((l + 1) * (l + 1) - (l * l)));           add_rib(g, j * 50 + y, (j + 1) * 50 + x, 1,                   (k::c) + (k::d) * ((l + 1) * (l + 1) - (l * l)));         }       }     }     s = 0, t = 1;     long long flow = 0, cost = 0;     while (flow < k) {       vector<long long> id(n, 0);       vector<long long> d(n, INF);       vector<long long> q(n);       vector<long long> p(n);       vector<size_t> p_rib(n);       long long qh = 0, qt = 0;       q[qt++] = s;       d[s] = 0;       while (qh != qt) {         long long v = q[qh++];         id[v] = 2;         if (qh == n) qh = 0;         for (size_t i = 0; i < g[v].size(); ++i) {           rib& r = g[v][i];           if (r.f < r.u && d[v] + r.c < d[r.b]) {             d[r.b] = d[v] + r.c;             if (id[r.b] == 0) {               q[qt++] = r.b;               if (qt == n) qt = 0;             } else if (id[r.b] == 2) {               if (--qh == -1) qh = n - 1;               q[qh] = r.b;             }             id[r.b] = 1;             p[r.b] = v;             p_rib[r.b] = i;           }         }       }       if (d[t] == INF) break;       long long addflow = k - flow;       for (long long v = t; v != s; v = p[v]) {         long long pv = p[v];         size_t pr = p_rib[v];         addflow = min(addflow, g[pv][pr].u - g[pv][pr].f);       }       for (long long v = t; v != s; v = p[v]) {         long long pv = p[v];         size_t pr = p_rib[v], r = g[pv][pr].back;         g[pv][pr].f += addflow;         g[v][r].f -= addflow;         cost += g[pv][pr].c * addflow;       }       flow += addflow;     }     cout << cost <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int s, n, x, y;     cin >> s >> n;     vector<pair<int, int> > v;     pair<int, int> p;     for (int i = 0; i < n; i++) {       cin >> x >> y;       p = make_pair(x, y);       v.push_back(p);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       if (v[i].first < s)         s += v[i].second;       else {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10, maxm = 10000 + 10;   long long n, m, drt = 1, x = 1, y = 1, ans = 0, dis = 0, o = 0;   char mat[maxn][maxm];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       mat[i][0] =  # ;       mat[i][m + 1] =  # ;       for (int j = 1; j <= m; j++) {         cin >> mat[i][j];       }     }     while (x != n) {       if (mat[x][y + drt] ==  #  && o == 2) {         break;       }       if (mat[x + 1][y] ==  . ) {         x++;         dis = 0;         o = 0;       } else if (mat[x][y + drt] ==  # ) {         drt *= (-1);         y += (drt * dis);         ans += dis;         o++;       } else if (mat[x][y + drt] ==  + ) {         mat[x][y + drt] =  . ;         drt *= (-1);         y += (drt * dis);         ans += dis;         o = 0;       } else {         y += drt;         dis++;         o = 0;       }       ans++;     }     if (o == 2) {       cout <<  Never  << endl;     } else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 12, INF = 1e9 + 7;   int a[N];   int main() {     int n, m, i, j, k;     scanf( %d , &(n));     ;     vector<int> dp;     dp.push_back(-100001);     for (i = 0; i < (n); ++i) {       dp.push_back(100001);       scanf( %d , &(a[i]));       ;     }     for (i = 0; i < n; ++i) {       int j = int(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin());       if (dp[j - 1] < a[i] && a[i] < dp[j]) dp[j] = a[i];     }     for (i = 1; i <= n; ++i) {       if (dp[i] == 100001) break;     }     cout << i - 1;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int SIZE = 1e5 + 10;   int t[SIZE * 3], thing[SIZE * 3];   int main() {     int a, b, c, d, start, len, n;     scanf( %d%d%d%d%d%d%d , &n, &a, &b, &c, &d, &start, &len);     for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &thing[i]);     vector<int> T;     T.push_back(-1);     for (int i = 0; i < n; i++) T.push_back(t[i]);     int now = 0;     long long ori = start, ans = 0, MIN = 0;     for (int i = 0; i < n; i++) {       while (now < n && t[now] - t[i] < len) {         ans += thing[now] ? c : -d;         MIN = min(ans, MIN);         now++;       }       if (MIN + ori >= 0) {         printf( %d n , T[i] + 1);         return 0;       }       ans -= (thing[i] ? c : -d);       MIN -= (thing[i] ? c : -d);       ori += (thing[i] ? a : -b);       if (ori < 0) {         printf( -1 n );         return 0;       }     }     printf( %d n , T[n] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int n, x, y;   void upd(pair<int, int> &pos, char mv, int d) {     switch (mv) {       case  U :         pos.second += d;         break;       case  D :         pos.second -= d;         break;       case  L :         pos.first -= d;         break;       case  R :         pos.first += d;         break;     }   }   bool can(pair<int, int> u, pair<int, int> v, int len) {     int d = abs(u.first - v.first) + abs(u.second - v.second);     if ((d & 1) != (len & 1)) return false;     return len >= d;   }   bool ok(int len) {     pair<int, int> pos = make_pair(0, 0);     for (int i = len; i < n; ++i) upd(pos, s[i], 1);     int l = 0, r = len;     while (true) {       if (can(pos, make_pair(x, y), len)) return true;       if (r == n) break;       upd(pos, s[l++], 1);       upd(pos, s[r++], -1);     }     return false;   }   int main() {     cin >> n >> s >> x >> y;     if (!ok(n)) {       cout << -1 << endl;       return 0;     }     int l = 0, r = n;     while (l < r) {       int m = (l + r) >> 1;       if (ok(m))         r = m;       else         l = m + 1;     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const long long int INF = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     long long int i, j, k, a, b, flag = 0, m, n, q, sum, x, y, temp = 1, l, r, g,                                  ans = LLONG_MAX, idx = 0;     cin >> n;     vector<pair<long long int, long long int> > arr;     long long int front[n], back[n];     for (i = 0; i < n; i++) {       cin >> a;       arr.push_back(make_pair(a, i + 1));     }     sort(arr.begin(), arr.end());     front[n - 2] = back[n - 2] = arr[n - 1].second;     for (i = n - 3; i >= 0; i--) {       front[i] = min(front[i + 1], arr[i + 1].second);       back[i] = max(back[i + 1], arr[i + 1].second);     }     for (i = 0; i < n - 1; i++) {       idx = max(abs(arr[i].second - front[i]), abs(arr[i].second - back[i]));       if (arr[i].first < idx)         temp = 0;       else {         temp = arr[i].first / idx;       }       ans = min(ans, temp);       if (ans == 0) break;     }     if (ans == LLONG_MAX) ans = 0;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     while (cin >> str) {       int len = str.size();       int times = 0;       int c = 0, p = 0;       char tmp;       for (int i = int(0); i <= int(len - 1); i++) {         c = 0, p = 0;         tmp = str[i];         if (tmp ==  C ) {           while (str[i] == tmp && i < len) {             c++;             if (c > 5) {               break;             }             i++;           }           i--;           times++;         }         if (tmp ==  P ) {           while (str[i] == tmp && i < len) {             p++;             if (p > 5) {               break;             }             i++;           }           i--;           times++;         }       }       cout << times << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long ans = LONG_LONG_MAX;       for (int i = 1; i * i <= n; i++) {         ans = min(ans, ((i - 1) + ((n + i - 1) / i) - 1));       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int* array;   int f(int index) {     if (array[index] == -1) {       array[index] = index;       return index;     }     if (array[index] == index) return index;     int r = f(array[index]);     array[index] = r;     return r;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int coils = 0;     int connect[n];     array = connect + 0;     int notcoils[n];     for (int i = 0; i < n; i++) {       connect[i] = -1;       notcoils[i] = 0;     }     for (int i = 0; i < m; i++) {       int b, e;       scanf( %d %d , &b, &e);       --b;       --e;       if (b == e) {         if (connect[b] == -1) connect[b] = b;         ++coils;       } else {         int rootb = f(b);         int roote = f(e);         connect[roote] = rootb;         ++notcoils[b];         ++notcoils[e];       }     }     int notcoilsTotal = m - coils;     int r = -1;     for (int i = 0; i < n; i++) {       if (connect[i] != -1)         if (f(i) != r) {           if (r == -1)             r = connect[i];           else {             printf( %d , 0);             return 0;           }         }     }     long long ans = coils;     ans = ans * (ans - 1) / 2 + notcoilsTotal * ans;     for (int i = 0; i < n; i++) {       long long nc = notcoils[i];       ans += nc * (nc - 1) / 2;     }     std::cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MM = 2e5 + 34;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  ( ;     os << v.first <<  ,  << v.second <<  ) ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     int sz = v.size();     for (int i = 0; i < sz; ++i) {       os << v[i];       if (i != sz - 1) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     T last = *v.rbegin();     os <<  [ ;     for (auto it : v) {       os << it;       if (it != last) os <<  , ;     }     os <<  ] n ;     return os;   }   vector<int> fact[MM];   void pre() {     for (int i = 1; i < MM; i++) {       for (int j = i; j < MM; j += i) {         fact[j].push_back(i);       }     }   }   int dp[MM];   bool done[MM];   int ans[MM];   int cnt = 100;   int grund(int x) {     if ((x & (x - 1)) == 0) {       done[x] = 1;       dp[x] = 0;     }     if (done[x]) {       return dp[x];     }     int maxx = fact[2 * x].size() + 5;     vector<bool> mex(maxx, 0);     for (int u : fact[2 * x]) {       if (u == 1) {         continue;       }       int cnt = u;       int st = (((2 * x) / u) + 1 - u) / 2;       if ((((2 * x) / u) + 1 - u) % 2) {         continue;       }       int cur = 0;       if (st <= 0) {         break;       }       for (int i = 0; i < cnt; i++) {         cur ^= grund(st + i);       }       if (cur == 0) {         ans[x] = min(ans[x], cnt);       }       if (cur < maxx) {         mex[cur] = 1;       }     }     done[x] = 1;     while (mex[dp[x]]) {       dp[x]++;     }     return dp[x];   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     pre();     int N;     cin >> N;     ans[N] = 1e9;     int u = grund(N);     if (u == 0) {       cout << -1 <<   n ;       return 0;     }     cout << ans[N];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, dp[200000];   vector<long long> bit(200000, 0);   void update(long long x, long long val) {     while (x <= n) {       bit[x] ^= val;       x += x & -x;     }   }   long long query(long long x) {     long long ans = 0;     while (x) {       ans ^= bit[x];       x -= x & -x;     }     return ans;   }   long long mex(vector<long long> v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), v.end());     v.push_back(1000000000000000000);     long long i = 0;     while (v[i] == i) i++;     return i;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> n;     for (long long i = 3; i < n + 1; i++) {       vector<long long> v;       for (long long j = 2; j * (j + 1) / 2 <= i; j++) {         if ((2 * i - j * (j + 1)) % (2 * j) != 0) continue;         long long l = (2 * i - j * (j + 1)) / (2 * j) + 1;         long long r = l + j - 1;         v.push_back(query(r) ^ query(l - 1));       }       dp[i] = mex(v);       update(i, dp[i]);     }     if (!dp[n])       cout <<  -1 n ;     else {       for (long long j = 2; j * (j + 1) / 2 <= n; j++) {         if ((2 * n - j * (j + 1)) % (2 * j) != 0) continue;         long long l = (2 * n - j * (j + 1)) / (2 * j) + 1;         long long r = l + j - 1;         if ((query(r) ^ query(l - 1)) == 0) return cout << j <<   n , 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int mxnn = 300000 + 10, inf = 0x3f3f3f3f;   int n, q, a, cnt;   int head[mxnn], son[mxnn], ans[mxnn], fa[mxnn];   struct node {     int u, v, next;   } e[mxnn << 1];   void adde(int u, int v) {     e[++cnt].u = u;     e[cnt].v = v;     e[cnt].next = head[u];     head[u] = cnt;   }   void read(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = getchar();     }     x *= f;   }   void dfs(int u, int va) {     ans[u] = u;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       dfs(v, u);       son[u] += son[v];     }     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].v;       if (v == va) continue;       if (son[v] * 2 > son[u]) {         ans[u] = ans[v];         break;       }     }     while (son[u] > 2 * son[ans[u]]) ans[u] = fa[ans[u]];   }   int main() {     memset(head, -1, sizeof head);     read(n), read(q);     for (int i = 1; i <= n; ++i) son[i] = 1;     for (int i = 2; i <= n; ++i) {       read(a);       adde(a, i);       adde(i, a);       fa[i] = a;     }     dfs(1, 0);     while (q--) {       read(a);       printf( %d n , ans[a]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > v(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> v[i][j];       }     }     vector<vector<int> > res(n, vector<int>(m));     for (int j = 0; j < m; j++) {       for (int i = 0; i < n; i++) {         if (i == 0)           res[i][j] = 0;         else {           if (v[i][j] >= v[i - 1][j])             res[i][j] = res[i - 1][j];           else             res[i][j] = i;         }       }     }     vector<int> ans(n);     for (int i = 0; i < n; i++) {       int curres = 0;       for (int j = 0; j < m; j++) {         int c = res[i][j];         if (res[i][j] < res[i][curres]) {           curres = j;         }       }       ans[i] = res[i][curres];     }     int k;     cin >> k;     for (int i = 0; i < k; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       if (ans[r] <= l)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }     return 0;   }