#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[100005];   int sum = 0, m;   char s[10005][105];   void f(int target, int n) {     int i, j, k, l;     m = max((a[n].first - target), ((sum - n * target) / 2));     for (i = 0; i < m; i++) {       for (j = 0; j < n; j++) s[i][j] =  0 ;       s[i][j] =   0 ;     }     int total = sum - n * target;     for (i = n, j = 0, k = 0, l = 1; l <= total || k < 2;) {       s[j][a[i].second - 1] =  1 ;       a[i].first--;       if (a[i].first <= target && i > 1) i--;       j++;       l++;       if (j >= m) {         j = 0;         k++;       }     }     return;   }   int main() {     int i, j, k, l, n;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       int val;       scanf( %d , &val);       a[i] = make_pair(val, i);       sum += a[i].first;     }     sort(a + 1, a + n + 1);     for (i = a[1].first; i >= 1; i--) {       if ((sum - n * i) / 2 >= (a[n].first - i)) break;     }     f(i, n);     cout << i << endl << m << endl;     for (i = 0; i < m; i++) printf( %s n , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 310;   int a[N][N], n, p[N], vis[N];   void dfs(int v) {     vis[v] = 1;     for (int i = 1; i <= n; i++) {       if (a[v][i] && !vis[i]) {         dfs(i);       }     }   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &p[i]);     }     scanf(  n );     char ch;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         ch = getchar();         if (ch ==  0 ) {           a[i][j] = 0;         } else {           a[i][j] = 1;         }       }       scanf(  n );     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         vis[j] = 0;       }       dfs(i);       int pos = -1;       for (j = i; j <= n; j++) {         if (vis[j]) {           if ((pos == -1) || (p[pos] > p[j])) {             pos = j;           }         }       }       swap(p[pos], p[i]);     }     for (i = 1; i <= n; i++) {       printf( %d  , p[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int inf = 0x3f3f3f3f;   const long long int INF = 1e15;   const int mod = 1e9 + 7;   const int maxn = 2e3 + 5;   int cas = 1;   int sum[maxn];   vector<int> v;   map<int, int> mp;   void solve() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       memset(sum, 0, sizeof(sum));       v.clear();       mp.clear();       for (int i = 1; i <= n; i++) {         int u;         scanf( %d , &u);         sum[i] = sum[i - 1] + u;       }       sort(sum + 1, sum + 1 + n);       int len = unique(sum + 1, sum + 1 + n) - (sum + 1);       for (int i = 1; i <= k; i++) {         int u;         scanf( %d , &u);         for (int j = 1; j <= len; j++) {           v.push_back(u - sum[j]);         }       }       sort(v.begin(), v.end());       for (int i = 0; i < v.size(); i++) {         mp[v[i]]++;       }       int res = 0;       for (int i = 0; i < v.size(); i++) {         if (mp[v[i]] >= k) {           res++;           mp[v[i]] = 0;         }       }       printf( %d n , res);     }   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAX_N = 200002;   int n;   int a[MAX_N], t[MAX_N];   void solve() {     vector<pair<int, int>> v;     for (int i = 0; i < n; ++i) v.emplace_back(a[i], t[i]);     sort(v.begin(), v.end());     ll cur = -1;     int idx = 0;     multiset<ll> eq;     ll ans = 0, sum = 0;     while (idx < n || !eq.empty()) {       if (eq.empty()) cur = v[idx].first;       while (idx < n && v[idx].first == cur) {         sum += v[idx].second;         eq.insert(-v[idx].second);         idx++;       }       sum += *eq.begin();       eq.erase(eq.begin());       ans += sum;       cur++;     }     cout << ans <<   n ;   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> t[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 605;   int n;   vector<int> g[N];   map<vector<int>, int> memo;   int ask(vector<int> &vs) {     if (int((vs).size()) <= 1) return 0;     sort((vs).begin(), (vs).end());     if (memo.count(vs)) return memo[vs];     cout <<  ?   << int((vs).size()) << endl;     for (int x = (0), qwerty = (int((vs).size())); x < qwerty; x++) {       if (x) cout <<    ;       cout << vs[x];     }     cout << endl;     int v;     cin >> v;     return memo[vs] = v;   }   pair<int, int> f(vector<int> vs1, vector<int> vs2, bool b) {     if (int((vs1).size()) == 1 && int((vs2).size()) == 1) {       if (!b) {         vector<int> vs = {vs1[0], vs2[0]};         int v = ask(vs);         if (!v) return {-1, -1};       }       return {vs1[0], vs2[0]};     }     vector<int> vs = vs1;     for (int v : vs2) vs.push_back(v);     int A, B, AB, abo;     if (!b)       A = ask(vs1), B = ask(vs2), AB = ask(vs), abo = AB - A - B;     else       abo = 1;     if (!abo) return {-1, -1};     bool rev = 0;     if (int((vs2).size()) == 1) swap(vs1, vs2), rev = 1;     vector<int> vs2_0, vs2_1;     for (int x = (0), qwerty = (int((vs2).size()) / 2); x < qwerty; x++)       vs2_0.push_back(vs2[x]);     for (int x = (int((vs2).size()) / 2), qwerty = (int((vs2).size()));          x < qwerty; x++)       vs2_1.push_back(vs2[x]);     pair<int, int> tmp = f(vs1, vs2_0, 0);     if (tmp.first == -1) tmp = f(vs1, vs2_1, 1);     if (rev) swap(tmp.first, tmp.second);     return tmp;   }   vector<int> cs[2];   int dep[N], par[N];   void dfs(int u, int p, int c) {     cs[c].push_back(u);     for (int v : g[u])       if (v != p) par[v] = u, dep[v] = dep[u] + 1, dfs(v, u, !c);   }   pair<int, int> solve(vector<int> vs) {     vector<int> vs1, vs2;     for (int x = (0), qwerty = (int((vs).size()) / 2); x < qwerty; x++)       vs1.push_back(vs[x]);     for (int x = (int((vs).size()) / 2), qwerty = (int((vs).size())); x < qwerty;          x++)       vs2.push_back(vs[x]);     int A = ask(vs1), B = ask(vs2), AB = ask(vs), ABo = AB - A - B;     if (A) return solve(vs1);     if (B) return solve(vs2);     assert(ABo > 0);     return f(vs1, vs2, 0);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<int> nused, used;     for (int x = (1), qwerty = (n + 1); x < qwerty; x++) nused.push_back(x);     random_shuffle((nused).begin(), (nused).end());     used.push_back(nused.back());     nused.pop_back();     for (int x = (1), qwerty = (n); x < qwerty; x++) {       pair<int, int> tmp = f(used, nused, 0);       int idx = -1;       for (int i = (0), qwerty = (int((nused).size())); i < qwerty; i++)         if (nused[i] == tmp.second) idx = i;       assert(idx != -1);       swap(nused.back(), nused[idx]);       nused.pop_back();       used.push_back(tmp.second);       sort((used).begin(), (used).end());       g[tmp.first].push_back(tmp.second);       g[tmp.second].push_back(tmp.first);     }     dfs(1, 0, 0);     if (ask(cs[0]) == 0 && ask(cs[1]) == 0) {       cout <<  Y   << int((cs[0]).size()) << endl;       for (int x = (0), qwerty = (int((cs[0]).size())); x < qwerty; x++) {         if (x) cout <<    ;         cout << cs[0][x];       }       cout << endl;     } else {       if (ask(cs[0]) == 0) swap(cs[0], cs[1]);       pair<int, int> tmp = solve(cs[0]);       assert(tmp.first != -1);       vector<int> vs1, vs2;       int u = tmp.first, v = tmp.second;       while (u != v) {         if (dep[u] < dep[v]) {           vs2.push_back(v);           v = par[v];         } else {           vs1.push_back(u);           u = par[u];         }       }       vs1.push_back(u);       reverse((vs1).begin(), (vs1).end());       for (int v : vs2) vs1.push_back(v);       cout <<  N   << int((vs1).size()) << endl;       for (int x = (0), qwerty = (int((vs1).size())); x < qwerty; x++) {         if (x) cout <<    ;         cout << vs1[x];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int cnt2[maxn];   int cnt[maxn];   struct trie {     int nxt[maxn][26], fail[maxn], g[maxn];     int ed[maxn];     int rt, L;     int newnode() {       memset(nxt[L], -1, sizeof nxt[L]);       ed[L++] = 0;       return L - 1;     }     void init() {       L = 0;       rt = newnode();     }     void insert(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         if (nxt[now][buf[i] -  a ] == -1) nxt[now][buf[i] -  a ] = newnode();         now = nxt[now][buf[i] -  a ];       }       ed[now]++;     }     void build() {       queue<int> q;       fail[rt] = rt;       g[rt] = rt;       for (int i = 0; i < 26; ++i) {         if (nxt[rt][i] == -1)           nxt[rt][i] = rt;         else {           fail[nxt[rt][i]] = rt;           g[nxt[rt][i]] = rt;           q.push(nxt[rt][i]);         }       }       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = 0; i < 26; ++i) {           if (nxt[now][i] == -1)             nxt[now][i] = nxt[fail[now]][i];           else {             fail[nxt[now][i]] = nxt[fail[now]][i];             if (ed[fail[nxt[now][i]]]) {               g[nxt[now][i]] = fail[nxt[now][i]];             } else               g[nxt[now][i]] = g[fail[nxt[now][i]]];             q.push(nxt[now][i]);           }         }       }     }     void query(const string& buf) {       int len = buf.size();       int now = rt;       for (int i = 0; i < len; ++i) {         now = nxt[now][buf[i] -  a ];         int tmp = now;         while (tmp != rt) {           cnt[i] += ed[tmp];           tmp = g[tmp];         }       }     }   } a, b;   string t;   string s[maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     int n;     cin >> n;     a.init();     for (int i = 1; i <= n; ++i) {       cin >> s[i];       a.insert(s[i]);     }     a.build();     a.query(t);     memcpy(cnt2, cnt, sizeof cnt);     memset(cnt, 0, sizeof cnt);     b.init();     for (int i = 1; i <= n; ++i) {       reverse(s[i].begin(), s[i].end());       b.insert(s[i]);     }     b.build();     reverse(t.begin(), t.end());     b.query(t);     long long ans = 0;     for (int i = 0; i < t.size() - 1; ++i) {       ans += 1ll * cnt2[i] * cnt[t.size() - i - 2];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     cin >> a >> b;     if (a > b + 1 or (a + 1) * 2 < b) {       cout << -1;       return 0;     }     string s;     s.push_back( 1 );     int n = a + b, ok = 1;     for (int i = 1; i < n; i++) {       if (ok and b > a) {         s.push_back( 1 );         ok = 0;         b--;       } else {         if (s[i - 1] ==  0 ) {           ok = 1;           s.push_back( 1 );           b--;         } else {           s.push_back( 0 );           a--;         }       }     }     if (a == 1) s.pop_back(), s =  0  + s;     cout << s;   }


