malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, k, ans[5];   char s[N];   void solve(int l, int r) {     while (l != r) {       int mid = l + r >> 1;       printf( 1 %d %d n , mid, mid + 1);       fflush(stdout);       scanf( %s , s);       if (!strcmp(s,  NIE ))         l = mid + 1;       else         r = mid;     }     ans[++m] = l;   }   int main() {     scanf( %d%d , &n, &k);     solve(1, n);     if (ans[1] > 1) solve(1, ans[1] - 1);     if (ans[1] < n) solve(ans[1] + 1, n);     if (m == 2) {       printf( 2 %d %d n , ans[1], ans[2]);       exit(0);     }     printf( 1 %d %d n , ans[2], ans[3]);     fflush(stdout);     scanf( %s , s);     if (!strcmp(s,  NIE )) ans[2] = ans[3];     printf( 2 %d %d n , ans[1], ans[2]);     return 0;   }
#include <bits/stdc++.h>   const int N = 2e5 + 5;   const int highestboolN = 1e9;   const long long unsigned inf = 1234568901234567890;   const long double pi = 3.141592653589793;   const int md = 1e9 + 7;   using namespace std;   int here = 1;   void force_break() {     here++;     if (here >= (N * 100)) {       cout <<   n n t Infinite loop  n n ;       exit(1);     }     return;   }   int board[105][105];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     scanf( %d , &n);     memset(board, 0, sizeof(board));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (board[i][j]) continue;         char temp;         if ((i + j) % 2) {           board[i][j] = 1;           temp = 2;         } else {           board[i][j] = 2;           temp = 1;         }         if (i + 2 < n and j + 1 < n) board[i + 2][j + 1] = temp;         if (i + 1 < n and j + 2 < n) board[i + 1][j + 2] = temp;         if (i + 2 < n and j - 1 >= 0) board[i + 2][j - 1] = temp;         if (i + 1 < n and j - 2 >= 0) board[i + 1][j - 2] = temp;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (board[i][j] == 1)           cout <<  B ;         else if (board[i][j] == 2)           cout <<  W ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long arr[1010], brr[1010];   int main() {     long long n, i, j, x, y, ans;     cin >> n;     for (i = 1; i <= n; i++) cin >> arr[i];     for (i = 1; i <= n; i++) cin >> brr[i];     ans = 0;     for (i = 1; i <= n; i++) {       x = arr[i];       y = brr[i];       ans = max(ans, x + y);       for (j = i + 1; j <= n; j++) {         x = (x | arr[j]);         y = (y | brr[j]);         ans = max(ans, x + y);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long dp[26][2][2];   long long need;   bool hasone = 0;   int ans[55];   inline void upd(long long &a, long long b) { a += b; }   inline long long getval(int p, int v) {     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     for (int i = 0; i < (n + 1) / 2; i++) {       for (int x = 0; x < 2; x++) {         for (int y = 0; y < 2; y++) {           if (!dp[i][x][y]) continue;           for (int a = 0; a < 2; a++) {             if (!i && a) continue;             if (i <= p && a != ans[i]) continue;             for (int b = 0; b < 2; b++) {               if ((n - 1 - i) <= p && b != ans[n - 1 - i]) continue;               if (i == n - 1 - i && a != b) continue;               if (a > b && !x) continue;               if (a > !b && !y) continue;               upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]);             }           }         }       }     }     return dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] + dp[(n + 1) / 2][1][0] +            dp[(n + 1) / 2][1][1] - !hasone;   }   int main() {     cin >> n >> need;     dp[0][0][0] = 1;     for (int i = 0; i < (n + 1) / 2; i++) {       for (int x = 0; x < 2; x++) {         for (int y = 0; y < 2; y++) {           if (!dp[i][x][y]) continue;           for (int a = 0; a < 2; a++) {             if (!i && a) continue;             for (int b = 0; b < 2; b++) {               if (i == n - 1 - i && a != b) continue;               if (a > b && !x) continue;               if (a > !b && !y) continue;               upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]);             }           }         }       }     }     long long all = dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] +                     dp[(n + 1) / 2][1][0] + dp[(n + 1) / 2][1][1];     all--;     if (all < need) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; i++) {       ans[i] = 0;       long long num = getval(i, ans[i]);       if (num < need || (i == n - 1 && !hasone)) {         ans[i] = 1;         need -= num;         hasone = 1;       }     }     for (int i = 0; i < n; i++) printf( %d , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     int f = 0, c = getchar();     x = 0;     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     if (f) x = -x;   }   template <typename T, typename... Args>   inline void read(T& x, Args&... args) {     read(x);     read(args...);   }   template <typename T>   void write(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   void writes(T x) {     write(x);     putchar(   );   }   template <typename T>   void writeln(T x) {     write(x);     puts(  );   }   template <typename T>   inline bool chkmin(T& x, const T& y) {     return y < x ? (x = y, true) : false;   }   template <typename T>   inline bool chkmax(T& x, const T& y) {     return x < y ? (x = y, true) : false;   }   const int maxn = (int)3e5 + 10;   const long long inf = (long long)1e18;   const int mod = (int)1e9 + 7;   int n, a[maxn];   long long ans;   vector<int> v[maxn];   int main() {     read(n);     for (int i = (1); i < (2 * n + 1); i++) read(a[i]);     for (int i = (1); i < (2 * n + 1); i++) {       v[a[i]].push_back(i);     }     int now = 1;     for (int i = (1); i < (n + 1); i++) {       ans += abs(v[i][0] - now);       now = v[i][0];     }     now = 1;     for (int i = (1); i < (n + 1); i++) {       ans += abs(v[i][1] - now);       now = v[i][1];     }     write(ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[3][3];     int cnt1, cnt2, cnt3;     for (int i = 0; i < 3; i++)       for (int j = 0; j < 3; j++) scanf( %d , &arr[i][j]);     cnt1 = arr[0][1] + arr[0][2];     cnt2 = arr[1][0] + arr[1][2];     cnt3 = arr[2][0] + arr[2][1];     if (cnt1 >= cnt2 && cnt1 >= cnt3) {       for (int i = 1; i <= 1e5; i++)         if (cnt1 + i == cnt2 + (cnt1 - cnt2 + i) &&             cnt1 + i == cnt3 + (cnt1 - cnt3 + i) &&             i + (cnt1 - cnt3 + i) + (cnt1 - cnt2 + i) == cnt1 + i) {           arr[0][0] = i;           arr[1][1] = (cnt1 - cnt2 + i);           arr[2][2] = (cnt1 - cnt3 + i);           break;         }     } else if (cnt2 >= cnt1 && cnt2 >= cnt3) {       for (int i = 1; i <= 1e5; i++)         if (cnt2 + i == cnt1 + (cnt2 - cnt1 + i) &&             cnt2 + i == cnt3 + (cnt2 - cnt3 + i) &&             i + (cnt2 - cnt3 + i) + (cnt2 - cnt1 + i) == cnt2 + i) {           arr[0][0] = (cnt2 - cnt1 + i);           arr[1][1] = i;           arr[2][2] = (cnt2 - cnt3 + i);           break;         }     } else if (cnt3 >= cnt1 && cnt3 >= cnt2) {       for (int i = 1; i <= 1e5; i++)         if (cnt3 + i == cnt1 + (cnt3 - cnt1 + i) &&             cnt3 + i == cnt2 + (cnt3 - cnt2 + i) &&             i + (cnt3 - cnt2 + i) + (cnt3 - cnt1 + i) == cnt3 + i) {           arr[0][0] = (cnt3 - cnt1 + i);           arr[1][1] = (cnt3 - cnt2 + i);           arr[2][2] = i;           break;         }     }     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) printf( %d  , arr[i][j]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, a1, a2;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &x);       if (i % 2 == 0) {         a1 += (x + 1) / 2;         a2 += x / 2;       } else {         a1 += x / 2;         a2 += (x + 1) / 2;       }     }     printf( %lld n , min(a1, a2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     int a, b, c;     cin >> a >> b >> c;     cout << ((a + c - 1) * (b + c - 1) - c * (c - 1)) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   vector<long long> p(10000005, -1);   void f(long long n = 10000005) {     p[2] = 2;     for (long long i = 4; i < n; i += 2) {       p[i] = 2;     }     for (long long i = 3; i < n; i += 2) {       if (p[i] == -1) {         p[i] = i;         for (long long j = i * i; j < n; j += i) {           if (p[j] == -1) p[j] = i;         }       }     }   }   void find(long long x, vector<long long>& v) {     while (x != 1) {       v.push_back(p[x]);       x /= p[x];     }   }   void solve() {     long long n, m;     cin >> n >> m;     vector<vector<long long>> v(n, vector<long long>(m));     map<long long, vector<long long>> z;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> v[i][j];         z[i + j].push_back(v[i][j]);       }     }     long long f = 0, r = n + m - 2;     long long ans = 0;     while (f < r) {       map<long long, long long> p;       for (auto x : z[f]) p[x]++;       for (auto x : z[r]) p[x]++;       long long t = 0, mx = 0;       for (auto x : p) {         t += x.second;         mx = max(mx, x.second);       }       ans += t - mx;       f++;       r--;     }     cout << ans <<   n ;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   char str[100005];   int cnt[250];   int main() {     scanf( %s , &str);     int len = strlen(str);     set<char> myset;     for (int i = 0; i < len; i++) {       myset.insert(str[i]);       cnt[str[i]]++;     }     if (myset.size() == 1 || myset.size() > 4) {       printf( NO );       return 0;     }     if (myset.size() == 4) {       printf( YES );       return 0;     }     if (myset.size() == 3) {       if (len == 3) {         printf( NO );         return 0;       } else {         printf( YES );         return 0;       }     }     if (myset.size() == 2) {       for (int i =  a ; i <=  z ; i++) {         if (cnt[i] == 1) {           printf( NO );           return 0;         }       }       printf( YES );     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100005;   int n, m;   int t[MAX_N], x[MAX_N];   int nxt;   int idx[MAX_N];   int res[MAX_N];   bool mycmp(const int a, const int b) {     if (x[a] != x[b]) return x[a] < x[b];     return a < b;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d%d , &t[i], &x[i]);     int time = 0;     for (int step = 0; step < n; step += m) {       nxt = 0;       for (int i = step; i < min(step + m, n); ++i) idx[nxt++] = i;       time += max(0, t[idx[nxt - 1]] - time);       sort(idx, idx + nxt, mycmp);       for (int i = 0; i < nxt;) {         int j = i;         for (; j < nxt && x[idx[i]] == x[idx[j]]; ++j)           ;         time += x[idx[i]];         if (i > 0) time -= x[idx[i - 1]];         for (int k = i; k < j; ++k) res[idx[k]] = time;         time += 1 + (j - i) / 2;         i = j;       }       time += x[idx[nxt - 1]];     }     printf( %d , res[0]);     for (int i = 1; i < n; ++i) printf(  %d , res[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   const int mod = 1e9 + 7;   const long long INF = 1e18;   string a[30], b[30], ans[407];   void rua() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int cnt = 0, s1 = -1, s2 = -1;     while (cnt < n * m) {       s1 = (s1 + 1) % n;       s2 = (s2 + 1) % m;       ans[cnt++] = a[s1] + b[s2];     }     int q;     cin >> q;     while (q--) {       int x;       cin >> x;       cout << ans[(x - 1) % (n * m)] << endl;     }   }   int main() {     rua();     return 0;   }
#include <bits/stdc++.h>   int main(int argc, char *argv[]) {     int n, i, a, b, c, d;     long int s;     scanf( %d , &n);     s = 0;     for (i = 1; i <= n; i++) {       scanf( %d %d %d %d , &a, &b, &c, &d);       s = s + (1 + abs(a - c)) * (1 + abs(b - d));     }     printf( %ld , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<vector<int> > edges(n + 10, vector<int>());     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       edges[x].push_back(y);       edges[y].push_back(x);     }     map<int, int> not_first;     map<int, int> not_second;     map<int, int> not_third;     set<int> first;     set<int> second;     set<int> third;     for (int i = 1; i < n + 1; i++) {       if (not_first.find(i) == not_first.end()) {         first.insert(i);         for (int j = 0; j < edges[i].size(); j++) {           not_first[edges[i][j]]++;         }       } else if (not_second.find(i) == not_second.end()) {         second.insert(i);         for (int j = 0; j < edges[i].size(); j++) {           not_second[edges[i][j]]++;         }       } else if (not_third.find(i) == not_third.end()) {         third.insert(i);         for (int j = 0; j < edges[i].size(); j++) {           not_third[edges[i][j]]++;         }       } else {         cout << -1;         return 0;       }     }     if (second.size() == 0 or third.size() == 0) {       cout << -1;     } else {       for (auto i = not_first.begin(); i != not_first.end(); i++) {         if (i->second != first.size()) {           cout << -1;           return 0;         }       }       for (auto i = not_second.begin(); i != not_second.end(); i++) {         if (i->second != second.size()) {           cout << -1;           return 0;         }       }       for (auto i = not_third.begin(); i != not_third.end(); i++) {         if (i->second != third.size()) {           cout << -1;           return 0;         }       }       vector<int> cols(n + 1, 0);       for (auto i = first.begin(); i != first.end(); i++) {         cols[*i] = 1;       }       for (auto i = second.begin(); i != second.end(); i++) {         cols[*i] = 2;       }       for (auto i = third.begin(); i != third.end(); i++) {         cols[*i] = 3;       }       for (int i = 1; i < n + 1; i++) {         cout << cols[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimization( unroll-loops )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4 )   using namespace std;   const int BASE = 1000000;   char what[1 << 20];   pair<int, int> nxt[10][1 << 20];   pair<long long, int> to[10][10];   inline long long Calc(long long x) {     long long suff = x / BASE, pref = x % BASE;     long long ans = suff;     while (suff > 0) {       ans += nxt[what[suff]][pref].first;       pref = nxt[what[suff]][pref].second;       pref += BASE - max(what[suff], what[pref]);       --suff;     }     return ans + nxt[0][pref].first;   }   inline long long Process(long long x) {     long long suff = x / (1LL * BASE * BASE), psuff = x / BASE % BASE,               pref = x % BASE;     if (suff == 0) {       return Calc(x);     }     long long ans = 0;     while (psuff >= 0) {       ans += nxt[max(what[psuff], what[suff])][pref].first + 1;       pref = nxt[max(what[psuff], what[suff])][pref].second;       pref += BASE - max(what[psuff], max(what[suff], what[pref]));       --psuff;     }     --suff;     while (suff > 0) {       ans += to[what[suff]][BASE - pref].first;       pref = to[what[suff]][BASE - pref].second;       --suff;     }     return ans + Calc(1LL * (BASE - 1) * BASE + pref);   }   int main() {     for (int i = 1; i <= BASE; ++i) {       what[i] = i % 10 > what[i / 10] ? i % 10 : what[i / 10];       for (int d = 0; d < 10; ++d) {         char r = what[i] < d ? d : what[i];         if (i >= r) {           nxt[d][i] = make_pair(nxt[d][i - r].first + 1, nxt[d][i - r].second);         } else {           nxt[d][i] = make_pair(0, i);         }       }     }     for (char d = 1; d < 10; ++d) {       for (int l = 0; l < 10; ++l) {         int suff = BASE - 1, pref = BASE - l;         to[d][l].first = BASE;         while (suff >= 0) {           char r = (d < what[suff] ? what[suff] : d);           to[d][l].first += nxt[r][pref].first;           pref = nxt[r][pref].second;           pref += BASE - (r < what[pref] ? what[pref] : r);           --suff;         }         to[d][l].second = pref;       }     }     long long n;     cin >> n;     cout << Process(n) <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 200000 + 10;   const int INF = 0x7fffffff;   using namespace std;   struct EDGE {     int u, v, w;     bool operator<(const EDGE &b) const { return w > b.w; }   };   int fa[MAXN + MAXN];   int n, m, vis[MAXN];   int Min[MAXN];   vector<EDGE> edge;   int Find(int x) { return fa[x] < 0 ? x : fa[x] = Find(fa[x]); }   int main() {     edge.clear();     scanf( %d%d , &n, &m);     memset(fa, -1, sizeof(fa));     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= m; i++) {       int a, b, w;       scanf( %d%d%d , &a, &b, &w);       edge.push_back((EDGE){a, b, w});     }     sort(edge.begin(), edge.end());     long long Ans = 0ll;     for (int i = 0; i < m; i++) {       int u = edge[i].u, v = edge[i].v;       u = Find(u);       v = Find(v);       if (u == v) {         if (fa[u] == -2) continue;         fa[u] = -2;         Ans += (long long)edge[i].w;         continue;       }       if (fa[u] == -2 && fa[v] == -2) continue;       fa[v] = min(fa[v], fa[u]);       Ans += (long long)edge[i].w;       fa[u] = v;     }     printf( %lld n , Ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int intervalo[200010];   int aparicoes[200010];   int aceito[200010];   int main() {     int n, k, q;     cin >> n >> k >> q;     int l, r;     for (int i = 0; i < n; i++) {       cin >> l >> r;       intervalo[l] += 1;       intervalo[r + 1] -= 1;     }     int x = 0;     for (int i = 1; i <= 200000; i++) {       x += intervalo[i];       aparicoes[i] = x;     }     for (int i = 1; i <= 200000; i++) {       if (aparicoes[i] >= k)         aceito[i] = 1;       else         aceito[i] = 0;       aceito[i] += aceito[i - 1];     }     for (int i = 0; i < q; i++) {       cin >> l >> r;       cout << aceito[r] - aceito[l - 1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const int inf = 1000000007;   const int MOD = 1000000007;   int f(int x) {     int res = 0;     while (x > 0) {       res += x % 10;       x /= 10;     }     return res;   }   bool calc(int n, int k) {     int sm = 0;     for (int i = 0; i < k; ++i) {       sm += f(i);     }     for (int i = k; i <= 100000; ++i) {       sm += f(i);       if (sm == n) {         cout << i - k <<   n ;         return true;       }       sm -= f(i - k);     }     if (n <= 45) {       cout << -1 <<   n ;       return true;     }     return false;   }   void solve() {     int n, k;     cin >> n >> k;     if (calc(n, k)) return;     n -= k * (k + 1) / 2;     if (n < 0) {       cout << -1 <<   n ;       return;     }     int top = 0;     string mid;     int last = 0;     int cnt = 0;     while (n % (k + 1) != 0) {       n += 9;       cnt++;       if (cnt > 9) {         cout << -1 <<   n ;         return;       }     }     if (n - cnt * 9 < (k - cnt) * 9) {       cout << -1 <<   n ;       return;     }     last = 9 - (k - cnt);     n /= (k + 1);     n -= last;     while (n > 9) {       n -= 9;       mid +=  9 ;     }     top = n;     if (cnt > 0) {       int l = mid.length();       if (l != 0) {         mid[l - 1] =  8 ;         top++;       }     }     string hoge;     while (top > 9) {       top -= 9;       hoge +=  9 ;     }     if (top > 0) cout << top;     cout << hoge << mid << last <<   n ;   }   signed main() {     int t;     cin >> t;     for (int i = 0; i < t; ++i) solve();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3,no-stack-protector,unroll-loops,fast-math )   using namespace std;   struct coor {     long long x, y, x1, y1;   };   vector<struct coor> v;   struct coor ldp[200005], rdp[200005];   struct coor inter(struct coor l, struct coor r) {     struct coor res = {INT_MIN, INT_MIN, INT_MIN, INT_MIN};     if (min(l.x1, r.x1) < max(r.x, l.x) || min(l.y1, r.y1) < max(r.y, l.y))       return res;     res.x = max(l.x, r.x);     res.x1 = min(l.x1, r.x1);     res.y = max(l.y, r.y);     res.y1 = min(l.y1, r.y1);     return res;   }   bool check(struct coor l) { return (l.x != INT_MIN); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a >> b >> c >> d;       v.push_back({a, b, c, d});     }     ldp[0] = v[0];     for (i = 1; i < n; i++) {       ldp[i] = inter(ldp[i - 1], v[i]);     }     rdp[n - 1] = v[n - 1];     for (i = n - 2; i >= 0; i--) {       rdp[i] = inter(rdp[i + 1], v[i]);     }     if (check(ldp[n - 2])) {       cout << ldp[n - 2].x <<     << ldp[n - 2].y <<   n ;     } else if (check(rdp[1])) {       cout << rdp[1].x <<     << rdp[1].y <<   n ;     } else {       for (i = 1; i < n - 1; i++) {         struct coor fin = inter(ldp[i - 1], rdp[i + 1]);         if (check(fin)) {           cout << fin.x <<     << fin.y <<   n ;           return 0;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, a, b, c, d;     cin >> t;     while (t--) {       cin >> n >> a >> b >> c >> d;       int mi = (a - b) * n, ma = (a + b) * n;       if ((mi > c + d) || (ma < c - d))         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long long mod = 1000000007;   void solve() {     int n, m, u, v;     cin >> n >> m;     vector<int> adj[n + 1];     for (int i = 0; i < m; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     vector<pair<long long, long long> > hash, hash_orig;     hash.reserve(n);     long long p1 = 31, p2 = 53, h1, h2;     long long pow_p1[n + 1], pow_p2[n + 1];     pow_p1[0] = pow_p2[0] = 1;     for (int i = 1; i <= n; i++) {       pow_p1[i] = pow_p1[i - 1] * p1 % mod;       pow_p2[i] = pow_p2[i - 1] * p2 % mod;     }     for (int i = 1; i <= n; i++) {       h1 = 0;       h2 = 0;       for (int &j : adj[i]) {         h1 += pow_p1[j];         h2 += pow_p2[j];       }       hash.push_back({h1, h2});     }     hash_orig = hash;     sort((hash).begin(), (hash).end());     long long ans = 0;     int cnt = 1;     for (int i = 1; i < n; i++) {       if (hash[i] != hash[i - 1]) {         ans += 1ll * cnt * (cnt - 1) / 2;         cnt = 1;       } else         cnt++;     }     ans += 1ll * cnt * (cnt - 1) / 2;     for (int i = 1; i <= n; i++) {       hash_orig[i - 1].first += pow_p1[i];       hash_orig[i - 1].second += pow_p2[i];     }     for (int i = 1; i <= n; i++) {       for (int &j : adj[i]) {         if (j < i || adj[i].size() != adj[j].size()) continue;         if (hash_orig[i - 1] == hash_orig[j - 1]) ans++;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m = 0;     cin >> n;     int last;     for (int(i) = 0; (i) < (n); ++(i)) {       cin >> last;       m += last;     }     cout << ((n - m == 1 && n > 1) || (n == 1 && m == 1) ?  YES n  :  NO n );   }