#include <bits/stdc++.h>   static const int N = 1 << 17;   struct Fenwick {     int n;     int t[N * 4];     void set(int n) { this->n = n; }     void add(int x, int v) {       for (int i = x; i <= n; i += (i & -i)) t[i] += v;     }     void clear(int x) {       for (int i = x; i <= n; i += (i & -i)) t[i] = 0;     }     int query(int x) {       int ans = 0;       for (int i = x; i > 0; i -= (i & -i)) ans += t[i];       return ans;     }     int query(int l, int r) { return query(r) - query(l - 1); }   } fenwick;   int readInt() {     int x = 0, f = 1;     int c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return x * f;   }   struct node {     long long x, R, l, r, q;     bool operator<(node const& o) const { return R < o.R; }   } s[N];   bool cmp(const node& a, const node& b) { return a.q < b.q; }   long long ans;   int n, k, cc;   long long d[N * 4];   void merge(int l, int r) {     if (l == r) return;     int m = (l + r) >> 1;     merge(l, m);     merge(m + 1, r);     int st = m + 1, e = m;     for (int i = l; i <= m; ++i) {       while (e < r && s[e + 1].q <= s[i].q + k) {         ++e;         fenwick.add(s[e].x, +1);       }       while (st <= e && s[st].q < s[i].q - k) {         fenwick.add(s[st].x, -1);         ++st;       }       ans += fenwick.query(s[i].l, s[i].r);     }     for (int i = m + 1; i <= r; ++i) fenwick.clear(s[i].x);     std::inplace_merge(s + l, s + m + 1, s + r + 1, cmp);   }   int solve() {     n = readInt();     k = readInt();     cc = 0;     for (int i = 1; i <= n; ++i) {       s[i].x = readInt();       s[i].R = readInt();       s[i].q = readInt();       d[cc++] = s[i].x;       d[cc++] = s[i].x - s[i].R;       d[cc++] = s[i].x + s[i].R;     }     std::sort(d, d + cc);     cc = std::unique(d, d + cc) - d;     for (int i = 1; i <= n; ++i) {       s[i].l = std::lower_bound(d, d + cc, s[i].x - s[i].R) - d;       s[i].r = std::lower_bound(d, d + cc, s[i].x + s[i].R) - d;       s[i].x = std::lower_bound(d, d + cc, s[i].x) - d;       ++s[i].l;       ++s[i].r;       ++s[i].x;     }     std::sort(s + 1, s + n + 1);     fenwick.set(cc);     ans = 0;     merge(1, n);     printf( %lld n , ans);     return 0;   }   int main(int argc, char* argv[]) { solve(); }


#include <bits/stdc++.h>   using namespace std;   long long n, q;   long long a[755], mx[755];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 0; i <= n; i++) {       long long l = 0, r = 1000000000000000, ans = 0;       while (l <= r) {         long long m = (l + r + 1) / 2;         long long sum = m, cnt = 0;         priority_queue<long long, vector<long long>, greater<long long>> pq;         for (long long j = 1; j <= n; j++) {           sum += a[j];           pq.push(a[j]);           while (sum < 0 && (long long)pq.size()) {             sum -= pq.top();             pq.pop();             cnt++;           }         }         if (cnt <= i) {           ans = m;           r = m - 1;         } else           l = m + 1;       }       mx[i] = ans;     }     while (q--) {       long long r;       cin >> r;       for (long long i = 0; i <= n; i++)         if (r >= mx[i]) {           cout << i <<   n ;           break;         }     }   }


#include <bits/stdc++.h>   using namespace std;   int root[1000005], weight[1000005];   vector<int> vec[26];   int findroot(int x) {     while (x != root[x]) {       root[x] = root[root[x]];       x = root[x];     }     return x;   }   void merge(int x, int y) {     x = findroot(x);     y = findroot(y);     if (x == y) return;     if (weight[x] > weight[y])       weight[x] += weight[y], root[y] = x;     else       weight[y] += weight[x], root[x] = y;   }   int main() {     int n, i, j, ans = 0;     cin >> n;     string s;     for (i = 0; i < n; i++) {       root[i] = i;       weight[i] = 1;     }     for (i = 0; i < n; i++) {       cin >> s;       for (char c : s) vec[c -  a ].push_back(i);     }     for (i = 0; i < 26; i++) {       for (j = 1; j < vec[i].size(); j++) merge(vec[i][j - 1], vec[i][j]);     }     for (i = 0; i < n; i++)       if (root[i] == i) ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   bool done[333333];   int main(int argc, char *argv[]) {     int N;     scanf( %d , &N);     int pt = N;     printf( 1 );     for (int i = 0; i < (N); i++) {       int a;       scanf( %d , &a);       done[a] = true;       while (done[pt]) pt--;       printf(  %d , (i + 2) - (N - pt));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int fast_expo(long long int x, long long int p) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long int t = fast_expo(x, p / 2) % 998244353;       return (t * t) % 998244353;     } else       return (x * (fast_expo(x, p - 1)) % 998244353) % 998244353;   }   int main() {     string s;     cin >> s;     int n = s.size();     int flag = 0;     for (int i = 0; i < n; i++) {       int r = i + 25;       if (r < n) {         set<char> st;         int q = 0;         for (int j = i; j <= r; j++) {           if (s[j] ==  ? )             q++;           else             st.insert(s[j]);         }         int sz = 26 - st.size();         if (q == sz) {           set<char> st2;           for (int j = 0; j < 26; j++) {             char ch = j +  A ;             if (st.find(ch) == st.end()) st2.insert(ch);           }           auto it = st2.begin();           for (int j = i; j <= r; j++) {             if (s[j] ==  ? ) {               char ch = *it;               s[j] = ch;               it++;             }           }           flag = 1;         }       }       if (flag) break;     }     char ch =  A ;     for (int i = 0; i < n; i++) {       if (s[i] ==  ? ) s[i] = ch;     }     if (flag)       cout << s << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   void solve() {     vector<pair<int, int> > points;     vector<int> xval, yval;     for (int i = 0; i < 3; i++) {       int x, y;       cin >> x >> y;       points.push_back({x, y});       xval.push_back(x);       yval.push_back(y);     }     sort(xval.begin(), xval.end());     sort(yval.begin(), yval.end());     pair<int, int> med = {xval[1], yval[1]};     set<pair<int, int> > ans;     for (int i = 0; i < 3; i++) {       int x = points[i].first;       int y = points[i].second;       ans.insert({x, y});       if (x >= med.first) {         while (x != med.first) {           ans.insert({--x, y});         }       } else {         while (x != med.first) {           ans.insert({++x, y});         }       }       if (y >= med.second) {         while (y != med.second) {           ans.insert({x, --y});         }       } else {         while (y != med.second) {           ans.insert({x, ++y});         }       }     }     cout << ans.size() << endl;     for (auto c : ans) {       cout << c.first <<     << c.second << endl;     }   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int A[n];     for (int i = 0; i < n; i++) {       cin >> A[i];     }     sort(A, A + n);     long long ans = 0;     for (int i = 0; i < n / 2; i++) {       ans += (A[i] + A[n - i - 1]) * (A[i] + A[n - 1 - i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, root;   vector<int> adj[N];   bool ok;   int dfs(int v, int p = -1) {     int ret = 0;     int cnt = 2;     if (v == root) cnt++;     for (int u : adj[v]) {       if (u == p) continue;       int res = dfs(u, v);       if (res) ret = 2;       if (res == 2) cnt--;     }     if (cnt <= 0) {       ok = false;     }     if (adj[v].size() == 3) ret = max(1, ret);     if (adj[v].size() > 3) ret = 2;     return ret;   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     ok = true;     root = 0;     for (int i = 0; i < n; i++)       if (adj[root].size() < adj[i].size()) root = i;     dfs(root);     if (!ok && adj[root].size() == 3) {       ok = true;       for (int u : adj[root]) {         if (adj[u].size() == 3) {           root = u;           break;         }       }       dfs(root);     }     if (ok)       puts( Yes );     else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const int mod = 1e9 + 7;   const int P = 257;   int H[MAXN];   char s[MAXN];   char t[MAXN];   int iP[MAXN];   int add(int a, int b) { return (a + b) % mod; }   int mul(long long a, long long b) { return (a * b) % mod; }   int range(int l, int r) {     if (l == 0) return H[r];     return mul(add(H[r], mod - H[l - 1]), iP[l]);   }   int n, m;   bool check(int x, int y) {     int pos = 0;     int hx = -1, hy = -1;     for (int i = 0; i < n; ++i) {       if (s[i] ==  1 ) {         if (hx == -1)           hx = range(pos, pos + x - 1);         else if (hx != range(pos, pos + x - 1))           return 0;         pos += x;       } else {         if (hy == -1)           hy = range(pos, pos + y - 1);         else if (hy != range(pos, pos + y - 1))           return 0;         pos += y;       }     }     if (x == y) return hx != hy;     return 1;   }   int ex(int a, int b) {     int r = 1;     while (b > 0) {       if (b & 1) r = mul(r, a);       a = mul(a, a);       b >>= 1;     }     return r;   }   int main() {     scanf( %s , s);     scanf( %s , t);     n = strlen(s);     m = strlen(t);     int c1 = 0, c0 = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  0 )         c0 += 1;       else         c1 += 1;     }     int h = 0;     int ip = ex(P, mod - 2);     int p = 1;     for (int i = 0; i < m; ++i) {       h = add(h, mul(t[i], p));       p = mul(p, P);       H[i] = h;     }     iP[0] = 1;     for (int i = 1; i < m; ++i) {       iP[i] = mul(iP[i - 1], ip);     }     int ans = 0;     for (int x = 1; x * c1 < m; ++x) {       if ((m - c1 * x) % c0 == 0) {         int y = (m - c1 * x) / c0;         ans += check(x, y);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, ta, b, tb, x, y, sum, A, AA, B, BB;   char ch;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> a >> ta >> b >> tb >> x >> ch >> y;     A = 60 * x + y;     AA = A + ta;     for (int i = 5 * 60; i <= 1439; i += b) {       B = i;       BB = B + tb;       int maxx = max(A, B);       int mini = min(AA, BB);       if (maxx < mini) sum++;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i;   vector<string> pos;   string s;   set<vector<string> > st;   set<vector<string> >::iterator iter;   bool srch(vector<string> pos) {     if (pos.size() == 1) return true;     iter = st.find(pos);     if (iter != st.end()) return false;     int x = pos.size() - 1;     if (pos.size() >= 4) {       if (pos[x][0] == pos[x - 3][0] || pos[x][1] == pos[x - 3][1]) {         vector<string> nv = pos;         nv[x - 3] = nv[x];         nv.pop_back();         if (srch(nv)) return true;         st.insert(nv);       }     }     if (pos[x][0] == pos[x - 1][0] || pos[x][1] == pos[x - 1][1]) {       vector<string> nv = pos;       nv[x - 1] = nv[x];       nv.pop_back();       if (srch(nv)) return true;       st.insert(nv);     }     return false;   }   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> s;       pos.push_back(s);     }     if (srch(pos))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct block {     int x, y;     inline bool operator<(const block &cpr) const {       if (x != cpr.x) return x < cpr.x;       return y < cpr.y;     }     inline bool operator==(const block &cpr) const {       return ((x == cpr.x) && (y == cpr.y));     }   };   struct nblock {     int x, y, id;     inline bool operator<(const nblock &cpr) const {       if (y != cpr.y) return y < cpr.y;       return x < cpr.x;     }   };   block bl[100005];   nblock nbl[100005];   int vis[100005];   int n, m;   queue<int> pq;   int mov[8][2]{       1, 1, 1, 0, 1, -1, 0, -1, 0, 1, -1, 1, -1, 0, -1, -1,   };   int main() {     scanf( %d , &n);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &bl[i].x, &bl[i].y);     sort(bl + 1, bl + 1 + m);     for (int i = 1; i <= m; i++) {       nbl[i].x = bl[i].x;       nbl[i].y = bl[i].y;       nbl[i].id = i;     }     sort(nbl + 1, nbl + 1 + m);     for (int i = 1; i <= m; i++)       if (bl[i].x == n || bl[i].y == 1) {         vis[i] = 1;         pq.push(i);       }     while (pq.size()) {       block cur;       int cid;       cid = pq.front();       cur = bl[cid];       pq.pop();       if (cur.x > 1) {         block nw;         nw = cur;         nw.x--;         int top, bot, tr;         top = m;         bot = 1;         while (top > bot) {           tr = (top + bot + 1) / 2;           if (bl[tr] < nw)             bot = tr;           else             top = tr - 1;         }         if (bl[top].x == nw.x)           if (bl[top].y < nw.y)             if (vis[top] == 0) {               vis[top] = 1;               pq.push(top);             }       }       if (cur.y < n) {         nblock nw;         nw.x = cur.x;         nw.y = cur.y + 1;         int top, bot, tr;         top = m;         bot = 1;         while (top > bot) {           tr = (top + bot) / 2;           if (nw < nbl[tr])             top = tr;           else             bot = tr + 1;         }         if (nbl[top].y == nw.y)           if (nbl[top].x > nw.x)             if (vis[nbl[top].id] == 0) {               vis[nbl[top].id] = 1;               pq.push(nbl[top].id);             }       }       for (int dr = 0; dr < 8; dr++) {         block nw;         nw = cur;         nw.x += mov[dr][0];         nw.y += mov[dr][1];         int top, bot, tr;         top = m;         bot = 1;         while (top > bot) {           tr = (top + bot + 1) / 2;           if (nw < bl[tr])             top = tr - 1;           else             bot = tr;         }         if (nw == bl[top])           if (vis[top] == 0) {             vis[top] = 1;             pq.push(top);           }       }     }     for (int i = 1; i <= m; i++)       if (vis[i] == 1)         if (bl[i].x == 1 || bl[i].y == n) {           printf( -1 n );           return 0;         }     printf( %d n , 2 * (n - 1));   }


