#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int fact[2 * 100005];   long long int func() {     fact[0] = fact[1] = 1;     for (long long int i = 2; i < 200001; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;     }     return 0;   }   set<pair<int, int> > m;   set<int> k;   set<pair<int, int> > h;   int arr[100005], pp[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x == 1) {         k.insert(i + 1);       } else {         h.insert(make_pair(x, i + 1));       }       arr[i + 1] = x;       pp[i + 1] = x;     }     set<int>::iterator it;     set<pair<int, int> >::iterator ii, iii;     set<pair<int, int> > ans;     int cnt = 0;     int mm = 0;     ii = h.begin();     iii = h.begin();     if (h.size() == 0) {       if (k.size() > 2) {         cout <<  NO ;         return 0;       }       cout <<  YES 1 n1 n1 2 ;       return 0;     }     for (ii = h.begin(); iii != h.end();) {       pair<int, int> p1 = *ii;       iii = ++ii;       if (iii == h.end()) break;       pair<int, int> p2 = *iii;       ans.insert(make_pair(p1.second, p2.second));       arr[p1.second]--;       arr[p2.second]--;       mm++;     }     if (k.size() && h.size()) {       pair<int, int> p = *(h.begin());       int x = *(k.begin());       ans.insert(make_pair(x, p.second));       arr[x]--;       arr[p.second]--;       k.erase(x);       mm++;     }     if (k.size() && h.size()) {       pair<int, int> p = *(--h.end());       int x = *(k.begin());       ans.insert(make_pair(x, p.second));       arr[x]--;       arr[p.second]--;       k.erase(x);       mm++;     }     for (int i = 1; i <= n; i++) {       if (arr[i] && k.find(i) == k.end()) m.insert(make_pair(arr[i], i));     }     int gg = 0;     for (it = k.begin(); it != k.end(); it++) {       if (arr[*it] == 0) continue;       m.erase(make_pair(arr[*it], *it));       if (m.size() == 0) break;       pair<int, int> p = *(m.rbegin());       ans.insert(make_pair(*it, p.second));       m.erase(make_pair(arr[p.second], p.second));       arr[p.second]--;       if (arr[p.second]) m.insert(make_pair(arr[p.second], p.second));     }     int sum = 0;     for (int i = 0; i < n; i++) {       sum += pp[i + 1];     }     if (sum < 2 * n - 2) {       cout <<  NO ;       return 0;     }     cout <<  YES   << mm << endl;     cout << ans.size() << endl;     for (set<pair<int, int> >::iterator i = ans.begin(); i != ans.end(); i++) {       cout << (*i).first <<     << (*i).second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned int gcd(unsigned int x, unsigned int y) {     unsigned int temp;     if (x < y) {       temp = x;       x = y;       y = temp;     }     for (unsigned int i = y; i > 0; i--) {       if ((x % i == 0) && (y % i == 0)) return i;     }     return x;   }   int main() {     int a, b, n;     cin >> a >> b >> n;     while (1) {       n -= gcd(n, a);       if (n < 0) {         cout <<  1 ;         break;       }       n -= gcd(n, b);       if (n < 0) {         cout <<  0 ;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i;     cin >> a >> b;     int n;     for (i = 0; i < 10; i++) {       if (a < b) {         a = a * 3;         b = b * 2;       } else if (a > b) {         cout << i;         break;       } else if (a == b) {         cout << i + 1;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1500][1500];   int visited[1500][1500];   int n, m;   struct node {     int x, y;   };   node vis[1500][1500];   int main() {     int sx, sy;     char x;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf(  n );       for (int j = 0; j < m; j++) {         scanf( %c , &x);         if (x ==  # )           a[i][j] = 0;         else if (x ==  . )           a[i][j] = 1;         else {           a[i][j] = 1;           sx = i;           sy = j;         }       }     }     bool flag = false;     visited[sx][sy] = 1;     vis[sx][sy].x = sx;     vis[sx][sy].y = sy;     queue<node> q;     node tmp;     tmp.x = sx;     tmp.y = sy;     q.push(tmp);     while (!q.empty()) {       tmp = q.front();       q.pop();       node tmp1, tmp2;       tmp1.x = tmp.x;       tmp1.y = tmp.y - 1;       tmp2 = tmp1;       tmp1.x = tmp1.x % n;       tmp1.y = tmp1.y % m;       if (tmp1.x < 0) tmp1.x += n;       if (tmp1.y < 0) tmp1.y += m;       if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) {         visited[tmp1.x][tmp1.y] = 1;         vis[tmp1.x][tmp1.y] = tmp2;         q.push(tmp2);       } else if (visited[tmp1.x][tmp1.y] == 1 &&                  (vis[tmp1.x][tmp1.y].x != tmp2.x ||                   vis[tmp1.x][tmp1.y].y != tmp2.y)) {         flag = true;       }       tmp1.x = tmp.x;       tmp1.y = tmp.y + 1;       tmp2 = tmp1;       tmp1.x = tmp1.x % n;       tmp1.y = tmp1.y % m;       if (tmp1.x < 0) tmp1.x += n;       if (tmp1.y < 0) tmp1.y += m;       if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) {         visited[tmp1.x][tmp1.y] = 1;         vis[tmp1.x][tmp1.y] = tmp2;         q.push(tmp2);       } else if (visited[tmp1.x][tmp1.y] == 1 &&                  (vis[tmp1.x][tmp1.y].x != tmp2.x ||                   vis[tmp1.x][tmp1.y].y != tmp2.y)) {         flag = true;       }       tmp1.x = tmp.x - 1;       tmp1.y = tmp.y;       tmp2 = tmp1;       tmp1.x = tmp1.x % n;       tmp1.y = tmp1.y % m;       if (tmp1.x < 0) tmp1.x += n;       if (tmp1.y < 0) tmp1.y += m;       if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) {         visited[tmp1.x][tmp1.y] = 1;         vis[tmp1.x][tmp1.y] = tmp2;         q.push(tmp2);       } else if (visited[tmp1.x][tmp1.y] == 1 &&                  (vis[tmp1.x][tmp1.y].x != tmp2.x ||                   vis[tmp1.x][tmp1.y].y != tmp2.y)) {         flag = true;       }       tmp1.x = tmp.x + 1;       tmp1.y = tmp.y;       tmp2 = tmp1;       tmp1.x = tmp1.x % n;       tmp1.y = tmp1.y % m;       if (tmp1.x < 0) tmp1.x += n;       if (tmp1.y < 0) tmp1.y += m;       if (visited[tmp1.x][tmp1.y] == 0 && a[tmp1.x][tmp1.y] == 1) {         visited[tmp1.x][tmp1.y] = 1;         vis[tmp1.x][tmp1.y] = tmp2;         q.push(tmp2);       } else if (visited[tmp1.x][tmp1.y] == 1 &&                  (vis[tmp1.x][tmp1.y].x != tmp2.x ||                   vis[tmp1.x][tmp1.y].y != tmp2.y)) {         flag = true;       }     }     if (flag)       printf( Yes n );     else       printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long int t = 0;     long long int i, x = 0;     while (1) {       t = 0;       long long int l = s.length();       if (s.length() == 1) {         break;       }       for (i = 0; i < l; i++) {         t += s[i] -  0 ;       }       x++;       s = to_string(t);     }     cout << x;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = (long long)1e9 + 7;   const double PI = 2 * acos(0.0);   const long long oo = 1e17 + 100;   const string DIGITS =  0123456789 , alph =  abcdefghijklmnopqrstuvwxyz ,                ALPH =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   const long long N = (long long)1e5 + 200;   vector<long long> g[N];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, x, y;     cin >> n >> x >> y;     vector<long long> l(n), r(n);     vector<pair<long long, pair<long long, long long> > > a(2 * n);     for (long long i = 0; i < n; i++) {       cin >> l[i] >> r[i];       a[2 * i] = {l[i], {0, i}};       a[2 * i + 1] = {r[i], {1, i}};     }     sort(a.begin(), a.end());     stack<long long> past;     long long p = 0, sum = 0;     for (long long i = 0; i < 2 * n; i++) {       if (a[i].second.first == 0) {         p++;         long long v = a[i].second.second;         if (past.empty()) {           sum = (sum + ((x + (y * (r[v] - l[v]) % M)) % M)) % M;         } else {           long long t = past.top();           past.pop();           if ((l[v] - t) * y < x)             sum = (sum + ((r[v] - t) * y % M)) % M;           else             sum = (sum + ((x + (y * (r[v] - l[v]) % M)) % M)) % M;         }       } else {         p--;         long long v = a[i].second.second;         past.push(r[v]);       }     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n, m;     cin >> n >> m;     string s[n], v[n], a[n], o[n], b[n];     bool t[n];     string buf;     for (long long i = 0; i < n; i++) {       cin >> s[i];       cin >> buf;       cin >> buf;       t[i] = isdigit(buf[0]);       if (t[i])         v[i] = buf;       else {         a[i] = buf;         cin >> o[i] >> b[i];       }     }     map<string, long long> ms;     for (long long i = 0; i < n; i++) ms[s[i]] = i;     ms[ ? ] = n;     string ans, ans2;     for (long long i = 0; i < m; i++) {       long long tmp[2] = {};       long long res[n + 1];       memset(res, 0, sizeof(res));       for (long long k = 0; k < 2; k++) {         res[n] = k;         for (long long j = 0; j < n; j++) {           if (t[j]) {             res[j] = v[j][i] -  0 ;             continue;           }           long long ba = res[ms[a[j]]], bb = res[ms[b[j]]];           if (o[j] ==  AND ) res[j] = ba & bb;           if (o[j] ==  OR ) res[j] = ba | bb;           if (o[j] ==  XOR ) res[j] = ba ^ bb;         }         for (long long j = 0; j < n; j++) tmp[k] += res[j];       }       if (tmp[0] <= tmp[1])         ans +=  0 ;       else         ans +=  1 ;       if (tmp[0] >= tmp[1])         ans2 +=  0 ;       else         ans2 +=  1 ;     }     cout << ans << endl << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     int arr[m];     for (int i = 0; i < m; i++) cin >> arr[i];     int amount = 0;     sort(arr, arr + m);     int count = 0;     for (int j = 0; j < m; j++) {       if (arr[j] < 0 && count < n) {         amount += (-arr[j]);         count++;       }     }     cout << amount;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pd(int ans) {     if (ans == 1 || ans == 2 || ans == 3 || ans == 5 || ans == 7 || ans == 11)       return -1;     int num = ans / 4 - ans % 2;     return num ? num : -1;   }   int main() {     int n, m;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) {         scanf( %d , &m);         printf( %d n , pd(m));       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int a, b;     double n = 1.000000011, g, h;     scanf( %lld %lld , &a, &b);     g = pow(n, b);     h = a * g;     printf( %.10lf , h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 9;   int book[maxn];   int main() {     int q, x;     scanf( %d%d , &q, &x);     int now = 0;     int hu = 0, ans = 0;     while (q--) {       int y;       scanf( %d , &y);       int h = y % x;       book[h]++;       if (h == now) {         ans++;         now++;         while (book[now] > hu && now < x) {           ans++;           now++;         }         if (now == x) {           now = 0;           hu++;         }         while (book[now] > hu && now < x) {           now++;           ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 999998727899999ll, MAXN = 300001;   long long c[MAXN];   vector<long long> g[MAXN];   set<long long> s[MAXN];   string t;   bool mark[MAXN];   long long base = 101;   long long diff[MAXN];   long long ans[MAXN];   long long n;   void dsu(long long a1, long long a2) {     set<long long>::iterator it = s[a2].begin();     while (it != s[a2].end()) {       s[a1].insert(*it);       it++;     }     s[a2].clear();   }   int dfs(long long v, long long h) {     long long hash = ((h * base) + (t[v - 1] -  a  + 1)) % MOD;     mark[v] = 1;     vector<int> child;     for (int i = 0; i < g[v].size(); i++) {       long long u = g[v][i];       if (!mark[u]) {         child.push_back(dfs(u, hash));       }     }     if (child.size() == 0) {       diff[v] = 1;       s[v].insert(hash);       return v;     } else {       int w = 0;       for (int i = 1; i < child.size(); i++) {         if (s[child[i]].size() > s[child[w]].size()) {           w = i;         }       }       for (int i = 0; i < child.size(); i++) {         if (i != w) {           dsu(child[w], child[i]);         }       }       s[child[w]].insert(hash);       diff[v] = s[child[w]].size();       return child[w];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> c[i];       ans[i] = i;     }     cin >> t;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[v].push_back(u);       g[u].push_back(v);     }     dfs(1, 0);     long long mx = 0;     for (int i = 1; i <= n; i++) {       mx = max(diff[i] + c[i], mx);     }     long long cnt = 0;     for (int i = 1; i <= n; i++) {       if (diff[i] + c[i] == mx) {         cnt++;       }     }     cout << mx << endl;     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   struct TMat {     long long a[16][16];   } base, start;   int n, i, c;   long long k, a, b;   void init() {     memset(base.a, 0, sizeof(base.a));     for (int i = 0; i < 16; i++) base.a[i][i] = 1;     start = base;   }   TMat cur(const int &c) {     TMat ans;     memset(ans.a, 0, sizeof(ans.a));     ans.a[0][0] = ans.a[1][0] = 1;     if (c == 0) {       ans.a[1][0] = 0;       return ans;     }     ans.a[c - 1][c] = ans.a[c][c] = 1;     for (int i = 1; i < c; i++)       ans.a[i - 1][i] = ans.a[i][i] = ans.a[i + 1][i] = 1;     return ans;   }   TMat operator*(const TMat &a, const TMat &b) {     TMat ans;     memset(ans.a, 0, sizeof(ans.a));     for (int i = 0; i < 16; i++)       for (int j = 0; j < 16; j++)         for (int k = 0; k < 16; k++) {           ans.a[i][j] += a.a[i][k] * b.a[k][j];           ans.a[i][j] %= mod;         }     return ans;   }   TMat operator^(const TMat &a, const long long &b) {     if (b == 0) return base;     TMat ans = a ^ (b / 2);     ans = ans * ans;     if (b & 1) ans = ans * a;     return ans;   }   int main() {     scanf( %d%I64d , &n, &k);     init();     for (i = 1; i <= n; i++) {       scanf( %I64d%I64d%d , &a, &b, &c);       start = start * (cur(c) ^ (min(b, k) - a));     }     printf( %I64d , start.a[0][0]);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   using i32 = int;   using i64 = long long;   using u8 = unsigned char;   using u32 = unsigned;   using u64 = unsigned long long;   using f64 = double;   using f80 = long double;   long long power(long long a, long long b, long long p) {     if (!b) return 1;     long long t = power(a, b / 2, p);     t = t * t % p;     if (b & 1) t = t * a % p;     return t;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long px, py;     long long d = exgcd(b, a % b, px, py);     x = py;     y = px - a / b * py;     return d;   }   template <class T>   inline void freshmin(T &a, const T &b) {     if (a > b) a = b;   }   template <class T>   inline void freshmax(T &a, const T &b) {     if (a < b) a = b;   }   namespace io {   const int BUFSIZE = 1 << 20;   int isize, osize;   char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10];   char *is, *it, *os = obuf, *ot = obuf + BUFSIZE;   char getchar() {     if (is == it) {       is = ibuf;       it = ibuf + fread(ibuf, 1, BUFSIZE, stdin);       if (is == it) return EOF;     }     return *is++;   }   char getalpha() {     char c = getchar();     while (!isalpha(c)) c = getchar();     return c;   }   void putchar(char c) {     *os++ = c;     if (os == ot) {       fwrite(obuf, 1, BUFSIZE, stdout);       os = obuf;     }   }   int inp() {     int x = 0, f = 0;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return f ? -x : x;   }   long long inp_ll() {     long long x = 0;     int f = 0;     char ch;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) f = 1;     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return f ? -x : x;   }   template <class T>   bool read(T &x) {     x = 0;     char ch = getchar();     if (ch == EOF) return 0;     for (; !isdigit(ch);) {       ch = getchar();       if (ch == EOF) return 0;     }     for (; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     return 1;   }   template <class T>   void write(T x) {     static char s[22];     static char *it = s + 20;     static char *end = s + 20;     if (x < 0) {       putchar( - );       x = -x;     }     do {       *--it = x % 10 +  0 ;       x /= 10;     } while (x);     for (; it < end; ++it) putchar(*it);   }   template <>   void write(const char *s) {     for (; *s; ++s) putchar(*s);   }   template <>   void write(char c) {     putchar(c);   }   template <class T, class V>   void write(T x, V y) {     write(x);     write(y);   }   template <class T>   void writeln(T x) {     write(x);     putchar(  n );   }   struct ender {     ~ender() {       if (os != obuf) fwrite(obuf, 1, os - obuf, stdout);     }   } __ender;   }  // namespace io   template <class T>   void print(const T &a) {     for (auto x : a) printf( %d  , x);     puts(  );   }   const int MAXN = 1 << 18;   const int MAXK = 17;   const int INF = 1000000010;   using namespace io;   using tiii = tuple<int, int, int>;   int n, m;   vector<pair<int, int> > v[MAXN];   vector<tiii> e;   int pre[MAXN], weight[MAXN], dis[MAXN];   void dfs(int x) {     for (auto p : v[x]) {       int y = p.first, z = p.second;       if (y == pre[x]) continue;       pre[y] = x;       weight[y] = z;       dis[y] = dis[x] + 1;       dfs(y);     }   }   int F[MAXN];   int father(int x) { return F[x] == x ? x : F[x] = father(F[x]); }   const int K = 2;   const int mods[] = {1000000007, 998244353, 1000000009};   void FWT(int a[], int n, int mod) {     int MOD = mod;     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           long long x = a[i + j], y = a[i + j + d];           a[i + j] = (x + y) % MOD;           a[i + j + d] = (x - y + MOD) % MOD;         }   }   void IFWT(int a[], int n, int mod) {     int MOD = mod;     int inv = (mod + 1) / 2;     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           long long x = a[i + j], y = a[i + j + d];           a[i + j] = (x + y) % MOD;           a[i + j + d] = (x - y + MOD) % MOD;           a[i + j] = (long long)a[i + j] * inv % MOD;           a[i + j + d] = (long long)a[i + j + d] * inv % MOD;         }   }   int a[K][MAXN];   int b[MAXN];   void solve() {     n = inp();     m = inp();     int sum = 0;     for (int i = 1; i <= n; ++i) F[i] = i;     for (int i = 1; i <= m; ++i) {       int x = inp(), y = inp(), z = inp();       sum ^= z;       int fx = father(x), fy = father(y);       if (fx == fy) {         e.push_back(tiii{x, y, z});       } else {         F[fx] = fy;         v[x].push_back({y, z});         v[y].push_back({x, z});       }     }     dfs(1);     for (int k = 0; k < K; ++k) {       a[k][sum] = 1;       FWT(a[k], 1 << 17, mods[k]);     }     for (auto p : e) {       int x, y, z;       tie(x, y, z) = p;       vector<int> w(1, z);       while (x != y) {         if (dis[x] < dis[y]) swap(x, y);         w.push_back(weight[x]);         x = pre[x];       }       for (int k = 0; k < K; ++k) {         for (int i = 0; i < 1 << 17; ++i) b[i] = 0;         for (auto x : w) b[x]++;         FWT(b, 1 << 17, mods[k]);         for (int i = 0; i < 1 << 17; ++i) a[k][i] = (u64)a[k][i] * b[i] % mods[k];       }     }     for (int k = 0; k < K; ++k) {       IFWT(a[k], 1 << 17, mods[k]);     }     for (int i = 0; i < 1 << 17; ++i)       if (a[0][i] || a[1][i]) {         printf( %d %d n , i, a[0][i]);         break;       }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int UNDEF = -1;   const long long INF = 1e18;   template <typename T>   inline bool chkmax(T &aa, T bb) {     return aa < bb ? aa = bb, true : false;   }   template <typename T>   inline bool chkmin(T &aa, T bb) {     return aa > bb ? aa = bb, true : false;   }   const int mn = 1e6 + 4;   const int MAXFACT = mn;   int fact[MAXFACT + 1], invfact[MAXFACT + 1];   int mod_pow(int a, int n) {     const int mod = MOD;     int ret = 1;     int p = a % mod;     while (n) {       if (n & 1) ret = (ret * (long long)p) % mod;       p = (p * (long long)p) % mod;       n >>= 1;     }     return ret;   }   inline int mod_inv(int a) { return mod_pow(a, MOD - 2); }   inline int add(int a, int b) {     int res = a + b;     if (res >= MOD) res -= MOD;     return res;   }   inline int mul(int a, int b) { return (a * (long long)b) % MOD; }   int fast_max(vector<int> a, int k) {     int n = a.size();     int ans = 0;     int offset = 0;     for (int i = 0; i < n; ++i)       if (ans < a[i]) {         ans = a[i];         offset = 0;       } else {         offset = offset + 1;         if (offset == k) return ans;       }     return ans;   }   bool isgood(vector<int> a, int k) {     int n = a.size();     int ans = 0;     int offset = 0;     for (int i = 0; i < n; ++i)       if (ans < a[i]) {         ans = a[i];         offset = 0;       } else {         offset = offset + 1;         if (offset == k) return false;       }     return true;   }   int bf(int n, int k) {     vector<int> v;     for (int x = 1; x <= n; x++) v.push_back(x);     int ans = 0;     do {       if (isgood(v, k)) ans++;     } while (next_permutation(v.begin(), v.end()));     return ans;   }   int g1[mn];   int g[mn];   int makeg(int lim, int k) {     for (int n = 0; n <= lim; n++) {       int gn;       if (n == 0)         gn = 1;       else {         int sum1 = (n - k - 1 >= 0) ? g1[n - k - 1] : 0;         int sum3 = 1 + (MOD - sum1);         gn = mul(fact[n], sum3);       }       g[n] = gn;       g1[n] =           add(n > 0 ? g1[n - 1] : 0, mul(gn, mod_inv(mul(n + k + 1, fact[n]))));     }     return g[lim];   }   void init() {     int got = 1;     for (int x = 0; x <= MAXFACT; x++) {       fact[x] = got;       got = mul(got, x + 1);     }     got = mod_pow(got, MOD - 2);     for (int x = MAXFACT; x >= 0; x--) {       got = mul(got, x + 1);       invfact[x] = got;     }   }   int binom(int n, int k) {     if (n < k) return 0;     if (n < 0 || k < 0) return 0;     return mul(fact[n], mul(invfact[k], invfact[n - k]));   }   int solve(int n, int k) {     makeg(n, k);     int final = 0;     for (int x = 0; x <= n - (k + 2); x++) {       int ans = mul(mul(binom(n - 1, x + k + 1), binom(x + k, x)), g[x]);       int ans2 = mul(ans, mul(fact[k], fact[n - (x + k + 1)]));       final += ans2;       if (final >= MOD) final -= MOD;     }     return final;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     init();     int n, k;     scanf( %d%d , &n, &k);     int ans = solve(n, k);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long int spf[100001];   void sieve();   set<long long int> factors(long long int x);   void getZarr(string str, long long int Z[]);   int n;   vector<int> ans;   vector<bool> vis;   vector<int> mas;   vector<int> del;   vector<int> koll;   vector<vector<int>> edges;   int nod(int a, int b) {     if (b == 0) return a;     return nod(b, a % b);   }   void dfs1(int v) {     vis[v] = 1;     for (auto u : edges[v])       if (!vis[u]) {         ans[u] = nod(ans[v], mas[u]);         dfs1(u);       }   }   void dfs2(int v, int dist) {     vis[v] = 1;     for (int i = 0; i < del.size(); i++) {       koll[i] += (mas[v] % del[i] == 0);       if (koll[i] >= dist) ans[v] = max(ans[v], del[i]);     }     for (auto u : edges[v])       if (!vis[u]) dfs2(u, dist + 1);     for (int i = 0; i < del.size(); i++) koll[i] -= (mas[v] % del[i] == 0);   }   signed main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     ans.resize(n);     vis.resize(n);     mas.resize(n);     edges.resize(n);     for (int i = 0; i < n; i++) cin >> mas[i];     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edges[a].push_back(b);       edges[b].push_back(a);     }     int p = mas[0];     mas[0] = 0;     ans[0] = 0;     dfs1(0);     mas[0] = p;     for (int i = 0; i < n; i++) vis[i] = 0;     for (int i = 1; i * i <= mas[0]; i++) {       if (mas[0] % i == 0) {         del.push_back(i);         del.push_back(mas[0] / i);         if (i * i == mas[0]) del.pop_back();       }     }     sort(del.begin(), del.end());     koll.resize(del.size());     dfs2(0, 0);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }   void sieve() {     spf[1] = 1;     for (long long int i = 2; i < 100001; i++) spf[i] = i;     for (long long int i = 4; i < 100001; i += 2) spf[i] = 2;     for (long long int i = 3; i * i < 100001; i++) {       if (spf[i] == i) {         for (long long int j = i * i; j < 100001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   void getZarr(string str, long long int Z[]) {     long long int n = str.length();     long long int L, R, k;     L = R = 0;     for (long long int i = 1; i < n; ++i) {       if (i > R) {         L = R = i;         while (R < n && str[R - L] == str[R]) R++;         Z[i] = R - L;         R--;       } else {         k = i - L;         if (Z[k] < R - i + 1)           Z[i] = Z[k];         else {           L = i;           while (R < n && str[R - L] == str[R]) R++;           Z[i] = R - L;           R--;         }       }     }   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, sum1 = 0;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] >= 0) {         sum += a[i];       } else         sum1 += a[i];     }     cout << sum - sum1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N, cnt1 = 0, cnt2 = 0;   int main(int argc, char *argv[]) {     string a, b;     cin >> N;     for (int i = 1; i <= N; i++)       cin >> a >> b, cnt1 += (b ==  soft ), cnt2 += (b ==  hard );     for (int i = 1; i <= N; i++) {       int q1 = i * i / 2, q2 = (i * i + 1) / 2;       if ((q1 >= cnt1 && q2 >= cnt2) || (q2 >= cnt1 && q1 >= cnt2)) {         printf( %d n , i);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     int hm = 0, wm = 0;     for (int i = 0; i < (int)(n); i++) {       char c;       int h, w;       cin >> c >> h >> w;       if (h < w) {         swap(h, w);       }       if (c ==  + ) {         hm = max(hm, h);         wm = max(wm, w);       } else {         if (h >= hm && w >= wm) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, k;   char str[MAXN];   vector<int> loc[2];   int main() {     scanf( %d%d%s , &n, &k, str);     for (int i = 0; i < n; i++) loc[str[i] -  0 ].push_back(i);     if (loc[0].empty() || loc[1].empty()) return 0 * printf( tokitsukaze n );     int flag = 0;     for (int l = 0, r = k - 1; r < n; l++, r++) {       vector<int> tmp[2];       for (int i = 0; i < 2; i++) {         if (loc[i].front() < l || loc[i].front() > r)           tmp[i].push_back(loc[i].front());         if (loc[i].back() < l || loc[i].back() > r)           tmp[i].push_back(loc[i].back());         auto itr = lower_bound(loc[i].begin(), loc[i].end(), l);         if (itr != loc[i].begin()) tmp[i].push_back(*--itr);         itr = upper_bound(loc[i].begin(), loc[i].end(), r);         if (itr != loc[i].end()) tmp[i].push_back(*itr);         sort(tmp[i].begin(), tmp[i].end());       }       if (tmp[0].empty() || tmp[1].empty()) return 0 * printf( tokitsukaze n );       flag |= (tmp[0].back() - tmp[0].front() >= k ||                tmp[1].back() - tmp[1].front() >= k);     }     return 0 * printf( %s n , (flag ?  once again  :  quailty ));   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d;   long long din[2][150003];   long long a[303];   long long mx[150003];   long long b[303];   long long t[303];   deque<long long> deq;   int main() {     cin >> n >> m >> d;     t[0] = 0;     for (int i = 0; i < m; i++) {       cin >> a[i + 1] >> b[i + 1] >> t[i + 1];     }     for (int i = 1; i <= m; i++) {       deq.clear();       long long T = (t[i] - t[i - 1]) * d;       for (int j = 0; j < n && j < T; j++) {         while (deq.size() && deq.back() < din[(i - 1) % 2][j]) {           deq.pop_back();         }         deq.push_back(din[(i - 1) % 2][j]);       }       for (int j = 0; j < n; j++) {         if (T + j < n) {           while (deq.size() && deq.back() < din[(i - 1) % 2][T + j]) {             deq.pop_back();           }           deq.push_back(din[(i - 1) % 2][T + j]);         }         mx[j] = deq.front();         if (j - T >= 0 && deq.front() == din[(i - 1) % 2][j - T]) deq.pop_front();       }       for (int j = 0; j < n; j++) {         din[i % 2][j] = mx[j] + (b[i] - abs(a[i] - (j + 1)));       }     }     long long res = din[m % 2][0];     for (int i = 0; i < n; i++) {       if (din[m % 2][i] > res) res = din[m % 2][i];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l, p, q;     cin >> l >> p >> q;     double ans;     ans = (double)l * p / ((p + q));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       int k = s.size();       if (s[k - 1] ==  o )         cout <<  FILIPINO  << endl;       else if (s[k - 1] ==  u )         cout <<  JAPANESE  << endl;       else         cout <<  KOREAN  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double w, h, d;   const double pi = acos(-1);   int main() {     scanf( %lf%lf%lf , &w, &h, &d);     if (d >= 90) d = 180 - d;     if (w < h) swap(w, h);     if (d == 0 || d == 180)       printf( %.10f n , w * h);     else if (d == 90)       printf( %.10f n , min(w, h) * min(w, h));     else {       d = d * pi / 180;       double mid = 2 * atan(h / w);       if (d >= mid) {         printf( %.10f n , h * h / sin(d));       } else {         double u = (w + h) / (1 + 1 / cos(d) + tan(d));         double v = (w - h) / (1 + 1 / cos(d) - tan(d));         double x = (u + v) / 2;         double y = (u - v) / 2;         printf( %.10f n , w * h - (x * x + y * y) * tan(d));       }     }     return 0;   }