#include <iostream>   #include <iomanip>   #include <cstdio>   #include <cstdlib>   #include <algorithm>   #include <cmath>   #include <vector>   #include <set>   #include <map>   #include <unordered_set>   #include <unordered_map>   #include <queue>   #include <ctime>   #include <cassert>   #include <complex>   #include <string>   #include <cstring>   #include <chrono>   #include <random>   #include <bitset>      using namespace std;   #define ll long long   #define pi pair<int,int>   #define pll pair<ll,ll>   #define ld  long double        const int INF = 1e9 + 7;   long long MOD;            const int N = 405;      long long dp[N][N];   long long ncr[N][N];   long long p2[N];      void solve(){       int n;       cin >> n >> MOD;       /*           Trivial observation : If the number of segments of `x` is k and the sizes are x_1 , x_2 , ... , x_k.            Then, the number of ways is X! / (x_1! x_2!... x_k!) 2^(x_1 - 1) 2^(x_2 - 1) ..        */              p2[0] = 1LL;       for(int i = 1; i < N; i++){           p2[i] = p2[i - 1] * 2LL % MOD;        }       ncr[1][0] = ncr[1][1] = 1;          for(int i = 2; i < N; i++){           for(int r = 0; r <= i; r++){               if(r == 0 || r == i) ncr[i][r] = 1;               else ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % MOD;           }       }              dp[1][1] = 1;          for(int i = 2; i <= n; i++){           for(int manual = 0; manual <= i; manual++){               for(int last = 1; last <= min(manual , i); last++){                   if(i - last - 1 >= 0){                       dp[i][manual] += dp[i - last - 1][manual - last] * ncr[manual][last] % MOD * p2[last - 1] % MOD;                       dp[i][manual] %= MOD;                   } else{                       assert(i == last);                       dp[i][manual] = p2[i - 1];                   }               }           }       }          long long ans = 0;       for(int manual = 1; manual <= n; manual++){           ans += dp[n][manual]; ans %= MOD;       }       cout << ans << endl;   }      int main(){       ios :: sync_with_stdio(false);        cin.tie(nullptr);        cout.tie(nullptr);       int tt = 1;       #ifdef SIEVE       construct();       #endif       for(int tc = 1; tc <= tt; tc++){           // cout <<  Case #  << tc <<  :  ;           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a = 100, c = 20, d = 10, e = 5;     long long int note, n, rem;     while (scanf( %lld , &n) != EOF) {       note = n / a;       rem = n % a;       note = note + (rem / c);       rem = rem % c;       note = note + (rem / d);       rem = rem % d;       note = note + (rem / e) + (rem % e);       cout << note << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 2000000009;   const int Max = 1000007;   const double PI = acos(-1.0);   long long nc2(long long n) { return (n * (n - 1)) / 2; }   map<long long, long long> mp1, mp2;   map<pair<long long, long long>, long long> mp3;   int main() {     long long i, j, k, l, temp, t, n, m, caseno = 0, ans;     string str;     while (cin >> n) {       mp1.clear();       mp2.clear();       mp3.clear();       for (i = 0; i < n; i++) {         cin >> j >> k;         if (mp1.find(j) == mp1.end()) mp1[j] = 0;         if (mp2.find(k) == mp2.end()) mp2[k] = 0;         mp1[j]++;         mp2[k]++;         pair<long long, long long> ttmp = make_pair(j, k);         if (mp3.find(ttmp) == mp3.end()) mp3[ttmp] = 0;         mp3[ttmp]++;       }       map<long long, long long>::iterator it;       ans = 0;       for (it = mp1.begin(); it != mp1.end(); ++it) {         ans += nc2(it->second);       }       for (it = mp2.begin(); it != mp2.end(); ++it) {         ans += nc2(it->second);       }       map<pair<long long, long long>, long long>::iterator itr;       for (itr = mp3.begin(); itr != mp3.end(); ++itr) {         ans -= nc2(itr->second);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int lis(vector<int>& a) {     if (a.empty()) return 0;     int n = a.size();     int INF = 1000;     vector<int> b(n + 1, INF);     b[0] = -INF;     for (int i = 0; i < n; ++i) {       int val = a[i];       int pos = upper_bound(b.begin(), b.end(), val) - b.begin();       b[pos] = min(b[pos], val);     }     int res = 0;     for (int j = n; j >= 0; --j)       if (b[j] != INF) {         res = j;         break;       }     return res;   }   int brute(int n, int t, vector<int> a) {     for (int i = 0; i < t - 1; ++i)       for (int j = 0; j < n; ++j) a.push_back(a[j]);     int res = lis(a);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n, t;     cin >> n >> t;     vector<int> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     int t0 = 100;     int t1 = 101;     int res = -1;     if (t <= t0) {       res = brute(n, t, a);     } else {       int res0 = brute(n, t0, a);       int res1 = brute(n, t1, a);       res = res1 + (t - t1) * (res1 - res0);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 1;   int n, ans[51], t[51];   long long k, fac[51], dp[51];   bool v[51];   long long mul(long long x, long long y) {     return !x ? 0 : inf / x < y ? inf : x * y;   }   long long cal(int x) { return x < 2 ? 1 : fac[x - 2]; }   void work(int l, int r) {     for (auto i = (l); i <= (r); ++i) t[i] = i, v[i] = 0;     ans[l] = r;     v[r] = 1;     swap(t[l], t[r]);     for (auto i = (l + 1); i <= (r - 1); ++i) {       for (auto j = (l); j <= (r); ++j)         if (!v[j] && i != t[j]) {           if (mul(fac[r - i - 1], dp[n - r]) >= k) {             ans[i] = j;             v[j] = 1;             int x = t[i], y = t[j];             t[x] = y;             t[y] = x;             break;           } else             k -= mul(fac[r - i - 1], dp[n - r]);         }     }     ans[r] = t[r];   }   void sol() {     scanf( %d%lld , &n, &k);     if (dp[n] < k) return (void)printf( -1 n );     int nw = 1;     while (nw <= n)       for (auto i = (1); i <= (n - nw + 1); ++i) {         if (mul(cal(i), dp[n - nw - i + 1]) >= k) {           work(nw, nw + i - 1);           nw += i;           break;         } else           k -= mul(cal(i), dp[n - nw - i + 1]);       }     for (auto i = (1); i <= (n); ++i) printf( %d%c , ans[i], i == n ?   n  :    );   }   int main() {     int t;     fac[0] = 1;     dp[0] = 1;     for (auto i = (1); i <= (50); ++i) fac[i] = mul(fac[i - 1], i);     for (auto i = (1); i <= (50); ++i)       for (auto j = (1); j <= (i); ++j)         dp[i] = min(inf, dp[i] + mul(dp[i - j], cal(j)));     scanf( %d , &t);     for (auto i = (1); i <= (t); ++i) sol();   }


# include <bits/stdc++.h>   # define sz(x) (int)x.size()   # define f first   # define s second      using namespace std;   using ll = long long;      void solve() {     int n, a, b;     cin >> n >> a >> b;     int x, y;     cin >> x >> y;     int c = n - max(a, b) + abs(a - b) / 2;     int d = min(a, b) + abs(a - b) / 2;     if (d >= x && c >= y) cout <<  YES n ;     else cout <<  NO n ;   }       int main(){     ios_base::sync_with_stdio(false);     cin.tie(0);     int t; cin >> t; while (t--)      solve();   }