#include <bits/stdc++.h>   using namespace std;   const int MAXn = 100;   int adj[MAXn + 5][MAXn + 5];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int u, v, c;       cin >> u >> v >> c;       u--;       v--;       adj[u][v] = c;       adj[v][u] = -1 * c;     }     bool dir = 0;     int sum[2] = {0, 0}, u = -1, v = 0;     for (int i = 0; i < n; i++)       if (adj[v][i] > 0) dir = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++)         if (adj[v][j] != 0 && j != u) {           if (dir) {             if (adj[v][j] > 0)               sum[dir] += adj[v][j];             else {               sum[!dir] += -1 * adj[v][j];               dir = !dir;             }           } else {             if (adj[v][j] > 0) {               sum[!dir] += adj[v][j];               dir = !dir;             } else               sum[dir] += -1 * adj[v][j];           }           u = v;           v = j;           break;         }     }     cout << min(sum[0], sum[1]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class trio {    public:     long long first, second, third;   };   const long long MOD = 163577857;   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     long long res = (x % m + m) % m;     return res;   }   long long power(long long x, long long y) {     long long ans = 1, second = x;     while (y) {       if (y & 1) {         ans *= second;         ans %= MOD;       }       second *= second;       second %= MOD;       y >>= 1;     }     return ans;   }   bool comp(trio &a, trio &b) { return a.first < b.first; }   vector<long long> a;   long long m, n, k, third;   vector<trio> trap;   bool func(long long mid) {     if (mid == m + 1) return 0;     if (mid <= 0) return 1;     long long val = a[mid - 1];     long long ans = 0;     long long j = 1, i = 0, tr = 0;     while (i <= n) {       bool fl = 0;       while (tr < k && trap[tr].first <= j) {         if (trap[tr].third <= val) {           tr++;           continue;         }         j = max(trap[tr].second, j);         fl = 1;         tr++;       }       if (!fl)         ans += 1;       else {         ans += (j - i) * 3;       }       i = j;       j++;     }     return ans <= third;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> m >> n >> k >> third;     a.resize(m);     trap.resize(k);     for (long long i = 0; i < m; ++i) {       cin >> a[i];     }     for (long long i = 0; i < k; ++i) {       cin >> trap[i].first >> trap[i].second >> trap[i].third;     }     sort(a.begin(), a.end(), greater<long long>());     sort(trap.begin(), trap.end(), comp);     long long l = 0, h = m, mid;     while (l <= h) {       mid = (l + h) / 2;       bool t1 = func(mid);       bool t2 = func(mid + 1);       if (t1 && !t2) break;       if (t1)         l = mid + 1;       else         h = mid - 1;     }     cout << mid;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define sim template < class c   #define ris return * this   #define dor > debug & operator <<   #define eni(x) sim > typename      enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {   sim > struct rge { c b, e; };   sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }   sim > auto dud(c* x) -> decltype(cerr << *x, 0);   sim > char dud(...);   struct debug {   #ifndef ONLINE_JUDGE   ~debug() { cerr << endl; }   eni(!=) cerr << boolalpha << i; ris; }   eni(==) ris << range(begin(i), end(i)); }   sim, class b dor(pair < b, c > d) {     ris <<  (  << d.first <<  ,   << d.second <<  ) ;   }   sim dor(rge<c> d) {     *this <<  [ ;     for (auto it = d.b; it != d.e; ++it)       *this <<  ,   + 2 * (it == d.b) << *it;     ris <<  ] ;   }   #else   sim dor(const c&) { ris; }   #endif   };   #define imie(...)   [  << #__VA_ARGS__  :   << (__VA_ARGS__) <<  ]     // debug & operator << (debug & dd, P p) { dd <<  ,   << p.x <<  ,   << p.y <<  ) ; return dd; }      #define ll long long   const ll mod = 1e9 + 7;      ll powM(ll a, ll b) {       ll res = 1;       ll base = 1;       while(base <= b) {           if(base & b) {               res = res * a;               res = res % mod;               if(res < 0) {                   res = res + mod;                }           }           base = base * 2;           a = a * a;           a = a % mod;           if(a < 0) {               a = a + mod;            }       }       return res;   }      ll mod_inverse(ll n) {       return powM(n, mod - 2);   }      int main() {       ll n;       cin >> n;       // calculate dp.       vector<vector<ll>> dp(205, vector<ll> (205));       dp[0][0] = 0;       for(ll i = 0; i < 205; ++i) {           dp[0][i] = 1;           dp[i][0] = 0;       }       for(ll i = 1; i < 205; ++i) {           for(ll j = 1; j < 205; ++j) {               dp[i][j] = dp[i - 1][j] + dp[i][j - 1];               dp[i][j] = dp[i][j] % mod;               dp[i][j] = dp[i][j] * mod_inverse(2);               dp[i][j] = dp[i][j] % mod;               if(dp[i][j] < 0) {                   dp[i][j] = dp[i][j] + mod;               }           }       }       // debug() << imie(dp);       // read tree.       vector<vector<ll>> graph(n, vector<ll> (n, 0));       for(ll i = 0; i < n - 1; ++i) {           ll x, y;           cin >> x >> y;           x--;           y--;           graph[x][y] = 1;           graph[y][x] = 1;       }       // debug() << imie(graph);       // floyd warshall.       vector<vector<ll>> dist(n, vector<ll> (n, 800));       for(ll i = 0; i < n; ++i) {           dist[i][i] = 0;       }       for(ll i = 0; i < n; ++i) {           for(ll j = 0; j < n; ++j) {               if(graph[i][j]) {                   dist[i][j] = 1;               }           }       }       for(ll k = 0; k < n; ++k) {           for(ll i = 0; i < n; ++i) {               for(ll j = 0; j < n; ++j) {                   dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);               }           }       }       // debug() << imie(dist);       // calculate answer.       ll ans = 0;       for(ll i = 0; i < n; ++i) {           for(ll j = i + 1; j < n; ++j) {               for(ll k = 0; k < n; ++k) {                   ll dmin = dist[i][k];                   ll dmax = dist[j][k];                   ll t = (dmin + dmax - dist[i][j]) / 2;                   dmin = dmin - t;                   dmax = dmax - t;                   ans = ans + dp[dmax][dmin];                   ans = ans % mod;                   if(ans < 0) {                       ans = ans + mod;                    }               }           }       }       ans = (ans * mod_inverse(n) % mod);       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int numRows, numCols;     scanf( %d %d n , &numRows, &numCols);     bool *rowArray = new bool[numRows];     for (int k = 0; k < numRows; k++) {       rowArray[k] = 1;     }     bool *colArray = new bool[numCols];     for (int k = 0; k < numCols; k++) {       colArray[k] = 1;     }     char temp;     for (int row = 0; row < numRows; row++) {       for (int col = 0; col < numCols; col++) {         scanf( %c , &temp);         if (temp ==  S ) {           rowArray[row] = 0;           colArray[col] = 0;         }       }       scanf(  n );     }     int freeRows(0), freeCols(0);     for (int k = 0; k < numRows; k++) {       if (rowArray[k]) {         ++freeRows;       }     }     for (int k = 0; k < numCols; k++) {       if (colArray[k]) {         ++freeCols;       }     }     printf( %d n , freeRows * numCols + freeCols * numRows - freeRows * freeCols);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long lol(long long a, long long b) { return a / b; }   int main() {     int n, a[300009];     cin >> n;     while (n--) {       long long s, a, b, c;       cin >> s >> a >> b >> c;       long long nani = s / c;       long long nande = nani / a;       long long kirito = nande * (a + b);       long long asuna = kirito + nani % a;       cout << asuna << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v;   vector<bool> vis;   string ans =   ;   void dfs(int temp) {     ans += temp +  a ;     for (auto it = v[temp].begin(); it != v[temp].end(); ++it) {       if (!vis[*it]) {         vis[*it] = true;         dfs(*it);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       v.resize(26);       vis.resize(26);       set<pair<char, char> > sc;       for (int i = 0; i < s.size() - 1; i += 1) {         pair<int, int> cc = {min(s[i], s[i + 1]), max(s[i], s[i + 1])};         if (sc.find(cc) == sc.end()) {           sc.insert(cc);           v[s[i] -  a ].emplace_back(s[i + 1] -  a );           v[s[i + 1] -  a ].emplace_back(s[i] -  a );         }       }       int cnt = 0, temp = 0;       for (int i = 0; i < 26; i += 1) {         if (v[i].size() == 1) {           temp = i;           cnt++;         } else if (v[i].size() > 2) {           cnt = -1;           break;         }       }       if (cnt != 2 && s.size() != 1)         cout <<  NO n ;       else {         cout <<  YES n ;         vis[temp] = true;         dfs(temp);         for (int i = 0; i < 26; i += 1) {           if (!vis[i]) ans += i +  a ;         }         cout << ans <<   n ;       }       ans =   ;       vis.clear();       for (int i = 0; i < 26; i += 1) v[i].clear();       v.clear();     }   }