/* cerberus97 - Hanit Banga */      #include <iostream>   #include <iomanip>   #include <cassert>   #include <cmath>   #include <cstdio>   #include <cstring>   #include <cstdlib>   #include <map>   #include <set>   #include <queue>   #include <stack>   #include <vector>   #include <algorithm>   #include <numeric>      using namespace std;      #define pb push_back   #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)      typedef long long ll;   typedef long double ld;   typedef pair <int, int> pii;   typedef pair <ll, ll> pll;      const int N = 1e5 + 10;      int main() {    fast_cin();    int t; cin >> t;    while (t--) {     int n; cin >> n;     vector<ll> d(n);     for (auto& i : d) {      cin >> i;     }     sort(d.begin(), d.end());     ll ans = d[n - 1];     for (int i = 0; i < n; ++i) {      ans += d[i] * (n - 1 - 2 * i);     }     cout << ans <<   n ;    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float a, b, l, s = 0;     cin >> a >> b >> l;     s = (b * a) / (b + l);     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     long long int a1, b1, c1;     a1 = a - x;     b1 = b - y;     c1 = c - z;     long long int pol = 0, otr = 0;     pol += max(a1 / 2, (long long)0) + max(b1 / 2, (long long)0) +            max(c1 / 2, (long long)0);     otr += min(a1, (long long)0) + min(b1, (long long)0) + min(c1, (long long)0);     if (pol + otr >= 0)       cout <<  Yes ;     else       cout <<  No ;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<vector<int> > G;   vector<long long> cnt;   vector<long long> dp;   int main(int argc, char const* argv[]) {     cin >> N >> M;     for (int i = 0; i < N; i++) {       G.push_back(vector<int>());       cnt.push_back(0);       dp.push_back(1);     }     for (int i = 0; i < M; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       cnt[u]++;       cnt[v]++;       if (u >= v) {         swap(u, v);       }       G[u].push_back(v);     }     long long res = 0;     for (int i = 0; i < N; i++) {       const auto& es = G[i];       res = max(res, dp[i] * cnt[i]);       for (int j : es) {         dp[j] = max(dp[j], dp[i] + 1);       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     int x, y, z;     cin >> x >> y >> z;     int a_rest = 0, a_sh = 0, b_rest = 0, b_sh = 0, c_sh = 0, c_rest = 0;     if (a > x) {       a_rest = a - x;       if (a_rest % 2 == 1) a_rest--;       a_sh = 0;     } else {       a_rest = 0;       a_sh = x - a;     }     if (b > y) {       b_rest = b - y;       if (b_rest % 2 == 1) b_rest--;       b_sh = 0;     } else {       b_rest = 0;       b_sh = y - b;     }     if (c > z) {       c_rest = c - z;       if (c_rest % 2 == 1) c_rest--;       c_sh = 0;     } else {       c_rest = 0;       c_sh = z - c;     }     int free_pair = (a_rest + b_rest + c_rest) / 2;     int need = a_sh + b_sh + c_sh;     if (free_pair >= need)       cout <<  Yes  << endl;     else       cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct SCC {     int n;     vector<int> comp, order;     vector<bool> used;     vector<vector<int> > G, RG;     SCC(int _n = 0) : n(_n), comp(_n, -1), used(_n, false), G(_n), RG(_n) {}     void add_edge(int from, int to) {       G[from].push_back(to);       RG[to].push_back(from);     }     void copy(const vector<vector<int> >& H) {       for (int i = 0; i < H.size(); i++) {         for (int j = 0; j < H[i].size(); j++) {           G[i].push_back(H[i][j]);           RG[H[i][j]].push_back(i);         }       }     }     int operator[](int u) const { return comp[u]; }     void dfs(int u) {       used[u] = true;       for (int i = 0; i < G[u].size(); i++)         if (!used[G[u][i]]) dfs(G[u][i]);       order.push_back(u);     }     void rdfs(int u, int cnt) {       comp[u] = cnt;       for (int i = 0; i < RG[u].size(); i++)         if (comp[RG[u][i]] == -1) rdfs(RG[u][i], cnt);     }     int build() {       for (int i = 0; i < n; i++)         if (!used[i]) dfs(i);       int cnt = 0;       for (int i = n - 1; i >= 0; i--)         if (comp[order[i]] == -1) rdfs(order[i], cnt++);       return cnt;     }     int build(vector<vector<int> >& H) {       int ret = build();       H.assign(ret, vector<int>());       for (int i = 0; i < n; i++) {         for (int j = 0; j < G[i].size(); j++) {           if (comp[i] != comp[G[i][j]]) H[comp[i]].push_back(comp[G[i][j]]);         }       }       return ret;     }   };   int N, M, D, K;   vector<int> G[1 << 17];   long long S[1 << 17];   SCC P;   vector<int> vs[1 << 17];   long long dist[1 << 17];   int add[1 << 17][50], cnt[1 << 17][50];   int main() {     scanf( %d%d%d , &N, &M, &D);     P = SCC(N);     for (int i = 0; i < M; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--, v--;       G[u].push_back(v);       P.add_edge(u, v);     }     for (int i = 0; i < N; i++) {       scanf(  n );       for (int j = 0; j < D; j++) {         char c;         scanf( %c , &c);         if (c ==  1 ) S[i] |= 1LL << j;       }     }     int K = P.build();     for (int i = 0; i < N; i++) vs[P[i]].push_back(i);     const long long msk = (1LL << D) - 1;     for (int k = K; k--;) {       dist[vs[k][0]] = 1;       queue<int> Q;       Q.push(vs[k][0]);       while (!Q.empty()) {         int u = Q.front();         Q.pop();         for (int v : G[u]) {           if (k == P[v]) {             long long nxt = dist[u] << 1 & msk | dist[u] >> D - 1;             if (nxt & ~dist[v]) {               dist[v] |= nxt;               Q.push(v);             }           }         }       }       for (int u : vs[k])         for (int v : G[u])           if (k != P[v]) {             vector<int> ret(D);             for (int d2 = 0; d2 < D; d2++) {               int nd = (d2 + 1) % D;               for (int d3 = 0; d3 < D; d3++)                 if (dist[v] >> d3 & 1) {                   int d4 = (nd - d3 + D) % D;                   ret[d2] = max(ret[d2], cnt[P[v]][d4] + add[P[v]][d4]);                 }             }             for (int d = 0; d < D; d++) {               for (int d2 = 0; d2 < D; d2++)                 if (dist[u] >> d2 & 1) {                   add[k][d] = max(add[k][d], ret[(d + d2) % D]);                 }             }           }       for (int d = 0; d < D; d++) {         for (int u : vs[k]) {           long long now = dist[u];           if (now & S[u]) cnt[k][d]++;           dist[u] = dist[u] << 1 & msk | dist[u] >> D - 1;         }       }     }     printf( %d n , add[P[0]][0] + cnt[P[0]][0]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     if (n == m) {       cout << n - 1 <<     << n;     } else if (n > m) {       cout << n - 1 <<     << m;     } else       cout << m - 1 <<     << n;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v, v1;     for (int i = 0; i < n; i++) {       int t, y;       cin >> t >> y;       v.push_back(t);       v1.push_back(y);     }     sort(v.begin(), v.end());     sort(v1.begin(), v1.end());     long long ans = n;     for (int i = 0; i < n; i++) {       ans += max(v[i], v1[i]);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100009;   struct query {     long long a, b, op, s;   } q[N * 9], b[N * 9];   long long n, m, a[N], ans[N], cnt, cntq, tr[N];   set<long long> Set[N];   inline void add(long long x, long long c) {     while (x <= n) {       tr[x] += c, x += (x & -x);     }   }   inline long long ask(long long x) {     long long res = 0;     while (x) {       res += tr[x], x -= (x & -x);     }     return res;   }   inline bool cmp(query x, query y) {     if (x.op != y.op)       return x.op < y.op;     else if (x.op)       return x.a < y.a;     else       return x.b < y.b;   }   void cdq(long long l, long long r) {     if (l >= r) return;     long long mid = (l + r) >> 1;     cdq(l, mid), cdq(mid + 1, r);     long long p1 = l, p2 = mid + 1, Cnt = l;     for (long long i = mid + 1; i <= r; i++)       if (q[i].op) {         while (p1 <= mid && (q[p1].b <= q[i].b)) {           if (!q[p1].op) add(q[p1].a, (q[p1].s * (q[p1].b - q[p1].a)));           p1++;         }         ans[q[i].op] += ask(n) - ask(q[i].a - 1);       }     for (long long i = l; i < p1; i++)       if (!q[i].op) add(q[i].a, -(q[i].s * (q[i].b - q[i].a)));     for (long long k = l, i = l, j = mid + 1; k <= r; k++)       b[k] = (j > r || (i <= mid && q[i].b <= q[j].b)) ? q[i++] : q[j++];     for (long long i = l; i <= r; i++) q[i] = b[i];   }   signed main() {     scanf( %lld%lld , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       Set[a[i]].insert(i);       if (Set[a[i]].size() != 1) q[++cnt] = {*(--Set[a[i]].rbegin()), i, 0, 1};     }     for (long long i = 1; i <= m; i++) {       long long op, b, c, l = 0, r = 0;       scanf( %lld%lld%lld , &op, &b, &c);       if (op == 2) {         q[++cnt] = {b, c, ++cntq, 0};       } else {         set<long long>::iterator i = Set[a[b]].find(b);         if (i != Set[a[b]].begin()) {           l = *--i;           q[++cnt] = {l, b, 0, -1};           i++;         }         if (++i != Set[a[b]].end()) {           r = *i;           q[++cnt] = {b, r, 0, -1};         }         if (l && r) q[++cnt] = {l, r, 0, 1};         Set[a[b]].erase(b);         Set[c].insert(b);         l = r = 0;         i = Set[c].find(b);         a[b] = c;         if (i != Set[c].begin()) {           l = *--i;           q[++cnt] = {l, b, 0, 1};           i++;         }         if (++i != Set[c].end()) {           r = *i;           q[++cnt] = {b, r, 0, 1};         }         if (l && r) q[++cnt] = {l, r, 0, -1};       }     }     cdq(1, cnt);     for (long long i = 1; i <= cntq; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int func(char c) {     if (c >=  a  && c <=  z ) {       return 1;     }     if (c >=  A  && c <=  Z ) {       return 2;     }     return 0;   }   void solve() {     string s;     cin >> s;     long long int lw = 0;     long long int up = 0;     long long int nm = 0;     string str = s;     long long int mp[3] = {0};     for (long long int i = 0; i < s.length(); i++) {       mp[func(s[i])]++;     }     long long int cn = 0;     for (long long int i = 0; i < 3; i++) {       if (!mp[i]) cn++;     }     if (!cn) {       cout << s << endl;       return;     }     if (cn == 1) {       for (long long int i = 0; i < s.length(); i++) {         if (mp[func(s[i])] > 1) {           long long int index = 0;           for (long long int id = 0; id < 3; id++) {             if (!mp[id]) index = id;           }           if (index == 0) {             s[i] =  0 ;             break;           } else if (index == 1) {             s[i] =  a ;             break;           } else {             s[i] =  A ;             break;           }         }       }       cout << s << endl;     } else {       long long int index;       for (long long int i = 0; i < 3; i++) {         if (mp[i]) {           index = i;           break;         }       }       if (index == 1) {         s[0] =  A ;         s[1] =  0 ;       } else if (index == 0) {         s[0] =  A ;         s[1] =  a ;       } else {         s[0] =  0 ;         s[1] =  a ;       }       cout << s << endl;     }   }   int main() {     long long int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int main() {     int n, k, l, r, sall, sk, i, res, ext, j, a, b;     while (scanf( %d %d %d %d %d %d , &n, &k, &l, &r, &sall, &sk) == 6) {       v.clear();       if (sk % k == 0) {         res = sk / k;         for (i = 0; i < k; i++) {           v.push_back(res);         }       } else {         res = sk / k;         ext = sk % k;         for (i = 0, j = 0; i < k; i++, j++) {           if (j < ext)             v.push_back(res + 1);           else             v.push_back(res);         }       }       a = sall - sk;       b = n - k;       if (b > 0) {         if (a % b == 0) {           res = a / b;           for (i = 0; i < b; i++) {             v.push_back(res);           }         } else {           res = a / b;           ext = a % b;           for (i = 0, j = 0; i < b; i++, j++) {             if (j < ext)               v.push_back(res + 1);             else               v.push_back(res);           }         }       }       for (i = 0; i < ((int)v.size()); i++) {         if (!i)           cout << v[i];         else           cout <<     << v[i];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool pr[10000005] = {false};   vector<long long> prime;   void prim() {     pr[0] = true;     pr[1] = true;     for (long long i = 2; i <= sqrt(100005); i++) {       for (long long j = i * 2; j <= sqrt(100005); j += i) {         pr[j] = true;       }     }   }   vector<long long> divisor(long long n) {     vector<long long> div;     div.push_back(n);     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         div.push_back(i);         if (n / i != i) div.push_back(n / i);       }     }     sort(div.begin(), div.end());     return div;   }   long long modInverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long find(long long n) {     long long count = 0;     while (n) {       count++;       n = n / 2;     }     return count;   }   void solve() {     long long n;     cin >> n;     long long arr[n];     for (long long i = 0; i < (long long)n; i++) cin >> arr[i];     vector<vector<long long>> ans;     if (n % 2 == 0) {       long long ans1 = 0;       for (long long i = 0; i < n; i++) {         ans1 = ans1 ^ arr[i];       }       if (ans1 != 0) {         cout <<  NO n ;         return;       } else {         cout <<  YES n ;         for (long long i = 0; i < n - 2; i += 2) {           ans.push_back({i + 1, i + 2, i + 3});         }         for (long long i = 0; i < n - 2; i += 2) {           ans.push_back({i + 1, i + 2, n});         }         ans.push_back({n - 2, n - 1, n});         cout << ans.size() <<   n ;         for (long long i = 0; i < (long long)ans.size(); i++) {           cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] <<   n ;         }         return;       }     }     cout <<  YES n ;     for (long long i = 0; i < n - 2; i += 2) {       ans.push_back({i + 1, i + 2, n});       arr[n] = arr[n] ^ arr[i + 1] ^ arr[i + 2];     }     for (long long i = 0; i < n - 2; i += 2) {       ans.push_back({i + 1, i + 2, n});     }     cout << ans.size() <<   n ;     for (long long i = 0; i < (long long)ans.size(); i++) {       cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     prim();     for (long long i = 2; i <= 100005; i++) {       if (pr[i] == false) {         prime.push_back(i);       }     }     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     string s;     cin >> s;     n = s.size();     int z = 0, o = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 )         o++;       else         z++;     }     if (min(o, z) & 1) {       cout <<  DA n ;     } else {       cout <<  NET n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     getline(cin, s1);     getline(cin, s2);     int a;     for (int i = 0; i < s2.size(); i++) {       if (s2[i] ==    ) continue;       a = 0;       for (int j = 0; j < s1.size(); j++)         if (s1[j] ==    )           continue;         else if (s1[j] == s2[i]) {           a = 1;           s1.erase(j, 1);           break;         }       if (!a) {         cout <<  NO ;         break;       }     }     if (a) cout <<  YES ;   }


