malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T mdINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   template <class T>   bool ISLEFT(T a, T b, T c) {     if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -          (b.first.first - c.first.first) * (a.second.second - b.second.second)) <         0.0)       return 1;     else       return 0;   }   int main() {     int n;     scanf( %d , &n);     string a[n + 2];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = n - 1; i >= 1; i--) {       string s;       int l = a[i + 1].size();       int l1 = a[i].size();       int first = 0;       s +=  # ;       bool fl = 0;       for (int j = 1; j <= min(l - 1, l1 - 1); j++) {         if (a[i][j] < a[i + 1][j]) fl = 1;         if (a[i][j] > a[i + 1][j]) {           break;         }         s += a[i][j];       }       if (fl)         a[i] = a[i];       else         a[i] = s;     }     for (int i = 1; i <= n; i++) cout << a[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void pre() {}   void solve() {}   bool vis[200009];   int ans[200009];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int n;     cin >> n;     int a, b;     cin >> a >> b;     priority_queue<pair<int, int> > q;     q.push(make_pair(0, 0));     memset(ans, -1, sizeof(ans));     ans[0] = 0;     while (!q.empty()) {       pair<int, int> z = q.top();       q.pop();       if (vis[z.second]) continue;       vis[z.second] = 1;       if (z.second + a < a + b && !vis[z.second + a] &&           (ans[z.second + a] == -1 ||            ans[z.second + a] > max(z.second + a, ans[z.second]))) {         ans[z.second + a] = max(z.second + a, ans[z.second]);         q.push(make_pair(-ans[z.second + a], z.second + a));       }       if (z.second - b >= 0 && !vis[z.second - b] &&           (ans[z.second - b] == -1 || ans[z.second - b] > ans[z.second])) {         ans[z.second - b] = ans[z.second];         q.push(make_pair(-ans[z.second - b], z.second - b));       }     }     long long fns = 0;     int m = min(a + b - 2, n);     for (int i = 0; i < (a + b - 1); ++i) {       if (ans[i] == -1) {         continue;       }       fns += max(0, m + 1 - ans[i]);     }     if (n > a + b - 2) {       m = n;       for (int i = 0; i < (a); ++i) {         if (ans[i] == -1) continue;         int l = (m) / a;         if (m % a >= i) l++;         int d = -a;         int st = m - i + 1;         fns += 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2;       }       m = a + b - 2;       for (int i = 0; i < (a); ++i) {         if (ans[i] == -1) continue;         int l = (m) / a;         if (m % a >= i) l++;         int d = -a;         int st = m - i + 1;         fns -= 1ll * l * (2 * st + 1ll * (l - 1) * d) / 2;       }     }     cout << fns;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   map<string, int> m;   string s;   string pr[109];   int darab[109][26];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cout <<  ?   << 1 <<     << n << endl;     for (int i = 1; i <= (n * (n + 1)) / 2; i++) {       cin >> s;       sort(s.begin(), s.end());       m[s]++;     }     if (n == 1) {       cout <<  !   << s << endl;       return 0;     }     cout <<  ?   << 2 <<     << n << endl;     for (int i = 1; i <= (n * (n - 1)) / 2; i++) {       cin >> s;       sort(s.begin(), s.end());       m[s]--;     }     auto it = m.begin();     while (it != m.end()) {       if (it->second > 0) {         pr[(it->first).size()] = (it->first);       }       it++;     }     for (int i = n; i >= 1; i--) {       for (int j = 0; j < i; j++) {         darab[i][pr[i][j] -  a ]++;       }     }     string ans =   ;     for (int i = 1; i <= n; i++) {       int kul = 0;       for (int j = 0; j < 26; j++) {         if (darab[i][j] != darab[i - 1][j]) {           kul = j;           break;         }       }       ans += ((char)( a  + kul));     }     cout <<  !   << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long solve() {     long long a, b;     cin >> a >> b;     long long m = b / 2 + 1;     if (m > a)       return b % m;     else       return b % a;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       cout << solve() <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, mr;   vector<string> v;   string s, s2, tmp, res;   vector<pair<int, int> > e;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s;       v.push_back(s);     }     sort(v.begin(), v.end());     for (int i = 0; i < m; i++) {       cin >> s >> s2;       int a;       for (a = 0; a < n; a++)         if (v[a] == s) break;       int b;       for (b = 0; b < n; b++)         if (v[b] == s2) break;       e.push_back(make_pair(a, b));     }     int mx = (int)pow(2.0, n);     for (int x = mx - 1; x > 0; x--) {       bool f = true;       for (int i = 0; i < e.size(); i++) {         int e1 = n - e[i].first - 1, e2 = n - e[i].second - 1;         if ((x >> e1 & 1) && (x >> e2 & 1)) f = false;       }       if (f) {         int amx = mx;         int r = 0;         for (int o = 0; o < n; o++) {           if (x & (mx >> 1)) r++;           mx /= 2;         }         mx = amx;         tmp =   ;         for (int o = 0; o < n; o++) {           if (x & (mx >> 1)) tmp += v[o] +   n ;           mx /= 2;         }         mx = amx;         if (r > mr) res = tmp, mr = r;       }     }     cout << mr << endl;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 9e18 + 2e17;   const int inf = 2e9;   const int N = 1e5 + 22;   const double eps = 1e-10;   bool cmp(pair<int, int> A, pair<int, int> B) {     if (A.first != B.first) return A.first < B.first;     return A.second > B.second;   }   void _solve() {     int n, m;     cin >> n >> m;     pair<int, int> sr[n];     for (int i = (int)0; i < (int)n; i++) cin >> sr[i].first >> sr[i].second;     sort(sr, sr + n, cmp);     int c = 0;     for (int i = 0; i < n;) {       int x = sr[i].first;       while (i < n && x == sr[i].first) i++;       c++;     }     vector<vector<int> > row_sum(c);     vector<int> tot_sum;     int p = 0;     for (int i = 0; i < n;) {       int x = sr[i].first, sum = 0;       while (i < n && x == sr[i].first) {         sum += sr[i].second;         i++;         if (sum <= 0) continue;         row_sum[p].push_back(sum);       }       if (!row_sum[p].empty()) p++;     }     pair<int, int> row_sz[p];     for (int i = (int)0; i < (int)p; i++) row_sz[i] = {row_sum[i].size(), i};     sort(row_sz, row_sz + p);     for (int y = 0, i = 0; y < p;) {       int x = row_sz[y].first;       while (i < x) {         int sum = 0;         for (int j = (int)y; j < (int)p; j++) sum += row_sum[row_sz[j].second][i];         tot_sum.push_back(sum);         i++;       }       while (x == row_sz[y].first) y++;     }     int ans = 0;     for (int i = (int)0; i < (int)tot_sum.size(); i++) ans = max(ans, tot_sum[i]);     cout << ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     _solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, cnt;   vector<int> a[150004];   int num[150004], sl[150004];   int d[150004];   void DFS(int u) {     num[u] = cnt;     for (int i = 0; i < a[u].size(); i++)       if (num[a[u][i]] == 0) DFS(a[u][i]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       d[u]++, d[v]++;       a[u].push_back(v);       a[v].push_back(u);     }     for (int u = 1; u <= n; u++)       if (num[u] == 0) {         cnt++;         DFS(u);       }     for (int i = 1; i <= n; i++) sl[num[i]]++;     for (int i = 1; i <= n; i++)       if (d[i] != sl[num[i]] - 1) {         cout <<  NO ;         return 0;       }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool arng(pair<long long, long long> p, pair<long long, long long> q) {     if (p.first > q.first) return true;     if (p.first == q.first) {       return (p.second < q.second);     }     return false;   }   void solve() {     long long n, m;     cin >> n;     long long ac[n];     pair<long long, long long> a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       ac[i] = a[i].first;       a[i].second = i;     }     sort(a, a + n, arng);     cin >> m;     while (m--) {       long long k, pos;       cin >> k >> pos;       long long s = 0;       long long posa[k];       for (long long i = 0; i < k; i++) {         posa[i] = a[i].second;       }       sort(posa, posa + k);       cout << ac[posa[pos - 1]] << endl;     }     return;   }   int32_t main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n + 1];       for (int i = 1; i <= n; i++) cin >> arr[i];       sort(arr + 1, arr + n + 1);       int dp[n + 1][405];       for (int i = 0; i <= n; i++)         for (int j = 0; j < 405; j++) dp[i][j] = 1000000;       for (int j = 0; j < 405; j++) dp[0][j] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j < 405; j++) {           dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + abs(j - arr[i]));         }       }       cout << dp[n][404] << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 1e6 + 5;   using namespace std;   int n, k, a[N], cnt[N], Min = N;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       Min = min(Min, a[i]);       cnt[a[i]]++;     }     for (int i = 1; i < N; i++) cnt[i] += cnt[i - 1];     for (int i = Min; i > k; i--) {       bool ck = 0;       int j;       for (j = i; j < N; j += i) {         if (cnt[j - 1] - cnt[j - i + k]) {           ck = 1;           break;         }       }       if (j - i + k < N && cnt[N - 1] - cnt[j - i + k]) ck = 1;       if (!ck) return cout << i, 0;     }     cout << min(Min, k) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (long long i = 0; i < n; i++) cin >> a[i];     int ans = 1e9;     for (long long i = 0; i < n; i++) {       int j = max(n - i - 1, i);       int k;       if (i - j < 0)         k = min(a[n - 1], a[i]);       else         k = min(a[0], a[j]);       int cans = k / j;       ans = min(ans, cans);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); };     int n, cnt = 0;     cin >> n;     while (n) {       if (n >= 100) {         cnt += n / 100;         n %= 100;       }       if (n >= 20) {         cnt += n / 20;         n %= 20;       }       if (n >= 10) {         cnt += n / 10;         n %= 10;       }       if (n >= 5) {         cnt += n / 5;         n %= 5;       }       if (n >= 1) {         cnt += n;         n = 0;       }     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   string blank =   ;   const int N = 2e5 + 10;   vector<double> arr(N);   int n;   vector<double> can(double mid) {     vector<double> ans;     vector<double>::iterator i = arr.begin();     ans.push_back(min(arr[n - 1], *i + mid));     i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2));     if (i == arr.begin() + n) i = arr.begin() + n - 1;     ans.push_back(min(arr[n - 1], *i + mid));     i = upper_bound(arr.begin(), arr.begin() + n, *i + (mid * 2));     if (i == arr.begin() + n) i = arr.begin() + n - 1;     ans.push_back(min(arr[n - 1], *i + mid));     if (ans[2] + mid < arr[n - 1]) ans.clear();     return ans;   }   void solve() {     cin >> n;     for (long long i = (0); i < (n); i++) cin >> arr[i];     sort(arr.begin(), arr.begin() + n);     double l = 0, r = arr[n - 1] - arr[0], mid;     int rep = 100;     vector<double> ans;     while (rep--) {       mid = l + ((r - l) / 2.0);       vector<double> res = can(mid);       if (!res.empty())         r = mid, ans = res;       else         l = mid;     }     cout << fixed << setprecision(6) << l <<   n ;     for (long long i = (0); i < (3); i++)       cout << fixed << setprecision(6) << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const long long INF = 2e18;   void print(int a[], int n) {     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;   jump:     while (tc--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       string t =   ;       for (int i = 0; i < (n); i++) {         if (k == 0) {           for (int j = i; j < n; j++) t += s[j];           break;         }         int f =  z  - s[i];         int b = s[i] -  a ;         if (f > b) {           int x = s[i] + min(f, k);           t += (char)x;           k -= min(f, k);         } else {           int x = s[i] - min(b, k);           t += (char)x;           k -= min(b, k);         }       }       if (k > 0)         cout << -1;       else         cout << t;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 10e18;   map<long long, long long> mp;   int main() {     int t;     cin >> t;     long long int type, u, v, w;     while (t--) {       scanf( %lld , &type);       if (type == 1) {         scanf( %lld%lld%lld , &u, &v, &w);         while (u != v) {           if (u > v)             mp[u] += w, u /= 2;           else             mp[v] += w, v /= 2;         }       } else {         scanf( %lld%lld , &u, &v);         long long ans = 0;         while (u != v) {           if (u > v)             ans += mp[u], u /= 2;           else             ans += mp[v], v /= 2;         }         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct triplet {     int first, second, third;   } per[1005];   pair<int, int> pr[1005 / 2][1005], s[1005 / 2];   int n, a[1005], dp[1005], k, l, ind[1005 / 2][1005], indice, minim = 1 << 30,                                                                pas;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n + 2; i++) dp[i] = 1 << 30;     pas = 1;     per[1] = {1, 2, 3};     dp[1] = 0;     while (pas + 2 <= n) {       ++k;       for (int i = 1; i <= pas; i++) {         if (dp[pas + 1] > dp[i] + max(a[per[i].first], a[per[i].third])) {           dp[pas + 1] = dp[i] + max(a[per[i].first], a[per[i].third]);           pr[k][pas + 1] = {per[i].first, per[i].third};           ind[k][pas + 1] = i;         }         if (dp[pas + 2] > dp[i] + max(a[per[i].first], a[per[i].second])) {           dp[pas + 2] = dp[i] + max(a[per[i].first], a[per[i].second]);           pr[k][pas + 2] = {per[i].first, per[i].second};           ind[k][pas + 2] = i;         }         dp[i] = dp[i] + max(a[per[i].second], a[per[i].third]);         pr[k][i] = {per[i].second, per[i].third};         ind[k][i] = i;         per[i] = {i, pas + 3, pas + 4};       }       per[pas + 1] = {pas + 1, pas + 3, pas + 4};       per[pas + 2] = {pas + 2, pas + 3, pas + 4};       pas += 2;     }     l = 1;     for (int i = 1; i <= pas; i++)       if (dp[i] + max(a[per[i].first], a[per[i].second]) < minim) {         minim = dp[i] + max(a[per[i].first], a[per[i].second]);         s[l] = {per[i].first, per[i].second};         indice = i;       }     for (int i = k; i >= 1; i--) {       s[++l] = pr[i][indice];       indice = ind[i][indice];     }     cout << minim <<   n ;     for (int i = l; i > 1; i--) cout << s[i].first <<     << s[i].second <<   n ;     if (n % 2 == 0)       cout << s[1].first <<     << s[1].second;     else       cout << s[1].first;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005;   const int MD = 1000 * 1000 * 1000 + 7;   vector<int> g[maxn];   long long dp[maxn][2], mult[maxn][2], ans, cnt[maxn];   bool visited[maxn];   int binPow(int a, int b) {     if (!b) return 1;     if (b & 1) {       return (1LL * binPow(a, b - 1) * a) % MD;     } else {       int half = binPow(a, b / 2);       return (1LL * half * half) % MD;     }   }   long long inv(int a) { return binPow(a, MD - 2); }   void dfs(int v) {     cnt[v] = 1;     visited[v] = true;     mult[v][0] = mult[v][1] = 1;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (visited[to]) continue;       dfs(to);       cnt[v] += cnt[to];       mult[v][0] *= dp[to][0];       mult[v][0] %= MD;       mult[v][1] *= dp[to][1];       mult[v][1] %= MD;     }     if (cnt[v] == 1) {       dp[v][0] = dp[v][1] = 1;     } else {       dp[v][0] = (mult[v][0] + mult[v][1]) % MD;       dp[v][1] = (mult[v][0] + mult[v][1]) % MD;     }   }   void set_root(int v, int to) {     cnt[v] -= cnt[to];     cnt[to] += cnt[v];     mult[v][0] *= inv(dp[to][0]);     mult[v][0] %= MD;     mult[v][1] *= inv(dp[to][1]);     mult[v][1] %= MD;     if (cnt[v] > 1) {       dp[v][0] = (mult[v][0] + mult[v][1]) % MD;       dp[v][1] = (mult[v][0] + mult[v][1]) % MD;     } else {       dp[v][0] = dp[v][1] = 1;     }     mult[to][0] *= dp[v][0];     mult[to][0] %= MD;     mult[to][1] *= dp[v][1];     mult[to][1] %= MD;     dp[to][0] = (mult[to][0] + mult[to][1]) % MD;     dp[to][1] = (mult[to][0] + mult[to][1]) % MD;   }   void calc(int v, int parent) {     ans += dp[v][0];     if (ans >= MD) ans -= MD;     for (auto to : g[v]) {       if (to == parent) continue;       set_root(v, to);       calc(to, v);       set_root(to, v);     }   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     ans = 0;     memset(visited, false, sizeof(visited));     dfs(1);     calc(1, 0);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int m = 1e9;     for (int i = 0; i < n; i++)       if (s[i] ==  R  && s[i + 1] ==  L ) m = min(m, (a[i + 1] - a[i]) / 2);     if (m == 1e9)       cout << -1 << endl;     else       cout << m << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string f0 =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   string fi1 =  What are you doing while sending   ;   string fi2 =   ? Are you busy? Will you send   ;   string fi3 =   ? ;   string ff =        What are you doing while sending  What are you doing at the end of the          world? Are you busy? Will you save us? ? Are you busy? Will you send           What are you doing at the end of the world? Are you busy? Will you save          us? ? ;   string answer;   long long l0, li1, li2, li3;   long long q, n, k, maxn = 53;   long long len[54];   void prep() {     l0 = f0.size();     li1 = fi1.size();     li2 = fi2.size();     li3 = fi3.size();     len[0] = l0;     for (int i = 1; i <= maxn; i++) {       len[i] = 2 * len[i - 1] + li1 + li2 + li3;     }   }   char ans(long long n, long long k) {     if (n > maxn)       return k <= (n - maxn) * li1 ? fi1[(k - 1) % li1]                                    : ans(maxn, k - (n - maxn) * li1);     if (k > len[n]) return  . ;     if (n == 0) return f0[k - 1];     if (k <= li1) return fi1[k - 1];     if (k <= li1 + len[n - 1]) return ans(n - 1, k - li1);     if (k <= li1 + len[n - 1] + li2) return fi2[k - li1 - len[n - 1] - 1];     if (k <= li1 + len[n - 1] + li2 + len[n - 1])       return ans(n - 1, k - li1 - len[n - 1] - li2);     return fi3[k - li1 - len[n - 1] - li2 - len[n - 1] - 1];   }   int main() {     prep();     cin >> q;     for (int i = 1; i <= q; i++) {       cin >> n >> k;       answer += ans(n, k);     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O3 )   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a1, a2, k1, k2, n;     cin >> a1 >> a2 >> k1 >> k2 >> n;     if (k1 > k2) {       swap(a1, a2);       swap(k1, k2);     }     if (n <= a1 * (k1 - 1) + a2 * (k2 - 1)) {       cout <<  0  ;     } else {       cout << n - (a1 * (k1 - 1) + a2 * (k2 - 1)) <<    ;     }     long long int ans = n / k1;     n = n % k1;     if (ans > a1) {       n += (ans - a1) * k1;       ans = a1;     }     ans += n / k2;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, a, b, c, d;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> a >> b >> c >> d;       long long l = 0, r = (c + d - 1) / d;       while (l < r) {         long long mid = l + r + 1 >> 1;         long long sum1 = (mid + 1) * mid / 2 * d * b - (mid + 1) * a;         if (mid == (c + d - 1) / d) sum1 -= (mid * d - c) * b;         long long sum2 = (mid - 1) * mid / 2 * d * b - mid * a;         if (sum1 >= sum2)           r = mid - 1;         else           l = mid;       }       if (l == (c + d - 1) / d)         cout <<  -1 n ;       else {         long long sum = (l + 1) * l / 2 * d * b - (l + 1) * a;         cout << -sum <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   void show() {}   template <typename T, typename... V>   void show(T t, V... v) {     cerr << t;     if (sizeof...(v)) cerr <<  ,  ;     show(v...);   }   template <class X>   bool mini(X& a, const X& b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class X>   bool maxi(X& a, const X& b) {     if (a < b) {       a = b;       return true;     }     return false;   }   typedef const int& ci;   int n;   int dp[1 << 24];   void enter() {     cin >> n;     for (int i = 1, _b = (n) + 1; i < _b; ++i) {       char a, b, c;       cin >> a >> b >> c;       ++dp[(1 << a -  a ) | (1 << b -  a ) | (1 << c -  a )];     }   }   void solve() {     int MASK = (1 << 24);     for (int i = 0; i < 24; ++i)       for (int mask = 0; mask < MASK; ++mask)         if (mask >> i & 1) dp[mask] += dp[mask ^ (1 << i)];     int res = 0;     for (int mask = 0; mask < MASK; ++mask)       if (dp[mask] != n) res ^= (n - dp[mask]) * (n - dp[mask]);     cout << res;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     enter();     solve();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms ;   }