#include <bits/stdc++.h>   using namespace std;   char types[11];   bool possible[1005][12][11];   int m;   int pre[1005][12][11][3];   int main() {     scanf( %s , types);     scanf( %d , &m);     for (int i = 0; i < 11; ++i)       for (int d = 0; d <= 10; ++d) possible[0][i][d] = 0;     possible[0][0][0] = 1;     int best = 0;     int bestVal[3];     for (int j = 1; j <= m; ++j) {       for (int d = 0; d <= 10; ++d) possible[j][0][d] = 0;       for (int i = 1; i < 11; ++i)         for (int d = 0; d <= 10; ++d) {           possible[j][i][d] = 0;           if (types[i - 1] ==  0  || !d || d > i) {             continue;           }           for (int k = 0; k < 11; ++k) {             if (!possible[j - 1][k][i - d] || k == i) continue;             possible[j][i][d] = 1;             pre[j][i][d][0] = j - 1;             pre[j][i][d][1] = k;             pre[j][i][d][2] = i - d;             best = j;             bestVal[0] = j;             bestVal[1] = i;             bestVal[2] = d;           }         }     }     if (best == m) {       printf( YES n );       int j = bestVal[0], i = bestVal[1], d = bestVal[2];       int ansList[1005];       ansList[j - 1] = i;       while (j > 1) {         int jp = pre[j][i][d][0], ip = pre[j][i][d][1], kp = pre[j][i][d][2];         j = jp;         i = ip;         d = kp;         ansList[j - 1] = i;       }       for (int a = 0; a < m; ++a) printf( %d  , ansList[a]);     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, cnt[1010], ans;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       cnt[x]++;     }     for (int i = 1; i <= (n + 1) / 2; i++) {       int idx = -1, mx = -1;       for (int j = 1; j <= k; j++) {         if (cnt[j] > mx) {           mx = cnt[j];           idx = j;         }       }       if (cnt[idx] >= 2) {         ans += 2;         cnt[idx] -= 2;       } else {         ans += cnt[idx];         cnt[idx] = 0;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[5000], rev[5000];   bool used[5000];   vector<int> ord;   bool curcm[5000];   vector<int> cm;   void dfs1(int v) {     used[v] = true;     for (int to : g[v])       if (!used[to]) {         dfs1(to);       }     ord.push_back(v);   }   void dfs2(int v) {     used[v] = true;     cm.push_back(v);     curcm[v] = true;     for (int to : rev[v])       if (!used[to]) {         dfs2(to);       }   }   int dist[5000][5000];   int q[5000];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(m); ++i) {       int from, to;       scanf( %d%d , &from, &to), --from, --to;       g[from].push_back(to);       rev[to].push_back(from);     }     memset(dist, -1, sizeof dist);     for (int i = 0; i < (int)(n); ++i) {       int(&d)[5000] = dist[i];       d[i] = 0;       q[0] = i;       for (int qh = 0, qt = 1; qh < qt; ++qh) {         int v = q[qh];         for (int to : g[v])           if (d[to] == -1) {             d[to] = d[v] + 1;             q[qt++] = to;           }       }     }     for (int i = 0; i < (int)(n); ++i) used[i] = false;     for (int i = 0; i < (int)(n); ++i)       if (!used[i]) {         dfs1(i);       }     reverse(ord.begin(), ord.end());     for (int i = 0; i < (int)(n); ++i) used[i] = false;     int ans = n;     for (int v : ord)       if (!used[v]) {         cm.clear();         for (int i = 0; i < (int)(n); ++i) curcm[i] = false;         dfs2(v);         bool ok = false;         for (int x : cm) {           for (int y : g[x])             if (!curcm[y]) {               ok = true;               break;             }           if (ok) break;         }         if (!ok && (int)cm.size() > 1) {           ++ans;           int z = 12341234;           for (int x : cm)             for (int y : cm) {               if (y == x) break;               z = min(z, dist[x][y] + dist[y][x]);             }           ans += z * 998;         }       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   int N, M;   string s[100];   long long d[1 << 20];   long double f[1 << 20];   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin >> N;     for (int(i) = 0, j123 = N; (i) < j123; (i)++) cin >> s[i];     M = s[0].size();     for (int(i) = 0, j123 = N; (i) < j123; (i)++)       for (int(j) = 0, j123 = N; (j) < j123; (j)++)         if (i != j) {           int same = 0;           for (int(k) = 0, j123 = M; (k) < j123; (k)++)             if (s[i][k] == s[j][k]) same |= (1 << k);           d[same] |= (1LL << i);         }     for (int mask = (1 << M) - 1; mask >= 0; mask--)       for (int(i) = 0, j123 = M; (i) < j123; (i)++)         if (!((mask >> i) & 1)) d[mask] |= d[mask | (1 << i)];     for (int mask = (1 << M) - 1; mask >= 0; mask--) {       if (d[mask] == 0) continue;       long double tot = 0;       int cnt = 0;       for (int(i) = 0, j123 = M; (i) < j123; (i)++)         if (!((mask >> i) & 1)) {           cnt++;           tot += f[mask | (1 << i)] * __builtin_popcountll(d[mask | (1 << i)]) /                  __builtin_popcountll(d[mask]);         }       tot /= cnt;       tot += 1;       f[mask] = tot;     }     cout << f[0] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(0) * 2;   const double EPS = 1e-8;   const long long MOD = 1e9 + 7;   const int MAXN = 1e4 + 5;   const int oo = 1e9;   const double foo = 1e30;   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcounll(s);   }   template <class T>   T sqr(T x) {     return x * x;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   int n;   long double val[MAXN], f[MAXN];   vector<int> has[MAXN], ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int s, r;       scanf( %d%d , &s, &r);       if (r > val[s]) {         val[s] = r;         has[s].clear();       }       if (r == val[s]) has[s].push_back(i);     }     for (int i = 1; i <= 10000; i++) {       if (!has[i].empty()) f[i] = val[i] / i;     }     for (int i = 1; i <= 10000; i++) {       if (has[i].empty()) continue;       long double r = 10000000000000.0;       long double l = 0;       int cant = 0;       for (int j = 1; j < i; j++) {         if (!has[j].empty() && val[j] > val[i]) {           long double tmp =               ((long double)i - (long double)j) / (val[j] - val[i]) * f[i] * f[j];           r = min(r, tmp);         }       }       for (int j = i + 1; j <= 10000; j++) {         if (cant) break;         if (!has[j].empty()) {           if (val[i] > val[j]) {             long double tmp = ((long double)j - (long double)i) /                               (val[i] - val[j]) * f[i] * f[j];             l = max(l, tmp);           } else             cant = 1;         }       }       if ((l == 10000000000000.0 || r == 0 || l <= r) && !cant) {         for (int j = 0; j < ((int)(has[i]).size()); j++) {           ans.push_back(has[i][j]);         }       }     }     sort(ans.begin(), ans.end());     for (int i = 0; i < ((int)(ans).size()); i++) {       printf( %d  , ans[i] + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   using LLI = long long;   long long NWD(long long blep, long long b) {     return (b == 0) ? blep : NWD(b, blep % b);   }   long long NWW(long long blep, long long b) { return blep / NWD(blep, b) * b; }   const int MX = 3e5 + 400;   int n, T[MX];   long long ans[MX];   void out() {     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> T[i];     T[n + 1] = T[1];     T[0] = T[n];     for (int i = 1; i <= n; i++) {       if (T[i] > T[i - 1]) {         ans[i] = T[i];         if (i == 1)           ans[n + 1] = ans[1];         else if (i == n)           ans[0] = ans[n];         for (int j = i - 1; j > i - n; j--) {           int blep = (j + n) % n;           if (blep == 0) blep = n;           ans[blep] = ans[blep + 1] + T[blep];           while (ans[blep] <= (long long)T[blep - 1]) ans[blep] += ans[blep + 1];           if (j == 1)             ans[n + 1] = ans[1];           else if (j == n)             ans[0] = ans[n];         }         return out(), 0;       }     }     for (int i = 1; i <= n; i++) ans[i] = 1;     if (T[1] == 0)       out();     else       cout <<  NO  << endl;     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 1;   int n;   int main() {     scanf( %d , &n);     n = abs(n);     int i = 0;     while (1) {       int s = i * (i + 1);       s /= 2;       if (s >= n) {         if (s % 2 && n % 2) {           printf( %d , i);           exit(0);         }         if (s % 2 == 0 && n % 2 == 0) {           printf( %d , i);           exit(0);         }       }       i++;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     string s;     cin >> s;     int n = s.size();     if (n % 2 == 1) {       for (int i = 0; i < n + 1; ++i) {         cout << (i < (n + 1) / 2 ? 4 : 7);       }       cout << endl;       return 0;     }     int seven = 0, four = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  4 ) {         four++;       }       if (s[i] ==  7 ) {         seven++;       }     }     if (seven == four && seven + four == n) {       cout << s << endl;       return 0;     }     for (int i = n - 1; i >= 0; --i) {       if (s[i] ==  4 ) {         four--;       }       if (s[i] ==  7 ) {         seven--;       }       if (seven + four != i) {         continue;       }       if (seven > n / 2 || four > n / 2) {         continue;       }       if (s[i] <  4  && n / 2 - four > 0) {         s[i] =  4 ;         four++;         int x = i + 1;         while (four < n / 2) {           s[x++] =  4 ;           four++;         }         while (seven < n / 2) {           s[x++] =  7 ;           seven++;         }         cout << s << endl;         return 0;       }       if (s[i] <  7  && n / 2 - seven > 0) {         s[i] =  7 ;         seven++;         int x = i + 1;         while (four < n / 2) {           s[x++] =  4 ;           four++;         }         while (seven < n / 2) {           s[x++] =  7 ;           seven++;         }         cout << s << endl;         return 0;       }     }     for (int i = 0; i < n + 2; ++i) {       cout << (i < (n + 2) / 2 ? 4 : 7);     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100005];   long long d[800][800], g[800][800];   int w[100];   vector<long long> v;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       long long x = a[i];       int cnt = 0;       while (x) {         if (x % 2) w[cnt]++;         cnt++;         x /= 2;       }     }     for (int i = 0; i < 70; i++) {       if (w[i] >= 3) {         printf( 3 n );         return 0;       }     }     v.push_back(0);     for (int i = 1; i <= n; i++) {       if (a[i]) v.push_back(a[i]);     }     n = v.size() - 1;     if (n > 300) {       printf( 3 n );       return 0;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) d[i][j] = g[i][j] = 0x3f3f3f3f;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (v[i] & v[j]) d[i][j] = 1, d[j][i] = 1, g[i][j] = 1, g[j][i] = 1;       }     }     long long ans = 0x3f3f3f3f;     for (int k = 1; k <= n; k++) {       for (int i = 1; i < k; i++) {         for (int j = i + 1; j < k; j++)           ans = min(ans, d[i][j] + g[i][k] + g[k][j]);       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);       }     }     if (ans == 0x3f3f3f3f) ans = -1;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   signed main() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     multiset<long long> kek;     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == -1) {         break;       }       kek.insert(a[i]);       if ((i & (i + 1)) == 0) {         ans += *(kek.begin());         kek.erase(kek.begin());       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long dp[4];   int a[100005];   string s;   int main() {     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (s[i] ==  h )         dp[0] += a[i];       else if (s[i] ==  a )         dp[1] = min(dp[0], dp[1] + a[i]);       else if (s[i] ==  r )         dp[2] = min(dp[1], dp[2] + a[i]);       else if (s[i] ==  d )         dp[3] = min(dp[2], dp[3] + a[i]);     }     cout << dp[3];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Work {   int c[100010], f[100010], l[100010];   int n, d, s;   void solve(FILE* fin, FILE* fout) {     fscanf(fin,  %d%d%d , &n, &d, &s);     for (int i = 0; i < n; i++) fscanf(fin,  %d%d%d , c + i, f + i, l + i);     vector<int> a, b;     a.clear();     b.clear();     for (int i = 0; i < n; i++)       if (c[i] == 0 && l[i] >= d) a.push_back(f[i]);     sort(a.begin(), a.end());     int acnt = 0, acost = 0;     int sum = 0;     for (int i = 0; i < (int)a.size(); i++)       if (sum + a[i] <= s) {         sum += a[i];         if (i + 1 > acnt || (i + 1 == acnt && sum < acost)) {           acnt = i + 1;           acost = sum;         }       }     bool flag = false;     for (int i = 0; i < n; i++)       if (c[i] > 0 && f[i] <= s && l[i] >= d) flag = true;     if (flag) {       int carry = 0;       for (int i = 0; i < n; i++) {         carry += c[i];         carry = min(carry, n);       }       a.clear();       for (int i = 0; i < n; i++)         if (l[i] >= d) {           if (c[i] > 0)             a.push_back(f[i]);           else             b.push_back(f[i]);         }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       int i = 1, j = 0;       sum = a[0];       while (true) {         int cnt = min(n, carry + i + j);         if (cnt > acnt || (cnt == acnt && sum < acost)) {           acnt = cnt;           acost = sum;         }         if (i == a.size() && j == b.size()) break;         if (i < a.size() && (j == b.size() || a[i] < b[j])) {           sum += a[i];           i++;         } else {           sum += b[j];           j++;         }         if (sum > s) break;       }     }     fprintf(fout,  %d %d , acnt, acost);   }   }  // namespace Work   int main() {     Work::solve(stdin, stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, n, ret;   long long retr(long long x) {     long long t = 0;     while (x > 0) {       t = 10 * t + (x % 10);       x /= 10;     }     return t;   }   int main() {     int i;     cin >> a >> b;     ret = retr(b);     ret += a;     cout << ret;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char s[200100];   int x[200100];   int main() {     scanf( %d , &n);     scanf( %s , s);     int mint = 0x3f3f3f3f;     for (int i = 0; i < n; i++) {       scanf( %d , &x[i]);       if (i && s[i] ==  L  && s[i - 1] ==  R )         mint = min((x[i] - x[i - 1]) / 2, mint);     }     if (mint == 0x3f3f3f3f) mint = -1;     printf( %d , mint);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int N = 100100;   struct point {     int id, val, sum;   } a[N], b[N];   bool cmp(point x, point y) { return x.val > y.val; }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int na = 0;     int nb = 1;     b[0].val = 0;     for (int i = 1; i <= n; ++i) {       int op;       scanf( %d , &op);       if (op == 1) {         scanf( %d , &a[na].val);         a[na++].id = i;       } else {         scanf( %d , &b[nb].val);         b[nb++].id = i;       }     }     sort(a, a + na, cmp);     sort(b + 1, b + nb, cmp);     for (int i = 0; i < na; ++i) {       if (i == 0)         a[i].sum = a[i].val;       else         a[i].sum = a[i - 1].sum + a[i].val;     }     int sum = 0;     int ia = 0;     int ib = 1;     int ans = 0;     for (int i = 0; i < nb && 2 * i <= m; ++i) {       sum += b[i].val;       int id = min(m - 2 * i - 1, na - 1);       int tmp = sum;       if (id >= 0) tmp += a[id].sum;       if (tmp > ans) {         ans = tmp;         ia = id + 1;         ib = i + 1;       }     }     printf( %d n , ans);     for (int i = 0; i < ia; ++i) printf( %d  , a[i].id);     for (int i = 1; i < ib; ++i) printf( %d  , b[i].id);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> dg, og;   vector<bool> vist;   vector<int> dist;   void bfs(int begin) {     vist[begin] = true;     dist[begin] = 0;     queue<int> pq;     pq.push(begin);     while (!pq.empty()) {       int a = pq.front();       pq.pop();       for (int i = 0; i < dg[a].size(); i++) {         if (!vist[dg[a][i]]) {           vist[dg[a][i]] = true;           dist[dg[a][i]] = dist[a] + 1;           pq.push(dg[a][i]);         }       }     }   }   int distcounter(int a) {     int count = 0;     for (int i = 0; i < og[a].size(); i++) {       if (dist[og[a][i]] == dist[a] - 1) count++;     }     return count;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     dg.resize(n + 1);     dist.resize(n + 1);     og.resize(n + 1);     vist.assign(n + 1, false);     int u, v;     for (int i = 1; i <= m; i++) {       cin >> u >> v;       og[u].push_back(v);       dg[v].push_back(u);     }     int k;     cin >> k;     vector<int> p;     p.resize(k + 1);     for (int i = 1; i <= k; i++) cin >> p[i];     bfs(p[k]);     int small = 0, large = 0;     for (int i = 1; i < k; i++) {       int count = distcounter(p[i]);       if (dist[p[i + 1]] != dist[p[i]] - 1) {         small++;         large++;       } else {         if (count > 1) {           large++;         }       }     }     cout << small <<     << large << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:128777216 )   using namespace std;   const long long LINF = 1000000000000000000LL;   const int INF = 1000000000;   const long double eps = 1e-9;   const long double PI = 3.1415926535897932384626433832795l;   void prepare(string s) {     if (s.length() != 0) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   const int NMAX = 1000100;   const int MOD = INF + 7;   char s[NMAX];   int n;   int c[4];   char sym[] = { A ,  C ,  G ,  T };   int get(char c) {     for (int i = 0; i < (int)(4); i++)       if (sym[i] == c) return i;     assert(false);     return -1;   }   void read() {     scanf( %d n , &n);     scanf( %s , s);   }   int bpow(int a, int n) {     int r = 1;     for (; n > 0; n >>= 1) {       if (n & 1) r = ((long long)r * (long long)a) % MOD;       a = ((long long)a * (long long)a) % MOD;     }     return r;   }   void solve() {     memset(c, 0, sizeof(c));     for (int i = 0; i < (int)(n); i++) c[get(s[i])]++;     int mx = *max_element(c, c + 4);     int cnt = 0;     for (int i = 0; i < (int)(4); i++)       if (c[i] == mx) cnt++;     printf( %d n , bpow(cnt, n));   }   int main() {     prepare(  );     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, s;     cin >> n >> k;     for (i = 1; i <= n + 5; i++) {       s = i * k;       if (s > n) {         cout << s;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt, h;   bool f = true;   int main() {     long long s, x;     cin >> s >> x;     h = sizeof(long long) * 8 - __builtin_clzll(max(s, x)) - 1;     for (; h >= 0; h--) {       if (x & (1LL << h))         cnt++, s -= (1LL << h);       else if (s >= (1LL << h + 1))         s -= (1LL << h + 1), f = false;     }     if (s || (cnt < 2 && f))       cout << 0 << endl;     else       cout << (1LL << (cnt)) - f * 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mtx[555][555];   long long comb[555][555];   int n, m, MOD;   map<pair<int, int>, long long> dp[555];   long long solve(int col, int empty, int halfempt) {     if (empty < 0 || halfempt < 0) return 0;     if (col == n) {       return empty == 0 && halfempt == 0;     }     if (dp[col].find(make_pair(empty, halfempt)) == dp[col].end()) {       long long ans = 0;       int cnt = 0;       for (int(i) = 0; (i) < (m); (i)++)         if (mtx[i][col] ==  1 ) cnt++;       if (cnt == 0) {         if (halfempt == 0) {           ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);         } else {           ans += comb[halfempt][2] * solve(col + 1, empty, halfempt - 2);           if (empty != 0) {             ans += comb[halfempt][1] * comb[empty][1] *                    solve(col + 1, empty - 1, halfempt);             ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2);           }         }       } else if (cnt == 1) {         ans = comb[empty][1] * solve(col + 1, empty - 1, halfempt + 1);         ans += comb[halfempt][1] * solve(col + 1, empty, halfempt - 1);       } else         ans = solve(col + 1, empty, halfempt);       ans %= MOD;       dp[col][make_pair(empty, halfempt)] = ans;     }     return dp[col][make_pair(empty, halfempt)];   }   int main() {     scanf( %d%d%d , &n, &m, &MOD);     for (int i = 1; i < 505; i++) {       comb[i][0] = comb[i][i] = 1;       for (int j = 0; j < i; j++) {         comb[i + 1][j + 1] = (comb[i][j] + comb[i][j + 1]) % MOD;       }     }     if (n == m) {       printf( 1 n );       return 0;     }     for (int(i) = 0; (i) < (m); (i)++) scanf( %s , mtx[i]);     long long ans = solve(0, n - m, 0);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, m, k, top, a[N];   pair<int, int> op[N * 3];   int main() {     scanf( %d%*d%d%d , &n, &m, &k);     k--;     m /= 2;     if (!k) {       return puts( 0 0 n ), 0;     }     for (int i = (int)(1); i <= (int)(n); i++) {       int x;       scanf( %*d%d , &x);       a[i] = (x %= m);       int l = (x + 1) % m, r = (x + k) % m;       op[++top] = pair<int, int>(l, 1);       op[++top] = pair<int, int>(r + 1, -1);       if (l > r) op[++top] = pair<int, int>(0, 1);     }     op[++top] = pair<int, int>(m, 0);     sort(op + 1, op + top + 1);     int mnv = 1 << 30, mnp = 0, s = 0;     for (int i = (int)(1); i <= (int)(top - 1); i++) {       s += op[i].second;       if (op[i].first != op[i + 1].first) {         if (s < mnv) mnv = s, mnp = op[i].first;       }     }     cout << mnv <<     << mnp << endl;     for (int i = (int)(1); i <= (int)(n); i++) {       int d = (mnp + m - a[i]) % m;       if (d >= 1 && d <= k) cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, p = 0;     cin >> n;     int ara[n];     for (i = 0; i < n; i++) {       cin >> ara[i];     }     sort(ara + 0, ara + n);     for (i = 0; i < n - 1; i++) {       if (ara[i] + 1 != ara[i + 1]) p = p - 1 + ara[i + 1] - ara[i];     }     cout << p;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[101];   int n, m;   bool visited[101];   void dfs(int v) {     visited[v] = true;     for (int i = 0; i < g[v].size(); i++) {       if (!visited[g[v][i]]) dfs(g[v][i]);     }   }   bool isConnected() {     fill(visited, visited + n, false);     dfs(0);     for (int i = 0; i < n; i++)       if (!visited[i]) return false;     return true;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %d , &x, &y);       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     if (n == m && isConnected())       cout <<  FHTAGN!  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 55;   const long long mod = 1000000007;   double add[N << 2], sum[N << 2];   struct node {     int pos, h, l, r;   } a[N];   map<int, int> b;   vector<int> v, v2;   int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; }   int get_id(int x) { return upper_bound(v.begin(), v.end(), x) - v.begin() + 1; }   int getid2(int x) {     return lower_bound(v2.begin(), v2.end(), x) - v2.begin() + 1;   }   void PushUp(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }   void PushDown(int rt, int m, int l, int r) {     if (fabs(add[rt] - 1) > 0.00001) {       add[rt << 1] *= add[rt];       add[rt << 1 | 1] *= add[rt];       sum[rt << 1] *= add[rt];       sum[rt << 1 | 1] *= add[rt];       add[rt] = 1;     }   }   void build(int l, int r, int rt) {     add[rt] = 1;     sum[rt] = 0;     if (l == r) {       if (v2[getid2(v[l - 1]) - 1] == v[l - 1]) {         sum[rt] = b[v[l - 1]];       } else         sum[rt] = 0;       return;     }     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     PushUp(rt);   }   void upedit(int L, int R, double c, int l, int r, int rt) {     if (L <= l && r <= R) {       add[rt] *= c;       sum[rt] *= c;       return;     }     int m = (l + r) >> 1;     PushDown(rt, m, l, r);     if (L <= m) upedit(L, R, c, l, m, rt << 1);     if (m < R) upedit(L, R, c, m + 1, r, rt << 1 | 1);     PushUp(rt);   }   double query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return sum[rt];     }     int m = (l + r) >> 1;     PushDown(rt, m, l, r);     double ret = 0;     if (L <= m) ret += query(L, R, l, m, rt << 1);     if (m < R) ret += query(L, R, m + 1, r, rt << 1 | 1);     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n, m, k, kk;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i].pos >> a[i].h >> a[i].l >> a[i].r;       v.push_back(a[i].pos);       v.push_back(a[i].pos + a[i].h);       v.push_back(a[i].pos - a[i].h);     }     for (int i = 1; i <= m; i++) {       cin >> k >> kk, v.push_back(k), v2.push_back(k);       b[k] += kk;     }     sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());     sort(v2.begin(), v2.end()), v2.erase(unique(v2.begin(), v2.end()), v2.end());     int sz = v.size();     build(1, sz, 1);     for (int i = 1; i <= n; i++) {       int L = getid(a[i].pos - a[i].h);       int R = get_id(a[i].pos + a[i].h) - 1;       int M = getid(a[i].pos);       if (L < M) {         upedit(L, M - 1, 1 - a[i].l * 1.0 / 100, 1, sz, 1);       }       if (R > M) {         upedit(M + 1, R, 1 - a[i].r * 1.0 / 100, 1, sz, 1);       }     }     printf( %.5f n , sum[1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[55][55], a, b, n, m;   int solve() {     int res = 1000000000;     for (int _n((n - a + 1) - 1), i(0); i <= _n; i++)       for (int _n((m - b + 1) - 1), j(0); j <= _n; j++) {         int cnt = 0;         for (int _n((a)-1), k(0); k <= _n; k++)           for (int _n((b)-1), t(0); t <= _n; t++) cnt += x[i + k][j + t];         res = min(res, cnt);       }     return res;   }   int main() {     scanf( %d%d , &n, &m);     for (int _n((n)-1), i(0); i <= _n; i++)       for (int _n((m)-1), j(0); j <= _n; j++) scanf( %d , &x[i][j]);     scanf( %d%d , &a, &b);     int r1 = solve();     swap(a, b);     int r2 = solve();     cout << min(r1, r2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[550005];   int main() {     int n, d, c, i, j, x, flog;     scanf( %d %d , &n, &d);     dp[0] = 1;     for (i = 0; i < n; i++) {       scanf( %d , &c);       for (j = 500000; j >= c; j--) {         dp[j] |= dp[j - c];       }     }     int day = 0;     x = 0;     while (1) {       flog = 0;       for (j = x + d; j > x; j--) {         if (dp[j]) {           flog = 1;           day++;           x = j;           break;         }       }       if (!flog) break;     }     printf( %d %d n , x, day);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T Dist(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   long long int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   long long int a[300005], b[300005];   int n, m;   int Check(long long int x) {     int pos = 1;     for (int i = 1; i <= n; i++) {       if (pos <= m && b[pos] <= a[i] && (a[i] - b[pos]) > x) return 0;       if (a[i] < b[pos]) {         while (pos <= m && b[pos] - a[i] <= x) pos++;       } else {         int now = pos;         pos++;         while (pos <= m) {           long long int p = (a[i] - b[now]) * 2LL + (-a[i] + b[pos]);           long long int q = (a[i] - b[now]) + 2LL * (-a[i] + b[pos]);           if (min(p, q) > x) break;           pos++;         }       }     }     return (pos > m);   }   int main() {     n = in<int>(), m = in<int>();     int id = 0;     for (int i = 1; i < n + 1; i++) {       a[i] = in<long long int>();     }     for (int i = 1; i < m + 1; i++) {       b[i] = in<long long int>();     }     long long int L = 0, R = 100000000000000, ans, mid;     while (L <= R) {       mid = (L + R) / 2LL;       if (Check(mid)) {         R = mid - 1LL;         ans = mid;       } else {         L = mid + 1LL;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int main() {     int a[1010], b[1010];     int n;     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> a[i] >> b[i];       int ans = 0;       for (int i = 0; i < n; i++) {         int s = a[i];         while (s <= ans) s += b[i];         ans = s;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100010;   int n, i, Ans, b[M], pos[M];   long long A, w1, w2, m, ans, s[M];   struct shit {     long long w;     int id;   } a[M];   bool cmp(shit x, shit y) { return x.w > y.w; }   int main() {     scanf( %d%I64d%I64d%I64d%I64d , &n, &A, &w1, &w2, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i].w);       a[i].id = i;     }     sort(a + 1, a + n + 1, cmp);     for (i = 1; i <= n; i++) s[i] = a[i].w + s[i - 1];     if (m + s[n] - A * n >= 0) {       printf( %I64d n , w1 * n + w2 * A);       for (i = 1; i <= n; i++) printf( %d  , A);       puts(  );       return 0;     }     int now = 1;     for (i = 0; i < n; i++) {       if (m - A * i + s[i] < 0) break;       while (now <= i ||              a[now].w * (n - now + 1) - s[n] + s[now - 1] > m - A * i + s[i])         now++;       pos[i] = now;       long long tmp = (m - A * i + s[i] + s[n] - s[now - 1]) / (n - now + 1);       if (w1 * i + w2 * tmp > ans) ans = w1 * i + w2 * tmp, Ans = i;     }     printf( %I64d n , ans);     long long p =         (m - A * Ans + s[Ans] + s[n] - s[pos[Ans] - 1]) / (n - pos[Ans] + 1);     for (i = 1; i <= Ans; i++) b[a[i].id] = A;     for (i = Ans + 1; i < pos[Ans]; i++) b[a[i].id] = a[i].w;     for (i = pos[Ans]; i <= n; i++) b[a[i].id] = p;     for (i = 1; i <= n; i++) printf( %d  , b[i]);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> A(100);   bool f(int m) {     int k1 = 0, k2 = 0;     for (int i = 0; i < n; i++) {       k1 += A[i];       k2 += m - A[i];     }     if (k2 > k1)       return true;     else       return false;   }   int main() {     cin >> n;     int MAX = -1;     for (int i = 0; i < n; i++) {       cin >> A[i];       if (A[i] > MAX) MAX = A[i];     }     int l = MAX - 1, r = 201;     while (r - l > 1) {       int m = (l + r) / 2;       if (f(m))         r = m;       else         l = m;     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[105][105];   inline int get(int x, int y) {     bool vis[11];     for (register int i = 0; i <= 10; i++) vis[i] = 0;     vis[a[x - 1][y]] = vis[a[x + 1][y]] = vis[a[x][y - 1]] = vis[a[x][y + 1]] = 1;     for (register int i = 1; i <= 10; i++) {       if (!vis[i]) return i;     }     return 0;   }   inline void draw(int x, int y, int p, int sign) {     for (register int i = 0; i < p; i++) {       for (register int j = 0; j < p; j++) {         a[x + i][y + j] = sign;       }     }   }   inline void slove(int x, int y) {     if (y > m) {       y = 1;       x = x + 1;     }     if (x > n) return;     if (a[x][y]) {       slove(x, y + 1);       return;     }     int p = 1, sign = get(x, y);     while (1) {       if (x + p > n || y + p > m) break;       if (a[x][y + p]) break;       int tmp = get(x, y + p);       if (tmp != sign) break;       p++;     }     draw(x, y, p, sign);     slove(x, y + 1);   }   int main() {     scanf( %d%d , &n, &m);     slove(1, 1);     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= m; j++) {         printf( %c , (a[i][j] - 1 +  A ));       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = 1e9;   const int MAX = 1e5 + 7, N = 1e5 + 3;   double pi = acos(-1);   long long r, l, k, m, n, ans;   int main() {     cin >> n;     cin >> k >> l;     long long m1 = k - 1 + l - 1;     long long m2 = n - k + n - l;     if (m1 <= m2) {       cout <<  White  << endl;     } else {       cout <<  Black  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char _c;   bool _f;   template <class T>   inline void IN(T &x) {     x = 0, _f = 0;     while (_c = getchar(), !isdigit(_c))       if (_c ==  - ) _f = 1;     while (isdigit(_c)) x = x * 10 + _c -  0 , _c = getchar();     if (_f) x = -x;   }   template <class T>   inline void chkmax(T &x, T y) {     if (x < y) x = y;   }   template <class T>   inline void chkmin(T &x, T y) {     if (x > y) x = y;   }   const int N = 5e5 + 5;   const int mod = 1e9 + 7;   int mul(int x, int y) { return 1ll * x * y % mod; }   int n, cnt = 1, dep[N], parent[N], head[N];   int fa[N << 1], tof[N], nxt[N << 1], pre[N << 1], st[N], ed[N], deg[N];   struct Edge {     int nxt, to;   } G[N << 1];   void addedge(int u, int v) {     G[++cnt] = (Edge){head[u], v}, head[u] = cnt, ++deg[u];     G[++cnt] = (Edge){head[v], u}, head[v] = cnt, ++deg[v];   }   void dfs(int u, int lst) {     parent[u] = lst, dep[u] = dep[lst] + 1;     for (int v, i = head[u]; i; i = G[i].nxt)       if (v = G[i].to, v != lst) dfs(v, u), tof[v] = i ^ 1;   }   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   bool merge(int x, int y) {     x = find(x), y = find(y);     return (x == y) ? false : (fa[x] = y, true);   }   void solve(int x, int y) {     std ::stack<int> s;     std ::queue<int> q;     const int _x = x, _y = y;     while (dep[x] > dep[y]) q.push(tof[x]), --deg[x], x = parent[x];     while (dep[x] < dep[y]) s.push(tof[y]), --deg[y], y = parent[y];     while (x != y) {       q.push(tof[x]), --deg[x], x = parent[x];       s.push(tof[y]), --deg[y], y = parent[y];     }     --deg[x];     while (!s.empty()) q.push(s.top() ^ 1), s.pop();     int lst = q.front();     q.pop();     if (st[_x] || pre[lst]) {       puts( 0 );       exit(0);     };     st[_x] = lst, pre[lst] = -1;     while (!q.empty()) {       int now = q.front();       q.pop(), lst ^= 1;       if (pre[now] || nxt[lst] || !merge(lst, now)) {         puts( 0 );         exit(0);       };       pre[now] = lst, nxt[lst] = now, lst = now;     }     lst ^= 1;     if (ed[_y] || nxt[lst]) {       puts( 0 );       exit(0);     };     ed[_y] = lst, nxt[lst] = -1;     return;   }   int u, v, a[N];   int fac(int x) { return x == 0 ? 1 : mul(x, fac(x - 1)); }   int main() {     IN(n);     for (int i = 1; i <= n - 1; ++i) IN(u), IN(v), addedge(u, v);     for (int i = 1; i <= cnt; ++i) fa[i] = i;     dfs(1, 0);     for (int i = 1; i <= n; ++i) IN(a[i]);     for (int i = 1; i <= n; ++i)       if (a[i] == i) {         puts( 0 );         exit(0);       };     for (int i = 1; i <= n; ++i)       if (a[i]) solve(a[i], i);     int ans = 1;     for (int i = 1; i <= n; ++i) {       if (st[i] && ed[i])         if (find(st[i]) == find(ed[i]) && ~deg[i]) {           puts( 0 );           exit(0);         };       ans = mul(ans, fac(deg[i] == -1 ? 1 : deg[i]));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pr(vector<T> &v) {     for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ;     cout << endl;   }   template <typename T>   void pr(vector<vector<T>> &v) {     for (int i = 0; i < (int)(v).size(); i++) {       pr(v[i]);     }   }   template <typename T>   void re(T &first) {     cin >> first;   }   template <typename T>   void re(vector<T> &a) {     for (int i = 0; i < (int)(a).size(); i++) re(a[i]);   }   template <class Arg, class... Args>   void re(Arg &first, Args &...rest) {     re(first);     re(rest...);   }   template <typename T>   void pr(T first) {     cout << first << endl;   }   template <class Arg, class... Args>   void pr(const Arg &first, const Args &...rest) {     cout << first <<    ;     pr(rest...);     cout << endl;   }   void ps() { cout << endl; }   template <class T, class... Ts>   void ps(const T &t, const Ts &...ts) {     cout << t;     if (sizeof...(ts)) cout <<    ;     ps(ts...);   }   void solve() {     int n;     re(n);     pr(1 + 3 * (n + 1));     ps(0, 0);     for (int i = 0; i < n + 1; i++) {       ps(i, i + 1);       ps(i + 1, i + 1);       ps(i + 1, i);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     for (int tt = 0; tt < t; tt++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int const N = 100000;   int n;   int ans;   char digits[8][8];   int ten[8];   bitset<N> isprime;   int sum[8];   struct Integer {     int i, j, x;     Integer(int i, int j, int x) : i(i), j(j), x(x) {}     operator int() { return x; }     Integer(int x = 0) : x(x), i(-1), j(-1) {}     void operator=(int other) {       if (i >= 0) {         sum[i] -= x * ten[n - 1 - j];         sum[j] -= x * ten[n - 1 - i];         x = other;         sum[i] += x * ten[n - 1 - j];         sum[j] += x * ten[n - 1 - i];       } else {         x = other;       }     }   };   template <class T>   struct Counter {     vector<int> bnd;     vector<T> value;     Counter<T>(vector<int> bnd) : bnd(bnd), value(bnd.size(), 0) {}     bool operator++(int) {       int n = bnd.size();       int add = -1;       for (int i = n - 1; i >= 0; --i) {         if ((int)value[i] != bnd[i] - 1) {           add = i;           break;         }       }       if (add == -1) {         return false;       }       value[add] = value[add] + 1;       for (int i = add + 1; i < n; ++i) {         value[i] = 0;       }       return true;     }     T &operator[](int x) { return value[x]; }   };   int count_valid_after_fill[8][N];   int main() {     isprime.set();     isprime[0] = isprime[1] = false;     for (int i = 4; i < isprime.size(); i += 2) isprime[i] = false;     for (int i = 3; i < isprime.size(); i += 2)       if (isprime[i]) {         for (int k = i * 3; k < isprime.size(); k += i + i) isprime[k] = false;       }     ten[0] = 1;     for (int i = 1; i < 8; ++i) {       ten[i] = ten[i - 1] * 10;     }     memset(count_valid_after_fill, 0, (sizeof count_valid_after_fill));     for (int i = 0; i < isprime.size(); ++i) {       for (int p = 0; p < 5; ++p) {         int x = i;         if (x / ten[p] % 10 == 0) {           for (int n_ = (10), k = 0; k < n_; ++k) {             if (x < ((int)(isprime).size()) && isprime[x]) {               count_valid_after_fill[p][i]++;             }             x += ten[p];           }         }       }     }     int ca;     cin >> ca;     for (int n_ = (ca), ica = 0; ica < n_; ++ica) {       string input;       cin >> input;       n = input.size();       memset(digits, 0, (sizeof digits));       memset(sum, 0, (sizeof sum));       for (int n_ = (n), i = 0; i < n_; ++i) {         digits[0][i] = digits[i][0] = input[i] -  0 ;         sum[0] += ten[n - 1 - i] * digits[i][0];         if (i != 0) {           sum[i] += ten[n - 1] * digits[i][0];         }       }       vector<int> bnd((n - 1) * (n - 2) / 2, 10);       Counter<Integer> counter(bnd);       int p = 0;       for (int i = 1; i < n; ++i) {         for (int j = i + 1; j < n; ++j) {           counter[p] = Integer(i, j, 0);           p++;         }       }       int ans = 0;       do {         int way = 1;         for (int i = 1; i < n; ++i) {           int way2 = count_valid_after_fill[n - 1 - i][sum[i]];           way *= way2;         }         ans += way;       } while (counter++);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long x, long long y) {     if (y == 0) return x;     return GCD(y, x % y);   }   long long LCM(long long x, long long y) { return (x * y) / (GCD(x, y)); }   long long LOGK(long long x, long long k) {     if (x >= k) return 1 + LOGK(x / k, k);     return 0;   }   long long MPOW(long long a, long long b, long long m) {     if (b == 0) return 1;     long long x = MPOW(a, b / 2, m);     x = (x * x) % m;     if (b % 2 == 1) x = (x * a) % m;     return x;   }   int main() {     long long test = 1;     while (test--) {       long long n;       cin >> n;       long long ar[n + 1];       long long dp[n + 1];       dp[0] = 1;       for (long long i = 1; i <= n; i++) dp[i] = 0;       long long ans = 0;       for (long long i = 1; i <= n; i++) {         cin >> ar[i];         vector<long long> g;         for (long long j = 1; j <= (long long)(sqrt(ar[i])); j++) {           if (ar[i] % j == 0) {             g.push_back(j);             if (ar[i] / j != j) {               g.push_back(ar[i] / j);             }           }         }         sort(g.begin(), g.end());         reverse(g.begin(), g.end());         for (auto it : g) {           if (it <= n) {             dp[it] += dp[it - 1];             dp[it] %= 1000000007;           }         }       }       for (long long i = 1; i <= n; i++) {         ans += dp[i];         ans %= 1000000007;       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long t, n;   long long quickpower(int a, int b) {     long long res = 1;     while (b) {       if (b % 2 == 1) res *= a;       a *= a;       b >>= 1;     }     return res;   }   int main() {     cin >> t;     while (t--) {       cin >> n;       long long r = 0;       for (int i = 2;; i++) {         r = quickpower(2, i) - 1;         if (n % r == 0) {           cout << n / r << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   const int MAXN = 1e5 + 1e4;   int n, pos_ = 0;   vector<int> g[MAXN];   vector<int> a[MAXN];   vector<int> ans;   vector<vector<int>> t(4 * MAXN);   vector<int> parent(MAXN), depth(MAXN), heavy(MAXN, -1), pos(MAXN), head(MAXN);   int dfs(int v) {     int sz = 1;     int h_sz = 0;     for (int u : g[v]) {       if (parent[v] == u) {         continue;       }       parent[u] = v;       depth[u] = depth[v] + 1;       int cur_sz = dfs(u);       sz += cur_sz;       if (h_sz < cur_sz) {         h_sz = cur_sz;         heavy[v] = u;       }     }     return sz;   }   void hld(int v, int root) {     head[v] = root;     pos[v] = pos_++;     ;     if (heavy[v] != -1) {       hld(heavy[v], root);     }     for (int u : g[v]) {       if (u == heavy[v] || u == parent[v]) {         continue;       }       hld(u, u);     }   }   void build(int v = 1, int l = 0, int r = n) {     if (r - l == 1) {       t[v] = a[l];       while (((int32_t)(t[v]).size()) > 10) {         t[v].pop_back();       };       return;     }     int m = (l + r) / 2;     build(v * 2, l, m);     build(v * 2 + 1, m, r);     t[v].resize(20, INT_MAX);     merge((t[v * 2]).begin(), (t[v * 2]).end(), (t[v * 2 + 1]).begin(),           (t[v * 2 + 1]).end(), t[v].begin());     while (((int32_t)(t[v]).size()) > 10 ||            t[v][((int32_t)(t[v]).size()) - 1] == INT_MAX) {       t[v].pop_back();     }   }   void get_ans(int ql, int qr, int v = 1, int l = 0, int r = n) {     if (ql <= l && r <= qr) {       vector<int> ans_new(20, INT_MAX);       merge((ans).begin(), (ans).end(), (t[v]).begin(), (t[v]).end(),             ans_new.begin());       for (int i = 0; i < 20; i++) {         ;       }       while (((int32_t)(ans_new).size()) > 10 ||              ans_new[((int32_t)(ans_new).size()) - 1] == INT_MAX) {         ans_new.pop_back();       }       ans = ans_new;       return;     }     if (qr <= l || r <= ql) {       return;     }     int m = (l + r) / 2;     get_ans(ql, qr, v * 2, l, m);     get_ans(ql, qr, v * 2 + 1, m, r);   }   void query(int a, int b) {     while (head[a] != head[b]) {       if (depth[head[a]] > depth[head[b]]) {         swap(a, b);       };       get_ans(pos[head[b]], pos[b] + 1);       b = parent[head[b]];     }     if (depth[a] > depth[b]) {       swap(a, b);     };     get_ans(pos[a], pos[b] + 1);   }   int32_t main() {     {       cin.tie(0);       cout.tie(0);       ios_base::sync_with_stdio(0);     };     int m, q;     cin >> n >> m >> q;     for (int i = 1; i < n; i++) {       int v, u;       cin >> v >> u;       v--;       u--;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(0);     hld(0, 0);     for (int i = 0; i < m; i++) {       int tmp;       cin >> tmp;       ;       a[pos[tmp - 1]].push_back(i + 1);     }     build();     while (q--) {       int v, u, a;       cin >> v >> u >> a;       v--;       u--;       ans.clear();       query(v, u);       ;       int k = min(a, ((int32_t)(ans).size()));       cout << k;       for (int i = 0; i < k; i++) {         cout <<     << ans[i];       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b, m = 0, c = 0;     scanf( %d , &n);     while (n--) {       scanf( %d%d , &a, &b);       if (a > b) {         m++;       } else if (a < b) {         c++;       }     }     if (m > c) {       printf( Mishka );     } else if (m < c) {       printf( Chris );     } else {       printf( Friendship is magic!^^ );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -Ofast )   using namespace std;   void rearrange(long long arr[], long long n) {     long long temp[n];     long long small = 0, large = n - 1;     long long flag = true;     for (long long i = 0; i < n; i++) {       if (flag)         temp[i] = arr[large--];       else         temp[i] = arr[small++];       flag = !flag;     }     for (long long i = 0; i < n; i++) arr[i] = temp[i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string a;     cin >> a;     long long k, i;     cin >> k;     long long snow = 0, candy = 0;     for (i = 0; i < a.size(); i++) {       if (a[i] ==  * )         snow++;       else if (a[i] ==  ? )         candy++;     }     long long cha = k - (a.size() - snow - candy);     if (cha > 0) {       if (snow == 0)         cout <<  Impossible ;       else {         string ans =   ;         for (i = a.size() - 1; i >= 0; i--) {           if (a[i] ==  ? ) continue;           if (a[i] ==  * ) {             while (cha > 0) {               ans = ans + a[i - 1];               cha--;             }           } else {             ans = ans + a[i];           }         }         reverse(ans.begin(), ans.end());         cout << ans;       }     } else {       if (a.size() - 2 * snow - 2 * candy > k)         cout <<  Impossible ;       else {         vector<char> v(a.size(),  1 );         for (i = a.size() - 1; i >= 0; i--) {           if (a[i] ==  ?  || a[i] ==  * ) {             i--;           } else {             v[i] = a[i];             k--;           }         }         for (i = a.size() - 1; i >= 0; i--) {           if (k > 0 && (a[i] ==  ?  || a[i] ==  * )) {             k--;             v[i] = a[i - 1];           }         }         for (i = 0; i < a.size(); i++) {           if (v[i] !=  1 ) cout << v[i];         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long pow = 1;     long long L, R;     cin >> L >> R;     while (pow * 10 <= R) pow *= 10;     if (L < pow) {       if (R < pow * 5)         cout << R * (pow * 10 - 1 - R) << endl;       else         cout << pow * 5 * (pow * 5 - 1) << endl;     } else {       if (R >= pow * 5 && L <= pow * 5)         cout << pow * 5 * (pow * 5 - 1) << endl;       else         cout << max(R * (pow * 10 - 1 - R), L * (pow * 10 - 1 - L)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, k, ultim;   map<int, int> cnt;   int main() {     cin >> n >> k;     for (int i = 0; i <= 63; i++)       if ((n >> i) & 1) cnt[i]++, l++;     if (l > k) {       cout <<  No ;       return 0;     }     for (int i = 63; i >= -63; i--) {       if (l + cnt[i] <= k)         l += cnt[i], cnt[i - 1] += cnt[i] * 2, cnt[i] = 0;       else         break;     }     multiset<int> ms;     multiset<int>::iterator it;     for (int i = 63; i >= -63; i--)       for (int j = 0; j < cnt[i]; j++) ms.insert(i);     while (ms.size() < k) {       it = ms.begin();       int u = *it;       ms.erase(it);       ms.insert(u - 1);       ms.insert(u - 1);     }     cout <<  Yes n ;     for (auto it = ms.rbegin(); it != ms.rend(); it++) {       cout << *it <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void in(int &x) {     register int c = getchar();     x = 0;     for (; (c < 48 || c > 57); c = getchar())       ;     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }   }   const int N = 1 << 24;   long long dp[N];   string s[10004];   int main() {     int n, i, j, mask, full = N - 1;     in(n);     for (i = 0; i < n; i++) {       cin >> s[i];       mask = 0;       for (j = 0; j < 3; j++) mask |= 1 << (s[i][j] -  a );       mask ^= full;       dp[mask]++;     }     for (i = 0; i < 24; i++) {       for (mask = N - 1; mask >= 0; mask--)         if (mask & (1 << i)) {           dp[mask ^ (1 << i)] += dp[mask];         }     }     long long ret = 0;     for (i = 0; i < N; i++) ret ^= 1ll * (n - dp[i]) * (n - dp[i]);     printf( %lld n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, rt;   long long a[4005], rmq[4005][20], ch[4005][2], lg2[4005], siz[4005];   long long d[4005][4005];   int getmin(int l, int r) {     int k = lg2[r - l + 1];     return a[rmq[l][k]] < a[rmq[r - (1 << k) + 1][k]] ? rmq[l][k]                                                       : rmq[r - (1 << k) + 1][k];   }   int build(int l, int r) {     int mid = getmin(l, r);     if (l != mid) ch[mid][0] = build(l, mid - 1);     if (r != mid) ch[mid][1] = build(mid + 1, r);     return mid;   }   void dfs(int u) {     if (!u) return;     siz[u] = 1;     dfs(ch[u][0]), dfs(ch[u][1]);     siz[u] += siz[ch[u][0]] + siz[ch[u][1]];     for (int i = 0; i <= siz[ch[u][0]]; i++) {       for (int j = 0; j <= siz[ch[u][1]]; j++) {         chkmax(d[u][i + j], d[ch[u][0]][i] + d[ch[u][1]][j] - 2ll * i * j * a[u]);         chkmax(d[u][i + j + 1], d[ch[u][0]][i] + d[ch[u][1]][j] -                                     2ll * i * j * a[u] + 1ll * (m - 1) * a[u] -                                     2ll * (i + j) * a[u]);       }     }   }   int main() {     n = readint();     m = readint();     for (int i = 1; i <= n; i++) a[i] = readint();     for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;     for (int i = 1; i <= n; i++) rmq[i][0] = i;     for (int i = 1; (1 << i) <= n; i++)       for (int j = 1; j + (1 << i) - 1 <= n; j++)         rmq[j][i] = a[rmq[j][i - 1]] < a[rmq[j + (1 << (i - 1))][i - 1]]                         ? rmq[j][i - 1]                         : rmq[j + (1 << (i - 1))][i - 1];     rt = build(1, n);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) d[i][j] = -(1ll << 60);     d[0][0] = 0;     dfs(rt);     printf( %lld n , d[rt][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int inp() { return 0; }   inline int inp(bool& A) {     if (cin >> A) return 1;     return -1;   }   inline int inp(char& A) { return scanf(  %c , &A); }   inline int inp(int& A) { return scanf( %d , &A); }   inline int inp(float& A) {     if (cin >> A) return 1;     return -1;   }   inline int inp(long long& A) { return scanf( %I64d , &A); }   inline int inp(double& A) { return scanf( %lf , &A); }   inline int inp(char* A) { return scanf( %s , A); }   inline int inp(string& A) {     if (cin >> A) return 1;     return -1;   }   template <class Front, class... Queue>   inline int inp(Front& A, Queue&... B) {     return inp(A) + inp(B...);   }   inline int oup() { return 0; }   inline int oup(bool A) {     if (cout << A) return 1;     return -1;   }   inline int oup(char A) { return printf( %c , A); }   inline int oup(int A) { return printf( %d , A); }   inline int oup(float A) {     if (cout << A) return 1;     return -1;   }   inline int oup(long long A) { return printf( %I64d , A); }   inline int oup(double A) { return printf( %lf , A); }   inline int oup(char* A) { return printf(A); }   inline int oup(const char* A) { return printf( %s , A); }   inline int oup(string& A) {     if (cout << A) return 1;     return -1;   }   template <class Front, class... Queue>   inline int oup(Front A, Queue... B) {     return oup(A) + oup(B...);   }   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {   in:;     int n, m, v;     if (inp(n, m, v) != 3) return;     if (m < n - 1) {       oup( -1 n );       return;     }     if (m > (((n - 1) * (n - 2)) >> 1) + 1) {       oup( -1 n );       return;     }     int tmp = 1;     if (v == 1) ++tmp;     for (int i = 1; i <= n; ++i)       if (i != v) oup(i,    , v,   n );     m -= n - 1;     for (int i = 1; i <= n && m; ++i)       if (i != v && i != tmp)         for (int j = i + 1; j <= n && m; ++j)           if (j != v && j != tmp) {             oup(i,    , j,   n );             --m;           }     goto in;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string ans =   , s;     int n;     cin >> s >> n;     for (int i = 0; i < n; i++) {       string t;       cin >> t;       if (t.length() >= s.length())         if (s == t.substr(0, s.length()))           if (ans ==    || ans > t) ans = t;     }     if (ans ==   )       cout << s << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline bool valid(int64_t x, int64_t y, int64_t n, int64_t m) {     return (x >= 0 && x < n && y >= 0 && y < m);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int64_t n, m, q;     cin >> n >> m >> q;     vector<string> v(n);     for (int64_t i = 0; i < n; ++i) {       cin >> v[i];     }     int64_t dx[4] = {-1, 1, 0, 0};     int64_t dy[4] = {0, 0, -1, 1};     queue<pair<int64_t, int64_t> > qu;     vector<vector<int64_t> > dis(n, vector<int64_t>(m, -1));     for (int64_t i = 0; i < n; ++i) {       for (int64_t j = 0; j < m; ++j) {         int64_t k = 0;         for (; k < 4; ++k) {           int64_t x = i + dx[k], y = j + dy[k];           if (valid(x, y, n, m)) {             if (v[i][j] == v[x][y]) {               break;             }           }         }         if (k < 4) {           qu.push({i, j});           dis[i][j] = 0;         }       }     }     while (!qu.empty()) {       pair<int64_t, int64_t> p = qu.front();       qu.pop();       for (int64_t k = 0; k < 4; ++k) {         int64_t x = p.first + dx[k], y = p.second + dy[k];         if (valid(x, y, n, m) && dis[x][y] == -1) {           dis[x][y] = 1 + dis[p.first][p.second];           qu.push({x, y});         }       }     }     while (q--) {       int64_t i, j, p;       cin >> i >> j >> p;       --i;       --j;       char ans = v[i][j];       if (dis[i][j] > -1 && p - dis[i][j] > 0 && (p - dis[i][j]) % 2 != 0) {         if (ans ==  1 )           ans =  0 ;         else           ans =  1 ;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 998244353;   int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }   int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }   int mul(int a, int b) { return 1ll * a * b % Mod; }   void Add(int &a, int b) { a = add(a, b); }   void Dec(int &a, int b) { a = dec(a, b); }   void Mul(int &a, int b) { a = mul(a, b); }   int ksm(int a, int b) {     int ans = 1;     for (; b; b >>= 1, Mul(a, a))       if (b & 1) Mul(ans, a);     return ans;   }   const int N = 2e5 + 50;   int n, q, ans, p[N];   int sm[N], mt[N];   set<int> S;   int calc(int l, int r) {     int iv = ksm(mt[l - 1], Mod - 2);     int y = mul(mt[r - 1], iv);     int x = 1 + mul(iv, dec(sm[r - 2], sm[l - 1]));     return mul(x, ksm(y, Mod - 2));   }   void era(int x) {     auto r = S.find(x), l = r;     --l, Dec(ans, calc(*l, x));     ++r, Dec(ans, calc(x, *r));     Add(ans, calc(*l, *r));     S.erase(x);   }   void ins(int x) {     auto r = S.insert(x).first, l = r;     --l, Add(ans, calc(*l, x));     ++r, Add(ans, calc(x, *r));     Dec(ans, calc(*l, *r));   }   int main() {     cin >> n >> q;     S.insert(1);     S.insert(n + 1);     int iv = ksm(100, Mod - 2);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]), Mul(p[i], iv);     mt[0] = 1;     for (int i = 1; i <= n; i++)       mt[i] = mul(mt[i - 1], p[i]), sm[i] = add(sm[i - 1], mt[i]);     ans = calc(1, n + 1);     for (int i = 1, x; i <= q; i++) {       scanf( %d , &x);       if (S.find(x) != S.end())         era(x);       else         ins(x);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char inp[1000010];   char out[1000010];   int main() {     int i, j, dot_index, nonzero_index = 0, start, end, p = 0, B;     cin >> inp;     int len = strlen(inp);     dot_index = len;     for (i = 0; inp[i] ==  0  || inp[i] ==  . ; i++)       ;     for (j = len - 1; inp[j] ==  0  || inp[j] ==  . ; j--)       ;     start = i;     end = j;     for (i = 0; i < len; i++) {       if (inp[i] ==  . ) {         dot_index = i;         break;       }     }     out[p++] = inp[start];     if (start != end) out[p++] =  . ;     nonzero_index = start;     for (i = start + 1; i <= end; i++) {       if (inp[i] !=  . ) out[p++] = inp[i];     }     cout << out;     if (dot_index > nonzero_index)       B = dot_index - nonzero_index - 1;     else       B = dot_index - nonzero_index;     if (B) cout <<  E  << B;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   const long double eps = 1e-8;   const int MAXN = 1111;   int n, m;   char g[MAXN][MAXN];   int col[MAXN][MAXN];   int sz[MAXN * MAXN];   char ans[MAXN][MAXN];   bool vis[MAXN][MAXN];   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, 1, 0, -1};   int qx[MAXN * MAXN], qy[MAXN * MAXN];   void bfs(int x0, int y0) {     static int tot = 0;     ;     int l = 1, r = 1;     ++tot;     for (qx[1] = x0, qy[1] = y0, vis[x0][y0] = 1; l <= r; ++l) {       col[qx[l]][qy[l]] = tot;       for (int d = 0; d <= 3; ++d) {         int tx = qx[l] + dx[d];         int ty = qy[l] + dy[d];         if (tx > 0 && tx <= n && ty > 0 && ty <= m && !vis[tx][ty] &&             g[tx][ty] ==  . ) {           vis[tx][ty] = 1;           ++r;           qx[r] = tx;           qy[r] = ty;         }       }     }     sz[tot] = r;     ;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %s , g[i] + 1);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (g[i][j] ==  .  && !vis[i][j]) bfs(i, j);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (g[i][j] ==  . )           ans[i][j] =  . ;         else {           int p[4], t = 0, s = 1;           for (int d = 0; d <= 3; ++d) {             int tx = i + dx[d], ty = j + dy[d];             if (tx > 0 && tx <= n && ty > 0 && ty <= m && g[tx][ty] ==  . ) {               bool ok = 1;               for (int k = 0; k <= t - 1; ++k)                 if (p[k] == col[tx][ty]) {                   ok = 0;                   break;                 }               if (ok) {                 p[t++] = col[tx][ty];                 s += sz[col[tx][ty]];               }             }           }           ans[i][j] =  0  + s % 10;         }     for (int i = 1; i <= n; ++i) printf( %s n , ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   int32_t main()   {       int t;       cin >> t;       while (t--)       {           int n;           cin >> n;          int c=0,i=1;          while(n>0){              c++;              n-=i;              i+=2;          }          cout<<c<<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool vis[100][100];   char g[100][100];   void dfs(int a, int b) {     if (vis[a][b] || a > n || a < 1 || b < 1 || b > n || g[a][b] ==  1 ) return;     vis[a][b] = 1;     dfs(a + 1, b);     dfs(a, b + 1);     dfs(a - 1, b);     dfs(a, b - 1);   }   int dist(pair<int, int> a, pair<int, int> b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   int main() {     cin >> n;     int r1, c1, r2, c2;     cin >> r1 >> c1 >> r2 >> c2;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> g[i][j];       }     }     set<pair<int, int>> a;     set<pair<int, int>> b;     dfs(r1, c1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j]) a.insert({i, j});         vis[i][j] = 0;       }     }     dfs(r2, c2);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (vis[i][j]) b.insert({i, j});       }     }     if (a == b)       cout << 0 << endl;     else {       int s = 10000000;       for (auto x : a) {         for (auto y : b) {           s = min(s, dist(x, y));         }       }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef vector<vector<int>> graph;   ifstream in( buffcraft.in , ios::in);   ofstream out( buffcraft.out , ios::out);   int main() {     double m, R, ans = 0;     cin >> m >> R;     for (int x = 2; x < m; x++)       ans += ((x - 1) * 2 + 2 * sqrt(2.0)) * 2 * (m - x);     ans += 2 * m + (2 + sqrt(2.0)) * 2 * (m - 1);     cout << setprecision(15) << ans / (m * m) * R;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct rect {     int x1, y1, x2, y2;   };   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<rect> v(n);     int minx = 1000000000;     int miny = 1000000000;     for (int i = 0; i < n; ++i) {       cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;       minx = min(minx, v[i].x1);       miny = min(miny, v[i].y1);     }     cout <<  YES  << endl;     for (int i = 0; i < n; ++i) {       int x = (v[i].x1 - minx) % 2;       int y = (v[i].y1 - miny) % 2;       if (x == 0 && y == 0) {         cout << 1;       } else if (x == 1 && y == 0) {         cout << 2;       } else if (x == 0 && y == 1) {         cout << 3;       } else {         cout << 4;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   pair<long long, int> p[200005];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < (n); i++) {       cin >> p[i].first;       p[i].second = i;     }     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         que[3];     for (int cnt = 0; cnt < (2); cnt++) {       for (int i = 0; i < (n); i++) {         int a;         cin >> a;         a--;         que[a].push(p[i]);       }     }     bool used[n];     fill(used, used + n, false);     cin >> m;     for (int i = 0; i < (m); i++) {       int c;       cin >> c;       c--;       while (!que[c].empty() && used[que[c].top().second]) que[c].pop();       if (que[c].empty())         cout << -1;       else {         cout << que[c].top().first;         used[que[c].top().second] = true;         que[c].pop();       }       if (i < m - 1)         cout <<    ;       else         cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       int ans = n / 2;       if (n % 2 == 0) ans -= 1;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h> // Include every standard library   using namespace std;      typedef long long LL;   typedef pair<int, int> pii;   typedef pair<LL, LL> pll;   typedef pair<string, string> pss;   typedef vector<int> vi;   typedef vector<vi> vvi;   typedef vector<pii> vii;   typedef vector<LL> vl;   typedef vector<vl> vvl;      double EPS = 1e-9;   int INF = 1000000005;   long long INFF = 1000000000000000005LL;   double PI = acos(-1);   int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };   int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };      #ifdef TESTING   #define DEBUG fprintf(stderr,  ====TESTING==== n )   #define VALUE(x) cerr <<  The value of   << #x <<   is   << x << endl   #define debug(...) fprintf(stderr, __VA_ARGS__)   #else   #define DEBUG   #define VALUE(x)   #define debug(...)   #endif      #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))   #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))   #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))   #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))   #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))   #define FOREACH(a, b) for (auto&(a) : (b))   #define REP(i, n) FOR(i, 0, n)   #define REPN(i, n) FORN(i, 1, n)   #define MAX(a, b) a = max(a, b)   #define MIN(a, b) a = min(a, b)   #define SQR(x) ((LL)(x) * (x))   #define RESET(a, b) memset(a, b, sizeof(a))   #define fi first   #define se second   #define mp make_pair   #define pb push_back   #define ALL(v) v.begin(), v.end()   #define ALLA(arr, sz) arr, arr + sz   #define SIZE(v) (int)v.size()   #define SORT(v) sort(ALL(v))   #define REVERSE(v) reverse(ALL(v))   #define SORTA(arr, sz) sort(ALLA(arr, sz))   #define REVERSEA(arr, sz) reverse(ALLA(arr, sz))   #define PERMUTE next_permutation   #define TC(t) while (t--)            int main()   {       int line;       cin>>line;          TC(line)       {           LL n;           cin>>n;           if(n==1)cout<<0<<endl;           else if(n==2)cout<<1<<endl;           else if(n==3)cout<<2<<endl;           else           {               if(n&1) cout<<3<<endl;               else cout<<2<<endl;           }       }         }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, rem, k, f = 0, c = 0;     cin >> n;     vector<string> s;     if (n == 0) {       cout <<  zero ;       return 0;     }     while (n != 0) {       rem = n % 10;       n = n / 10;       c++;       if (rem == 0) {         rem = n % 10;         if (rem == 1) {           cout <<  ten ;         } else if (rem == 2) {           cout <<  twenty ;         } else if (rem == 3) {           cout <<  thirty ;         } else if (rem == 4) {           cout <<  forty ;         } else if (rem == 5) {           cout <<  fifty ;         } else if (rem == 6) {           cout <<  sixty ;         } else if (rem == 7) {           cout <<  seventy ;         } else if (rem == 8) {           cout <<  eighty ;         } else if (rem == 9) {           cout <<  ninety ;         }         return 0;       } else if (f == 0) {         f = 1;         if (rem == 1) {           s.push_back( one );         } else if (rem == 2) {           s.push_back( two );         } else if (rem == 3) {           s.push_back( three );         } else if (rem == 4) {           s.push_back( four );         } else if (rem == 5) {           s.push_back( five );         } else if (rem == 6) {           s.push_back( six );         } else if (rem == 7) {           s.push_back( seven );         } else if (rem == 8) {           s.push_back( eight );         } else if (rem == 9) {           s.push_back( nine );         }       } else if (f == 1) {         if (rem == 1) {           if (s[0] ==  one ) {             cout <<  eleven ;             return 0;           } else if (s[0] ==  two ) {             cout <<  twelve ;             return 0;           } else if (s[0] ==  three ) {             cout <<  thirteen ;             return 0;           } else if (s[0] ==  four ) {             cout <<  fourteen ;             return 0;           } else if (s[0] ==  five ) {             cout <<  fifteen ;             return 0;           } else if (s[0] ==  six ) {             cout <<  sixteen ;             return 0;           } else if (s[0] ==  seven ) {             cout <<  seventeen ;             return 0;           } else if (s[0] ==  eight ) {             cout <<  eighteen ;             return 0;           } else if (s[0] ==  nine ) {             cout <<  nineteen ;             return 0;           }         } else if (rem == 2) {           s.push_back( twenty );         } else if (rem == 3) {           s.push_back( thirty );         } else if (rem == 4) {           s.push_back( forty );         } else if (rem == 5) {           s.push_back( fifty );         } else if (rem == 6) {           s.push_back( sixty );         } else if (rem == 7) {           s.push_back( seventy );         } else if (rem == 8) {           s.push_back( eighty );         } else if (rem == 9) {           s.push_back( ninety );         }       }     }     if (c == 1) {       cout << s[0];     } else {       cout << s[1] <<  -  << s[0];     }     return 0;   }