malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int const maxn = 4e6;   int tr01[maxn][2], x;   int len, check[maxn], n, tot;   void insert(int x) {     int ex, v = 0;     for (int i = 29; i >= 0; i--) {       ex = !!(x & (1 << i));       if (tr01[v][ex])         v = tr01[v][ex];       else {         tr01[v][ex] = ++tot;         v = tot;       }     }   }   void init() {     tot = 0;     memset(tr01, 0, sizeof(tr01));   }   int work(int x, int wei) {     if (!tr01[x][0] && !tr01[x][1]) return 0;     if (tr01[x][0] == 0) return work(tr01[x][1], wei - 1);     if (tr01[x][1] == 0) return work(tr01[x][0], wei - 1);     return (1 << wei) + min(work(tr01[x][1], wei - 1), work(tr01[x][0], wei - 1));   }   int main() {     scanf( %d , &n);     init();     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       insert(x);     }     printf( %d n , work(0, 29));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   inline void YES() {     puts( Yes );     exit(0);   }   inline void NO() {     puts( No );     exit(0);   }   int main() {     cin >> s;     int n = (int)s.length();     string baru =   ;     int score = 0;     int pl = -1, mn = 1;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  - )         score += pl;       else         score += mn;       swap(mn, pl);     }     if (score == 0)       YES();     else       NO();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int l, r, a;     cin >> l >> r >> a;     int total = 0;     while (l > 0 && r > 0) {       l--, r--, total += 2;     }     while (l > 0 && a > 0) {       l--, a--, total += 2;     }     while (r > 0 && a > 0) {       r--, a--, total += 2;     }     if (a > 0)       if (a % 2 == 0)         total += a;       else         total += a - 1;     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long mod(long int a) { return (a > 0 ? a : (-a)); }   long min(long int a, long int b) { return (a) > (b) ? (b) : (a); }   long max(long int a, long int b) { return (a) < (b) ? (b) : (a); }   bool sortbyff(const pair<int, int> &a, const pair<int, int> &b) {     return (a.first < b.first);   }   long num[1000001], t[5001][2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long n, m, k, i, j, l, r, a = -1, b = -1, c, d, s, u, w, x = 0, y, z, sum = 0,                               p = 0, ans = 0, M = 10000000;     cin >> n;     cout << n <<    ;     for (i = 1; i < n; i++) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200 + 5;   int n, m, p[N];   double dp[N][N][N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(10);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) dp[j][i][0] = 1;     long double pi = n * (n + 1) / 2;     pi = 1 / pi;     for (int k = 1; k <= m; k++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           if (i == j) continue;           for (int L = 0; L < n; L++)             for (int R = L; R < n; R++) {               int x = i, y = j;               if (L <= x && x <= R) x = L + R - x;               if (L <= y && y <= R) y = L + R - y;               dp[i][j][k] += dp[x][y][k - 1] * pi;             }         }     }     long double ans = 0;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         if (p[i] > p[j])           ans += dp[j][i][m];         else           ans += dp[i][j][m];       }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   char s[100002];   int main() {     cin.getline(s, 100002);     int l = strlen(s), flag;     for (int i = 0; i < l; i++) {       char c = s[i];       if (s[i] == s[l - i - 1] &&           (c ==  A  || c ==  H  || c ==  I  || c ==  M  || c ==  O  || c ==  T  ||            c ==  U  || c ==  V  || c ==  W  || c ==  X  || c ==  Y ))         flag = 1;       else {         flag = 0;         break;       }     }     if (l % 2 == 1 && flag) {       char c = s[l / 2];       if (c ==  A  || c ==  H  || c ==  I  || c ==  M  || c ==  O  || c ==  T  ||           c ==  U  || c ==  V  || c ==  W  || c ==  X  || c ==  Y )         flag = 1;       else         flag = 0;     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct res {     double l, r, w;   } T[800000];   double x[210000], s[210000], p, c, ans, w;   int N, M, i, l, r;   int init(int i, int l, int r, int x, double w) {     if (x < l || r < x) return 0;     if (l == r) {       T[i].w = T[i].l = T[i].r = w;       return 0;     }     int mid = l + r >> 1;     init(i * 2, l, mid, x, w);     init(i * 2 + 1, mid + 1, r, x, w);   }   int build(int i, int l, int r) {     if (l == r) return 0;     int mid = l + r >> 1, ls = i << 1, rs = (i << 1) + 1;     build(ls, l, mid);     build(rs, mid + 1, r);     T[i].l = max(T[ls].l, s[mid] - s[l - 1] + T[rs].l);     T[i].r = max(T[rs].r, T[ls].r + s[r] - s[mid]);     T[i].w =         max(T[ls].r + T[rs].l, max(max(T[ls].w, T[rs].w), max(T[i].l, T[i].r)));   }   res get(int i, int l, int r, int x, int y) {     if (x <= l && r <= y) return T[i];     int mid = l + r >> 1, ls = i << 1, rs = (i << 1) + 1;     res X;     if (y <= mid)       X = get(ls, l, mid, x, y);     else if (mid < x)       X = get(rs, mid + 1, r, x, y);     else {       res L = get(ls, l, mid, x, mid);       res R = get(rs, mid + 1, r, mid + 1, y);       X.w = max(max(L.w, R.w), L.r + R.l);       X.l = max(L.l, s[mid] - s[x - 1] + R.l);       X.r = max(R.r, s[y] - s[mid] + L.r);     }     return X;   }   int main() {     scanf( %d%d%lf , &N, &M, &c);     for (i = 1; i <= N; i++) scanf( %lf , &x[i]);     --N;     for (i = 1; i <= N; i++) {       scanf( %lf , &p);       w = (x[i + 1] - x[i]) / 2.0 - p * c / 100.0;       s[i] = s[i - 1] + w;       init(1, 1, N, i, w);     }     build(1, 1, N);     while (M--) {       scanf( %d%d , &l, &r);       res delta = get(1, 1, N, l, r - 1);       ans += max(0.0, delta.w);     }     printf( %.8lf n , ans);   }
#include <bits/stdc++.h>   int n;   int m;   char str[3000100];   int preveri(int x) {     int stevec = 0;     if (x - 1 >= 0 && str[x - 1] ==  . ) {       stevec++;     }     if (x + 1 < n && str[x + 1] ==  . ) {       stevec++;     }     return stevec;   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     scanf( %s , str);     int vsota = 0;     for (int i = 1; i < n; i++) {       if (str[i - 1] ==  .  && str[i] ==  . ) {         vsota++;       }     }     for (int i = 0; i < m; i++) {       int x;       char c;       scanf( %d %c , &x, &c);       int a = preveri(x - 1);       if (c ==  .  && str[x - 1] !=  . ) {         vsota = vsota + a;       } else if (c !=  .  && str[x - 1] ==  . ) {         vsota = vsota - a;       }       str[x - 1] = c;       printf( %d n , vsota);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10, Mod = 1e9 + 7;   int n, m, k, A[N], P[N];   map<int, int> M;   long long tot;   int main() {     scanf( %d%d , &n, &k);     m = (1 << k) - 1;     for (int i = 1; i <= n; i++)       scanf( %d , &A[i]), P[i] = P[i - 1] ^ A[i], M[min(P[i], m - P[i])]++;     M[0]++;     for (auto X : M) {       int a = X.second >> 1;       int b = X.second - a;       tot += 1ll * a * (a - 1) / 2;       tot += 1ll * b * (b - 1) / 2;     }     tot = 1ll * (n + 1) * n / 2 - tot;     printf( %lld , tot);     return (0);   }
#include <bits/stdc++.h>   using namespace std;   class TaskD {    public:     void solve(std::istream &in, std::ostream &out) {       long long n;       in >> n;       vector<long long> a(n), b(n), sa(n), sb(n);       for (auto &i : a) in >> i;       for (auto &i : b) in >> i;       for (long long i = 0; i < n; ++i) {         sa[i] = a[i] - b[i];         sb[i] = b[i] - a[i];       }       sort((sa).begin(), (sa).end());       sort((sb).begin(), (sb).end());       long long ans = 0;       for (long long i = 0; i < n; ++i) {         ans += (long long)(sa.end() -                            lower_bound((sa).begin(), (sa).end(), sb[i] + 1));         if (sb[i] < 0) ans -= 1;       }       out << ans / 2 << endl;     }   };   signed main() {     TaskD solver;     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[400][400];   int main() {     int n;     cin >> n;     long long k = n * n;     for (int j = 1; j <= n; j++) {       if (j % 2 != 0) {         for (int i = 1; i <= n; i++) {           a[i][j] = k--;         }       } else {         for (int i = n; i >= 1; i--) {           a[i][j] = k--;         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[20][110], b[20][110], c[20][110];   vector<int> res;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; i++) {       char st[15];       scanf( %s , st);       for (int j = 0; j < m; j++) scanf( %d%d%d , &a[i][j], &b[i][j], &c[i][j]);     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         res.clear();         for (int h = 0; h < m; h++)           for (int ik = 0; ik < c[i][h]; ik++) res.push_back(b[j][h] - a[i][h]);         sort(res.begin(), res.end());         reverse(res.begin(), res.end());         int v = 0;         for (int kp = 0; kp < k && kp < (int)res.size(); kp++)           v += max(res[kp], 0);         ans = max(ans, v);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> sorted;   vector<set<int> > v;   set<int> solve(int lf, int rg) {     if (lf == rg) {       return v[lf];     }     int md = (lf + rg) >> 1;     set<int> x = solve(lf, md);     set<int> y = solve(md + 1, rg);     for (int val : y) {       v[md + 1].insert(val);     }     for (int val : x) {       v[md].insert(val);     }     if ((int)(x).size() < (int)(y).size()) {       for (int val : x) {         v[md + 1].insert(val);         y.insert(val);       }       return y;     } else {       for (int val : y) {         v[md].insert(val);         x.insert(val);       }       return x;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<pair<int, int> > a(n);     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       sorted.push_back(x);       a[i] = {x, y};     }     sort((sorted).begin(), (sorted).end());     sorted.resize(unique((sorted).begin(), (sorted).end()) - sorted.begin());     v.resize((int)(sorted).size());     for (int i = 0; i < n; ++i) {       a[i].first = lower_bound((sorted).begin(), (sorted).end(), a[i].first) -                    sorted.begin();       v[a[i].first].insert(a[i].second);     }     solve(0, (int)(v).size() - 1);     vector<pair<int, int> > ans;     for (int i = 0; i < (int)(v).size(); ++i) {       for (int y : v[i]) {         ans.push_back({sorted[i], y});       }     }     cout << (int)(ans).size() <<   n ;     for (int i = 0; i < (int)(ans).size(); ++i) {       cout << ans[i].first <<     << ans[i].second <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int N = 1e12;   string a[105];   int dp1[105], dp2[105], dp3[105];   int main() {     int n, m, i, j, k;     cin >> n >> m;     for (i = 0; i < n; i++) {       cin >> a[i];       dp1[i] = maxn;       dp2[i] = maxn;       dp3[i] = maxn;     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (a[i][j] >=  a  && a[i][j] <=  z )           dp1[i] = min(dp1[i], min(j, m - j));         else if (a[i][j] >=  0  && a[i][j] <=  9 )           dp2[i] = min(dp2[i], min(j, m - j));         else           dp3[i] = min(dp3[i], min(j, m - j));       }     }     int ans = INT_MAX;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         for (k = 0; k < n; k++) {           if (i != j && j != k && i != k)             ans = min(ans, dp1[i] + dp2[j] + dp3[k]);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   struct T {     int l, h, a;     void scan() { scanf( %d%d%d , &l, &h, &a); }   };   const int INF = 1e9;   T Map[6][6];   int F[6];   int minF, maxC;   int cost;   int N;   void check() {     for (int i = 1; i < N - 1; ++i) {       if (F[i] != 0) return;     }     if (F[N - 1] < minF || F[N - 1] == minF && cost > maxC) {       minF = F[N - 1];       maxC = cost;     }   }   void rec(int from, int to) {     if (F[0] < INF - minF) return;     if (from == N - 1 && to == N) {       check();     }     if (from - 1 > 0 && F[from - 1] > 0) return;     int nextF, nextT;     nextT = to == N - 1 ? from + 2 : to + 1;     nextF = to == N - 1 ? from + 1 : from;     for (int i = Map[from][to].l; i <= Map[from][to].h && i <= F[from]; ++i) {       int d;       if (i == 0)         d = 0;       else {         d = Map[from][to].a + i * i;       }       cost += d;       F[from] -= i;       F[to] += i;       rec(nextF, nextT);       cost -= d;       F[from] += i;       F[to] -= i;     }   }   int main() {     scanf( %d , &N);     F[0] = INF;     for (int i = 0; i < N * (N - 1) / 2; ++i) {       int from, to;       scanf( %d%d , &from, &to);       --from;       --to;       Map[from][to].scan();     }     minF = INF;     maxC = -1;     cost = 0;     rec(0, 1);     if (minF == INF) {       printf( -1 -1 );       return 0;     }     printf( %d %d , minF, maxC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[1000000];   long long ncr(int n, int k) {     long long ans = 1;     k = k > n - k ? n - k : k;     int j = 1;     for (; j <= k; j++, n--) {       if (n % j == 0) {         ans *= n / j;       } else if (ans % j == 0) {         ans = ans / j * n;       } else {         ans = (ans * n) / j;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     long long n, m, t;     cin >> n >> m >> t;     long long sum = 0;     for (long long i = 4; i <= n; i++)       for (long long j = 1; j <= m; j++)         if (i + j == t) sum += ncr(n, i) * ncr(m, j);     cout << sum << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1000001;   const int MI = 100001;   const int MT = 10001;   int main() {     long long int n, ans = 0;     cin >> n;     ans = (n * (n + 1)) / 2;     n--;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       ans -= x;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e15;   const int N = 1e6 + 6;   int n, q, b[N], t;   queue<int> even, odd, ans;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       if (i % 2)         odd.push(i);       else         even.push(i);     }     int len, Lipoter = 1, flag = 1;     for (int i = 1; i <= q; i++) {       scanf( %d , &t);       if (t == 1) {         scanf( %d , &len);         flag = (flag + len + n) % n;         if (flag == 0) flag = n;       } else {         if (flag % 2) {           if (Lipoter == 0) {             even.push(even.front());             even.pop();           } else             Lipoter = 0;         } else {           if (Lipoter == 1) {             odd.push(odd.front());             odd.pop();           } else             Lipoter = 1;         }         if (flag % 2)           flag++;         else           flag--;         if (flag == 0) flag = n;       }     }     if (Lipoter) {       while (!even.empty() && !odd.empty()) {         ans.push(odd.front());         odd.pop();         ans.push(even.front());         even.pop();       }     } else {       while (!even.empty() && !odd.empty()) {         ans.push(even.front());         even.pop();         ans.push(odd.front());         odd.pop();       }     }     while (1) {       if (ans.front() == 1)         break;       else {         ans.push(ans.front());         ans.pop();       }     }     while (flag <= n) {       b[flag++] = ans.front();       ans.pop();     }     int cnt = 1;     while (!ans.empty()) {       b[cnt++] = ans.front();       ans.pop();     }     for (int i = 1; i <= n; i++) printf( %d  , b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, ar[500000], ps[500000], q, tp, a, b, bd[500000], sb[500000];   long res, fb;   long gs(long v) {     fb = v / 200;     res = 0;     for (int i = 0; i < fb; i++) res += sb[i];     for (int i = fb * 200; i <= v; i++) res += bd[i];     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i];       ps[ar[i]] = i;     }     for (int i = 2; i <= n; i++)       if (ps[i] < ps[i - 1]) {         bd[i] = 1;         sb[i / 200]++;       }     cin >> q;     for (; q; --q) {       cin >> tp;       if (tp == 1) {         cin >> a >> b;         cout << gs(b) - gs(a) + 1 << endl;       } else {         cin >> a >> b;         swap(ar[a], ar[b]);         ps[ar[a]] = a;         ps[ar[b]] = b;         a = ar[a];         b = ar[b];         sb[a / 200] -= bd[a];         sb[b / 200] -= bd[b];         bd[a] = 0;         bd[b] = 0;         sb[(a + 1) / 200] -= bd[a + 1];         sb[(b + 1) / 200] -= bd[b + 1];         bd[a] = bd[b] = bd[a + 1] = bd[b + 1] = 0;         if (a > 1 && ps[a] < ps[a - 1]) {           bd[a] = 1;           sb[a / 200]++;         }         if (a < n && ps[a] > ps[a + 1]) {           bd[a + 1] = 1;           sb[(a + 1) / 200]++;         }         if (b > 1 && ps[b] < ps[b - 1]) {           sb[b / 200] += 1 - bd[b];           bd[b] = 1;         }         if (b < n && ps[b] > ps[b + 1]) {           sb[(b + 1) / 200] += 1 - bd[b + 1];           bd[b + 1] = 1;         }       }     }     cin.get();     cin.get();     return 0;   }
#pragma GCC optimize( O3 )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )       #include <iostream>   #include <cstdio>   #include <vector>   #include <set>   #include <map>   #include <string>   #include <cstring>   #include <cstdlib>   #include <algorithm>   #include <cassert>   #include <cmath>   #include <queue>   #include <ctime>   #include <unordered_map>   #include <unordered_set>   #include <sstream>       using namespace std;       #define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)   #define SZ(a) (int)(a).size()   #define ALL(a) (a).begin(), (a).end()      const int N = 5005;   long long a[N], b[N], d[N];   short e[N][N];   vector<long long> c[2 * N];       int main() {    ios::sync_with_stdio(false);    cin.tie(nullptr);    int n;    cin >> n;    REP(i, n) cin >> a[i];    REP(i, n) cin >> b[i];    REP(i, n) {     int aidx = i, bidx = 0, cidx = i;     c[cidx].reserve(i + 2);     c[cidx].push_back(0);     while (aidx >= 0) {      e[aidx][bidx] = SZ(c[cidx]);      c[cidx].push_back(c[cidx].back() + a[aidx] * b[bidx]);      --aidx, ++bidx;     }    }    for (int i = 1; i < n; i++) {     int aidx = n - 1, bidx = i, cidx = n - 1 + i;     c[cidx].reserve(n - i + 1);     c[cidx].push_back(0);     while (bidx < n) {      e[aidx][bidx] = SZ(c[cidx]);      c[cidx].push_back(c[cidx].back() + a[aidx] * b[bidx]);      --aidx, ++bidx;     }    }    d[0] = 0;    for (int i = 1; i <= n; i++) {     d[i] = d[i - 1] + a[i - 1] * b[i - 1];    }    long long res = d[n];    REP(L, n) {     for (int R = L; R < n; R++) {      long long fs = d[n] - d[R + 1] + d[L];      int st = e[R][L], fn = e[L][R];      long long sc = c[L + R][fn] - c[L + R][st - 1];      res = max(res, fs + sc);     }    }    cout << res << endl;    return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( 3 ,  inline ,  Ofast )   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     T f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();     x *= f;   }   inline void Setfile(string Str =   ) {     if (Str ==   ) return;     freopen((Str +  .in ).c_str(),  r , stdin);     freopen((Str +  .out ).c_str(),  w , stdout);   }   const int maxn = 500005, mod = 998244353;   int n, f[maxn][2], pw2[maxn], sz[maxn], ans;   vector<int> G[maxn];   inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }   inline int Mul(int x, int y) { return 1ll * x * y % mod; }   inline void dfs(int u = 1, int p = 0) {     f[u][0] = sz[u] = 1;     for (int i = 0; i < (int)G[u].size(); ++i) {       int v = G[u][i];       if (v == p) continue;       dfs(v, u), sz[u] += sz[v],           f[u][1] = Add(Mul(f[u][1], Mul(2, Add(f[v][0], f[v][1]))),                         Mul(f[u][0], f[v][0])),           f[u][0] = Mul(f[u][0], Add(Mul(f[v][1], 2), f[v][0]));     }     ans = Add(ans, Mul(f[u][1], pw2[n - sz[u] + 1]));   }   int main() {     Setfile();     pw2[0] = 1;     for (int i = 1; i < maxn; ++i) pw2[i] = Add(pw2[i - 1], pw2[i - 1]);     read(n);     for (int i = 1, x, y; i < n; ++i)       read(x), read(y), G[x].push_back(y), G[y].push_back(x);     dfs(), printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     int a, b, c;     cin >> a >> b >> c;     c -= 2;     b -= 1;     int ans = min({a, b, c});     if (ans < 0) {       cout << 0;     } else {       ans = ans * 3 + 3;       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 998244353;   const long long int mxn = 1e5 + 7;   long long int a[mxn];   long long int power(long long int a, long long int b);   long long int flcm(long long int n, long long int m);   long long int fgcd(long long int n, long long int m);   long long int modinv(long long int x);   long long int max_val(long long int start, long long int end) {     long long int pres_max, global_max;     for (long long int i = start; i <= end; i++) {       if (i == start) {         pres_max = a[i];         global_max = a[i];       } else {         pres_max = max(pres_max + a[i], a[i]);         global_max = max(global_max, pres_max);       }     }     return global_max;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, k, u, v, t = 1, temp, ans = 0, flag = 1, c = 0, min_el,                                  max_el, sum_el;     string s, s1, s2;     cin >> t;     while (t--) {       ans = 0;       c = 0;       flag = 1;       sum_el = 0;       cin >> n;       memset(a, 0, sizeof(a));       for (long long int i = 0; i < n; i++) cin >> a[i];       max_el = max(max_val(0, n - 2), max_val(1, n - 1));       if (max_el < max_val(0, n - 1))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b % 2) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b /= 2;     }     return res;   }   long long int flcm(long long int n, long long int m) {     long long int temp = fgcd(n, m);     return (n * m) / temp;   }   long long int fgcd(long long int n, long long int m) {     long long int temp;     while (m != 0) {       temp = n;       n = m;       m = temp % m;     }     return n;   }   long long int modinv(long long int x) { return power(x, mod - 2); }