#include <bits/stdc++.h>   int x[30];   template <class T>   inline void read(T &num) {     num = 0;     char c = getchar();     T sign = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) sign = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       num = (num << 1) + (num << 3) + (c ^ 48);       c = getchar();     }     num *= sign;   }   int main() {     int t, a;     read(t);     while (t--) {       read(a);       int tag = a, cnt = 0, ok = 0, ans = 0;       while (tag) {         x[++cnt] = tag & 1;         if (!x[cnt]) ok = 1;         tag >>= 1;       }       if (ok) {         for (register int i = cnt; i; --i) {           ans <<= 1;           if (!x[i]) ++ans;         }         printf( %d n , ans ^ a);       } else {         for (register int i = 2; i * i <= a; ++i)           if (a % i == 0) {             printf( %d n , a / i);             ok = 1;             break;           }         if (!ok) puts( 1 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const int N = 155;   int old[N][N * N];   int now[N][N * N];   int q[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n, k, s;     cin >> n >> k >> s;     for (int i = 0; i < n; i++) cin >> q[i];     for (int i = 0; i < N; i++)       for (int j = 0; j < N * N / 2; j++) old[i][j] = INF;     old[0][0] = 0;     for (int pos = 0; pos < n; pos++) {       for (int i = 0; i < N; i++)         for (int j = 0; j < N * N / 2; j++) now[i][j] = INF;       for (int taken = 0; taken <= k; taken++) {         for (int swaps = 0; swaps <= N * N / 2; swaps++) {           now[taken][swaps] = min(now[taken][swaps], old[taken][swaps]);           if (taken <= pos)             now[taken + 1][swaps + pos - taken] = min(                 now[taken + 1][swaps + pos - taken], old[taken][swaps] + q[pos]);         }       }       for (int i = 0; i < N; i++)         for (int j = 0; j < N * N / 2; j++) old[i][j] = now[i][j];     }     int res = INF;     for (int swaps = 0; swaps <= min(N * N / 2 - 1, s); swaps++)       res = min(res, now[k][swaps]);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<int> col;   int n, m;   void dfs(int v) {     int cnt = 0;     for (size_t i = 0; i < g[v].size(); i++)       if (col[g[v][i]] == col[v]) cnt++;     if (cnt > 1) {       col[v] ^= 1;       for (size_t i = 0; i < g[v].size(); i++)         if (col[g[v][i]] == col[v]) dfs(g[v][i]);     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin >> n >> m;     int x, y;     g.resize(n);     col.resize(n, 0);     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < n; i++) {       dfs(i);     }     for (int i = 0; i < n; i++) cout << col[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt0, cnt1, timer;   void dfs(int v, vector<int> &colour, vector<int> &comp,            vector<vector<pair<int, int>>> &g) {     if (colour[v] == 0)       cnt0++;     else       cnt1++;     comp[v] = timer;     for (auto &now : g[v])       if (colour[now.first] == -1) {         colour[now.first] = (colour[v] ^ now.second);         dfs(now.first, colour, comp, g);       }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       timer = 0;       int n;       cin >> n;       vector<int> a(n), b(n);       for (int i = 0; i < n; i++) {         cin >> a[i];         a[i]--;       }       for (int i = 0; i < n; i++) {         cin >> b[i];         b[i]--;       }       vector<int> cnt(n);       for (int i = 0; i < n; i++) cnt[a[i]]++, cnt[b[i]]++;       bool tf = true;       for (int i = 0; i < n; i++)         if (cnt[i] != 2) tf = false;       if (!tf) {         cout << -1 <<   n ;         continue;       }       vector<int> pos1(n, -1), pos2(n, -1);       for (int i = 0; i < n; i++) {         if (pos1[a[i]] == -1)           pos1[a[i]] = i;         else           pos2[a[i]] = i;       }       for (int i = 0; i < n; i++) {         if (pos1[b[i]] == -1)           pos1[b[i]] = i;         else           pos2[b[i]] = i;       }       vector<vector<pair<int, int>>> g(n);       for (int i = 0; i < n; i++) {         if (pos1[i] == pos2[i]) continue;         int ina_1 = (a[pos1[i]] != i), ina_2 = (a[pos2[i]] != i);         g[pos1[i]].push_back({pos2[i], ina_1 == ina_2});         g[pos2[i]].push_back({pos1[i], ina_1 == ina_2});       }       vector<int> colour(n, -1), comp(n, -1);       int ans = 0;       vector<bool> arr;       for (int i = 0; i < n; i++)         if (colour[i] == -1) {           cnt0 = cnt1 = 0;           colour[i] = 0;           dfs(i, colour, comp, g);           timer++;           ans += min(cnt0, cnt1);           arr.push_back((bool)(cnt0 < cnt1));         }       for (int i = 0; i < n; i++)         for (auto &now : g[i])           if (colour[i] != (colour[now.first] ^ now.second)) tf = false;       if (!tf) {         cout << -1 <<   n ;         continue;       }       cout << ans <<   n ;       for (int i = 0; i < n; i++)         if (arr[comp[i]] ^ colour[i]) cout << i + 1 <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   using VV = vector<vector<T>>;   template <class T>   inline T SMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   template <class T>   inline T SMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class Iter>   void __kumaerrc(Iter begin, Iter end) {     for (; begin != end; ++begin) {       cerr << *begin <<  , ;     }     cerr << endl;   }   void __kumaerr(istream_iterator<string> it) {     (void)it;     cerr << endl;   }   template <typename T, typename... Args>   void __kumaerr(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<  =  << a <<  ,  , __kumaerr(++it, args...);   }   template <typename S, typename T>   std::ostream& operator<<(std::ostream& _os, const std::pair<S, T>& _p) {     return _os <<  {  << _p.first <<  ,  << _p.second <<  } ;   }   const int MAX_N = 1e6 + 1;   long long A[MAX_N];   int N;   long long f(vector<long long> bs) {     int N = int((bs).size());     long long cur = 0, mn = 0, res = 0;     for (int i = 0; i < (N); ++i) {       cur += bs[i];       SMAX(res, cur - mn);       SMIN(mn, cur);     }     return res;   }   void solve() {     long long base = 0;     for (int i = 0; i < (N); ++i)       if (i % 2 == 0) base += A[i];     vector<long long> bs;     for (int i = 0; i < (N / 2); ++i) bs.push_back(A[2 * i + 1] - A[2 * i]);     long long res = base;     SMAX(res, base + f(bs));     bs.clear();     for (int i = (1); i <= ((N - 1) / 2); ++i)       bs.push_back(A[2 * i - 1] - A[2 * i]);     SMAX(res, base + f(bs));     cout << res << endl;   }   const long long Inf = 1e18;   long long dp[MAX_N][4];   void solve_dp() {     for (int i = 0; i <= (N); ++i)       for (int j = 0; j < (4); ++j) dp[i][j] = -Inf;     dp[0][0] = dp[0][2] = dp[0][3] = 0;     for (int i = 0; i < (N); ++i)       for (int j = 0; j < (4); ++j) {         if (j == 0) {           if (i % 2 == 0) {             SMAX(dp[i + 1][j], dp[i][j] + A[i]);             SMAX(dp[i + 1][1], dp[i][j] + A[i]);           } else {             SMAX(dp[i + 1][j], dp[i][j]);             SMAX(dp[i + 1][2], dp[i][j]);           }         }         if (j == 1 || j == 2) {           if (i % 2 == 0) {             SMAX(dp[i + 1][j], dp[i][j]);             if (j == 1) SMAX(dp[i + 1][3], dp[i][j]);           } else {             SMAX(dp[i + 1][j], dp[i][j] + A[i]);             if (j == 2) SMAX(dp[i + 1][3], dp[i][j] + A[i]);           }         }         if (j == 3) {           if (i % 2 == 0) {             SMAX(dp[i + 1][j], dp[i][j] + A[i]);           } else {             SMAX(dp[i + 1][j], dp[i][j]);           }         }       }     long long res = 0;     if (N % 2 == 0) dp[N][1] = -Inf;     for (int j = 0; j < (4); ++j) {       SMAX(res, dp[N][j]);     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << setprecision(12) << fixed;     int t;     cin >> t;     while (t--) {       cin >> N;       for (int i = 0; i < (N); ++i) cin >> A[i];       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   long long n, k;   vector<long long int> v[50005];   long long ans;   vector<long long int> dfs(long long node, long long par) {     vector<long long int> temp(k + 1);     temp[0] = 1;     for (auto i : v[node]) {       if (i != par) {         vector<long long int> cc = dfs(i, node);         for (long long i = 0; i <= k; i++) ans += cc[i] * temp[k - i];         for (long long i = 0; i <= k; i++) temp[i] += cc[i];       }     }     for (long long i = k; i >= 1; i--) temp[i] = temp[i - 1];     temp[0] = 0;     return temp;   }   void solve() {     cin >> n >> k;     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     ans = 0;     dfs(1, -1);     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 9;   int Pow(int x, int e) {     int ret = 1;     while (e) {       if (e & 1) ret = 1ll * ret * x % Mod;       x = 1ll * x * x % Mod;       e >>= 1;     }     return ret;   }   const int N = 1e5 + 10;   char S[N];   int main() {     int n, a, b, k;     scanf( %d%d%d%d%s , &n, &a, &b, &k, S);     int ia = Pow(a, Mod - 2);     int coe = Pow(a, n), ans = 0;     for (int i = 0; i <= k - 1; i++) {       ans = (ans + 1ll * (S[i] ==  +  ? 1 : Mod - 1) * coe) % Mod;       coe = 1ll * coe * ia % Mod * b % Mod;     }     int p = 1ll * Pow(ia, k) * Pow(b, k) % Mod;     if (p == 1)       ans = 1ll * ans * ((n + 1) / k) % Mod;     else       ans =           1ll * ans * (Pow(p, (n + 1) / k) - 1) % Mod * Pow(p - 1, Mod - 2) % Mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, su = 0;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i];       su += a[i];     }     if (su % 2) {       cout <<  NO n ;       return;     }     long long s = 0, ind = -1;     for (long long i = 0; i < n; ++i) {       if (!a[i] && s % 2 == 0) {         ind = i;         break;       }       s += a[i];     }     vector<long long> ans;     if (ind == -1) {       for (long long i = n - 2; i > 0; i -= 2) {         if (a[i - 1] && a[i]) continue;         ans.push_back(i);         a[i] = 1;         if (a[i - 1]) {           ind = i - 1;           a[i - 1] = a[i] = a[i + 1] = 0;           break;         }         a[i - 1] = 1;       }       if (ind == -1) {         cout <<  NO n ;         return;       }     }     for (long long i = ind - 1; i >= 0; --i) {       if (a[i]) {         if (a[i - 1]) {           ans.push_back(i);           a[i - 1] = a[i] = 0;         } else {           if (a[i - 2]) {             ans.push_back(i - 1);             a[i - 2] = a[i] = 0;           } else {             ans.push_back(i - 1);             ans.push_back(i);             a[i - 2] = 1;             a[i] = 0;           }         }       }     }     for (long long i = ind + 1; i < n; ++i) {       if (a[i]) {         if (a[i + 1]) {           ans.push_back(i);           a[i + 1] = a[i] = 0;         } else {           if (a[i + 2]) {             ans.push_back(i + 1);             a[i + 2] = a[i] = 0;           } else {             ans.push_back(i + 1);             ans.push_back(i);             a[i + 2] = 1;             a[i] = 0;           }         }       }     }     cout <<  YES n  << ans.size() <<   n ;     for (long long i = 0; i < ans.size(); ++i) {       cout << ans[i] <<    ;     }     cout <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   int main() {     int vladik, valera;     std::cin >> vladik >> valera;     int vladik_rounds = sqrt(vladik);     int valera_rounds = valera > vladik_rounds ? sqrt(valera - vladik_rounds) : 0;     if (valera_rounds >= vladik_rounds) {       std::cout <<  Vladik n ;     } else {       std::cout <<  Valera n ;     }     return 0;   }


