malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int INF = LLONG_MAX;   vector<long long int> v1;   vector<pair<long long int, long long int> > v2;   string s1, s2, s3;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int a, b, c, d, e, f, i, j, k, cnt1 = 0, cnt2 = 0, sum1 = 0,                                              sum2 = 0, chk1 = 0, chk2 = 0, T;     cin >> T;     while (T--) {       cnt1 = 0;       v1.clear();       cin >> a >> b;       vector<long long int> ara(b + b + 3, 0);       for (i = 0; i < a; i++) {         cin >> c;         v1.push_back(c);       }       ara[0] = a;       for (i = 0; i < a / 2; i++) {         long long int mx = max(v1[i], v1[a - i - 1]);         long long int mn = min(v1[i], v1[a - i - 1]);         ara[mn + 1]--;         ara[mx + mn]--;         ara[mx + mn + 1]++;         ara[mx + b + 1]++;       }       long long int ans = INT_MAX;       for (i = 1; i <= b + b + 2; i++) {         ara[i] += ara[i - 1];         ans = min(ara[i], ans);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<2005> a[2005];   int pos[2005];   int ans[2005];   bool gause(int n, int m) {     int d = 1;     for (int i = 1; i <= n; i++) {       if (!a[d][i]) {         for (int j = d + 1; j <= m; j++)           if (a[j][i]) {             swap(a[d], a[j]);             break;           }       }       if (!a[d][i]) continue;       pos[d] = i;       for (int j = 1; j <= m; j++)         if (j != d && a[j][i]) a[j] ^= a[d];       d++;     }     for (int i = d; i <= m; i++)       if (a[i][n + 1]) return 0;     for (int i = 1; i < d; i++) ans[pos[i]] = a[i][n + 1];     return 1;   }   bool num[1005][4];   int id[128], cur[1005];   const char *val =  .RYB ;   int main() {     id[ W ] = 0;     id[ R ] = 1;     id[ Y ] = 2;     id[ B ] = 3;     int n, m;     scanf( %d%d , &n, &m);     int sz = 0;     for (int i = 1; i <= n; i++) num[i][0] = num[i][3] = 1;     for (int i = 1; i <= m; i++) {       char str[5];       int k;       scanf( %s%d , str, &k);       for (int j = 1; j <= k; j++) scanf( %d , &cur[j]);       if (str[0] ==  m ) {         scanf( %s , str);         int v = id[str[0]];         ++sz;         for (int j = 1; j <= k; j++) {           int x = cur[j];           if (num[x][0]) a[sz].flip(2 * x - 1);           if (num[x][1]) a[sz].flip(2 * x);         }         if (v & 1) a[sz].flip(2 * n + 1);         ++sz;         for (int j = 1; j <= k; j++) {           int x = cur[j];           if (num[x][2]) a[sz].flip(2 * x - 1);           if (num[x][3]) a[sz].flip(2 * x);         }         if ((v >> 1) & 1) a[sz].flip(2 * n + 1);       } else if (str[0] ==  R  && str[1] ==  Y ) {         for (int j = 1; j <= k; j++) {           int x = cur[j];           swap(num[x][0], num[x][2]);           swap(num[x][1], num[x][3]);         }       } else if (str[0] ==  R  && str[1] ==  B ) {         for (int j = 1; j <= k; j++) {           int x = cur[j];           num[x][2] ^= num[x][0];           num[x][3] ^= num[x][1];         }       } else {         for (int j = 1; j <= k; j++) {           int x = cur[j];           num[x][0] ^= num[x][2];           num[x][1] ^= num[x][3];         }       }     }     if (!gause(2 * n, sz)) {       puts( NO );       return 0;     }     puts( YES );     for (int i = 1; i <= n; i++) {       int s = (ans[2 * i - 1] ^ (ans[2 * i] << 1));       putchar(val[s]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int nr, nr1, nr2, n, i, dif;   char s[2 * 1000005], t[2 * 1000005];   int main() {     cin >> n;     scanf( %s , s + 1);     scanf( %s , t + 1);     for (i = 1; i <= 2 * n; i++)       if (s[i] ==  1  && t[i] ==  1 ) {         nr++;         s[i] =  0 ;         t[i] =  0 ;       }     if (nr % 2 == 1) dif = 1;     for (i = 1; i <= 2 * n; i++) {       if (s[i] ==  1 ) nr1++;       if (t[i] ==  1 ) nr2++;     }     if (nr1 > nr2) {       cout <<  First ;       return 0;     }     if (dif == 0) {       if (nr1 == nr2) {         cout <<  Draw ;         return 0;       }       if (nr2 == nr1 + 1) {         cout <<  Draw ;         return 0;       }       if (nr2 > nr1 + 1) {         cout <<  Second ;         return 0;       }     }     if (dif == 1) {       if (nr1 == nr2) {         cout <<  First ;         return 0;       }     }     if (nr2 - nr1 <= 2) {       cout <<  Draw ;       return 0;     }     if (nr2 > nr1 + 2 && dif == 1) cout <<  Second ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, v = 0, c = 0;     cin >> x;     for (int i = 0; i < x; i++) {       cin >> y;       if (y == -1 && c == 0) {         v++;       } else if (y == -1 && c != 0) {         c--;       } else {         c += y;       }     }     cout << v;   }
#include <bits/stdc++.h>   using namespace std;   inline int read(int x = 0, int f = 1, char ch =  0 ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 1e5 + 5;   int head[N], ver[N], nxt[N], edge[N];   int n, m, Q, tot;   long long d[N], f[N], t;   bool v[N];   inline void add(int x, int y, int z) {     ver[++tot] = y;     nxt[tot] = head[x];     head[x] = tot;     edge[tot] = z;   }   inline void dij() {     priority_queue<pair<long long, int> > q;     memset(d, 0x3f, sizeof(d));     d[1] = 0;     q.push(make_pair(0, 1));     while (q.size()) {       int x = q.top().second;       q.pop();       if (v[x]) continue;       v[x] = 1;       for (register int i = head[x]; i; i = nxt[i]) {         int y = ver[i];         if (d[y] <= d[x] + edge[i]) continue;         d[y] = d[x] + edge[i];         q.push(make_pair(-d[y], y));       }     }   }   queue<int> q[N];   inline void work(int maxn) {     memset(f, 0x3f, sizeof(f));     f[1] = 0;     q[0].push(1);     for (register int now = 0; now <= t; ++now)       while (q[now].size()) {         int x = q[now].front();         q[now].pop();         if (f[x] < now) continue;         for (register int i = head[x]; i; i = nxt[i]) {           int y = ver[i], z = d[x] + edge[i] - d[y];           if (f[y] <= f[x] + z) continue;           f[y] = f[x] + z;           if (f[y] > maxn) continue;           q[f[y]].push(y);           t = max(t, f[y]);         }       }     for (register int i = (1); i <= (n); ++i) d[i] = min(d[0], d[i] + f[i]);   }   int main() {     n = read();     m = read();     Q = read();     for (register int i = (1); i <= (m); ++i) {       int x = read(), y = read(), z = read();       add(x, y, z);     }     dij();     while (Q--) {       int op = read();       if (op == 1) {         int x = read();         printf( %lld n , d[x] >= d[0] ? -1 : d[x]);       } else {         int c = read(), k;         for (register int i = (1); i <= (c); ++i) k = read(), ++edge[k];         work(min(c, n - 1));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int maxn = 5e5;   struct line {     double x, y;   } A[maxn];   long long X, Y, R;   double x0, Y0, v, T, d, x, y, r, M, D;   double a, b, now, ans, th, l, Max;   int i, n, la;   double sqr(double x) { return x * x; }   double dist(double x, double y, double x0, double Y0) {     return sqrt(sqr(x - x0) + sqr(y - Y0));   }   bool cmp(line a, line b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }   int main() {     scanf( %lf%lf%lf%lf , &x0, &Y0, &v, &T);     M = v * T;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %lf%lf%lf , &x, &y, &r);       X = x - x0;       Y = y - Y0;       R = r;       if (X * X + Y * Y <= R * R) {         printf( 1 );         return 0;       }       d = dist(x0, Y0, x, y);       a = d - r;       b = sqrt(sqr(d) - sqr(r));       double B = atan2(y - Y0, x - x0);       if (a < M) {         if (b <= M) {           th = asin(r / d);         } else {           th = acos((M * M + d * d - r * r) / (2 * M * d));         }         l = B - th;         r = B + th;         if (l < -PI) {           A[++la] = (line){l + 2 * PI, PI};           l = -PI;         }         if (r > PI) {           A[++la] = (line){-PI, r - 2 * PI};           r = PI;         }         A[++la] = (line){l, r};       }     }     if (!la) {       printf( 0 );       return 0;     }     sort(A + 1, A + la + 1, cmp);     now = A[1].y - A[1].x;     Max = A[1].y;     for (i = 2; i <= la; i++) {       Max = max(Max, A[i].x);       if (A[i].y < Max) continue;       now += A[i].y - Max;       Max = A[i].y;     }     ans = now / (2 * PI);     printf( %.10lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char A[21], B[21];   long i, N, d, t, j, lg;   map<string, vector<pair<string, long> > > lista;   map<string, vector<pair<string, long> > >::const_iterator iter;   vector<pair<string, string> > rez;   string a, b;   inline int modul(long x) { return (x < 0) ? -x : ((x == 0) ? d + 1 : x); }   void adauga(string a, string b) {     bool ok = true;     long q, lg;     for (q = 0, lg = rez.size(); q < lg; ++q) {       if (rez[q].first.compare(a) == 0 && rez[q].second.compare(b) == 0) {         ok = false;         break;       }     }     if (ok) {       rez.push_back(make_pair(a, b));     }   }   int main() {     scanf( %ld %ld , &N, &d);     for (i = 1; i <= N; ++i) {       scanf( %s %s %ld , A, B, &t);       a = A;       b = B;       for (j = 0, lg = lista[b].size(); j < lg; ++j) {         if (lista[b][j].first == a) {           if (modul(lista[b][j].second - t) <= d) {             if (a.compare(b) < 0) {               adauga(a, b);             } else {               adauga(b, a);             }           }         }       }       lista[a].push_back(make_pair(b, t));     }     printf( %ld n , lg = rez.size());     for (i = 0; i < lg; ++i) {       printf( %s %s n , rez[i].first.c_str(), rez[i].second.c_str());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e7 + 7;   const int mod = 998244353;   const long long INF = 1e18;   long long jc[maxn];   long long n, k;   long long inv2 = 499122177;   void init() {     jc[0] = 1;     for (long long i = 1; i < maxn; i++) jc[i] = jc[i - 1] * i % mod;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1;       y = 0;       return a;     }     long long d = exgcd(b, a % b, y, x);     y -= a / b * x;     return d;   }   long long inv(long long a, long long n) {     long long x, y;     exgcd(a, n, x, y);     return (x + n) % n;   }   long long C(long long n, long long m) {     return jc[n] * inv(jc[m] * jc[n - m] % mod, mod) % mod;   }   long long qpow(long long x, int n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;       n /= 2;     }     return res;   }   void rua() {     init();     scanf( %lld%lld , &n, &k);     if (k >= n) {       printf( 0 n );       return;     }     long long ans = 0;     n -= k;     for (int i = 0; i <= n; i += 2)       ans = (ans + C(n, i) * qpow(n - i, n + k) % mod) % mod;     for (int i = 1; i <= n; i += 2)       ans = (ans - C(n, i) * qpow(n - i, n + k) % mod + mod) % mod;     ans = ans * 2ll % mod * C(n + k, n) % mod;     if (k == 0) ans = (ans * 499122177) % mod;     printf( %lld n , ans);   }   int main() {     rua();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     long long temp, ans;     cin >> t;     while (t--) {       cin >> n;       long long ary[n];       for (int i = 0; i < n; i++) {         cin >> ary[i];       }       ans = ary[0];       for (int i = 1; i < n; i++) {         ans = ans & ary[i];       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   long long xabs(long long a) { return a < 0 ? -a : +a; }   bool check(long long p, long long q, long long x, long long y, long long a,              long long b) {     if (a * x + b * y == p && a * y - b * x == q)       return true;     else       return false;   }   bool can(long long ax, long long ay, long long bx, long long by, long long x,            long long y) {     long long p = bx - ax;     long long q = by - ay;     if (x == 0 && y == 0) {       if (p == 0 && q == 0)         return true;       else         return false;     }     if (y != 0) swap(x, y), swap(p, q);     long long b = (p * y - q * x) / (y * y + x * x);     long long a = (p - b * y) / x;     if (check(p, q, x, y, a, b))       return true;     else       return false;   }   int main() {     long long ax, ay, bx, by, x, y;     cin >> ax >> ay >> bx >> by >> x >> y;     bool fl = false;     for (int i = 0; i < 4; ++i) {       fl |= can(ax, ay, bx, by, x, y);       swap(ax, ay);       ax = -ax;     }     if (fl)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD(1000000007);   const int INF((1 << 30) - 1);   const int MAXN(1505);   vector<int> a[MAXN];   int b[MAXN], ans[MAXN];   struct pt {     int x, y, idx;     double r;   } d[MAXN];   pt o;   bool compare(const pt &p, const pt &q) {     long long u1 = p.x - o.x, v1 = p.y - o.y, u2 = q.x - o.x, v2 = q.y - o.y;     return u1 * v2 - u2 * v1 > 0;   }   void DFS(int node, int p) {     b[node] = 1;     for (int i = 0; i < a[node].size(); i++)       if (a[node][i] != p) {         DFS(a[node][i], node);         b[node] += b[a[node][i]];       }   }   void DFS2(int node, int p, int f, int l) {     int id = f;     for (int i = f + 1; i <= l; i++)       if (pair<int, int>(d[i].y, d[i].x) < pair<int, int>(d[id].y, d[id].x))         id = i;     swap(d[f], d[id]);     o = d[f];     sort(d + f + 1, d + l + 1, compare);     ans[d[f].idx] = node;     f++;     for (int i = 0; i < a[node].size(); i++)       if (a[node][i] != p) {         int u = a[node][i];         DFS2(u, node, f, f + b[u] - 1);         f += b[u];       }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       a[u].push_back(v);       a[v].push_back(u);     }     DFS(1, -1);     for (int i = 0; i < n; i++) {       scanf( %d%d , &d[i].x, &d[i].y);       d[i].idx = i;     }     DFS2(1, -1, 0, n - 1);     for (int i = 0; i < n; i++) printf( %d  , ans[i]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 5;   vector<pair<int, int> > adj[N];   int w[N];   int d[N];   bool mark[N];   set<pair<int, int> > s;   vector<int> ans;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> w[i];     }     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back({v, i});       adj[v].push_back({u, i});     }     for (int i = 1; i <= n; i++) {       d[i] = (int)adj[i].size() - w[i];       s.insert({d[i], i});     }     while (s.size()) {       int v = (*s.begin()).second;       s.erase(s.begin());       mark[v] = true;       if (d[v] > 0) {         cout <<  DEAD ;         return 0;       }       for (auto p : adj[v]) {         int u = p.first;         if (!mark[u]) {           s.erase({d[u], u});           d[u]--;           s.insert({d[u], u});           ans.push_back(p.second);         }       }     }     cout <<  ALIVE n ;     reverse(ans.begin(), ans.end());     for (auto x : ans) {       cout << x <<    ;     }     return 0;   }
#include <bits/stdc++.h>   char zebra[100005];   int max;   int main() {     scanf( %s , zebra + 1);     max = 0;     int n = strlen(zebra + 1);     int t = 0;     int ans = 0;     for (int i = 1; i <= n; i++) {       int k = 1;       while (zebra[i] != zebra[i + 1] && i + 1 <= n) {         k++;         i++;       }       if (i == n && t == 0) {         if (zebra[i] != zebra[1]) {           k++;           t++;           i = 1;         }       }       while (zebra[i] != zebra[i + 1] && i + 1 <= n) {         k++;         i++;       }       if (k > n) k = n;       if (k > ans) ans = k;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }   struct SegTree {     int size;     vector<pair<long long, long long> > seg;     SegTree() {}     SegTree(int size) {       this->size = size;       seg.resize(1 << (size + 1));     }     pair<long long, long long> Ident() {       return pair<long long, long long>(-1e18, -1e18);     }     pair<long long, long long> ope(pair<long long, long long> a,                                    pair<long long, long long> b) {       return max(a, b);     }     void init() {       for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = Ident();     }     void update(int i, pair<long long, long long> val) {       i += (1 << size);       seg[i] = val;       while (i > 1) {         i /= 2;         seg[i] = ope(seg[i * 2], seg[i * 2 + 1]);       }     }     pair<long long, long long> query(int a, int b, int k, int l, int r) {       if (b < l || r < a) return Ident();       if (a <= l && r <= b) return seg[k];       pair<long long, long long> lval = query(a, b, k * 2, l, (l + r) / 2);       pair<long long, long long> rval =           query(a, b, k * 2 + 1, (l + r) / 2 + 1, r);       return ope(lval, rval);     }     pair<long long, long long> query(int a, int b) {       if (a > b) return Ident();       return query(a, b, 1, 0, (1 << size) - 1);     }   };   long long n;   long long a[500005], b[500005];   SegTree seg(19);   bool used[500005];   long long ans[500005];   vector<long long> topo;   void dfs(int v) {     used[v] = true;     seg.update(v, pair<long long, long long>(-1e18, -1e18));     if (a[v] <= n && !used[a[v]]) dfs(a[v]);     while (1) {       pair<long long, long long> res = seg.query(1, b[v] - 1);       if (res.first <= v) break;       dfs(res.second);     }     topo.push_back(v);   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long(i) = (1); (i) <= (n); (i)++) {       cin >> a[i];       if (a[i] == -1) a[i] = n + 1;     }     for (long long(i) = (1); (i) <= (n); (i)++) b[a[i]] = i;     for (long long(i) = (1); (i) <= (n); (i)++)       if (b[i] == 0) b[i] = n + 1;     seg.init();     for (long long(i) = (1); (i) <= (n); (i)++)       seg.update(i, pair<long long, long long>(a[i], i));     for (long long(i) = (1); (i) <= (n); (i)++)       if (!used[i]) dfs(i);     reverse((topo).begin(), (topo).end());     for (long long(i) = 0; (i) < (long long)(topo).size(); (i)++)       ans[topo[i]] = i + 1;     for (long long(i) = (1); (i) <= (n); (i)++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200007;   const int mod = 998244353;   long long fast_pow(long long b, int k) {     long long s = 1;     while (k) {       if (k & 1) (s *= b) %= mod;       (b *= b) %= mod;       k >>= 1;     }     return s;   }   long long fact[maxn];   int N;   int A[maxn];   int sum[maxn], sum0[maxn];   int C[maxn];   void update(int x) {     while (x <= N) C[x]++, x += x & (-x);     return;   }   int query(int x) {     int re = 0;     while (x) re += C[x], x &= (x - 1);     return re;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %d , &A[i]);       if (A[i] == -1) A[i] = 0;       sum0[i] += sum0[i - 1] + (A[i] == 0);       if (A[i] > N) {         printf( 0 );         return 0;       }       sum[A[i]]++;     }     for (int i = 2; i <= N; i++) sum[i] += sum[i - 1];     fact[0] = 1;     for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % mod;     long long x, y;     long long ans = 0;     if (sum[0])       for (int i = 1; i <= N; i++) {         if (A[i] == 0) continue;         x = A[i] - sum[A[i]];         y = sum0[N] - sum0[i];         (ans += x * y % mod * fact[sum[0] - 1] % mod) %= mod;         x = (N - A[i]) - (sum[N] - sum[A[i]]);         y = sum0[i];         (ans += x * y % mod * fact[sum[0] - 1] % mod) %= mod;       }     x = 1ll * sum[0] * (sum[0] - 1) / 2 % mod;     if (sum[0] > 1)       y = fact[sum[0] - 2];     else       y = 0;     (ans += y * x % mod * x % mod) %= mod;     y = 0;     for (int i = 1; i <= N; i++) {       if (A[i] == 0) continue;       x = query(N) - query(A[i]);       (y += x) %= mod;       update(A[i]);     }     if (sum[0] > 0)       x = fact[sum[0]];     else       x = 1;     (ans += y * x % mod) %= mod;     (ans *= fast_pow(fact[sum[0]], mod - 2)) %= mod;     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int FASTBUFFER;   const int N = 1005;   const int INF = 1000000000;   char str[N][N];   int n, m, l[N], r[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s , str[i] + 1);     }     for (int i = 1; i <= n; i++) {       int ll = m + 1, rr = 0;       for (int j = 1; j <= m; j++) {         if (str[i][j] ==  X ) {           ll = j;           break;         }       }       for (int j = m; j >= 1; j--) {         if (str[i][j] ==  X ) {           rr = j;           break;         }       }       for (int j = ll; j <= rr; j++) {         if (str[i][j] !=  X ) {           printf( -1 n );           return 0;         }       }       l[i] = ll, r[i] = rr;     }     int st, end;     for (int i = 1; i <= n; i++) {       if (l[i] != m + 1) {         st = i;         break;       }     }     for (int i = n; i >= 1; i--) {       if (l[i] != m + 1) {         end = i;         break;       }     }     for (int i = st; i <= end; i++) {       if (l[i] == m + 1) {         printf( -1 n );         return 0;       }     }     int ans1 = -1, ans2 = -1, flag = 0;     for (int i = st + 1; i <= end; i++) {       if (l[i] < l[i - 1] || r[i] < r[i - 1]) {         printf( -1 n );         return 0;       }       if (l[i] > r[i - 1]) {         printf( -1 n );         return 0;       }       if (r[i] > r[i - 1]) {         flag = 1;       }       if (l[i] > l[i - 1] && ans1 == -1) {         int last;         for (last = i - 1; last >= st; last--) {           if (r[last] != r[i]) {             break;           }         }         if (last < st) {           last++;         }         ans1 = r[last] - l[i] + 1;       }     }     int ans = INF;     if (ans1 == -1) {       if (st == end) {         printf( 1 n );         return 0;       } else {         if (flag) {           ans1 = r[st] - l[st] + 1;         } else {           printf( %d n , min(end - st + 1, r[st] - l[st] + 1));           return 0;         }       }     }     for (int ans1 = 1; ans1 <= r[st] - l[st] + 1; ans1++) {       for (int ans2 = 1; ans2 <= end - st + 1; ans2++) {         int ok = 1;         for (int i = st; i <= st + ans2 - 1; i++) {           if (l[i] != l[st]) {             ok = 0;             break;           }         }         if (ok) {           int top = st, bo = st + ans2 - 1, now = l[st];           while (bo < end) {             while (r[top] > now + ans1 - 1) {               now++;             }             top++;             bo++;             if (now + ans1 - 1 > r[top]) {               ok = 0;             }             if (now != l[bo]) {               ok = 0;             }           }           for (int i = top; i <= bo; i++) {             if (r[i] != r[top]) {               ok = 0;             }           }         }         if (ok) {           ans = min(ans, ans1 * ans2);         }       }     }     if (ans == INF) {       printf( -1 n );       return 0;     } else {       printf( %d n , ans);     }     return 0;   }