#include <bits/stdc++.h>   using namespace std;   int a[1010], ans[1010];   int main() {     int n, i, cur = 0, x, y, l1 = 1, l2 = 1;     cin >> n;     for (i = 1; i < n; i++) {       cin >> x >> y;       if (x > y) swap(x, y);       a[x]++;       if (y != n) {         cout <<  NO ;         return 0;       }     }     for (i = 1; i < n; i++) {       cur += a[i];       if (cur > i) {         cout <<  NO ;         return 0;       }     }     cout <<  YES  << endl;     ans[1] = n;     for (i = n - 1; i; i--) {       if (!a[i]) {         while (ans[l2]) l2++;         ans[l2] = i;         continue;       }       l1 += a[i];       ans[l1] = i;     }     for (i = 1; i < n; i++) cout << ans[i] <<     << ans[i + 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)3e5 + 10;   const int inf = (int)1e9 + 5;   const long long llinf = (long long)1e18 + 5;   long long a[maxn];   long long d, i, n, k, l, query, first, second, pruf, pruf2, j, m, p, last, sum,       h, z, r;   int main() {     cin >> n;     for (i = 1; i < n + 1; i++) cin >> a[i];     string x;     for (i = 0; i < n + 1; i++) {       getline(cin, x);       k = 0;       if (i != 0) {         for (int re = 0; re < x.size(); re++) {           if ((x[re] ==  a ) or (x[re] ==  e ) or (x[re] ==  i ) or               (x[re] ==  o ) or (x[re] ==  u ) or (x[re] ==  y ))             k++;         }         if (k != a[i]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:32000000 )   const int nil = -1;   using namespace std;   inline bool read(int& val) { return scanf( %d , &val) != -1; }   inline bool read(long long& val) { return scanf( %I64d , &val) != -1; }   inline bool read(double& val) { return scanf( %lf , &val) != -1; }   inline bool read(char* val) { return scanf( %s , val) != -1; }   template <class T1, class T2>   inline bool read(T1& a, T2& b) {     return read(a) && read(b);   }   template <class T1, class T2, class T3>   inline bool read(T1& a, T2& b, T3& c) {     return read(a) && read(b) && read(c);   }   template <class T1, class T2, class T3, class T4>   inline bool read(T1& a, T2& b, T3& c, T4& d) {     return read(a) && read(b) && read(c) && read(d);   }   template <class T1, class T2, class T3, class T4, class T5>   inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e) {     return read(a) && read(b) && read(c) && read(d) && read(e);   }   const int N = 1111111;   const long long mod = 1000000007;   char str[N];   long long cnt[N];   int main() {     read(str);     int n = strlen(str);     cnt[0] = 0;     long long sum = 0;     long long pow2 = 1;     for (int i = 0, _ = (n); i < _; ++i) {       if (str[i] ==  a ) {         pow2 = pow2 * 2 % mod;       } else {         sum = (sum + pow2 - 1) % mod;       }     }     cout << sum % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   const int M = 1e6 + 500;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int BASE = 31337;   const int LOG = 18;   const int OFF = (1 << LOG);   const double EPS = 1e-9;   const double PI = 3.1415926535;   int n, k, bio[2 * M + 10];   vector<int> v;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       v.push_back(x);       bio[x]++;     }     for (int i = 1; i < 2 * M; i++) {       bio[i] += bio[i - 1];     }     int sol = 0;     for (int i = 0; i < v.size(); i++) {       if ((bio[v[i] + k] - bio[v[i]]) == 0) sol++;     }     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005], f[100005], cnt[100005], ans[100005];   int main() {     int i, j, k, l, n, m;     cin >> n >> m;     for (i = 1; i <= n; i++) {       cin >> j;       if (!cnt[j]) f[j] = i;       cnt[j]++;     }     int flag = 1;     l = 1;     for (i = 1; i <= m; i++) {       cin >> j;       if (flag)         if (!cnt[j])           flag = 0;         else if (cnt[j] > 1)           flag = 2;         else           ans[l++] = f[j];     }     if (l == m + 1) {       cout <<  Possible n ;       for (i = 1; i <= m; i++) cout << ans[i] <<    ;       cout << endl;     } else if (!flag)       cout <<  Impossible n ;     else       cout <<  Ambiguity n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     cin >> n >> x >> y;     cout << max((int)ceil((double)y * n / 100) - x, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[200010];   struct Node {     int sz, l;   } c[200010];   bool cmp(const Node &p, const Node &q) { return (p.sz - p.l) > (q.sz - q.l); }   void dfs(int x, int fa) {     c[x].l = c[fa].l + 1;     for (int i = 0; i < (int)e[x].size(); i++) {       int y = e[x][i];       if (y == fa) continue;       dfs(y, x);       c[x].sz += c[y].sz;     }     c[x].sz++;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     k = n - k;     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);     }     dfs(1, 0);     sort(c + 1, c + n + 1, cmp);     long long ans = 0;     for (int i = 1; i <= k; i++) {       ans += (c[i].sz - c[i].l);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long n, q;       cin >> n >> q;       while (q--) {         long long x;         cin >> x;         long long c = 1;         for (long long int i = 0; i < 63; i++)           if ((x + c - 2 * n) % (2 * c) == 0) {             cout << ((x + c - 2 * n) / (2 * c)) + n <<   n ;             break;           } else             c *= 2;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n <= 2)       cout <<  -1 ;     else if (n == 3)       cout <<  210 ;     else {       int mod = 1;       for (int i = 1; i < n; ++i) mod = (mod * 10) % 210;       if (n > 3) cout <<  1 ;       for (int i = 0; i < n - 4; ++i) cout <<  0 ;       if (210 - mod < 100) cout <<  0 ;       cout << 210 - mod;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int d[(100010)];   const long long int mod = 1e9 + 7;   int main() {     int n, m;     cin >> n >> m;     d[0] = d[1] = 1;     int k = max(n, m);     for (int i = 2; i <= k; i++) {       d[i] = (d[i - 1] + d[i - 2]) % mod;     }     long long int ans = (d[n] + d[m] - 1) % mod;     ans = (ans * 2) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:256000000 )   FILE *stream;   const int INF = 1e9 + 7;   const long long INFL = (long long)1e18 + 1;   const int SIZE = 2e5 + 10;   const int TSIZE = 1e3 + 10;   const long double eps = 0.000001;   const long long MOD = 1e9 + 7;   char POW(char a, char b) {     if (b == 0) return 1;     char cur = POW(a, b / 2);     if (b % 2 == 0)       return cur * cur;     else       return cur * cur * a;   }   long long gcd(long long &x, long long &y, long long a, long long b) {     if (a == 0) {       y = 1;       x = 0;       return abs(b);     }     long long x1 = 0, y1 = 0;     long long d = gcd(x1, y1, b % a, a);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return abs(b);     }     long long d = gcd(b % a, a);     return d;   }   void accept() {     int n, k, j = 2;     cin >> n >> k;     vector<int> ans;     while (n > 1 && ans.size() < k) {       while (n % j == 0 && ans.size() < k - 1) {         n /= j;         ans.push_back(j);       }       if (n > 1 && ans.size() == k - 1) {         ans.push_back(n);         break;       }       j++;     }     if (ans.size() == k) {       for (int i = 0; i < k; i++) {         cout << ans[i] <<    ;       }     } else {       cout << -1;     }   }   void solution() {     long long t = 1;     for (long long i = 0; i < t; i++) {       accept();     }     return;   }   void test() {     cout <<  100000 n ;     for (int k = 0; k < 100000 - 1; k++) {       cout << k + 1 <<    ;     }     cout <<  100000 n ;   }   int main() {     srand(time(0));     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pow_mod(long long int a, long long int b) {     long long int res = 1;     while (b != 0) {       if (b & 1) {         res = (res * a) % 1000000007;       }       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   void solve() {     long long int n, m, k;     cin >> n >> m >> k;     long long int a[n + 1][m];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) cin >> a[i][j];     }     for (long long int j = 0; j < m; j++) a[n][j] = 0;     long long int dp[n + 1][m];     memset(dp, 0, sizeof(dp));     long long int sum[n + 1][m], mx_p[n + 1][m], mx_s[n + 1][m];     memset(sum, 0, sizeof(sum));     memset(mx_s, 0, sizeof(mx_s));     memset(mx_p, 0, sizeof(mx_p));     for (long long int i = 0; i <= n; i++) {       for (long long int j = 0; j < m; j++) {         if (j == 0)           sum[i][j] = a[i][j];         else           sum[i][j] = a[i][j] + sum[i][j - 1];       }     }     for (long long int i = 1; i <= n; i++) {       for (long long int j = 0; j < m; j++) {         if (j - k + 1 >= 0) {           if (i == 0) {             dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL);           } else {             dp[i][j] = sum[i][j] - (j - k >= 0 ? sum[i][j - k] : 0LL);             dp[i][j] += sum[i - 1][j] - (j - k >= 0 ? sum[i - 1][j - k] : 0LL);             if (i != 1) {               long long int res = 0;               if (j + k < m) res = mx_s[i - 1][j + k];               if (j - k >= 0) res = max(res, mx_p[i - 1][j - k]);               for (long long int xx = j; xx > max(-1LL, j - k); xx--)                 res = max(res, dp[i - 1][xx] - sum[i - 1][xx] +                                    (j - k >= 0 ? sum[i - 1][j - k] : 0LL));               for (long long int xx = j + 1; xx < min(m, j + k); xx++)                 res = max(res, dp[i - 1][xx] - sum[i - 1][j] +                                    (xx - k >= 0 ? sum[i - 1][xx - k] : 0LL));               dp[i][j] += res;             }           }           mx_p[i][j] = dp[i][j];           if (j - 1 >= 0) mx_p[i][j] = max(mx_p[i][j], mx_p[i][j - 1]);         }       }       for (long long int j = m - 1; j >= 0; j--) {         if (j == m - 1)           mx_s[i][j] = dp[i][j];         else           mx_s[i][j] = max(mx_s[i][j + 1], dp[i][j]);       }     }     long long int ans = 0;     for (long long int j = 0; j < m; j++) {       ans = max(ans, dp[n][j]);     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T = 1;     cin >> T;     while (T--) {       string s;       int x;       cin >> s >> x;       string ans;       int n = s.size();       for (int i = 0; i < n; i++) ans.push_back( 1 );       for (int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           if (i - x >= 0) ans[i - x] =  0 ;           if (i + x < n) ans[i + x] =  0 ;         }       }       bool f = 1;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) {           bool t = 0;           if (i + x < n && ans[i + x] ==  1 ) t = 1;           if (i - x >= 0 && ans[i - x] ==  1 ) t = 1;           if (!t) f = 0;         }       }       if (f)         cout << ans << endl;       else         cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 1;   int n, m;   vector<int> A[MAXN];   int d[MAXN];   void dfs(int nod) {     for (int i = 0; i < A[nod].size(); i++) {       int v = A[nod][i];       if (d[v] == 0) {         d[v] = d[nod] + 1;         dfs(v);       }     }   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       A[a].push_back(b);       A[b].push_back(a);     }     d[1] = 1;     dfs(1);     int u = max_element(d + 1, d + n + 1) - d;     fill(d + 1, d + n + 1, 0);     d[u] = 1;     dfs(u);     int sol = *max_element(d + 1, d + n + 1);     sol--;     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7, mod = 1e9 + 7;   int dp[N], sum[N], i, n, m, j, k, nxt[N], v[N];   char a[N], b[N];   int main() {     for (scanf( %s%s , a + 1, b + 1), n = strlen(a + 1), m = strlen(b + 1), i = 2;          i <= m; ++i) {       while (b[j + 1] != b[i] && j) j = nxt[j];       if (b[j + 1] == b[i]) j++;       nxt[i] = j;     }     for (i = 1, j = 0; i <= n; ++i) {       while (b[j + 1] != a[i] && j) j = nxt[j];       if (b[j + 1] == a[i]) j++;       if (j == m) v[i] = 1, j = nxt[j];     }     for (i = 1, j = -1; i <= n; ++i) {       dp[i] = dp[i - 1];       if (v[i]) j = i - m + 1;       if (j != -1) dp[i] += sum[j - 1] + j, dp[i] %= mod;       sum[i] = (sum[i - 1] + dp[i]) % mod;     }     return 0 * printf( %d n , dp[n]);   }


#include <bits/stdc++.h>   using namespace std;   long long int vis[1005][1005];   char a[1005][1005];   pair<pair<long long int, long long int>, long long int> fuck[1005][1005];   long long int dfs(long long int i, long long int j,                     pair<long long int, long long int> par) {     vis[i][j] = 1;     long long int ret = 1;     if (a[i + 1][j] ==  .  && vis[i + 1][j] == 0) ret += dfs(i + 1, j, par);     if (a[i - 1][j] ==  .  && vis[i - 1][j] == 0) ret += dfs(i - 1, j, par);     if (a[i][j + 1] ==  .  && vis[i][j + 1] == 0) ret += dfs(i, j + 1, par);     if (a[i][j - 1] ==  .  && vis[i][j - 1] == 0) ret += dfs(i, j - 1, par);     fuck[i][j] = make_pair(par, ret);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int i, j;       for (i = 0; i < 1005; i++) {         for (j = 0; j < 1005; j++) {           vis[i][j] = 0;           a[i][j] =  * ;         }       }       long long int n, m;       cin >> n >> m;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           cin >> a[i][j];         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (a[i][j] ==  .  && vis[i][j] == 0) {             dfs(i, j, make_pair(i, j));           }         }       }       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (a[i][j] ==  . ) {             cout <<  . ;           } else {             map<pair<long long int, long long int>, long long int> ma;             if (a[i + 1][j] ==  . ) {               ma[fuck[i + 1][j].first] =                   fuck[fuck[i + 1][j].first.first][fuck[i + 1][j].first.second]                       .second;             }             if (a[i - 1][j] ==  . ) {               ma[fuck[i - 1][j].first] =                   fuck[fuck[i - 1][j].first.first][fuck[i - 1][j].first.second]                       .second;             }             if (a[i][j + 1] ==  . ) {               ma[fuck[i][j + 1].first] =                   fuck[fuck[i][j + 1].first.first][fuck[i][j + 1].first.second]                       .second;             }             if (a[i][j - 1] ==  . ) {               ma[fuck[i][j - 1].first] =                   fuck[fuck[i][j - 1].first.first][fuck[i][j - 1].first.second]                       .second;             }             long long int ans = 1;             for (auto it : ma) {               ans += it.second;             }             cout << ans % 10;           }         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, N = 1e5;   int cnt[200], seq[200][17], fac[20], inv[20], ifac[20], popcnt[N], ln[N][17],       tmp[N][17], ans[N], finalans[N], w[N], n, K, c;   int qmod1(const int &x) { return x >= mod ? x - mod : x; }   int qmod2(const int &x) { return x + (x >> 31 & mod); }   int qpower(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) ans = 1ll * ans * a % mod;     return ans;   }   void prework(int n) {     fac[0] = ifac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;     inv[1] = 1;     for (int i = 2; i <= n; i++)       inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;     for (int i = 1; i <= n; i++) ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;     for (int i = 1; i < (1 << 16); i++) popcnt[i] = popcnt[i >> 1] + (i & 1);   }   struct Basis {     int size, a[20], id[20];     void clear() {       for (int i = 0; i < c; i++) a[i] = 0, id[i] = -1;       size = 0;     }     void ins(int x) {       for (int i = c - 1; i >= 0; i--)         if (x >> i & 1) {           if (!a[i]) {             a[i] = x, id[i] = size++;             return;           }           x ^= a[i];         }     }     int get(int x) {       int ans = 0;       for (int i = c - 1; i >= 0; i--)         if (a[i] && (x >> i & 1)) ans ^= 1 << id[i], x ^= a[i];       return ans;     }     int iget(int x) {       int ans = 0;       for (int i = c - 1; i >= 0; i--)         if (a[i] && (x >> id[i] & 1)) ans ^= a[i];       return ans;     }   } xxj;   int main() {     scanf( %d%d%d , &n, &K, &c);     prework(K);     int wsum = 0;     int seqn = 0;     map<unsigned long long, int> mp;     for (int i = 1; i <= n; i++) {       scanf( %d , w + i);       wsum ^= w[i];       int tmpseq[17];       for (int j = 1; j <= K; j++) tmpseq[j] = w[i] ^ (w[i] - j);       unsigned long long hsh = 0;       for (int j = 1; j <= K; j++) hsh = hsh * 19260817 + tmpseq[j] + 233;       if (!mp[hsh]) {         ++seqn;         copy(tmpseq + 1, tmpseq + K + 1, seq[seqn] + 1);         mp[hsh] = seqn;         cnt[seqn] = 1;       } else         cnt[mp[hsh]]++;     }     for (int T = 1, tS[17]; T <= seqn; T++) {       xxj.clear();       for (int i = 1; i <= K; i++) xxj.ins(seq[T][i]);       int B = xxj.size;       for (int i = 1; i <= K; i++) tS[i] = xxj.get(seq[T][i]);       for (int S = 0; S < (1 << B); S++) fill(tmp[S], tmp[S] + K + 1, 0);       for (int i = 1; i <= K; i++) {         for (int S = 0; S < (1 << B); S++) {           unsigned long long t = 0;           for (int j = 1; j <= i; j++)             t += 1ull * tmp[S ^ tS[j]][i - j] * ifac[j];           tmp[S][i] = qmod2(-(int)(t % mod));         }         tmp[tS[i]][i] = qmod1(tmp[tS[i]][i] + ifac[i - 1]);       }       for (int S = 0, rS; S < (1 << B); S++) {         rS = xxj.iget(S);         for (int i = 1; i <= K; i++)           ln[rS][i] = (ln[rS][i] + 1ull * cnt[T] * tmp[S][i]) % mod;       }     }     for (int i = 1, tmp[17]; i < (1 << c); i <<= 1)       for (int j = 0; j < (1 << c); j += i << 1)         for (int k = 0; k < i; k++) {           int *a = ln[j + k], *b = ln[i + j + k];           copy(b, b + K + 1, tmp);           for (int t = 0; t <= K; t++)             b[t] = qmod2(a[t] - b[t]), a[t] = qmod1(a[t] + tmp[t]);         }     for (int S = 0, f[17], g[17]; S < (1 << c); S++) {       copy(ln[S], ln[S] + K + 1, f);       g[0] = 1;       for (int i = 1; i <= K; i++) {         unsigned long long t = 0;         for (int j = 1; j <= i; j++) t += 1ull * f[j] * g[i - j];         g[i] = t % mod * inv[i] % mod;       }       ans[S] = 1ll * g[K] * fac[K] % mod;     }     for (int i = 1; i < (1 << c); i <<= 1)       for (int j = 0; j < (1 << c); j += i << 1)         for (int k = 0; k < i; k++) {           int t = ans[i + j + k];           ans[i + j + k] = qmod2(ans[j + k] - t),                       ans[j + k] = qmod1(ans[j + k] + t);         }     int iv = mod - ((mod - 1) >> c);     iv = 1ll * iv * qpower(n, mod - 1 - K) % mod;     for (int i = 0; i < (1 << c); i++) ans[i] = 1ll * ans[i] * iv % mod;     for (int i = 0; i < (1 << c); i++) finalans[i ^ wsum] = ans[i];     for (int i = 0; i < (1 << c); i++) printf( %d  , finalans[i]);     puts(  );   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 45000;   int h, lgn, n, t, r, x, y, a[N], dis[N], lp[N], dp[N][17];   vector<pair<int, int> > e1, e2;   vector<int> g[N];   bool mark[N];   int lg(int xx) {     int l = 0;     while (xx > 1) {       xx /= 2;       ++l;     }     return l;   }   void bfs(int d, vector<int> &v) {     vector<int> w;     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < g[v[i]].size(); j++) {         if (dis[g[v[i]][j]] == INT32_MAX) {           dis[g[v[i]][j]] = d + 1;           w.push_back(g[v[i]][j]);         }       }     }     if (!w.empty()) bfs(d + 1, w);   }   void dfs(int v) {     mark[v] = true;     for (int i = 0; i < g[v].size(); i++) {       if (!mark[g[v][i]]) {         dis[g[v][i]] = dis[v] + 1;         dp[g[v][i]][0] = v;         for (int j = 1; j <= lgn; j++)           dp[g[v][i]][j] = dp[dp[g[v][i]][j - 1]][j - 1];         dfs(g[v][i]);       }     }   }   int par(int v, int p) {     while (p > 0) {       int pp = p & (-p);       v = dp[v][lg(pp)];       p -= pp;     }     return v;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> h >> t >> r >> x;     int hh, tt;     for (int i = 0; i < x; i++) {       cin >> hh >> tt;       e1.push_back({hh, tt});     }     cin >> y;     for (int i = 0; i < y; i++) {       cin >> hh >> tt;       e2.push_back({hh, tt});     }     for (int i = r; i >= 0; i--) {       for (int j = r - i; j >= 0; j--) {         for (int k = 0; k < min(x, i); k++) {           if ((i - k - 1 + e1[k].first + j + e1[k].second) <= r)             g[(r + 1) * i + j].push_back((i - k - 1 + e1[k].first) * (r + 1) + j +                                          e1[k].second);         }         for (int k = 0; k < min(y, j); k++) {           if ((i + e2[k].first + j - k - 1 + e2[k].second) <= r)             g[(r + 1) * i + j].push_back((i + e2[k].first) * (r + 1) + j - k - 1 +                                          e2[k].second);         }       }     }     n = (r + 1) * (r + 1);     lgn = lg(n);     int s = h * (r + 1) + t;     fill(dis, dis + n, INT32_MAX);     vector<int> v;     v.push_back(s);     dis[s] = 0;     bfs(0, v);     if (dis[0] != INT32_MAX) {       cout <<  Ivan n  << dis[0];       return 0;     }     for (int i = 0; i < n; i++) fill(dp[i], dp[i] + 17, s);     dfs(s);     for (int i = 0; i < n; i++) {       if (dis[i] != INT32_MAX) {         for (int j = 0; j < g[i].size(); j++) {           if (dis[g[i][j]] <= dis[i] &&               g[i][j] == par(i, dis[i] - dis[g[i][j]])) {             cout <<  Draw ;             return 0;           }         }       }     }     for (int i = 0; i < n; i++) {       if (dis[i] != INT32_MAX) {         for (int j = 0; j < g[i].size(); j++) ++a[g[i][j]];       }     }     vector<int> w;     w.push_back(s);     while (!w.empty()) {       int u = w[w.size() - 1];       w.pop_back();       for (int i = 0; i < g[u].size(); i++) {         --a[g[u][i]];         lp[g[u][i]] = max(lp[g[u][i]], lp[u] + 1);         if (a[g[u][i]] == 0) w.push_back(g[u][i]);       }     }     int ans = 0;     for (int i = 0; i < n; i++) ans = max(ans, lp[i]);     cout <<  Zmey n  << ans + 1;   }


#include <bits/stdc++.h>   typedef long long ll;   typedef long double ld;   #define fr(i, a, b) for (ll i = a; i < b; i++)   #define rf(i, a, b) for (ll i = a; i >= b; i--)   typedef std::vector<long long> vi;   #define F first   #define S second   #define fast                             ios_base::sync_with_stdio(0);        cin.tie(0);                          cout.tie(0);   #define mod 1000000007   #define PB push_back   #define MP make_pair   #define PI 3.14159265358979323846   #define all(a) a.begin(), a.end()   #define mx(a) *max_element(all(a))   #define mn(a) *min_element(all(a))   const ll INF = LLONG_MAX / 2;   const ll N = 2e5 + 1;   using namespace std;   void solve()   {       ll n, c;       cin >> n >> c;       ll a[n], b[n];       fr(i, 0, n)       {           cin >> a[i];       }       fr(i, 1, n)               cin >>           b[i];       ll ans = INF, prevcoins = 0, prevdays = 0;       fr(i, 0, n - 1)       {           if (c <= prevcoins)               ans = min(prevdays, ans);           ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans);           // cout << prevdays + (c - prevcoins + a[i] - 1) / a[i] <<    ;           if (prevcoins >= b[i + 1])           {               prevcoins = prevcoins - b[i + 1];               prevdays++;           }           else           {               prevdays = prevdays + (b[i + 1] + a[i] - 1 - prevcoins) / a[i] + 1;               prevcoins = ((b[i + 1] + a[i] - 1 - prevcoins) / a[i]) * a[i] + prevcoins - b[i + 1];           }           // cout << prevdays <<     << prevcoins <<   n ;       }       ll i = n - 1;       ans = min(prevdays + (c - prevcoins + a[i] - 1) / a[i], ans);       // cout <<   n ;       cout << ans <<   n ;   }   int main()   {       fast;       ll t = 1;       std::cin >> t;       while (t--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a > b) return a;     return b;   }   long long int min(long long int a, long long int b) {     if (a < b) return a;     return b;   }   long long int msb(long long int n) {     long long int ans;     for (long long int i = 31; i >= 0; i--)       if ((1LL << i) & (n)) {         ans = i;         break;       }     return ans;   }   long long power(long long x, int y, int p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modFact(long long int n, long long int p) {     if (n >= p) return 0;     long long int result = 1;     for (long long int i = 1; i <= n; i++) result = (result * i) % p;     return result;   }   long long modInverse(long long n, int p) { return power(n, p - 2, p); }   long long nCrModPFermat(long long n, int r, int p) {     if (r == 0) return 1;     long long fac[n + 1];     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   vector<long long int> primes;   void sieve(long long int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long int p = 2; p <= n; p++) {       if (prime[p] == true) {         for (long long int i = p * p; i <= n; i += p) prime[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (prime[p]) primes.push_back(p);   }   vector<long long int> adj[100001], rev[100001];   bool vis[100001], recur[100001];   void init(long long int n) {     for (long long int i = 0; i <= n; i++) {       adj[i].clear();       rev[i].clear();       vis[i] = false;       recur[i] = false;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, x, k;     cin >> n >> x >> k;     long long int ar[n];     for (int i = 0; i < n; i++) cin >> ar[i];     if (x > k)       cout << n << endl;     else {       int ct = 0;       for (int i = 0; i < n; i++) {         if (ar[i] <= x) ct++;       }       double ans = double(ct) / 2.0;       cout << ceil(ans) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long oo = 1LL << 55;   const int MAX_N = 100005;   const int MAX_M = 100005;   const int MAX_P = 105;   template <class T>   class Deque {    public:     Deque() { Clear(); }     void Clear() { front = 1, back = 0; }     void PushBack(const T x) { values[++back] = x; }     void PopBack() { --back; }     void PopFront() { ++front; }     T Front() const { return values[front]; }     T Back() const { return values[back]; }     bool Empty() const { return front > back; }     int Size() const { return back - front + 1; }     T &operator[](const int index) { return values[front + index]; }       private:     T values[MAX_M];     int front, back;   };   class Line {    public:     long long m, n;     Line() {}     Line(const long long m, const long long n) {       this->m = m;       this->n = n;     }     long long Value(const long long x) const { return m * x + n; }     static double Intersect(const Line &L1, const Line &L2) {       return (1.0 * L2.n - L1.n) / (1.0 * L1.m - L2.m);     }   };   int N, M, P, D[MAX_N], T[MAX_M];   long long SumT[MAX_M], DP[2][MAX_M], Solution;   void Preprocess() {     T[0] = 0;     sort(T + 1, T + M + 1);     SumT[0] = 0;     for (int i = 1; i <= M; ++i) SumT[i] = SumT[i - 1] + T[i];   }   void Solve() {     Preprocess();     DP[0][0] = 0;     for (int i = 1; i <= M; ++i) DP[0][i] = 1LL * T[i] * i - SumT[i];     for (int p = 2; p <= P; ++p) {       Deque<Line> deq;       for (int i = p; i <= M; ++i) {         Line L = Line(-(i - 1), SumT[i - 1] + DP[0][i - 1]);         while (deq.Size() > 1 &&                Line::Intersect(deq[deq.Size() - 1], L) <                    Line::Intersect(deq[deq.Size() - 2], deq[deq.Size() - 1]))           deq.PopBack();         deq.PushBack(L);         while (deq.Size() > 1 && Line::Intersect(deq[0], deq[1]) < 1.0 * T[i])           deq.PopFront();         DP[1][i] = deq.Front().Value(T[i]) + 1LL * i * T[i] - SumT[i];       }       memcpy(DP[0], DP[1], sizeof(DP[1]));     }     Solution = DP[0][M];   }   void Read() {     cin >> N >> M >> P;     D[1] = 0;     for (int i = 2; i <= N; ++i) {       cin >> D[i];       D[i] += D[i - 1];     }     for (int i = 1; i <= M; ++i) {       int h, t;       cin >> h >> t;       T[i] = t - D[h];     }   }   void Print() { cout << Solution <<   n ; }   int main() {     Read();     Solve();     Print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 355001;   const int SQRTN = 320;   const int LOGN = 20;   const long double PI = acos(-1);   const long double TAU = 2 * PI;   long long nk, n, k, a, b;   vector<long long> first, last;   long long gcd(long long x, long long b) {     if (b == 0) return x;     return gcd(b, x % b);   }   signed main() {     cin >> n >> k >> a >> b;     nk = n * k;     first.push_back(a);     first.push_back(k - a);     last.push_back(b);     last.push_back(k - b);     for (int i = 0; i < n; i++) {       last.push_back((last[0] + nk - i * k) % nk);       last.push_back((last[1] + nk - i * k) % nk);       last.push_back((i * k + last[0]) % nk);       last.push_back((i * k + last[1]) % nk);     }     long long mn = 100000000000000ll, mx = 0;     for (int i = 0; i < last.size(); i++) {       mn = min(mn, nk / gcd(nk, abs(last[i] - first[0])));       mx = max(mx, nk / gcd(nk, abs(last[i] - first[0])));       mx = max(mx, nk / gcd(nk, abs(last[i] - first[1])));       mn = min(mn, nk / gcd(nk, abs(last[i] - first[1])));     }     cout << mn <<     << mx << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long R[10 << 10][1 << 10];   int A[10 << 10];   int n, m, g, r;   int main() {     cin >> n >> m;     int i, j;     for (i = (0); i < (m); ++i) cin >> A[i];     cin >> g >> r;     sort(A, A + m);     for (i = (0); i < (m); ++i)       for (j = (0); j < (g + 1); ++j) R[i][j] = (1LL << 60);     R[0][0] = 0;     deque<pair<long long, pair<int, int>>> q;     q.push_front(make_pair(R[0][0], pair<int, int>(0, 0)));     long long res = (1LL << 60);     while (!q.empty()) {       int pos = q.front().second.first;       int rem = q.front().second.second;       long long val = q.front().first;       q.pop_front();       if (R[pos][rem] != val) continue;       if (pos == m - 1) res = min(res, val);       int p[] = {pos - 1, pos + 1};       int d[] = {pos == 0 ? -1 : A[pos] - A[pos - 1],                  pos + 1 == m ? -1 : A[pos + 1] - A[pos]};       for (i = (0); i < (2); ++i)         if (0 <= p[i] && p[i] < m && d[i] > 0 && rem + d[i] <= g) {           int pos2 = p[i];           int rem2 = rem + d[i];           int val2 = val + d[i];           if (R[pos2][rem2] > val2) {             R[pos2][rem2] = val2;             q.push_front(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2)));           }         }       if (rem == g) {         int pos2 = pos;         int rem2 = 0;         int val2 = val + r;         if (R[pos2][rem2] > val2) {           R[pos2][rem2] = val2;           q.push_back(make_pair(R[pos2][rem2], pair<int, int>(pos2, rem2)));         }       }     }     if (res == (1LL << 60)) res = -1;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b;       cin >> a >> b;       int moves = 0;       if (a == b) {         cout << 0 <<   n ;         continue;       } else if (a < b) {         int needed = b - a;         moves = needed % 2 == 1 ? 1 : 2;       } else {         int needed = a - b;         moves = needed % 2 == 0 ? 1 : 2;       }       cout << moves <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct lady {     int b, i, r;   } a[500005];   bool operator<(const lady& a, const lady& b) {     if (a.b != b.b) return a.b > b.b;     if (a.i != b.i) return a.i < b.i;     return a.r < b.r;   }   int n;   void inp() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].b);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].i);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].r);   }   set<int> s;   int x[500005], m;   void ready() {     for (int i = 1; i <= n; ++i) s.insert(a[i].i);     for (typeof((s).begin()) it = (s).begin(); it != (s).end(); ++it)       x[++m] = *it;   }   int bi[500005], ans;   inline void update(int u, int val) {     u = lower_bound(x + 1, x + m + 1, u) - x;     for (; u; u &= u - 1) bi[u] = max(bi[u], val);   }   inline int get(int u) {     u = lower_bound(x + 1, x + m + 1, u) - x;     int res = 0;     for (; u <= m; u += u & -u) res = max(res, bi[u]);     return res;   }   void solve() {     ready();     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       ans += get(a[i].i + 1) > a[i].r;       update(a[i].i, a[i].r);     }     printf( %d n , ans);   }   int main() {     srand(time(NULL));     inp();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, s;     cin >> n >> s;     vector<int> g(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u]++;       g[v]++;     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (g[i] == 1) {         cnt++;       }     }     double ans = s;     if (n > 2) {       ans = 2.0 * s / cnt;     }     cout.precision(10);     cout << fixed << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   double r, v, l;   double tim(double p1, double p2) {     double rem = p2 - p1;     double k = int(rem / l);     rem = rem - k * l;     double le = 0, ri = 1e9, mid;     for (int I = 1; I <= 200; I++) {       mid = (le + ri) / 2.0;       if (v * mid + 2 * sin(v * mid / (2 * r)) * r >= rem) {         ri = mid;       } else {         le = mid;       }     }     return mid + double(k * l) / v;   }   int main() {     scanf( %d%lf%lf , &n, &r, &v);     l = 3.141592653589 * r * 2;     for (int i = 1; i <= n; i++) {       int p1, p2;       scanf( %d%d , &p1, &p2);       printf( %.10f n , float(tim(double(p1), double(p2))));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 58;   const int MAXQ = 5000;   int n;   int bto[MAXN - 1], rto[MAXN - 1];   int nq;   int qat[MAXQ];   char qlast[MAXQ][MAXN - 1 + 1];   long long qans[MAXQ];   int dr[MAXN - 1];   void mlt64(unsigned long long x, unsigned long long y, unsigned long long& hi,              unsigned long long& lo) {     unsigned long long xhi = x >> 32, xlo = x & ((1ULL << 32) - 1), yhi = y >> 32,                        ylo = y & ((1ULL << 32) - 1);     unsigned long long zlo = xlo * ylo, tmp = xhi * ylo + (zlo >> 32),                        zmi = tmp & ((1ULL << 32) - 1), zhi = tmp >> 32;     zmi += xlo * yhi, zhi += xhi * yhi;     lo = (zlo & (1ULL << 32) - 1) + ((zmi & (1ULL << 32) - 1) << 32),     hi = zhi + (zmi >> 32);   }   template <int k>   struct MersenneMod64bit {     constexpr static unsigned long long mod() { return (1ULL << k) - 1; }     unsigned long long val;     MersenneMod64bit() { val = 0; }     MersenneMod64bit(unsigned long long _val) {       val = (_val & mod()) + (_val >> k);       if (val >= mod()) val -= mod();     }     const unsigned long long operator()() const { return val; }     MersenneMod64bit& operator+=(const MersenneMod64bit& other) {       val += other.val;       if (val >= mod()) val -= mod();       return *this;     }     MersenneMod64bit& operator-=(const MersenneMod64bit& other) {       if (val >= other.val)         val -= other.val;       else         val += mod() - other.val;       return *this;     }     MersenneMod64bit& operator*=(const MersenneMod64bit& other) {       unsigned long long hi, lo;       mlt64(val, other.val, hi, lo);       val = (lo & mod()) + (lo >> k) + (hi << (64 - k));       if (val >= mod()) val -= mod();       return *this;     }     MersenneMod64bit& operator/=(const MersenneMod64bit& other) {       return *this *= other.inverse();     }     MersenneMod64bit operator*(const MersenneMod64bit& other) const {       return MersenneMod64bit(*this) *= other;     }     bool operator==(const MersenneMod64bit& other) { return val == other.val; }     bool operator!=(const MersenneMod64bit& other) { return val != other.val; }     MersenneMod64bit pw(unsigned long long n) const {       MersenneMod64bit ret = 1, x = *this;       while (true) {         if (n & 1) ret *= x;         if ((n >>= 1) == 0) return ret;         x *= x;       }     }     MersenneMod64bit inverse() const { return pw(mod() - 2); }   };   template <int k>   ostream& operator<<(ostream& stream, const MersenneMod64bit<k>& number) {     return stream << number();   }   template <typename T>   struct Matrix {     int n, m;     vector<vector<T>> A;     Matrix(int n) : n(n), m(n) { A = vector<vector<T>>(n, vector<T>(m, 0)); }     Matrix(int n, int m) : n(n), m(m) {       A = vector<vector<T>>(n, vector<T>(m, 0));     }     vector<T>& operator[](int i) { return A[i]; }     void gaussjord() {       int R = n, C = m, r = 0, c = 0;       while (r < R && c < C) {         {           int rr = r;           while (rr < R && A[rr][c] == 0) ++r;           if (rr >= R) {             ++c;             continue;           }           if (rr != r)             for (int cc = (c); cc < (C); ++cc) swap(A[r][cc], A[rr][cc]);         }         if (A[r][c] != 1) {           T x = 1;           x /= A[r][c];           for (int cc = (c + 1); cc < (C); ++cc) A[r][cc] *= x;           A[r][c] = 1;         }         for (int rr = (0); rr < (R); ++rr)           if (rr != r && A[rr][c] != 0) {             for (int cc = (c + 1); cc < (C); ++cc)               A[rr][cc] -= A[rr][c] * A[r][cc];             A[rr][c] = 0;           }         ++r, ++c;       }     }     Matrix inverse() {       assert(n == m);       Matrix B(n, 2 * n);       for (int i = (0); i < (n); ++i)         for (int j = (0); j < (n); ++j)           B[i][j] = A[i][j], B[i][n + j] = i == j ? 1 : 0;       B.gaussjord();       for (int i = (0); i < (n); ++i) assert(B[i][i] == 1);       Matrix ret(n);       for (int i = (0); i < (n); ++i)         for (int j = (0); j < (n); ++j) ret[i][j] = B[i][n + j];       return ret;     }     Matrix operator*(const Matrix& other) const {       assert(m == other.n);       Matrix ret(n, other.m);       for (int i = (0); i < (n); ++i)         for (int j = (0); j < (other.m); ++j)           for (int k = (0); k < (m); ++k) ret[i][j] += A[i][k] * other.A[k][j];       return ret;     }     vector<T> operator*(const vector<T>& vec) const {       assert(m == ((int)(vec).size()));       vector<T> ret(n, 0);       for (int i = (0); i < (n); ++i)         for (int k = (0); k < (m); ++k) ret[i] += A[i][k] * vec[k];       return ret;     }     void print() {       for (int i = (0); i < (n); ++i) {         for (int j = (0); j < (m); ++j) {           if (j != 0) cout <<    ;           cout << A[i][j];         }         cout <<   n ;       }     }   };   using M61 = MersenneMod64bit<61>;   using Mat = Matrix<M61>;   using Vec = vector<M61>;   bool dec(unsigned long long& a, unsigned long long b) {     if (a < b) return false;     a -= b;     return true;   }   bool solveslinearequation(int q, const Vec& x) {     for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1;     bool ok = true;     vector<unsigned long long> bal(n, 0);     for (int i = (0); i < (n - 1); ++i) bal[i] += 2 * x[i]() + dr[i];     ++bal[qat[q]];     for (int i = (0); i < (n - 1); ++i) {       ok = ok && dec(bal[bto[i]], x[i]());       ok = ok && dec(bal[rto[i]], x[i]() + dr[i]);     }     ok = ok && dec(bal[0], 1);     for (int i = (0); i < (n); ++i) ok = ok && bal[i] == 0;     return ok;   }   bool visitedstatesgotodestination(int q, const Vec& x) {     for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1;     vector<bool> visited(n - 1);     for (int i = (0); i < (n - 1); ++i) visited[i] = x[i]() > 0 || dr[i] > 0;     vector<vector<int>> radj(n);     for (int i = (0); i < (n); ++i)       if (qlast[q][i] ==  B )         radj[bto[i]].push_back(i);       else         radj[rto[i]].push_back(i);     queue<int> queue;     vector<bool> todest(n, false);     todest[qat[q]] = true, queue.push(qat[q]);     while (!queue.empty()) {       int at = queue.front();       queue.pop();       for (int i = (0); i < (((int)(radj[at]).size())); ++i) {         int to = radj[at][i];         if (!todest[to]) todest[to] = true, queue.push(to);       }     }     for (int i = (0); i < (n); ++i)       if (visited[i] && !todest[i]) return false;     return true;   }   void solve() {     Mat A(n - 1);     for (int i = (0); i < (n - 1); ++i) {       A[i][i] -= 2;       if (bto[i] != n - 1) A[bto[i]][i] += 1;       if (rto[i] != n - 1) A[rto[i]][i] += 1;     }     Mat Ainv = A.inverse();     for (int q = (0); q < (nq); ++q) {       for (int i = (0); i < (n - 1); ++i) dr[i] = qlast[q][i] ==  B  ? 0 : 1;       Vec y(n - 1);       y[0] -= 1;       y[qat[q]] += 1;       for (int i = (0); i < (n - 1); ++i) {         y[i] += dr[i];         if (rto[i] != n - 1) y[rto[i]] -= dr[i];       }       Vec x = Ainv * y;       bool ok = solveslinearequation(q, x) && visitedstatesgotodestination(q, x);       if (!ok)         qans[q] = -1;       else {         qans[q] = 0;         for (int i = (0); i < (n - 1); ++i) qans[q] += 2 * x[i]() + dr[i];       }     }   }   void run() {     scanf( %d , &n);     for (int i = (0); i < (n - 1); ++i)       scanf( %d%d , &bto[i], &rto[i]), --bto[i], --rto[i];     scanf( %d , &nq);     for (int i = (0); i < (nq); ++i) scanf( %d%s , &qat[i], qlast[i]), --qat[i];     solve();     for (int i = (0); i < (nq); ++i) printf( %lld n , qans[i]);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double PI = 3.14159265359;   vector<long long> primes;   void GeneratingPrimes(int top) {     vector<bool> p(top + 1, 1);     p[0] = p[1] = 0;     for (int i = 2; i <= sqrt(top); i++) {       if (!p[i]) continue;       if (p[i]) {         for (int j = i * i; j <= top; j += i) {           p[j] = 0;         }       }     }     for (int i = 0; i < top + 1; i++)       if (p[i]) primes.push_back(i);   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   void EXTgcd(long long a, long long b, int& x0, int& y0) {     if (b == 0) {       x0 = 1, y0 = 0;       return;     }     EXTgcd(b, a % b, x0, y0);     long long x1 = y0;     long long y1 = x0 - (a / b) * y0;     x0 = x1;     y0 = y1;   }   unsigned long long power(unsigned long long x, unsigned long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   double dist(double a, double b, double x, double y) {     return sqrt(pow(a - x, 2) + pow(b - y, 2));   }   double dist3(double a, double b, double c, double x, double y, double z) {     return sqrt(pow(a - x, 2) + pow(b - y, 2) + pow(c - z, 2));   }   int xadd[9] = {1, -1, 0, 1, -1, 0, 1, -1, 0};   int yadd[9] = {1, -1, 0, -1, 0, 1, 0, 1, -1};   long long const N = 10007;   long long mod = 1e9 + 7;   int n;   long long x[N], y[N];   long long c[N], k[N];   int setsNum;   int siz[N], par[N];   void build(int n) {     setsNum = 0;     for (int i = 0; i < n; i++) {       par[i] = i;       siz[i] = 1;     }   }   int findSet(int x) {     if (par[x] == x) return x;     par[x] = findSet(par[x]);     return par[x];   }   bool sameSet(int x, int y) { return (par[findSet(x)] == par[findSet(y)]); }   void unionSets(int x, int y) {     int X = findSet(x), Y = findSet(y);     if (X == Y) return;     if (c[X] < c[Y]) {       par[Y] = par[X];     } else {       par[X] = par[Y];     }   }   vector<vector<long long>> sortedE;   int state[N];   vector<pair<int, int>> e;   int main() {     cin >> n;     long long ans = 0, conn = 0, st = n;     for (int i = 0; i < n; i++) state[i] = 1;     build(n + 100);     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (int i = 0; i < n; i++) cin >> c[i], ans += c[i];     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         vector<long long> t;         t.push_back((k[i] + k[j]) * (abs(x[i] - x[j]) + abs(y[i] - y[j])));         t.push_back(i);         t.push_back(j);         sortedE.push_back(t);       }     sort(sortedE.begin(), sortedE.end());     for (int i = 0; i < sortedE.size(); i++) {       if (!sameSet(sortedE[i][1], sortedE[i][2]) &&           sortedE[i][0] + min(c[par[sortedE[i][1]]], c[par[sortedE[i][2]]]) <               c[par[sortedE[i][1]]] + c[par[sortedE[i][2]]]) {         ans -= max(c[par[sortedE[i][1]]], c[par[sortedE[i][2]]]);         if (c[par[sortedE[i][1]]] > c[par[sortedE[i][2]]]) {           state[par[sortedE[i][1]]] = 0;         } else           state[par[sortedE[i][2]]] = 0;         ans += sortedE[i][0];         unionSets(sortedE[i][1], sortedE[i][2]);         e.push_back(make_pair(sortedE[i][1], sortedE[i][2]));         conn++, st--;       }     }     cout << ans << endl << st << endl;     for (int i = 0; i < n; i++)       if (state[i]) printf( %d  , i + 1);     cout << endl << conn << endl;     for (int i = 0; i < e.size(); i++) {       printf( %d %d n , e[i].first + 1, e[i].second + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, q;     string s;     bool can = true;     vector<string> vec;     int aux = 0;     int pos = 0;     cin >> n >> p >> q;     cin >> s;     aux = n;     if (n % p == 0) {       cout << n / p << endl;       for (int i = 0; i < n; i += p) {         cout << s.substr(i, p) << endl;       }     } else if (n % q == 0) {       cout << n / q << endl;       for (int i = 0; i < n; i += q) {         cout << s.substr(i, q) << endl;       }     } else {       while (((aux % q != 0)) && pos < n) {         vec.push_back(s.substr(pos, p));         pos += p;         aux -= p;         if (aux < 0) {           can = false;         }       }       if (can) {         while (pos < n) {           vec.push_back(s.substr(pos, q));           pos += q;         }         cout << vec.size() << endl;         for (int i = 0; i < vec.size(); i++) {           cout << vec[i] << endl;         }       } else {         cout << -1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     long long int i, a[n + 1];     for (i = 1; i <= n; i++) cin >> a[i];     if (a[1] == a[n]) {       cout << 1 << endl;       return;     }     if (k == 1 && a[1] != a[n]) {       cout << -1 << endl;       return;     }     long long int c = 0;     for (i = 1; i < n; i++) {       if (a[i] != a[i + 1]) c++;     }     long long int ans = ceil(c * 1.0 / (k - 1));     if (ans < 0) ans = 1;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   long long mod(long long n) {     if (n < 0) {       return (n % MOD + MOD) % MOD;     } else {       if (n < MOD)         return n;       else if (n < 2 * MOD)         return n - MOD;       else         return n % MOD;     }   }   long long fp(long long a, long long p) {     long long ans = 1, cur = a;     for (long long i = 0; (1 << i) <= p; ++i) {       if ((p >> i) & 1) ans = mod(ans * cur);       cur = mod(cur * cur);     }     return ans;   }   long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); }   const long long N = 101;   long long m[N][N], ans[N][N], t[N][N];   void add(long long a[N][N], long long b[N][N]) {     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         t[i][j] = 0;       }     }     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         for (long long k = 0; k < N; ++k) {           t[i][j] = mod(t[i][j] + a[i][k] * b[k][j]);         }       }     }     for (long long i = 0; i < N; ++i) {       for (long long j = 0; j < N; ++j) {         a[i][j] = t[i][j];       }     }   }   void pw(long long p) {     for (long long i = 0; i < N; ++i) ans[i][i] = 1;     for (long long i = 0; (1 << i) <= p; ++i) {       if ((p >> i) & 1) add(ans, m);       add(m, m);     }   }   bool a[N];   long long cnt[2];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       ++cnt[a[i]];     }     long long l = cnt[0];     long long r = n - l;     long long op = n * (n - 1) / 2;     for (long long l1 = 0; l1 <= cnt[0] && l1 <= cnt[1]; ++l1) {       long long l0 = l - l1;       long long r0 = cnt[0] - l0;       long long r1 = cnt[1] - l1;       m[l1][l1] = op;       if (l1) {         m[l1][l1 - 1] = mod(l1 * r0);         m[l1][l1] = mod(m[l1][l1] - m[l1][l1 - 1]);       }       m[l1][l1 + 1] = mod(l0 * r1);       m[l1][l1] = mod(m[l1][l1] - m[l1][l1 + 1]);     }     pw(k);     long long sum = 0;     for (long long i = 0; i < l; ++i) sum += a[i];     cout << dv(ans[sum][0], fp(op, k)) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b, ans;     cin >> a >> b;     int x = (a / 4) * 4;     int i = x, val = 0;     while (i < a) {       val = val ^ i;       i++;     }     if (val == b) {       ans = a;     } else if ((val ^ a) == b) {       ans = a + 2;     } else {       ans = a + 1;     }     cout << ans << endl;     return;   }   int main() {     int t;     cin >> t;     while (t > 0) {       solve();       t--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   typedef long double ld;   typedef string str;      #define pb push_back   #define ppp pop_back   #define pii pair<int,int>   #define fi first   #define se second   #define stie std::tie   #define vec vector   #define forn(i, l, r) for (int i=l; i<=r; i++)   #define forb(i, r, l) for (int i=r; i>=l; i--)   #define emp empty   #define beg begin   #define ins insert   #define cle clear   #define era erase   #define que queue   #define pque priority_queue   #define mset multiset   #define deq deque   #define sta stack   #define con const   #define rsz resize   #define ass assign   #define lowb lower_bound   #define uppb upper_bound      template<class T> void mini(T& a, T b) { a = min(a, b); }   template<class T> void maxi(T& a, T b) { a = max(a, b); }   template<class T1, class T2> ostream& operator<<(ostream &out, pair<T1, T2> a) { return out << a.first <<     << a.second; }   template<class T> ostream& operator<<(ostream& out, vector<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T> ostream& operator<<(ostream& out, set<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T> ostream& operator<<(ostream& out, multiset<T> a) { for (auto& i : a) out << i <<    ; return out; }   template<class T1, class T2> ostream& operator<<(ostream& out, map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; }   template<class T1, class T2> ostream& operator<<(ostream& out, unordered_map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; }   template<class T> ostream& operator<<(ostream& out, queue<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop(); } return out; }   template<class T> ostream& operator<<(ostream& out, deque<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop_front(); } return out; }   template<class T> ostream& operator<<(ostream& out, priority_queue<T> a) { while (!a.empty()) { out << a.top() <<   n ; a.pop(); } return out; }   template<class T> void out(T a) { cout << a << endl; }   template<class T1, class T2> void out(T1 a, T2 b) { cout << a <<     << b << endl; }   template<class T1, class T2, class T3> void out(T1 a, T2 b, T3 c) { cout << a <<     << b <<     << c << endl; }   template<class T1, class T2, class T3, class T4> void out(T1 a, T2 b, T3 c, T4 d) { cout << a <<     << b <<     << c <<     << d << endl; }   template<class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); }   template<class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] <<    ; cout << endl; }   void out() { cout <<  OK  << endl; }   template<class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); }   template<class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); }   template<class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; }   clock_t start_time; void start_timer() { start_time = clock(); }   double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }   #if __SIZEOF_INT128__ >= 16   typedef __int128 LL;   istream& operator>>(istream& in, __int128& a) { int64_t b; cin >> b; a = b; return in; }   ostream& operator<<(ostream& out, const __int128 a) {    unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c =  0123456789 [b % 10]; b /= 10; } while (b);    if (a < 0) { --c; *c =  - ; } int len = end(buf) - c; out.rdbuf()->sputn(c, len); return out;   }   #endif      con int N = 3005;      set<int> g[N];   int p[N];   int d[N];   set<pii> used;   vec<int> path;   int comps;      void init(int n) {    comps = n;    forn(i, 1, n) {     p[i] = i;     d[i] = 0;    }    used.cle();    path.cle();   }      int find(int v) {    if (p[v] == v) return v;    return p[v] = find(p[v]);   }      void unite(int u, int v) {    u = find(u);    v = find(v);    if (u == v) return;    if (d[u] < d[v]) swap(u, v);    p[v] = u;    if (d[u] == d[v]) d[u]++;    comps--;   }      bool connected() {    return comps == 1;   }      void rest(int i, set<int>& star) {    for (int j : star) {     g[i].ins(j);     g[j].ins(i);    }   }      void dfs(int v) {    for (int u : g[v]) {     if (used.count({min(u, v), max(u, v)})) continue;     used.ins({min(u, v), max(u, v)});     dfs(u);     path.pb(u);    }   }      void Solve() {    int n, m;    cin >> n >> m;    forn(i, 1, m) {     int u, v;     cin >> u >> v;     g[u].ins(v);     g[v].ins(u);    }    forn(i, 1, n) {     set<int> all;     for (int j : g[i]) {      if (g[j].size() & 1) all.ins(j);     }     vec<int> cand(all.begin(), all.end());     cand.pb(0);     for (int can : cand) {      set<int> star = all;      star.era(can);      for (int j : star) {       g[i].era(j);       g[j].era(i);      }      init(n);      set<int> odd;      forn(v, 1, n) {       for (int u : g[v]) {        unite(v, u);       }       if ((g[v].size() & 1) && odd.size() <= 2) {        odd.ins(v);       }      }      if (odd.size() > 2) {       rest(i, star);       continue;      }      bool ok = 1;      forn(v, 1, n) {       if (!g[v].emp() && find(v) != find(i)) {        ok = 0;        break;       }      }      if (!ok || (odd.size() == 2 && !odd.count(i))) {       rest(i, star);       continue;      }      dfs(i);      path.pb(i);      if (!star.emp()) path.pb(-1);      for (int j : star) {       path.pb(j);       path.pb(i);      }      out(path.size());      out(path);      return;     }    }    out(0);   }      int main() {    ios_base::sync_with_stdio(0); cin.tie(0);   #ifdef LOCAL    freopen( input.txt ,  r , stdin);   #endif    start_timer();    Solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int a[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int tot = 0;     for (int i = 1; i <= n; i++) {       if (m < (i - 1) / 2) break;       a[++tot] = i;       m -= (i - 1) / 2;     }     if (!m) {       int cnt = 1e8;       for (int i = tot + 1; i <= n; i++) a[i] = cnt, cnt += 10000;       for (int i = 1; i <= n; i++) cout << a[i] <<    ;     } else {       if (tot == n)         puts( -1 );       else {         a[tot + 1] = a[tot] + a[tot] - m * 2 + 1;         int cnt = 1e8;         for (int i = tot + 2; i <= n; i++) a[i] = cnt, cnt += 10000;         for (int i = 1; i <= n; i++) cout << a[i] <<    ;       }     }   }


#include <bits/stdc++.h>   const int N = 500500;   std::vector<int> g[N];   int d[N];   int n, maxM, maxD;   void go(int cur, int par = -1, int dist = 0) {     if (dist > maxD) maxD = dist;     bool f = false;     for (auto v : g[cur])       if (v != par) {         go(v, cur, dist + 1);         f = true;       }     if (!f) ++d[dist];   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (auto v : g[1]) {       for (int i = 0; i <= maxD; ++i) d[i] = 0;       maxD = 0;       go(v, 1);       int p = -1;       for (int i = 0; i <= maxD; ++i)         if (d[i] > 0) {           if (i > p)             p = i + d[i] - 1;           else             p += d[i];         }       if (p + 1 > maxM) maxM = p + 1;     }     printf( %d n , maxM);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     if (n == k || k == 0)       cout << 0 <<     << 0;     else {       long long int min = 1, max;       if (2 * k + k < n)         max = 2 * k;       else         max = n - k;       cout << min <<     << max;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<pair<int, bool>> v(2 * n);     for (int i = 0; i < 2 * n; i++) cin >> v[i].first, v[i].second = true;     long long ans = 0, cc = 0;     for (int i = 0; i < 2 * n; i++) {       if (!v[i].second) continue;       cc = 0;       v[i].second = false;       for (int j = i + 1; j < 2 * n; j++) {         if (v[j].second && v[i].first != v[j].first) {           cc++;         } else if (v[i].first == v[j].first) {           v[j].second = false;           break;         }       }       ans += cc;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int chill = 1;     while (chill--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, dp[1 << 21], b, ans = 3e18;   pair<long long, pair<long long, long long> > a[1 << 21];   int main() {     cin >> n >> m >> b;     for (long long i = 0, m, x; i < n; i++) {       cin >> a[i].second.first >> a[i].first >> m;       while (m--) cin >> x, x--, a[i].second.second += 1 << x;     }     for (long long i = 0; i < (1 << m); i++) dp[i] = ans;     dp[0] = 0, sort(a, a + n);     for (long long i = 0; i < n; i++) {       for (int j = 0; j < (1 << m); j++)         dp[j] = min(dp[j], dp[j & (j ^ a[i].second.second)] + a[i].second.first);       ans = min(ans, dp[(1 << m) - 1] + a[i].first * b);     }     cout << (ans < (long long)3e18 ? ans : -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int L;   int a[100005], n;   int Min[100005 << 2], sub[100005 << 2];   vector<pair<int, int> > ans;   void PushUp(int rt) { Min[rt] = min(Min[rt << 1], Min[rt << 1 | 1]); }   void PushDown(int rt) {     if (sub[rt]) {       sub[rt << 1] += sub[rt];       sub[rt << 1 | 1] += sub[rt];       Min[rt << 1] -= sub[rt];       Min[rt << 1 | 1] -= sub[rt];       sub[rt] = 0;     }   }   void Build(int l, int r, int rt) {     int m;     if (l == r) {       Min[rt] = a[l];       return;     }     m = (l + r) >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);     PushUp(rt);   }   void Update(int L, int R, int x, int l, int r, int rt) {     int m;     if (L <= l && R >= r) {       sub[rt] += x;       Min[rt] -= x;       return;     }     m = (l + r) >> 1;     PushDown(rt);     if (L <= m) Update(L, R, x, l, m, rt << 1);     if (R > m) Update(L, R, x, m + 1, r, rt << 1 | 1);     PushUp(rt);   }   int Query(int L, int R, int l, int r, int rt) {     int ans = 1 << 30, m;     if (L <= l && R >= r) return Min[rt];     m = (l + r) >> 1;     PushDown(rt);     if (L <= m) ans = min(ans, Query(L, R, l, m, rt << 1));     if (R > m) ans = min(ans, Query(L, R, m + 1, r, rt << 1 | 1));     PushUp(rt);     return ans;   }   pair<int, int> bin() {     while (L <= n && Query(L, L, 1, n, 1) == 0) L++;     if (L == n + 1) return pair<int, int>(n + 1, 0);     int R, l = L, r = n, m;     while (l <= r) {       m = (l + r) >> 1;       if (Query(L, m, 1, n, 1) == 0)         r = m - 1;       else         l = m + 1;     }     R = r;     return pair<int, int>(L, R);   }   int main() {     int i, minv, l, r;     while (scanf( %d , &n) != EOF && n) {       L = 1;       (ans).clear();       for (i = 1; i <= n; i++) scanf( %d , &a[i]);       Build(1, n, 1);       while (1) {         pair<int, int> now = bin();         l = now.first, r = now.second;         if (l == n + 1) break;         ans.push_back(pair<int, int>(l, r));         Update(l, r, 1, 1, n, 1);       }       printf( %d n , ((int)(ans).size()));       for (i = 0; i < ((int)(ans).size()); i++)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[10];   int n, h;   double tw[100];   int main() {     cin >> s >> n >> h;     if (s[0] ==  B ) {       printf( %d n , n);       return 0;     }     tw[0] = 1;     for (int i = 1; i <= 2 * h; i++) tw[i] = tw[i - 1] * 2.0;     double r = n;     for (int i = 1; i <= h; i++)       for (int j = 1; j <= n; j++)         r += ((double)n - (double)j) * (1 / tw[2 * i]) *              pow(1 - 1 / tw[i], j - 1) *              (tw[i] - tw[i - 1] * (1 + (j - 1) / (tw[i] - 1)));     printf( %.9lf n , r);   }


#include <bits/stdc++.h>   using namespace std;   const int c = 200002;   int n, m, maxi, pos = c, cnt, id[c], szint[c], kezd;   vector<int> sz[c];   bool v[c], v2[c], jo[c];   void dfs2(int a) {     v2[a] = true;     bool s = jo[a];     for (int x : sz[a]) {       if (!v2[x]) {         dfs2(x);         if (jo[x]) {           s = 1;         }       }     }     jo[a] = s;     cnt += jo[a] * 2;   }   void dfs(int a) {     if (!jo[a]) {       return;     }     v[a] = true;     int x1 = a, x2 = a;     for (int x : sz[a]) {       if (!v[x]) {         szint[x] = szint[a] + 1;         dfs(x);         int aa = szint[x1], bb = szint[x2], cc = szint[id[x]];         if (cc > bb || (cc == bb && id[x] < x2)) {           x2 = id[x];           if (cc > aa || (cc == aa && id[x] < x1)) {             swap(x1, x2);           }         }       }     }     id[a] = x1;     int s = szint[x1] + szint[x2] - 2 * szint[a];     if (s > maxi || (s == maxi && min(x1, x2) < pos)) {       maxi = s;       pos = min(x1, x2);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       sz[a].push_back(b), sz[b].push_back(a);     }     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       kezd = x;       jo[x] = 1;     }     dfs2(kezd), cnt -= 2;     szint[kezd] = 1, dfs(kezd);     cout << pos <<   n  << cnt - maxi <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int ans = 1000000000000, n, m, i, d, j, a, fo = 0;     vector<long long int> v;     set<long long int> mset;     cin >> n >> m >> d;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> a;         mset.insert(a);         v.emplace_back(a);       }     }     sort(v.begin(), v.end());     for (auto x : mset) {       long long int counter = 0;       for (j = 0; j < v.size(); j++) {         a = abs(x - v[j]);         if (a % d != 0 || counter >= ans) {           counter = 1000000000000;           break;         }         counter += (a / d);       }       if (ans > counter) {         ans = counter;       }     }     if (ans == 1000000000000)       cout <<  -1  << endl;     else       cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110005;   long long arr[maxn], arr1[maxn], n, m;   int judge(long long x) {     memcpy(arr1, arr, sizeof(arr));     long long i = n, countt = 1, t = 0;     while (i >= 1 && arr1[i] <= 0) --i;     while (countt <= m) {       t = x - i;       while (t > 0) {         if (t >= arr1[i]) {           t = t - arr1[i];           arr1[i] = 0;           i--;           if (i < 1) return 1;         } else {           arr1[i] = arr1[i] - t;           t = 0;         }       }       ++countt;     }     return 0;   }   long long aa(long long x) {     long long i = n, temp;     while (i >= 1 && arr[i] <= 0) --i;     temp = arr[i];     int countt = 1;     while (countt <= m) {       long long t = x - i;       while (t > 0) {         if (t >= temp) {           t -= temp;           i--;           while (i >= 1 && arr[i] <= 0) --i;           if (i < 1) return 1;           temp = arr[i];         } else {           temp -= t;           break;         }       }       countt++;     }     return 0;   }   int main() {     long long left, right, ans, mid;     scanf( %lld%lld , &n, &m);     left = 0;     right = 1e18;     ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &arr[i]);     }     while (left <= right) {       mid = (left + right) / 2;       if (aa(mid)) {         ans = mid;         right = mid - 1;       } else {         left = mid + 1;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int n, u, v, tp;   int par[2][N], sz[2][N];   long long ans;   int find_set(int v) {     if (par[tp][v] == v) return v;     return par[tp][v] = find_set(par[tp][v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (sz[tp][a] < sz[tp][b]) swap(a, b);     par[tp][b] = a;     sz[tp][a] += sz[tp][b];   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       par[0][i] = par[1][i] = i;       sz[0][i] = sz[1][i] = 1;     }     for (int i = 1; i < n; ++i) {       cin >> u >> v >> tp;       --u;       --v;       union_sets(u, v);     }     for (int i = 0; i < n; ++i) {       if (par[0][i] == i) ans += (long long)sz[0][i] * (sz[0][i] - 1);       if (par[1][i] == i) ans += (long long)sz[1][i] * (sz[1][i] - 1);       tp = 0;       int v = find_set(i);       tp = 1;       int u = find_set(i);       ans += (long long)(sz[0][v] - 1) * (sz[1][u] - 1);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct Tpoint {     double x, y;     Tpoint() {}     Tpoint(double _x, double _y) {       x = _x;       y = _y;     }     inline void read() { scanf( %lf%lf , &x, &y); }     inline void show() { printf( %lf %lf n , x, y); }     inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }   };   inline Tpoint operator+(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x + b.x, a.y + b.y);   }   inline Tpoint operator-(const Tpoint &a, const Tpoint &b) {     return Tpoint(a.x - b.x, a.y - b.y);   }   inline Tpoint operator*(const Tpoint &a, const double &b) {     return Tpoint(a.x * b, a.y * b);   }   inline Tpoint operator/(const Tpoint &a, const double &b) {     return Tpoint(a.x / b, a.y / b);   }   inline double det(const Tpoint &a, const Tpoint &b) {     return a.x * b.y - a.y * b.x;   }   inline double dot(const Tpoint &a, const Tpoint &b) {     return a.x * b.x + a.y * b.y;   }   const int maxn = 100005;   bool mark[(1 << 20) + 10];   int n, a[maxn], last[maxn][20];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < 20; ++i) {       last[n][i] = n;     }     for (int i = n - 1; i >= 0; --i) {       memcpy(last[i], last[i + 1], sizeof(last[i]));       for (int j = 0; j < 20; ++j) {         if (a[i] >> j & 1) {           last[i][j] = i;         }       }     }     for (int i = 0; i < n; ++i) {       int x = a[i], pos = i + 1;       mark[x] = true;       while (1) {         int u = -1;         for (int j = 0; j < 20; ++j) {           if (x >> j & 1) {             continue;           }           if (u == -1 || last[pos][j] < last[pos][u]) {             u = j;           }         }         if (u == -1 || last[pos][u] >= n) {           break;         }         pos = last[pos][u];         x |= a[pos];         mark[x] = true;         pos++;       }     }     int res = 0;     for (int i = 0; i < 1 << 20; ++i) {       res += mark[i];     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   map<long long, int> G;   map<long long, map<long long, int> > multiMap;   int main() {     long long i, j, k, f1, f2, f3, f4, t1, t2, t3, t4;     long long n, m, T;     long long a, b;     cin >> n >> a >> b;     m = 0;     for (i = 1; i <= n; i++) {       cin >> t1 >> t2 >> t3;       f1 = a * t2 - t3;       m += G[f1] * 2;       m -= 2 * multiMap[t2][t3];       multiMap[t2][t3]++;       G[f1]++;     }     cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vll = vector<ll>;   using vii = vector<int>;   using pii = pair<int, int>;   template <typename T = vii>   using vec = vector<T>;   const ll INF = 1e18, MOD = 1e9 + 7;   const int MAX = 1e6;   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     map<int, vec<pii> > d;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       d[w].emplace_back(--u, --v);     }     vii dp(n);     for (auto [_, V] : d) {       map<int, int> new_dp;       for (auto [u, v] : V) {         new_dp[v] = max({new_dp[v], dp[v], dp[u] + 1});       }       for (auto [i, x] : new_dp) {         dp[i] = x;       }     }     cout << *max_element(dp.begin(), dp.end()) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[1000000];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int cur = a[n - 1];     long long total = a[n - 1];     for (int i = n - 2; i >= 0; i--) {       cur = min(cur - 1, a[i]);       cur = max(0, cur);       total += cur;     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e8;   const int N = 300100;   int n, m, ans, nans;   string mat[N], ansmat[N], nmat[N];   void upd() {     if (nans >= ans) return;     ans = nans;     for (int i = 0; i < n; ++i) ansmat[i] = nmat[i];   }   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> mat[i];     for (int i = 0; i < n; ++i) ansmat[i] = nmat[i] = mat[i];     vector<char> v = { A ,  C ,  G ,  T };     ans = INF;     do {       nans = 0;       for (int j = 0; j < m; ++j) {         int op1 = 0, op2 = 0;         for (int i = 0; i < n; ++i) {           op1 += v[2 * (j & 1) + (i & 1)] != mat[i][j];           op2 += v[2 * (j & 1) + !(i & 1)] != mat[i][j];         }         nans += min(op1, op2);         bool f = op1 > op2;         for (int i = 0; i < n; ++i) nmat[i][j] = v[2 * (j & 1) + (f ^ (i & 1))];       }       upd();       nans = 0;       for (int i = 0; i < n; ++i) {         int op1 = 0, op2 = 0;         for (int j = 0; j < m; ++j) {           op1 += v[2 * (i & 1) + (j & 1)] != mat[i][j];           op2 += v[2 * (i & 1) + !(j & 1)] != mat[i][j];         }         nans += min(op1, op2);         bool f = op1 > op2;         for (int j = 0; j < m; ++j) nmat[i][j] = v[2 * (i & 1) + (f ^ (j & 1))];       }       upd();     } while (next_permutation(v.begin(), v.end()));     for (int i = 0; i < n; ++i) cout << ansmat[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   vector<int> e[N];   set<int> l[N];   int n;   void exitno() {     printf( -1 n );     exit(0);   }   int exitans(int x) {     while (x % 2 == 0) x /= 2;     printf( %d n , x);     exit(0);   }   void _dfs(int p, int fa) {     if (fa && e[p].size() == 1) l[p].insert(0);     for (int i = 0; i < e[p].size(); i++) {       int x = e[p][i];       if (x == fa) continue;       _dfs(x, p);       for (auto j : l[x]) l[p].insert(j + 1);     }     if (l[p].size() >= 3) exitno();   }   void work(int p) {     for (int i = 1; i <= n; i++) l[i].clear();     _dfs(p, 0);     int x = 0;     for (auto i : l[p]) x += i;     exitans(x);   }   void dfs(int p = 1, int fa = 0) {     if (fa && e[p].size() == 1) l[p].insert(0);     for (int i = 0; i < e[p].size(); i++) {       int x = e[p][i];       if (x == fa) continue;       dfs(x, p);       for (auto j : l[x]) l[p].insert(j + 1);     }     if (l[p].size() >= 3) exitno();     if (l[p].size() == 2) work(p);   }   int main() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }     dfs();     exitans(*l[1].begin());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int x;     string y, z;     cin >> x >> y >> z;     if (z[0] ==  w ) {       int fd = 5, ans = 0;       for (int i = 1; i <= 366; ++i) {         if (fd == x) ans++;         fd++;         if (fd == 8) fd = 1;       }       cout << ans <<   n ;     } else {       if (x <= 29)         cout << 12 <<   n ;       else if (x <= 30)         cout << 11 <<   n ;       else         cout << 7 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void show(T&&... args) {     ((cerr << args <<    ), ...);   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const pair<F, S>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  { ;     typename vector<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  } ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     os <<  [ ;     typename set<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& v) {     os <<  [ ;     typename multiset<T>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const map<F, S>& v) {     os <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const unordered_map<F, S>& v) {     os <<  [ ;     typename unordered_map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   inline void file_io(string path1 =   , string path2 =   ) {     if (path2.size() == 0) path2 = path1;     freopen(path1.c_str(),  r , stdin);     freopen(path2.c_str(),  w , stdout);   }   template <typename T>   T egcd(T a, T b, T& x, T& y) {     x = 1, y = 0;     T x1 = 0, y1 = 1, a1 = a, b1 = b;     while (b1) {       T q = a1 / b1;       tie(x, x1) = make_tuple(x1, x - q * x1);       tie(y, y1) = make_tuple(y1, y - q * y1);       tie(a1, b1) = make_tuple(b1, a1 - q * b1);     }     return a1;   }   template <typename F, typename S>   F bigMod(F a, F b, S mod) {     a %= mod;     F res = 1;     while (b > 0) {       if (b & 1) res = ((long long)res * a) % mod;       a = ((long long)a * a) % mod;       b >>= 1;     }     return res;   }   inline int modAdd(long long _a, long long _b, long long mod) {     if (_a < 0) {       _a += mod;     }     if (_b < 0) {       _b += mod;     }     if (_a + _b >= mod) return (_a + _b - mod);     return (_a + _b);   }   inline int modMul(long long _a, long long _b, long long mod) {     if (_a < 0) {       _a += mod;     }     if (_b < 0) {       _b += mod;     }     return (_a * _b) % mod;   }   inline int modInv(long long a, long long mod) {     return bigMod(a, mod - 2, mod);   }   const long long mod = 998244353;   int solve() {     int n;     cin >> n;     int dp[n + 5][2], ans = 0;     memset(dp, 0, sizeof dp);     dp[0][0] = 1;     for (int i = 0; i < n; i++) {       int val;       cin >> val;       dp[val + 1][0] = modAdd(dp[val + 1][0], dp[val + 1][0], mod);       dp[val + 1][0] = modAdd(dp[val + 1][0], dp[val][0], mod);       if (val - 1 >= 0)         dp[val - 1][1] = modAdd(dp[val - 1][1], dp[val - 1][1], mod);       if (val - 1 >= 0)         dp[val - 1][1] = modAdd(dp[val - 1][1], dp[val - 1][0], mod);       dp[val + 1][1] = modAdd(dp[val + 1][1], dp[val + 1][1], mod);     }     for (int i = 0; i < n + 5; i++) {       ans = modAdd(ans, dp[i][0], mod);       ans = modAdd(ans, dp[i][1], mod);     }     ans = modAdd(ans, -1, mod);     cout << ans <<   n ;     return 0;   }   int main() {     ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     ;     int t = 1, cs = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, s, f;     cin >> n >> m >> s >> f;     map<int, pair<int, int> > mop;     for (int i = 0; i < m; i++) {       int t, l, r;       cin >> t >> l >> r;       mop[t] = {l, r};     }     string ans;     while (s != f) {       pair<int, int> p = mop[ans.size() + 1];       if (s < f) {         if ((s >= p.first && s <= p.second) ||             (s + 1 >= p.first && s + 1 <= p.second))           ans +=  X ;         else           ans +=  R , s++;       } else {         if ((s >= p.first && s <= p.second) ||             (s - 1 >= p.first && s - 1 <= p.second))           ans +=  X ;         else           ans +=  L , s--;       }     }     cout << ans << endl;     return 0;   }