#include <bits/stdc++.h>   const int NUM = 100010;   const double eps = 1e-10, pi = acos(-1.0);   using namespace std;   int n;   vector<int> g[NUM];   pair<int, int> node[NUM], edge[NUM];   int tot, cnt;   void dfs(int u, int p, int x) {     for (int i = 0; i < g[u].size(); i++)       if (g[u][i] != p) {         node[tot++] = pair<int, int>(u, g[u][i]);         if (x == -1)           x = tot - 1;         else           edge[cnt++] = pair<int, int>(x + 1, tot);         dfs(g[u][i], u, tot - 1);       }   }   int main() {     int i, j;     int u, v;     scanf( %d , &n);     for (i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, -1, -1);     printf( %d n , tot);     for (i = 0; i < tot; i++) printf( 2 %d %d n , node[i].first, node[i].second);     for (i = 0; i < cnt; i++) printf( %d %d n , edge[i].first, edge[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c0, c1, h;       cin >> n >> c0 >> c1 >> h;       string second;       cin >> second;       int cost1 = 0, z = 0, o = 0;       for (int i = 0; i < second.length(); i++) {         if (second[i] ==  0 ) {           cost1 += c0;           z++;         } else {           cost1 += c1;           o++;         }       }       int cost2 = o * h + c0 * (second.length());       int cost3 = z * h + c1 * (second.length());       cout << min(cost1, min(cost2, cost3)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j, b, p, f, h, c, sum;     cin >> t;     while (t--) {       cin >> b >> p >> f >> h >> c;       sum = 0;       b /= 2;       if (h < c) {         if (b < f) {           sum += (c * b);           b = 0;         } else if (b > f) {           sum += (c * f);           b -= f;         } else {           sum += (c * f);           b = 0;         }         if (b > 0) {           if (b < p) {             sum += (h * b);           } else if (b > p) {             sum += (h * p);           } else             sum += (h * p);         }       } else if (h > c) {         if (b < p) {           sum += (h * b);           b = 0;         } else if (b > p) {           sum += (h * p);           b -= p;         } else {           sum += (h * p);           b = 0;         }         if (b > 0) {           if (b < f) {             sum += (c * b);           } else if (b > f) {             sum += (c * f);           } else             sum += (c * f);         }       } else         sum += (c * min(b, p + f));       cout << sum << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long s, x;     cin >> s >> x;     bool flag = true;     bool valid = true;     if ((s & 1) != (x & 1)) valid = false;     long long ans = 1;     for (int i = 62; i >= 1; i--) {       long long sb = (s >> i) & 1;       long long xb = (x >> i) & 1;       long long sp = (s >> (i - 1)) & 1;       long long xp = (x >> (i - 1)) & 1;       if (sb == 0 && xb == 0) {         if (sp == 0 && xp == 1) valid = false;       }       if (sb == 0 && xb == 1) {         if (sp == 1 && xp == 1) valid = false;       }       if (sb == 1 && xb == 0) {         if (sp == 1 && xp == 1) valid = false;       }       if (sb == 1 && xb == 1) {         if (sp == 0 && xp == 1) valid = false;       }       if (xb != sb) flag = false;     }     for (int i = 0; i < 62; i++)       if ((x >> i) & 1) ans *= 2;     if (!valid)       cout <<  0 n ;     else       cout << ans - flag * 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   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...);   }   inline long long int gcd(long long int a, long long int b) {     a = abs(a), b = abs(b);     while (b) a = a % b, swap(a, b);     return a;   }   inline long long int power(long long int a, long long int p) {     long long int res = 1, x = a;     while (p) {       if (p & 1) res = (res * x);       x = (x * x), p >>= 1;     }     return res;   }   inline long long int big_mod(long long int a, long long int p,                                long long int m) {     long long int res = 1 % m, x = a % m;     while (p) {       if (p & 1) res = (res * x) % m;       x = (x * x) % m, p >>= 1;     }     return res;   }   const long long int INF = 1e15;   const int nax = 2e5 + 5;   int parent[nax];   int sz[nax];   void makeset(int u) {     parent[u] = u;     sz[u] = 1;   }   void init_DSU(int N) {     for (int i = 0; i <= N; i++) {       makeset(i);     }   }   int Find(int r) {     if (parent[r] == r) {       return r;     }     parent[r] = Find(parent[r]);     return parent[r];   }   int FindSize(int r) { return sz[Find(r)]; }   void Union(int a, int b) {     int u = Find(a);     int v = Find(b);     if (u != v) {       parent[u] = v;       sz[v] += sz[u];     }   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       init_DSU(n);       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         Union(i, x);       }       for (int i = 1; i <= n; i++) {         cout << FindSize(i) <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   int a[2005];   int n, k;   int main() {     scanf( %d , &k);     k += 2;     int len = 0;     a[len++] = -1;     int res;     while (k > 1000000) {       k++;       a[len++] = 1000000;       k -= 1000000;     }     a[len++] = k;     printf( %d n , len);     for (int i = 0; i < len; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int sz[N], col[2];   int n;   long long ans = 0, odd;   vector<int> V[N];   void dfs(int a, int fa, int zt) {     sz[a] = 1;     col[zt]++;     for (int i = (0); i < (((int)(V[a]).size())); ++i) {       int nxt = V[a][i];       if (nxt == fa) continue;       dfs(nxt, a, zt ^ 1);       sz[a] += sz[nxt];       ans += 1ll * sz[nxt] * (n - sz[nxt]);     }   }   int main() {     scanf( %d , &n);     for (int i = (1); i < (n); ++i) {       int a, b;       scanf( %d%d , &a, &b);       V[a].push_back(b);       V[b].push_back(a);     }     dfs(1, 1, 0);     odd = 1ll * col[0] * col[1];     cout << ans / 2 + (odd + 1) / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ara[100010];   int cnt[50];   int func(int x) {     if (x == 0) return 0;     if (x % 2 == 0) {       return func(x / 2);     } else {       return 1 + func(x - 1);     }   }   int main() {     std::ios_base::sync_with_stdio(false);     ;     int n;     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> ara[i];       cnt[func(ara[i])]++;     }     long long ans = 0;     for (int i = 0; i <= 40; i++) {       if (cnt[i] == 0) continue;       long long yo = cnt[i];       ans += (yo * (yo - 1LL)) / 2LL;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a >> b >> c;     long long m, mi, mid;     long long v[3];     v[0] = a;     v[1] = b;     v[2] = c;     sort(v, v + 3);     a = v[2];     b = v[0];     c = v[1];     if (a - b < c) {       cout <<  0 ;     } else {       m = a - b - c + 1;       cout << m;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void printArray(const T* a, int n, ostream& out = cerr);   template <class T>   void printArray(const vector<T>& arr, ostream& out = cerr);   const long long mod = 1e9 + 7;   const double PI = acos(-1);   int n, i, j, k, t;   int m;   int a[200002];   int b[200002];   int c[200002];   int pos[200002];   int ac[200002];   int bc[200002];   int cc[200002];   int mab[200002];   int hitung(int st, int pem, int ed) {     int total = ac[st];     total += (bc[pem] - bc[st]);     total += (cc[ed] - cc[pem]);     return total;   }   int hitung2(int st, int pem, int ed) {     int total = ac[st];     total += (bc[pem] - bc[st]);     total += (cc[ed] - cc[pem]);     return total;   }   int main() {     scanf( %d %d %d , &n, &m, &k);     int tot = n + m + k;     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       pos[a[i]] = 1;     }     for (int i = 0; i < m; ++i) {       scanf( %d , b + i);       pos[b[i]] = 2;     }     for (int i = 0; i < k; ++i) {       scanf( %d , c + i);       pos[c[i]] = 3;     }     for (int i = 1; i <= tot; ++i) {       ac[i] = ac[i - 1] + (pos[i] == 1);       bc[i] = bc[i - 1] + (pos[i] == 2);       cc[i] = cc[i - 1] + (pos[i] == 3);     }     mab[tot] = bc[tot];     for (int i = tot - 1; i >= 0; --i) {       mab[i] = max(mab[i + 1], bc[i] + cc[tot] - cc[i]);     }     int ans = 0;     for (int i = 0; i <= tot; ++i) {       ans = max(ans, ac[i] + mab[i] - bc[i]);     }     printf( %d n , tot - ans);     return 0;   }   template <class T>   void printArray(const T* a, int n, ostream& out) {     for (int i = 0; i < n; ++i) {       out << a[i] <<    ;     }     out << endl;   }   template <class T>   void printArray(const vector<T>& arr, ostream& out) {     for (const T& x : arr) {       out << x <<    ;     }     out << endl;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<long long> a;   long long sm = 0;   long long n, m;   bool doo(long long x) {     long long res = 0;     for (long long i = 0; i < x; ++i) {       res += a[i];       long long k = i + x;       long long count = 1;       while (k < n and a[k] - count > 0) {         res += max(0ll, a[k] - count);         k += x;         count++;       }     }     return res >= m;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     (a).clear(), (a).resize(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i];       sm += a[i];     }     sort((a).rbegin(), (a).rend());     if (sm < m) {       cout <<  -1 ;       exit(0);     }     long long l = 1, h = n + 1;     long long mid;     long long ans = -1;     while (l <= h) {       mid = (l + h) / 2;       if (doo(mid)) {         ans = mid;         h = mid - 1;       } else         l = mid + 1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v1[1000100];   vector<long long> v2;   map<long long, long long> m1;   map<long long, long long> m2;   map<long long, long long> m3;   map<char, long long> ms1;   map<string, long long> ms2;   stack<long long> sta;   long long big = 999999999999999999, small = -999999999999999999;   long long z, y, x, n, m, i, j, k, t, l, ans, sum1, sum2, avg, test, b[500100],       c[500100], a[500100], d[500100], co1[100100], co2[100100];   char s[1000100], s1[1000100], s2[1000100], temp;   bool pro[1000100], pro1, pro2, pro3;   int main() {     cin >> n >> k;     k > (n + 1) / 2 ? cout << 2 * (k - (n + 1) / 2) : cout << 2 * k - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int segtree[400001];   int val[100001];   int inf = (1 << 30) - 1;   void build(int l, int r, int pos) {     if (l == r) {       segtree[pos] = val[r];       return;     }     int mid = (l + r) / 2;     build(l, mid, 2 * pos + 1);     build(mid + 1, r, 2 * pos + 2);     segtree[pos] = (segtree[2 * pos + 1] & segtree[2 * pos + 2]);   }   int query(int lq, int rq, int l, int r, int pos) {     if (rq < l || lq > r) return inf;     if (lq <= l && r <= rq) return segtree[pos];     int mid = (l + r) / 2;     return query(lq, rq, l, mid, 2 * pos + 1) &            query(lq, rq, mid + 1, r, 2 * pos + 2);   }   int main() {     int n;     cin >> n;     int m;     cin >> m;     int flag[n + 1][30];     memset(flag, 0, sizeof flag);     int l[m], r[m], v[m];     for (int i = 0; i < m; i++) {       cin >> l[i] >> r[i] >> v[i];       l[i]--;       r[i]--;       for (int j = 0; j < 30; j++) {         if (v[i] & (1 << j)) {           flag[l[i]][j] += 1;           flag[r[i] + 1][j] -= 1;         }       }     }     for (int j = 0; j < 30; j++) {       for (int i = 1; i < n; i++) {         flag[i][j] += flag[i - 1][j];       }     }     for (int i = 0; i < n; i++) {       val[i] = 0;       for (int j = 0; j < 30; j++) {         if (flag[i][j]) val[i] += (1 << j);       }     }     build(0, n - 1, 0);     for (int i = 0; i < m; i++) {       if (query(l[i], r[i], 0, n - 1, 0) != v[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (int j = 0; j < n; j++) cout << val[j] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     int t;     cin >> t;     for (; t--;) {       cin >> n >> m;       if (n == 1) {         cout << 0 << endl;         continue;       }       int ansl = 0, ansr = n, ans = (ansl + ansr) / 2;       for (; ansl < ansr; ans = (ansl + ansr) / 2) {         int tmp = n;         long long C = 1, all = 0;         for (int i = 0; i <= ans; ++i) {           all += (long long)min((long long)tmp, C) * i;           tmp -= min((long long)tmp, C);           if (!tmp) break;           C *= ans - i;           C /= i + 1;         }         if (!tmp)           if (all > (long long)m * ans)             ansl = ans + 1;           else             ansr = ans;         else           ansl = ans + 1;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 102;   pair<int, int> ar[N];   bool used[N];   vector<deque<int>> vc;   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> ar[i].first >> ar[i].second;     for (int i = 1; i <= n; ++i) {       if (used[i]) continue;       deque<int> q;       q.push_back(i);       int cur = i;       while (ar[cur].first) {         used[cur] = true;         cur = ar[cur].first;         q.push_front(cur);       }       used[cur] = true;       cur = i;       while (ar[cur].second) {         used[cur] = true;         cur = ar[cur].second;         q.push_back(cur);       }       used[cur] = true;       vc.push_back(q);     }     for (int i = 1; i < vc.size(); ++i) {       while (!vc[i].empty()) {         vc[0].push_back(vc[i].front());         vc[i].pop_front();       }     }     auto cur = vc[0];     ar[cur.front()].first = ar[cur.back()].second = 0;     for (int i = 0; i < (int)cur.size() - 1; ++i) ar[cur[i]].second = cur[i + 1];     for (int i = (int)cur.size() - 1; i > 0; --i) ar[cur[i]].first = cur[i - 1];     for (int i = 1; i <= n; ++i)       cout << ar[i].first <<     << ar[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rnd(long long l, long long r) { return l + rng() % (r - l + 1); }   const long long N = 5e5 + 5;   const long long K = 5005;   long long n, a[N], k;   long long f[2][K][2];   void minimize(long long &x, long long y) { x = min(x, y); }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> k >> n;     for (long long i = 1, __c = n; i <= __c; ++i) cin >> a[i];     vector<pair<long long, long long> > w;     sort(a + 1, a + n + 1);     for (long long i = 1, __c = n - 1; i <= __c; ++i)       w.emplace_back(a[i + 1] - a[i], i);     sort(begin(w), end(w));     long long m = min((long long)w.size(), 3 * k);     w.resize(m);     for (auto &v : w) swap(v.first, v.second);     w.push_back(make_pair(-1, 0));     sort(begin(w), end(w));     memset(f, 0x3f, sizeof(f));     f[0][0][0] = 0;     long long now = 0;     for (long long i = 1, __c = m; i <= __c; ++i) {       f[now][0][0] = f[now][0][1] = 0;       for (long long j = 1, __c = k; j <= __c; ++j) {         minimize(f[now ^ 1][j][0], f[now][j][0]);         minimize(f[now ^ 1][j][0], f[now][j][1]);         minimize(f[now ^ 1][j][1], f[now ^ 1][j][0]);         minimize(f[now ^ 1][j][1], f[now][j - 1][0] + w[i].second);         if (w[i].first != w[i - 1].first + 1)           minimize(f[now ^ 1][j][1], f[now][j - 1][1] + w[i].second);       }       now ^= 1;     }     cout << f[now][k][1] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int n1, n2, m, R, B, mxn, E[10005], nxt[10005], hd[10005], to[10005],       adj[10005], cost[10005], cur[10005], dis[10005], D[10005], second, T, s, t,       tot = 0, mnc = 0;   bool vis[10005], inq[10005];   char s1[10005], s2[10005];   inline void add(int u, int v, int w, int f) {     nxt[tot] = hd[u];     hd[u] = tot;     to[tot] = v;     adj[tot] = w;     cost[tot] = f;     ++tot;     nxt[tot] = hd[v];     hd[v] = tot;     to[tot] = u;     adj[tot] = 0;     cost[tot] = -f;     ++tot;     return;   }   inline bool spfa() {     for (int i = second; i <= T; ++i) dis[i] = 0x3f3f3f3f, inq[i] = 0;     queue<int> q;     q.push(T);     dis[T] = 0;     inq[T] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       inq[u] = 0;       for (int i = hd[u]; ~i; i = nxt[i])         if (adj[i ^ 1] && dis[to[i]] > dis[u] - cost[i]) {           dis[to[i]] = dis[u] - cost[i];           if (!inq[to[i]]) q.push(to[i]), inq[to[i]] = 1;         }     }     return dis[second] < 0x3f3f3f3f;   }   inline int dfs(int u, int low) {     vis[u] = 1;     if (u == T) return low;     int sum = 0, gt;     for (int &i = cur[u]; ~i; i = nxt[i])       if (adj[i] > 0 && dis[to[i]] == dis[u] - cost[i] && !vis[to[i]]) {         gt = dfs(to[i], min(low - sum, adj[i]));         if (gt) {           adj[i] -= gt;           adj[i ^ 1] += gt;           sum += gt;           mnc += gt * cost[i];         }         if (sum == low) break;       }     return sum;   }   inline int dinic() {     int mxf = 0;     while (spfa()) {       vis[T] = 1;       while (vis[T]) {         for (int i = second; i <= T; ++i) cur[i] = hd[i], vis[i] = 0;         mxf += dfs(second, 0x3f3f3f3f);       }     }     return mxf;   }   int main() {     int u, v;     scanf( %d%d%d%d%d%s%s , &n1, &n2, &m, &R, &B, s1 + 1, s2 + 1);     memset(hd, -1, sizeof(hd));     second = 1;     s = 2;     t = 3 + n1 + n2;     T = 4 + n1 + n2;     for (int i = 1; i <= n1; ++i) {       if (s1[i] ==  R ) {         --D[s];         ++D[i + 2];         add(s, i + 2, 0x3f3f3f3f, 0);       }       if (s1[i] ==  B ) {         --D[i + 2];         ++D[t];         add(i + 2, t, 0x3f3f3f3f, 0);       }       if (s1[i] ==  U ) {         add(s, i + 2, 0x3f3f3f3f, 0), add(i + 2, t, 0x3f3f3f3f, 0);       }     }     for (int i = 1; i <= n2; ++i) {       if (s2[i] ==  R ) {         --D[i + 2 + n1];         ++D[t];         add(i + 2 + n1, t, 0x3f3f3f3f, 0);       }       if (s2[i] ==  B ) {         ++D[i + 2 + n1];         --D[s];         add(s, i + 2 + n1, 0x3f3f3f3f, 0);       }       if (s2[i] ==  U ) {         add(s, i + 2 + n1, 0x3f3f3f3f, 0), add(i + 2 + n1, t, 0x3f3f3f3f, 0);       }     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       E[i] = tot;       add(u + 2, v + 2 + n1, 1, R);       add(v + 2 + n1, u + 2, 1, B);     }     for (int i = s; i <= t; ++i) {       if (D[i] < 0) add(i, T, -D[i], 0);       if (D[i] > 0) add(second, i, D[i], 0), mxn += D[i];     }     add(t, s, 0x3f3f3f3f, 0);     if (dinic() < mxn) {       puts( -1 );       return 0;     }     printf( %d n , mnc);     for (int i = 1; i <= m; ++i) {       if (!adj[E[i]])         putchar( R );       else if (!adj[E[i] + 2])         putchar( B );       else         putchar( U );     }     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int C = 26;   void add(int &x, int y) {     x += y;     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int fix(int x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;     return x;   }   int pw(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1ll * ret * a % MOD;       b >>= 1;       a = 1ll * a * a % MOD;     }     return ret;   }   const int MAXN = 105;   int n, m, dp[MAXN][MAXN], l[MAXN][MAXN], r[MAXN][MAXN];   void solve() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       for (int rep = 0; rep < k; rep++) {         int a, b;         cin >> a >> b;         --a;         for (int j = a; j < b; j++) {           r[i][j] = b;           l[i][j] = a;         }       }     }     for (int b = m - 1; ~b; --b) {       for (int e = b + 1; e <= m; e++) {         for (int k = b; k < e; k++) {           int val = 0;           for (int i = 0; i < n; i++)             if (b <= l[i][k] && r[i][k] <= e) ++val;           dp[b][e] = max(dp[b][e], val * val + dp[b][k] + dp[k + 1][e]);         }       }     }     cout << dp[0][m] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int te = 1;     for (int w = 1; w <= te; w++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, o, p, x, y, z;   vector<long long> a, b, c, d;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       int leftFirst = -1;       int rightFirst = -1;       for (long long i = 0; i < n; i++)         if (s[i] ==  1 ) {           leftFirst = i;           break;         }       for (long long i = 0; i < n; i++)         if (s[i] ==  1 ) {           rightFirst = i;         }       if (leftFirst == -1) {         cout << n << endl;         continue;       }       if (rightFirst >= n - leftFirst) {         cout << 2 * (rightFirst + 1) << endl;       } else         cout << 2 * (n - leftFirst) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, m, jm;   long long ans;   int main() {     cin >> n >> m >> jm;     ans = ceil(1.0 * n / jm) * ceil(1.0 * m / jm) * ((n - 1) % jm + 1) *           ((m - 1) % jm + 1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 2e5 + 10, M = 1e6 + 10;   long long f(long long x) {     long long y = x + 1;     if (x & 2)       y /= 2;     else       x /= 2;     return x * y;   }   void solve() {     long long n;     scanf( %lld , &n);     long long x = 3, cnt = 1;     n--;     while (1) {       long long t = f(x);       if (t > n) break;       cnt++;       n -= t;       x = (x << 1) + 1;     }     printf( %lld n , cnt);   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s[n];     set<string> store;     for (int i = 0; i < n; i++) {       cin >> s[i];       store.insert(s[i]);     }     int cnt = 0;     for (int i = 0; i < n; i++) {       set<string> v;       store.erase(s[i]);       for (int j = i + 1; j < n; j++) {         v.insert(s[j]);         store.erase(s[j]);         string temp;         for (int l = 0; l < k; l++) {           if (s[i][l] == s[j][l]) {             temp += s[i][l];           } else {             temp += ( S  +  E  +  T  - s[i][l] - s[j][l]);           }         }         if (store.find(temp) != store.end()) {           cnt++;           v.insert(temp);           store.erase(temp);         }       }       for (auto it : v) {         store.insert(it);       }     }     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool debug;   const int inf = 1e9 + 5;   const long long INF = (long long)inf * inf;   const int nax = 1e6 + 5;   const int D = 2;   const long long MM = 1000 * 1000 * 1000;   const long long m[5] = {MM + 7, MM + 9, MM + 21, MM + 33, 333333361LL};   char sl[nax];   long long preh[nax][D];   int n;   long long potega[nax][D];   long long h(pair<int, int> a, int j) {     long long x = preh[a.second][j];     if (a.first) x -= preh[a.first - 1][j];     if (x < 0) x += m[j];     x = (x * potega[n - a.first][j]) % m[j];     return x;   }   bool rowne(pair<int, int> a, pair<int, int> b) {     for (int j = 0; j <= (D)-1; ++j)       if (h(a, j) != h(b, j)) return false;     return true;   }   int porow(pair<int, int> a, pair<int, int> b) {     assert(a.second - a.first == b.second - b.first);     if (a.first > a.second) return true;     if (rowne(a, b)) return 1;     int low = 0, high = a.second - a.first;     while (low != high) {       int med = (low + high) / 2;       if (rowne(make_pair(a.first, a.first + med),                 make_pair(b.first, b.first + med)))         low = med + 1;       else         high = med;     }     if (sl[a.first + low] ==  ( ) return 0;     return 2;   }   int pref[nax];   int LICZ;   const int pot = 1024 * 1024;   int tr[2 * pot];   int mi(int a, int b) {     a += pot;     b += pot;     int ku = min(tr[a], tr[b]);     while (a < b - 1) {       ku = min(ku, tr[a + 1]);       ku = min(ku, tr[b - 1]);       a /= 2;       b /= 2;     }     return ku;   }   bool ok_podzial_szybkie(int i) {     int s1 = pref[i];     int s2 = LICZ - pref[i];     int k = 0;     if (LICZ < 0) k = -LICZ;     if (i + 1 <= n - 1 && k + mi(i + 1, n - 1) - s1 < 0) return false;     if (0 <= i && k + s2 + mi(0, i) < 0) return false;     return true;   }   bool ok_podzial(int i) {     int teraz = 0;     if (LICZ < 0) teraz = -LICZ;     for (int j = i + 1; j <= n - 1; ++j) {       if (sl[j] ==  ( )         ++teraz;       else         --teraz;       if (teraz < 0) return false;     }     for (int j = 0; j <= i; ++j) {       if (sl[j] ==  ( )         ++teraz;       else         --teraz;       if (teraz < 0) return false;     }     return true;   }   int best = -1;   bool jebaj(int i) {     if (best == -1) return true;     int kon = best + 1 + (n - 1 - (i + 1));     int pom = porow(make_pair(best + 1, kon), make_pair(i + 1, n - 1));     if (pom == 0) return false;     if (pom == 2) return true;     int kon2 = n - 1 - (kon + 1);     pom = porow(make_pair(kon + 1, n - 1), make_pair(0, kon2));     if (pom == 0) return false;     if (pom == 2) return true;     pom = porow(make_pair(0, best), make_pair(kon2 + 1, i));     if (pom == 0) return false;     return true;   }   int main(int argc, char *argv[]) {     debug = argc > 1;     scanf( %s , sl);     n = strlen(sl);     for (int i = 0; i <= (n)-1; ++i) {       if (i) pref[i] = pref[i - 1];       if (sl[i] ==  ( )         pref[i]++;       else         pref[i]--;     }     for (int i = 0; i <= (2 * pot) - 1; ++i) tr[i] = inf;     for (int i = 0; i <= (n)-1; ++i) tr[pot + i] = pref[i];     for (int i = pot - 1; i >= 1; --i) tr[i] = min(tr[2 * i], tr[2 * i + 1]);     LICZ = 0;     for (int i = 0; i <= (n)-1; ++i) {       if (sl[i] ==  ( )         ++LICZ;       else         --LICZ;     }     for (int j = 0; j <= (D)-1; ++j) {       potega[0][j] = 1;       for (int i = 1; i <= n; ++i)         potega[i][j] = ((j == 2 ? 3 : 2) * potega[i - 1][j]) % m[j];     }     for (int j = 0; j <= (D)-1; ++j)       for (int i = 0; i <= (n)-1; ++i) {         int teraz = int(sl[i] ==  ( );         preh[i][j] = ((i ? preh[i - 1][j] : 0LL) + teraz * potega[i][j]) % m[j];       }     for (int i = 0; i <= (n)-1; ++i)       if (ok_podzial_szybkie(i))         if (jebaj(i)) best = i;     assert(best != -1);     if (LICZ < 0)       for (int _ = 0; _ <= (-LICZ) - 1; ++_) printf( ( );     for (int j = best + 1; j <= n - 1; ++j) printf( %c , sl[j]);     for (int j = 0; j <= best; ++j) printf( %c , sl[j]);     if (LICZ > 0)       for (int _ = 0; _ <= (LICZ)-1; ++_) printf( ) );     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     long long loc;     long long num;   } amar;   bool operator<(amar x, amar y) {     if (x.num >= y.num)       return false;     else       return true;   }   int main() {     long long n, k, c[40];     char s[100005];     memset(c, 0, sizeof c);     cin >> n >> k >> s;     for (long long i = 0; i < n; i++) {       c[s[i] -  A ]++;     }     priority_queue<amar> a;     amar tmp;     for (long long i = 0; i < 40; i++) {       tmp.loc = i;       tmp.num = c[i];       a.push(tmp);     }     long long ans = 0;     while (k > 0 && !a.empty()) {       tmp = a.top();       if (k >= tmp.num) {         ans += (tmp.num * tmp.num);         k -= tmp.num;       } else if (k < tmp.num) {         ans += k * k;         k = 0;       }       a.pop();     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, inv = 5e8 + 4;   long long n, m, k;   long long pow(long long base, long long exp) {     long long res = 1;     while (exp) {       if (exp & 1) (res *= base) %= mod;       exp >>= 1;       (base *= base) %= mod;     }     return res;   }   int main() {     cin >> n >> m >> k;     --n;     --m;     if (k == -1 && n + m & 1)       cout << 0;     else       cout << pow(pow(2, n), m);   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> flag_pr(10001000, 0), flag_pal(10001000, 0);   vector<long long> prime_upto(10001000, 0), palin_upto(10001000, 0);   int gcd(int a, int b) {     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   bool isPalin(int num) {     int ret = 0, n = num;     while (n > 0) {       int val = (n / 10) * 10;       int dig = n - val;       ret = ret * 10 + dig;       n /= 10;     }     if (ret == num)       return true;     else       return false;   }   void init() {     flag_pr[2] = 1;     for (int i = 3; i * i < 10001000; i += 2)       if (!flag_pr[i])         for (int j = 2 * i; j < 10001000; j += i) flag_pr[j] = 1;     prime_upto[2] = 1;     for (int i = 3; i < 10001000; i++) {       if (i & 1) {         prime_upto[i] = prime_upto[i - 1] + (flag_pr[i] == 0 ? 1 : 0);       } else {         prime_upto[i] = prime_upto[i - 1];       }     }     for (int i = 1; i < 10001000; i++) {       if (i == 1)         palin_upto[i] = 1;       else {         palin_upto[i] = palin_upto[i - 1] + isPalin(i);       }     }     return;   }   void solve() {     int p, q;     cin >> p >> q;     int g = gcd(p, q);     p /= g;     q /= g;     int ret = -1;     for (int i = 1; i < 10001000; i++) {       if (q * prime_upto[i] <= p * palin_upto[i]) {         ret = max(ret, i);       }     }     cout << ret <<   n ;     return;   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     int count = 0;     for (int i = 0; (1LL << i) / 2 <= b; i++) {       for (int j = 0; j < i - 1; j++) {         long long n = (1LL << i) - 1 - (1LL << j);         if (a <= n && n <= b) count++;       }     }     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int func(vector<vector<long long int>> &d, vector<int> &v, int i,                      int k) {     if (d[k][i - 1] != 0) return d[k][i - 1];     if (k && (i + v[i - 1] <= d[0].size())) {       d[k][i - 1] = -1;       long long int y = func(d, v, i + v[i - 1], 1 - k);       if (y != -1) y += v[i - 1];       return d[k][i - 1] = y;     } else if (k)       return d[k][i - 1] = v[i - 1];     else if (i - v[i - 1] > 0) {       d[k][i - 1] = -1;       long long int y = func(d, v, i - v[i - 1], 1 - k);       if (y != -1) y += v[i - 1];       return d[k][i - 1] = y;     } else       return d[k][i - 1] = v[i - 1];   }   int main() {     long long int n, x, y, k = 1;     cin >> n;     vector<int> v;     v.push_back(0);     for (int i = 0; i < n - 1; i++) {       cin >> x;       v.push_back(x);     }     vector<vector<long long int>> d(2, vector<long long int>(n, 0));     for (int i = 1; i < n; i++) {       y = 0;       v[0] = i;       d[1][0] = d[0][0] = -1;       y = func(d, v, v[0] + 1, 0);       if (y != -1) y += i;       cout << y << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 998244353) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 998244353) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   struct Point {     int x, y;     Point() {}     Point(int x, int y) : x(x), y(y) {}     long double abs() const { return hypot(x, y); }     long double arg() const { return atan2(y, x); }     Point operator*(double o) const { return Point(x * o, y * o); }     Point operator+(const Point& o) const { return Point(x + o.x, y + o.y); }     Point operator-(const Point& o) const { return Point(x - o.x, y - o.y); }     Point operator/(double o) const { return Point(x / o, y / o); }     bool operator<(const Point& o) const {       return x < o.x - 1e-9 || (x < o.x + 1e-9 && y < o.y - 1e-9);     }     friend bool operator==(const Point& r1, const Point& r2) {       return r1.x == r2.x && r1.y == r2.y;     }     int cross(Point b) const { return x * b.y - b.x * y; }     void readin() { scanf( %d%d , &x, &y); }     void pp() { printf( %d %d n , x, y); }   } a[6135], b[6135];   int r[6135];   void cal(vector<int> A, vector<int> B) {     if (A.size() == 1) {       if (!debug)         for (int z : B) printf( %d %d n , z, A[0]);       return;     }     if (B.size() == 1) {       if (!debug)         for (int z : A) printf( %d %d n , B[0], z);       return;     }     assert(A.size() > 1 && B.size() > 1);     int mxR = 0, tar = -1;     for (int z : B)       if (mxR < r[z]) {         tar = z;         mxR = r[z];       }     vector<pair<long double, int>> vp;     for (int z : A) {       vp.push_back({(a[z] - b[tar]).arg(), z + m});     }     for (int z : B)       if (z != tar) {         vp.push_back({(b[z] - b[tar]).arg(), z});       }     sort(vp.begin(), vp.end());     int N = vp.size(), S = 0;     for (int i = 0, j = -1; i < N; i++) {       j = max(i, j);       if (i == j) {         S += 1 - r[vp[i].second];         j++;       }       Point cur = vp[i].second <= m ? b[vp[i].second] : a[vp[i].second - m];       cur = cur - b[tar];       while (1) {         int id = vp[j % N].second;         Point tt = id <= m ? b[id] : a[id - m];         tt = tt - b[tar];         if (tt.cross(cur) < 0) {           S += 1 - r[id];           j++;         } else           break;       }       if (S >= 1 && S <= mxR - 1) {         r[tar] = S;         vector<int> ta, tb;         tb.push_back(tar);         for (int z = i; z < j; z++) {           int id = vp[z % N].second;           if (id <= m)             tb.push_back(id);           else             ta.push_back(id - m);         }         cal(ta, tb);         r[tar] = mxR - S;         ta.clear();         tb.clear();         tb.push_back(tar);         for (int z = j;; z++) {           if (z % N == i) break;           int id = vp[z % N].second;           if (id <= m)             tb.push_back(id);           else             ta.push_back(id - m);         }         cal(ta, tb);         break;       }       S -= 1 - r[vp[i].second];     }   }   void fmain(int tid) {     scanf( %d%d , &n, &m);     for (int(i) = 1; (i) <= (int)(m); (i)++) {       scanf( %d , r + i);     }     for (int(i) = 1; (i) <= (int)(n); (i)++) r[m + i] = 0;     for (int(i) = 1; (i) <= (int)(n); (i)++) a[i].readin();     for (int(j) = 1; (j) <= (int)(m); (j)++) b[j].readin();     vector<int> A, B;     for (int(i) = 1; (i) <= (int)(n); (i)++) A.push_back(i);     for (int(j) = 1; (j) <= (int)(m); (j)++) B.push_back(j);     if (!debug) puts( YES );     cal(A, B);   }   int main() {     int t = 1;     scanf( %d , &t);     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }