malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int num = 0;     char c = getchar();     if (c ==  - ) return -read();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   inline long long READ() {     long long num = 0;     char c = getchar();     if (c ==  - ) return -READ();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   vector<int> nz[100007], nf[100007];   pair<int, int> en[100007];   int cost[100007];   int djg = 0;   bool lgl[100007], l8[100007];   int minv = ((int)0x3f3f3f3f), mincnt = 0;   long long ans = 1, ans2 = 0;   int n, m;   void dfs(int now) {     l8[now] = 1;     for (int i = 0; i < ((int)(nz[now]).size()); i++)       if (!l8[nz[now][i]]) dfs(nz[now][i]);     en[now] = make_pair(djg++, now);   }   void dfs2(int now) {     lgl[now] = 1;     if (cost[now] < minv) {       minv = cost[now];       mincnt = 1;     } else if (cost[now] == minv)       mincnt++;     for (int i = 0; i < ((int)(nf[now]).size()); i++)       if (!lgl[nf[now][i]]) dfs2(nf[now][i]);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , cost + i);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       nz[a].push_back(b);       nf[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (!l8[i]) dfs(i);     sort(en + 1, en + n + 1);     for (int i = n; i >= 1; i--)       if (!lgl[en[i].second]) {         minv = ((int)0x3f3f3f3f);         dfs2(en[i].second);         ans = ans * mincnt % 1000000007;         ans2 += minv;       }     printf( %I64d %I64d n , ans2, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int slope[150 + 1];   int main(void) {     int w, h;     scanf( %d%d , &w, &h);     for (int i = 0; i < 2; i++) {       int ww, hh;       scanf( %d%d , &ww, &hh);       slope[hh] = ww;     }     while (h > 0) {       w += h;       if (slope[h] > 0) w = max(0, w - slope[h]);       h--;     }     printf( %d n , w);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sign(long long x) { return x < 0 ? -1 : 1; }   pair<long long, long long> part(long long from, long long to, long long s,                                   long long dir) {     pair<long long, long long> res{dir, abs(to - from)};     if (to != from && sign(to - from) != sign(dir)) {       res.first *= -1;       res.second += 2 * abs(from - (dir == -1 ? 0 : s));     }     return res;   }   long long solve(long long s, long long x1, long long x2, long long t1,                   long long t2, long long p, long long d) {     auto toTram = part(p, x1, s, d);     return min(part(x1, x2, s, sign(x2 - x1)).second * t2,                (toTram.second + part(x1, x2, s, toTram.first).second) * t1);   }   void tests() {     assert(7 == solve(10, 3, 8, 1, 2, 1, 1));     assert(9 == solve(10, 3, 8, 1, 2, 1, -1));     assert(10 == solve(10, 3, 8, 1, 2, 2, -1));     assert(12 == solve(10, 3, 8, 1, 5, 4, -1));     assert(24 == solve(10, 3, 8, 1, 5, 4, 1));     assert(20 == solve(10, 3, 8, 1, 4, 4, 1));     assert(15 == solve(10, 3, 8, 1, 3, 10, -1));     assert(18 == solve(10, 3, 8, 1, 4, 10, -1));     assert(19 == solve(10, 3, 8, 1, 4, 9, 1));     assert(20 == solve(10, 3, 8, 2, 4, 9, 1));     assert(5 == solve(10, 3, 8, 1, 4, 3, 1));     assert(11 == solve(10, 3, 8, 1, 4, 3, -1));     assert(20 == solve(10, 3, 8, 1, 5, 8, 1));     assert(16 == solve(10, 3, 8, 1, 4, 8, -1));     assert(5 + 4 + 5 == solve(10, 8, 3, 1, 4, 3, 1));     assert(6 + 5 + 4 + 5 == solve(10, 8, 3, 1, 5, 3, -1));     assert(4 + 5 == solve(10, 8, 3, 1, 4, 8, 1));     assert(5 == solve(10, 8, 3, 1, 4, 8, -1));     assert(8 == solve(4, 2, 4, 3, 4, 1, 1));     assert(7 == solve(5, 4, 0, 1, 2, 3, 1));   }   int main() {     tests();     long long s, x1, x2, t1, t2, p, d;     while (cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d) {       cout << solve(s, x1, x2, t1, t2, p, d) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int f1(long int x, long int a) {     if ((x < 0 && x > (-1 * ((double)a) / 2)) || (x > 0 && x < ((double)a) / 2) ||         x == 0)       return 1;     else       return 0;   }   long long int f2(long long int x, long long int a) {     if ((x < 0 && x > (-1 * ((double)a))) || (x > 0 && x < ((double)a)))       return 1;     else       return 0;   }   int main() {     long long int x, y, a, num, p, flag = 1, ans;     cin >> a >> x >> y;     num = (y - a) % (2 * a);     ans = (y - a - num) / a;     ans = 1 + (ans / 2) * 3;     p = num / a;     if (p * a == num)       flag = 0;     else {       if (y < a) {         if (!f1(x, a)) flag = 0;       } else {         if (p < 1) {           if (f1(x, a))             ans += 1;           else             flag = 0;         } else {           if (f2(x, a)) {             if (x < 0)               ans += 2;             else               ans += 3;           } else             flag = 0;         }       }     }     if (flag)       cout << ans;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 1e5 + 5;   const int inf = 0x3f3f3f3f;   const double PI = acos(-1.0);   const long long INF = 0x3f3f3f3f3f3f3f3f;   int a[maxn], val[maxn];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       val[i] = a[i] + 1;     }     for (int i = 1; i <= n; ++i) {       val[i] = max(val[i], val[i - 1]);     }     for (int i = n; i > 0; --i) {       val[i] = max(val[i + 1] - 1, val[i]);     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += val[i] - a[i] - 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:268435456 )   using namespace std;   const double PI = 3.1415926535897932384626433832795;   template <class T>   T min(T &a, T &b) {     return (a < b) ? a : b;   }   template <class T>   T max(T &a, T &b) {     return (a > b) ? a : b;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T>   T abs(T &a) {     return (a < 0) ? (-a) : a;   }   inline void read(int &x) { scanf( %d , &x); }   inline void readln(int &x) { scanf( %d n , &x); }   inline void write(int x) { printf( %d , x); }   inline void writeln(int x) { printf( %d n , x); }   inline void read(long long &x) { scanf( %lld , &x); }   inline void readln(long long &x) { scanf( %lld n , &x); }   inline void write(long long x) { printf( %lld , x); }   inline void writeln(long long x) { printf( %lld n , x); }   inline void read(double &x) { scanf( %lf , &x); }   inline void readln(double &x) { scanf( %lf n , &x); }   inline void write(double x) { printf( %.15lf , x); }   inline void writeln(double x) { printf( %.15lf n , x); }   inline void read(char *s) { scanf( %s , s); }   inline void readln(char *s) { scanf( %s n , s); }   inline void write(char *s) { printf( %s , s); }   inline void writeln(char *s) { printf( %s n , s); }   inline int readInt() {     int x;     read(x);     return x;   }   inline long long readLong() {     long long x;     read(x);     return x;   }   inline double readDouble() {     double x;     read(x);     return x;   }   inline void showTime() {}   const double eps = 1e-10;   double x, y, yw, r;   double ya, yb, yao, ybo;   double wp(double x1, double y1, double x2, double y2) {     return x1 * y2 - x2 * y1;   }   double dist(double x1, double y1, double x2, double y2) {     return sqrt(sqr(x1 - x2) + sqr(y1 - y2));   }   bool goodb(double xt) {     double x1 = x;     double y1 = y;     double x2 = xt;     double y2 = yw;     double s = wp(x2 - x1, y2 - y1, 0 - x1, ybo - y1);     double d = s / dist(x1, y1, x2, y2);     if (d < r + eps) return false;     return true;   }   bool gooda(double xt) {     double x1 = x;     double y1 = y;     double x2 = xt;     double y2 = yw;     double s = wp(x2 - x1, y2 - y1, 0 - x1, yao - r - y1);     double d = s / dist(x1, y1, x2, y2);     if (d > -eps) return false;     return true;   }   int main() {     srand((unsigned)time(NULL));     cin >> ya >> yb >> yw >> x >> y >> r;     yw -= r;     yao = 2 * yw - ya;     ybo = 2 * yw - yb;     double xt = 0;     double step = x;     while (step > eps) {       if (!goodb(xt + step)) xt += step;       step /= 2;     }     while (!goodb(xt + step)) xt += step;     xt += step * 100000;     if (gooda(xt)) {       cout.setf(ios::fixed);       cout.precision(10);       cout << xt;     } else {       cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   const double pi = acos(-1.0);   const long long int inf = 0x3f3f3f3f3f3f3f3f;   const long long int mod = 998244353;   bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }   void fast() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   string s[2];   int n, k, h;   bool a[2][100005];   void dfs(int x, int y) {     if (s[x][y] !=  -  || a[x][y] == true || y < h) return;     if (y + k >= n) {       cout <<  YES ;       exit(0);     }     h++;     a[x][y] = true;     dfs(1 - x, y + k);     dfs(x, y + 1);     dfs(x, y - 1);     h--;   }   int main() {     cin >> n >> k >> s[0] >> s[1];     dfs(0, 0);     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 3, K = 11, M = N * 4;   const long long MOD = 998244353, oo = 1e9, OO = 1e18, mod = MOD;   const double pi = acos(-1), eps = 1e-17;   long long di[] = {0, 0, 1, -1};   long long dj[] = {1, -1, 0, 0};   long long pos[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     long long ret = 1;     long long n;     cin >> n;     long long arr2[n * n];     for (long long i = 0; i < n * n; i++) cin >> arr2[i];     vector<long long> v;     for (long long i = 0; i < n * n; i++) v.push_back(i);     do {       long long arr[n * n];       for (long long i = 0; i < n * n; i++) arr[i] = arr2[v[i]];       map<long long, long long> mp;       long long sum = 0;       for (long long i = 0; i < n; i++) {         sum += arr[i * n + i];       }       mp[sum]++;       if (mp.size() > 1) continue;       sum = 0;       for (long long i = 0; i < n; i++) {         sum = 0;         for (long long j = 0; j < n; j++) sum += arr[i * n + j];         mp[sum]++;         if (mp.size() > 1) continue;       }       for (long long j = 0; j < n; j++) {         sum = 0;         for (long long i = 0; i < n; i++) sum += arr[i * n + j];         mp[sum]++;         if (mp.size() > 1) continue;       }       long long r = 0, c = n - 1;       sum = 0;       while (c >= 0) {         sum += arr[r * n + c];         r++, c--;       }       mp[sum]++;       if (mp.size() > 1) continue;       if (mp.size() == 1) {         cout << sum <<   n ;         for (long long i = 0; i < n * n; i++) {           if (i && i % 3 == 0) cout <<   n ;           cout << arr[i] <<    ;         }         return 0;       }     } while (next_permutation(v.begin(), v.end()));   }
#include <bits/stdc++.h>   using namespace std;   int m, n;   int R[1005];   map<int, int> cnt;   long long bell[1005][1005];   void geneBell() {     bell[0][0] = 1;     for (int i = 1; i < m + 2; i++) {       bell[i][0] = bell[i - 1][i - 1];       for (int j = 1; j <= i; j++) {         bell[i][j] = (bell[i][j - 1] + bell[i - 1][j - 1]) % 1000000007;       }     }   }   int main() {     cin >> m >> n;     geneBell();     string tmp;     for (int i = 0; i < n; i++) {       cin >> tmp;       for (int j = 0; j < m; j++) {         R[j] = R[j] * 10 + tmp[j] -  0 ;       }     }     for (int i = 0; i < m; i++) {       cnt[R[i]]++;     }     map<int, int>::iterator it;     long long ans = 1;     for (it = cnt.begin(); it != cnt.end(); ++it) {       if ((it->second) > 0) {         ans = (ans * bell[it->second][0]) % 1000000007;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, a, b;     cin >> n >> a >> b;     if (a + b > n - 1 || a == n - 1 && n > 1)       cout << -1 << endl;     else {       if (n == 1)         cout << 1 << endl;       else {         cout << 1 <<    ;         n--;         int c;         n -= (a + b);         for (int i = 1; i <= b; i++) {           c = 1 << i;           cout << c <<    ;         }         while (n > 0) {           cout << c <<    ;           n--;         }         while (a > 0) {           c++;           cout << c <<    ;           a--;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       cout << max(a + b, c + d) << endl;     }   }
#include <bits/stdc++.h>   using std ::max;   using std ::min;   const int maxx = 300000 + 25;   int n, m, x, y, z, k, num;   int cnt, ans, tot;   int front, back, kr;   int cur[maxx];   std ::priority_queue<int, std ::vector<int>, std ::greater<int> > quq;   class Node {    public:     int x;     int y;     int id;   };   Node a[maxx];   bool cmp(Node a, Node b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   int main() {     scanf( %d%d , &n, &k);     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       scanf( %d%d , &a[i].x, &a[i].y);       a[i].id = i;     }     std ::sort(a + 1, a + n + 1, cmp);     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       quq.push(a[i].y);       tot++;       if (tot > k) {         quq.pop();         tot--;       }       if (tot == k) {         if (quq.top() - a[i].x + 1 > ans) {           ans = quq.top() - a[i].x + 1;           front = a[i].x;           back = quq.top();         }       }     }     printf( %d n , ans);     if (ans == 0) {       for (int i = (1), i_END = (k); i <= (i_END); ++i) printf( %d  , i);       putchar(10);       return 0;     }     for (int i = (1), i_END = (n); i <= (i_END); ++i) {       if (front >= a[i].x && a[i].y >= back) {         printf( %d  , a[i].id);         kr++;       }       if (kr == k) break;     }     putchar(10);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int k = 0; k < t; k++) {       int x, y, d = 0;       cin >> x >> y;       if (x >= y || x > 3) {         cout <<  YES  << endl;         d = 1;       }       if (d == 0) {         if (x == 1) {           cout <<  NO  << endl;         } else {           if (y > 3) {             cout <<  NO  << endl;           } else {             cout <<  YES  << endl;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int mx = 0, i, n, m, d, h, ld, lh;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> d >> h;       if (i == 0) {         ld = d;         lh = h;         mx = lh + ld - 1;         continue;       }       if (abs(h - lh) > d - ld) {         cout <<  IMPOSSIBLE ;         return 0;       }       if (h - lh < 0)         mx = max(mx, lh + (d - ld - abs(h - lh)) / 2);       else         mx = max(mx, h + (d - ld - abs(h - lh)) / 2);       ld = d;       lh = h;     }     mx = max(mx, lh + n - ld);     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string bad;   int k, ans = 0;   struct node {     node *edges[26];     node() {       for (int i = 0; i < 26; i++) edges[i] = NULL;     }   };   void insert(node *trie, string s) {     for (int i = 0; i < s.size(); i++) {       if (trie->edges[s[i] -  a ] == NULL) trie->edges[s[i] -  a ] = new node();       trie = trie->edges[s[i] -  a ];     }   }   void dfs(node *trie, int b) {     if (b <= k) ans++;     for (int i = 0; i < 26; i++) {       if (trie->edges[i]) {         int add = 0;         if (bad[i] ==  0 ) add++;         dfs(trie->edges[i], b + add);       }     }   }   int main() {     string s;     cin >> s >> bad >> k;     node *root = new node();     string t =   ;     for (int i = s.size() - 1; i >= 0; i--) {       t = s[i] + t;       insert(root, t);     }     dfs(root, 0);     cout << ans - 1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l, ans;   string s;   char t[1000005];   int cal(string s) {     int l = s.size(), p = 0, q = 0, cnt1 = 0, flag = 0;     char ch;     for (int i = 0; i < l; i++) {       ch = (q & 1) ?  R  :  L ;       if (s[i] ==  X ) {         q++;       } else {         if (s[i] == ch) {           p++;           q++;           flag = 0;         } else {           p++;           q += 2;           cnt1 += flag;           flag = !flag;         }       }     }     if (q & 1) {       q++;       cnt1 += flag;     }     if (p * 2 > q) {       p -= cnt1;       q -= cnt1 * 2;     }     return (long long)p * 100000000 / q;   }   int main() {     s =   ;     scanf( %s , &t);     l = strlen(t);     for (int i = 0; i < l; i++) {       if (i > 0 && t[i] == t[i - 1] && t[i] !=  X ) {         s +=  X ;       }       s += t[i];     }     if (s[0] == s[s.size() - 1] && s[0] !=  X ) {       ans = max(cal(s +  X ), cal( X  + s));     } else {       ans = cal(s);     }     printf( %d.%.06d n , ans / 1000000, ans % 1000000);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dpo[2010][15], dpe[2010][15], a[2010], b[2010];   long long combe[15], combo[15];   long long f[2010], c[2010];   long long nck(long long n, long long k) {     if (n < k) return 0;     long long ret = (f[n] * c[k]) % 998244353;     return (ret * c[n - k]) % 998244353;   }   long long pwr(long long b, long long e) {     b %= 998244353;     if (e == 0) return 1;     if (e == 1) return b;     return (pwr(b * b, e / 2) * pwr(b, e % 2)) % 998244353;   }   int conv(string str) {     int dir = 1, ret = 0;     for (auto x : str) ret += dir * (x - 48), dir *= -1;     ret %= 11;     if (ret < 0) ret += 11;     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     f[0] = c[0] = 1;     for (int i = 1; i < 2010; i++) (f[i] = f[i - 1] * i) %= 998244353;     c[2010 - 1] = pwr(f[2010 - 1], 998244353 - 2);     for (int i = 2010 - 2; i; i--) (c[i] = c[i + 1] * (i + 1)) %= 998244353;     int T;     cin >> T;     while (T--) {       int n;       string str;       int otot = 0, etot = 0, ocnt = 0, ecnt = 0;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> str;         if (str.length() % 2)           a[ocnt++] = conv(str);         else           b[ecnt++] = conv(str);       }       etot = accumulate(b, b + ecnt, 0) % 11;       if (ocnt == 0) {         cout << (etot ? 0 : f[n]) << endl;         continue;       }       for (int i = 0; i <= ecnt; i++) fill(dpe[i], dpe[i] + 15, 0);       dpe[0][0] = 1;       for (int i = 0; i < ecnt; i++)         for (int j = i; j >= 0; j--)           for (int rem = 0; rem < 11; rem++)             (dpe[j + 1][(rem + b[i]) % 11] += dpe[j][rem]) %= 998244353;       fill(combe, combe + 11, 0);       for (int i = 0; i <= ecnt; i++) {         long long r = f[i] * f[ecnt - i] % 998244353 *                       nck(ocnt / 2 + i, ocnt / 2) % 998244353 *                       nck((ocnt + 1) / 2 - 1 + ecnt - i, (ocnt + 1) / 2 - 1) %                       998244353;         for (int rpos = 0; rpos < 11; rpos++) {           int rneg = (rpos - etot) % 11;           if (rneg < 0) rneg += 11;           (combe[(rpos + rneg) % 11] += r * dpe[i][rpos]) %= 998244353;         }       }       otot = accumulate(a, a + ocnt, 0) % 11;       for (int i = 0; i <= ocnt; i++) fill(dpo[i], dpo[i] + 15, 0);       dpo[0][0] = 1;       for (int i = 0; i < ocnt; i++)         for (int j = i; j >= 0; j--)           for (int rem = 0; rem < 11; rem++)             (dpo[j + 1][(rem + a[i]) % 11] += dpo[j][rem]) %= 998244353;       fill(combo, combo + 11, 0);       {         int i = (ocnt + 1) / 2;         long long r = f[i] * f[ocnt - i] % 998244353;         for (int rpos = 0; rpos < 11; rpos++) {           int rneg = (rpos - otot) % 11;           if (rneg < 0) rneg += 11;           (combo[(rpos + rneg) % 11] += r * dpo[i][rpos]) %= 998244353;         }       }       long long res = 0;       for (int i = 0; i < 11; i++)         (res += combo[i] * combe[(11 - i) % 11]) %= 998244353;       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   int res = 0;   int r[10];   int v[10];   int main() {     int t;     cin >> t;     while (t--) {       long long x = 1;       int n;       cin >> n;       for (int i = 3; i <= n * 2; i++) {         x = x * i % mod;       }       cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[105];   map<int, bool> q;   int main() {     while (~scanf( %d %d , &n, &k)) {       q.clear();       for (int i = 0; i < k; i++) scanf( %d , &a[i]);       int t = 1;       int t2 = n;       for (int i = 0; i < k; i++) {         int t3 = (a[i] %= t2);         while (t3--) {           t++;           if (t > n) t = 1;           if (q[t]) t3++;         }         printf( %d%c , t, i == k - 1 ?   n  :    );         q[t] = 1;         t++;         if (t > n) t = 1;         while (q[t]) {           t++;           if (t > n) t = 1;         }         t2--;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int main() {     int t = 1;     cin >> t;     int n;     while (t--) {       cin >> n;       if (n == 1 || n == 2) {         cout << 1 <<   n ;         continue;       }       if (n & 1)         cout << n / 2 + 1 <<   n ;       else         cout << n / 2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     cin >> num;     for (int i = 1; i <= 2 * sqrt(num); i++) {       int x = (i * (i + 1)) / 2;       int tmp = num - x;       int st = 1, en = 2 * sqrt(num);       while (st <= en) {         int mid = st + (en - st) / 2;         int y = (mid * (mid + 1)) / 2;         if (y == tmp) {           cout <<  YES  << endl;           return 0;         } else if (y < tmp) {           st = mid + 1;         } else {           en = mid - 1;         }       }     }     cout <<  NO  << endl;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma GCC optimize(3)   template <typename T>   T min(T x, T y) {     return x < y ? x : y;   }   template <typename T>   T max(T x, T y) {     return x > y ? x : y;   };   const int INF = 1000000000;   const int MAXN = 100005;   const int B = 500;   int N, M, Q;   int low[MAXN];   std::vector<int> V[MAXN], ID[MAXN], up[MAXN];   int ans[MAXN];   int f[MAXN];   void solve() {     static int mx[MAXN][25];     for (int l = 1, r; l <= N; l = r + 1) {       r = min(l + B - 1, N);       for (int i = l; i <= r; i++) {         f[i] = i;         for (int j = l; j <= i; j++)           if (f[j] >= low[i] && low[i] >= j) f[j] = i;         for (int j = 0; j < V[i].size(); j++) {           if (V[i][j] >= l) {             ans[ID[i][j]] = f[V[i][j]];             continue;           }           ans[ID[i][j]] = f[V[i][j]];           for (int k = l; k <= i; k++)             if (low[k] >= V[i][j] && low[k] <= ans[ID[i][j]]) ans[ID[i][j]] = k;         }       }       memset(mx, 0, sizeof(mx));       memset(f, 0, sizeof(f));       for (int i = r; i >= 1; i--) {         f[i] = i;         for (int j = 0; j < up[i].size(); j++) {           if (up[i][j] > r) continue;           int t = 0;           while (1 << t <= up[i][j] - i) t++;           t--;           f[i] = max(f[i], max(mx[i + 1][t], mx[up[i][j] - (1 << t) + 1][t]));         }         mx[i][0] = f[i];         for (int j = 1; j < 25; j++)           mx[i][j] = max(mx[i][j - 1], mx[min(r, i + (1 << (j - 1)))][j - 1]);       }     }     for (int i = 1; i <= Q; i++) printf( %d n , ans[i]);   }   void init() {     int l, r;     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; i++) {       scanf( %d %d , &l, &r);       if (l == r) continue;       low[r] = l;       up[l].push_back(r);     }     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       scanf( %d %d , &l, &r);       V[r].push_back(l);       ID[r].push_back(i);     }   }   int main() {     init();     solve();     return 0;   }