#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T1, class T2>   inline void gmax(T1 &a, T2 b) {     if (b > a) a = b;   }   template <class T1, class T2>   inline void gmin(T1 &a, T2 b) {     if (b < a) a = b;   }   const int N = (1 << 20) + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;   template <class T1, class T2>   inline void gadd(T1 &a, T2 b) {     a = (a + b) % Z;   }   int n, m, top;   int a[N], b[N];   long long num[21];   long long sum[21];   int v[N];   void add(int x, int val) {     for (; x <= top; x += x & -x) v[x] += val;   }   int cnt(int x) {     int ret = 0;     for (; x; x -= x & -x) ret += v[x];     return ret;   }   void init() {     for (int i = 1; i <= n; ++i) {       int l = 1 << i;       int d = m / l;       sum[i] = 0;       num[i] = 0;       int st = 0;       while (d--) {         for (int j = l / 2 + 1; j <= l; ++j) add(a[st + j], 1);         for (int j = 1; j <= l / 2; ++j) {           int tmp1 = cnt(a[st + j] - 1);           int tmp2 = cnt(a[st + j]);           num[i] += tmp1;           sum[i] += l / 2 - (tmp2 - tmp1);         }         for (int j = l / 2 + 1; j <= l; ++j) add(a[st + j], -1);         st += l;       }     }   }   int main() {     while (~scanf( %d , &n)) {       m = 1 << n;       for (int i = 1; i <= m; ++i) scanf( %d , &a[i]), b[i] = a[i];       sort(b + 1, b + m + 1);       top = unique(b + 1, b + m + 1) - b - 1;       for (int i = 1; i <= m; ++i)         a[i] = lower_bound(b + 1, b + top + 1, a[i]) - b;       init();       int q;       scanf( %d , &q);       while (q--) {         int x;         scanf( %d , &x);         for (int i = x; i >= 1; --i) num[i] = sum[i] - num[i];         long long ans = 0;         for (int i = 1; i <= n; ++i) ans += num[i];         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   const int Mod = 1e9 + 7;   const int N = 3e5 + 100;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   inline long long dpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t) % Mod;       b >>= 1;       t = (t * t) % Mod;     }     return r;   }   inline long long fpow(long long a, long long b) {     long long r = 1, t = a;     while (b) {       if (b & 1) r = (r * t);       b >>= 1;       t = (t * t);     }     return r;   }   int a[N], ans[N], n;   int mx[N], lst[N];   void Init() {     for (int i = 1; i <= n; i++) mx[i] = lst[i] = ans[i] = 0;   }   int main() {     int T;     cin >> T;     while (T--) {       scanf( %d , &n);       Init();       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         mx[a[i]] = max(mx[a[i]], i - lst[a[i]]);         lst[a[i]] = i;       }       for (int i = 1; i <= n; i++)         if (lst[i]) mx[i] = max(mx[i], n + 1 - lst[i]);       int r = n;       for (int i = 1; i <= n; i++) {         if (!lst[i]) continue;         int j;         for (j = mx[i]; j <= r; j++) ans[j] = i;         r = min(r, mx[i] - 1);       }       for (int i = 1; i <= n; i++) {         if (!ans[i])           printf( -1  );         else           printf( %d  , ans[i]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[1005][1005], d[1005][1005], ans, D[10005];   pair<int, int> b[100005];   int ch(int x, int y) {     for (int i = 1; i <= k; i++) {       if (d[i][y] > d[i][x]) return 0;     }     return 1;   }   int main() {     cin >> n >> k;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) cin >> a[i][j];       for (int j = 1; j <= n; j++) d[i][a[i][j]] = j;       for (int j = 1; j <= n; j++) b[a[i][j]].first = max(b[a[i][j]].first, j);     }     for (int j = 1; j <= n; j++) b[j].second = j;     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) {       int ma = 0;       int I = b[i].second;       for (int j = 1; j < i; j++) {         int J = b[j].second;         if (ch(I, J) && D[j] > ma) ma = D[j];       }       D[i] = ma + 1;       ans = max(ans, D[i]);     }     cout << ans << endl;     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   int main() {     int n, l, i, j, cnt, area, ans;     scanf( %d%d , &n, &l);     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     ans = 0;     for (i = l; i <= 100; i++) {       cnt = 0;       for (j = 1; j <= n; j++) cnt += a[j] / i;       area = cnt * i;       ans = max(ans, area);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = getchar();     return x * f;   }   long long t, l, r, tot, cnt;   long long f[50 + 5][2520 + 5][50 + 5], in[2520 + 5], a[2520 + 5], bas[2520 + 5];   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long dfs(long long p, long long sum, long long lcm, bool limit) {     if (!p) return sum % lcm == 0 ? 1 : 0;     if (!limit && f[p][sum][in[lcm]] != -1) return f[p][sum][in[lcm]];     long long up = limit ? a[p] : 9, ans = 0;     for (register long long i = 0; i <= up; ++i) {       if (i == 0)         ans += dfs(p - 1, sum * 10 % 2520, lcm, limit && (i == up));       else         ans += dfs(p - 1, (sum * 10 + i) % 2520, lcm * i / gcd(lcm, i),                    limit && (i == up));     }     if (!limit) f[p][sum][in[lcm]] = ans;     return ans;   }   long long calc(long long x) {     cnt = 0;     while (x) a[++cnt] = x % 10, x /= 10;     return dfs(cnt, 0, 1, 1);   }   signed main() {     t = read();     memset(f, -1, sizeof(f));     ;     for (register long long i = 1; i <= 2520; ++i)       if (2520 % i == 0) in[i] = (++(tot));     while (t--) l = read(), r = read(), printf( %lld n , calc(r) - calc(l - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     long long arr[7] = {1, 2, 3, 1, 3, 2, 1};     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long full = min({a / 3, b / 2, c / 2});       a -= 3 * full;       b -= 2 * full;       c -= 2 * full;       long long extra = 0;       long long i = 0;       while (i < 7) {         long long a1 = a, b1 = b, c1 = c;         long long sta = i;         long long cue = 0;         while (1) {           if (arr[sta] == 1 && a1 == 0) break;           if (arr[sta] == 2 && b1 == 0) break;           if (arr[sta] == 3 && c1 == 0) break;           if (arr[sta] == 1) a1--;           if (arr[sta] == 2) b1--;           if (arr[sta] == 3) c1--;           cue++;           sta++;           if (sta == 7) sta = 0;         }         if (extra < cue) extra = cue;         i++;       }       cout << 7 * full + extra << endl;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 7;   vector<vector<int> > g;   vector<bool> used;   int main() {     int n, m;     cin >> n >> m;     g.resize(n);     used.resize(n, false);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     set<int> q;     q.insert(0);     used[0] = true;     while (!q.empty()) {       int u = *q.begin();       q.erase(q.begin());       cout << u + 1 <<    ;       for (auto v : g[u])         if (!used[v]) {           q.insert(v);           used[v] = true;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int fib(int n) {     int b = 1;     int c = 1;     while (n--) {       c = (c + b) % MOD;       swap(b, c);     }     return c;   }   int main() {     int n, m;     cin >> n >> m;     int a = fib(n);     int b = fib(m);     cout << (a + b - 1) % MOD * 2 % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10100], b[1010];   int main() {     int n, m, c, ans;     scanf( %d%d%d , &n, &m, &c);     ans = (n + m + c) / 2;     if (n + c >= ans && m + c >= ans)       printf( %d n , ans * 2);     else       printf( %d n , min(n + c, m + c) * 2);   }


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


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   char ch[4000010];   inline string get() {     scanf( %s , ch);     return string(ch);   }   inline void read(int *a, int n) {     for (int i = 0; i < n; i++) a[i] = in();   }   template <class blank>   inline void out(blank x) {     cout << x <<   n ;     exit(0);   }   template <class blank, class blank2>   inline void smin(blank &a, blank2 b) {     a = a <= b ? a : b;   }   template <class blank, class blank2>   inline void smax(blank &a, blank2 b) {     a = a >= b ? a : b;   }   const int maxn = 3e5 + 10;   const int maxm = 4e6 + 10;   const int maxlg = 20;   const int base = 29;   const int mod = 1e9 + 7;   const int inf = 2e18 + 10;   const double eps = 1e-9;   string code[maxn];   int correct[maxn];   int mark[maxn];   int n, m;   int res;   inline void bt(int pos = 0, int cnt = 0) {     if (cnt > correct[0] || n - pos + cnt < correct[0]) return;     if (pos == n) {       string cc = code[0];       for (int i = 0; i < n; i++) {         if (mark[i] == 0) {           cc[i] ^=  1  ^  0 ;         }       }       bool fl = true;       for (int i = 0; i < m; i++) {         int diff = 0;         for (int j = 0; j < n; j++) diff += code[i][j] != cc[j];         if (diff != n - correct[i]) fl = false;       }       res += fl;       return;     }     bt(pos + 1, cnt);     mark[pos] = true;     bt(pos + 1, cnt + 1);     mark[pos] = false;   }   int32_t main() {     n = in(), m = in();     for (int i = 0; i < m; i++) {       code[i] = get(), correct[i] = in();     }     bt(0);     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   bool getcell(vector<vector<bool>>& b, int i, int j) {     if (i >= b.size() || j >= b[0].size() || i < 0 || j < 0) return false;     return b[i][j];   }   bool isPlus(vector<vector<bool>>& b, int i, int j) {     return getcell(b, i + 1, j) && getcell(b, i - 1, j) && getcell(b, i, j + 1) &&            getcell(b, i, j - 1);   }   int genPlus(vector<vector<bool>>& b, int i, int j) {     int ret = 0;     int x, y;     x = i;     y = j;     while (getcell(b, x + 1, y)) {       ++x;       ++ret;     }     x = i;     y = j;     while (getcell(b, x - 1, y)) {       --x;       ++ret;     }     x = i;     y = j;     while (getcell(b, x, y + 1)) {       ++y;       ++ret;     }     x = i;     y = j;     while (getcell(b, x, y - 1)) {       --y;       ++ret;     }     return ret;   }   int main(int argc, char const* argv[]) {     cin.sync_with_stdio(0);     cin.tie(0);     int h, w;     cin >> h >> w;     int cnt = 0;     vector<vector<bool>> there(h, vector<bool>(w));     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         char c;         cin >> c;         there[i][j] = (c ==  * );         cnt += there[i][j];       }     }     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (there[i][j] && isPlus(there, i, j)) {           int g = genPlus(there, i, j);           if (g + 1 == cnt) {             cout <<  YES ;             return 0;           }           cout <<  NO ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[200000 + 5];   long long f[200000 + 5];   struct node {     int nxt[26];     int fa;     long long len;   } t[200000 + 10];   long long ans = 0;   int last, tot;   vector<int> g[200000 + 5];   void insrt(int x) {     int nd = ++tot;     f[nd] = 1;     int p = last;     last = nd;     t[nd].len = t[p].len + 1;     for (; p && t[p].nxt[x] == 0; p = t[p].fa) t[p].nxt[x] = nd;     if (!p)       t[nd].fa = 1;     else {       int q = t[p].nxt[x];       if (t[p].len + 1 == t[q].len)         t[nd].fa = q;       else {         int nt = ++tot;         t[nt] = t[q];         t[nd].fa = t[q].fa = nt;         t[nt].len = t[p].len + 1;         for (; t[p].nxt[x] == q && p; p = t[p].fa) t[p].nxt[x] = nt;       }     }   }   void init() {     last = 1, tot = 1;     memset(t, 0, sizeof(t));     for (int i = 0; i <= 200000 + 3; i++) g[i].clear(), f[i] = 0;   }   void dfs(int u) {     for (int i = 0; i < g[u].size(); i++) {       dfs(g[u][i]);       f[u] += f[g[u][i]];     }     ans += (t[u].len - t[t[u].fa].len) * f[u] * f[u];     return;   }   int main() {     int T_T;     cin >> T_T;     while (T_T--) {       scanf( %s , str);       int len = strlen(str);       init();       ans = 0;       for (int i = 0; i < len; i++) insrt(str[i] -  a );       for (int i = 1; i <= tot; i++) g[t[i].fa].push_back(i);       dfs(0);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int maximum_no = 1e18 + 1;   string A, B, C, curr;   long long int a, b, c, f[100005];   char solve(int n, long long int k) {     if (n == 0) {       if (k > f[0]) return  . ;       return curr[k - 1];     }     if (k <= a) return A[k - 1];     if (k <= a + f[n - 1]) return solve(n - 1, k - a);     if (k <= a + f[n - 1] + b) return B[k - a - f[n - 1] - 1];     if (k <= a + f[n - 1] + b + f[n - 1])       return solve(n - 1, k - a - f[n - 1] - b);     if (k <= a + f[n - 1] + b + f[n - 1] + c)       return C[k - (a + f[n - 1] + b + f[n - 1]) - 1];     return  . ;   }   int n, q;   long long int k;   int main() {     A =  What are you doing while sending   ;     B =   ? Are you busy? Will you send   ;     C =   ? ;     curr =          What are you doing at the end of the world? Are you busy? Will you save            us? ;     f[0] = curr.length();     a = A.length();     b = B.length();     c = C.length();     for (int i = 1; i <= 100000; i++) {       f[i] = min(maximum_no, a + f[i - 1] + b + f[i - 1] + c);     }     string ans =   ;     scanf( %d , &q);     while (q--) {       scanf( %d %lld , &n, &k);       if (f[n] < k)         ans.push_back( . );       else         ans.push_back(solve(n, k));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int len, k;       cin >> len >> k;       string s;       cin >> s;       sort(s.begin(), s.end());       if (s[0] != s[k - 1])         cout << s[k - 1] << endl;       else {         cout << s[k - 1];         if (s[k] == s[len - 1]) {           int q = (len - k) / k;           if ((len - k) % k) q++;           while (q--) cout << s[k];         } else           for (int i = k; i < len; i++) cout << s[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float i = 0;     int e;     double answer;     cin >> i;     for (int k = 0; k < i; k++) {       cin >> e;       answer += e;     }     cout << answer / i;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, m[N], t[N];   struct People {     int a, b, c, cnt;   } p[N], ran[N];   int read() {     int x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return x;   }   bool cmp(People x, People y) {     if (x.a != y.a)       return x.a > y.a;     else       return x.c < y.c;   }   int lowbit(int x) { return x & -x; }   void add(int x, int k) {     for (; x <= n; x += lowbit(x)) t[x] += k;     return;   }   int sum(int x) {     int ret = 0;     for (; x; x -= lowbit(x)) ret += t[x];     return ret;   }   void merge(int l, int r) {     if (l == r) return;     int mid = (l + r) / 2;     merge(l, mid);     merge(mid + 1, r);     int i = l, j = mid + 1, cur = l;     for (; i <= mid && j <= r;) {       if (p[i].b > p[j].b)         add(p[i].c, 1), ran[cur++] = p[i++];       else         p[j].cnt += sum(n) - sum(p[j].c), ran[cur++] = p[j++];     }     for (; i <= mid;) add(p[i].c, 1), ran[cur++] = p[i++];     for (; j <= r;) p[j].cnt += sum(n) - sum(p[j].c), ran[cur++] = p[j++];     for (i = l; i <= mid; ++i) add(p[i].c, -1);     for (i = l; i <= r; ++i) p[i] = ran[i];   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) p[i].a = read();     for (int i = 1; i <= n; ++i) p[i].b = read();     for (int i = 1; i <= n; ++i) p[i].c = read(), m[i] = p[i].c;     sort(m + 1, m + 1 + n);     for (int i = 1; i <= n; ++i)       p[i].c = lower_bound(m + 1, m + 1 + n, p[i].c) - m;     sort(p + 1, p + 1 + n, cmp);     merge(1, n);     int ans = 0;     for (int i = 1; i <= n; ++i)       if (p[i].cnt) ++ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using uint8 = unsigned char;   using uint16 = unsigned short int;   using uint32 = unsigned int;   using uint64 = unsigned long long;   using int8 = signed char;   using int16 = short int;   using int32 = int;   using int64 = long long;   using dr = double;   using pi32 = std::pair<int32, int32>;   using pi64 = std::pair<int64, int64>;   using pi64i32 = std::pair<int64, int32>;   using pi32pi32 = std::pair<int32, pi32>;   using cpdr = std::complex<dr>;   using vi32 = std::vector<int32>;   using qi32 = std::queue<int32>;   using spi32 = std::set<pi32>;   using spi32it = spi32::iterator;   namespace oct {   const int tn4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};   const int tn8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},                          {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};   const dr exp = 1e-8;   void sync(int pre = 8);   template <typename _Tp>   _Tp &mad(_Tp &x, _Tp y);   template <typename _Tp>   _Tp &mid(_Tp &x, _Tp y);   template <typename _Tp>   bool in(_Tp x, _Tp l, _Tp r);   template <typename _Tp>   _Tp sqr(_Tp x);   template <typename _Tp>   _Tp power(_Tp x, int64 m);   template <typename _Tp>   void sort(_Tp &x, _Tp &y);   template <typename _Tp1, typename _Tp2>   std::pair<_Tp1, _Tp2> operator+(std::pair<_Tp1, _Tp2> x,                                   std::pair<_Tp1, _Tp2> y);   template <typename _Tp>   _Tp &operator+=(_Tp &x, _Tp y);   inline void sync(int pre) {     std::ios::sync_with_stdio(0);     std::cin.tie(0), std::cout.tie(0);     std::cout.flags(std::ios::fixed);     std::cout.precision(pre);     std::cout.setf(std::ios::showpoint);   }   template <typename _Tp>   inline _Tp &mad(_Tp &x, _Tp y) {     return x = std::max(x, y);   }   template <typename _Tp>   inline _Tp &mid(_Tp &x, _Tp y) {     return x = std::min(x, y);   }   template <typename _Tp>   inline bool in(_Tp x, _Tp l, _Tp r) {     return l <= x && x <= r;   }   template <typename _Tp>   inline _Tp sqr(_Tp x) {     return x * x;   }   template <typename _Tp>   inline _Tp power(_Tp x, int64 m) {     return m == 1 ? x : (m & 1 ? power(x * x, m / 2) * x : power(x * x, m / 2));   }   template <typename _Tp>   inline void sort(_Tp &x, _Tp &y) {     if (x > y) std::swap(x, y);   }   template <typename _Tp1, typename _Tp2>   inline std::pair<_Tp1, _Tp2> operator+(std::pair<_Tp1, _Tp2> x,                                          std::pair<_Tp1, _Tp2> y) {     return x.first += y.first, x.second += y.second, x;   }   template <typename _Tp>   _Tp &operator+=(_Tp &x, _Tp y) {     return x = x + y;   }   }  // namespace oct   const int N = 100005;   dr ta, tb, tc;   dr a[N], b[N], s[N], t[N];   int n;   int main() {     oct::sync();     std::cin >> n;     for (int i = 1; i <= n; ++i) std::cin >> a[i], a[i] += a[i - 1];     for (int i = 1; i <= n; ++i) std::cin >> b[i], b[i] += b[i - 1];     for (int i = 1; i <= n; ++i) {       ta = 1, tb = -(a[i] + b[i]), tc = a[i];       s[i] = (-tb - sqrt(std::abs(tb * tb - 4 * ta * tc))) / (2 * ta);       t[i] = (-tb + sqrt(std::abs(tb * tb - 4 * ta * tc))) / (2 * ta);     }     for (int i = 1; i <= n; ++i) std::cout << s[i] - s[i - 1] <<    ;     std::cout << std::endl;     for (int i = 1; i <= n; ++i) std::cout << t[i] - t[i - 1] <<    ;     std::cout << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str;   string l;   map<string, int> m;   string Greedy_Solve() {     string res =   ;     for (int i = 0; i < l.length(); i += 10) {       str = l.substr(i, 10);       res += m[str] +  0 ;     }     return res;   }   int main() {     cin >> l;     for (int i = 0; i < 10; i++) {       cin >> str;       m[str] = i;     }     cout << Greedy_Solve();     return 0;   }


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


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


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double EPS = 0.000000001;   const double PI = 3.141592653589793;   const long long LLINF = 99999999999999999LL;   const int MAX_N = 100005;   const int MOD = 1000000007;   int N, M, n, cnt, ans;   vector<int> v[MAX_N], w[MAX_N], SCC[MAX_N], a;   bool cycle;   bool hasCycle[MAX_N], vis[MAX_N];   void DFS1(int x) {     vis[x] = 1;     for (int i = 0; i < (int)v[x].size(); ++i) {       int y = v[x][i];       if (vis[y] == 0) DFS1(y);     }     a.push_back(x);   }   void DFS2(int x) {     vis[x] = 1;     SCC[n].push_back(x);     for (int i = 0; i < (int)w[x].size(); ++i) {       int y = w[x][i];       if (vis[y] == 0) DFS2(y);     }   }   void DFS(int x) {     ++cnt;     vis[x] = 1;     if (hasCycle[x]) cycle = 1;     for (int i = 0; i < (int)v[x].size(); ++i) {       int y = v[x][i];       if (vis[y] == 0) DFS(y);     }     for (int i = 0; i < (int)w[x].size(); ++i) {       int y = w[x][i];       if (vis[y] == 0) DFS(y);     }   }   int main() {     cin >> N >> M;     for (int i = 1; i <= M; ++i) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       w[y].push_back(x);     }     for (int i = 1; i <= N; ++i)       if (!vis[i]) DFS1(i);     memset(vis, 0, sizeof(vis));     for (int i = a.size() - 1; i >= 0; --i)       if (!vis[a[i]]) {         ++n;         DFS2(a[i]);       }     for (int i = 1; i <= n; ++i)       if (SCC[i].size() > 1)         for (int j = 0; j < (int)SCC[i].size(); ++j) hasCycle[SCC[i][j]] = 1;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= N; ++i) {       if (vis[i]) continue;       cnt = 0;       cycle = 0;       DFS(i);       if (cycle)         ans += cnt;       else         ans += cnt - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int vis[N], parent[N];   vector<int> v[N];   void dfs(int node) {     vis[node] = 1;     for (auto i : v[node]) {       if (!vis[i]) {         parent[i] = node;         dfs(i);       }     }   }   int res[N];   int main() {     int n, l, r, k = 0;     scanf( %d   , &n);     parent[n] = n;     for (int i = 1; i < n; ++i) {       parent[i] = i;       scanf( %d %d , &l, &r);       v[l].push_back(r);       v[r].push_back(l);       k = max(k, max((int)v[l].size(), (int)v[r].size()));     }     k += 1;     vector<int> col(k + 1);     parent[1] = 1;     dfs(1);     memset(vis, 0, sizeof(vis));     queue<int> q;     vis[1] = true;     q.push(1);     res[1] = 1;     col[1] = true;     while (!q.empty()) {       int node = q.front();       q.pop();       col[res[parent[node]]] = true;       col[res[node]] = true;       int j = 1, x = (int)col.size();       for (auto i : v[node]) {         if (!vis[i]) {           q.push(i);           while (j < x and col[j] == true) ++j;           res[i] = j;           col[j] = true;           vis[i] = 1;         }       }       for (auto i : v[node]) col[res[i]] = false;       col[res[node]] = false;     }     printf( %d n , k);     for (int i = 1; i <= n; ++i) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e9 + 7;   int main() {     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int difference;     int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i] + a[i + 1] < k) {         difference = k - (a[i] + a[i + 1]);         ans += difference;         a[i + 1] = a[i + 1] + difference;       }     }     cout << ans;     cout << endl;     ;     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     vector<long long int> col;     int zero = 0, one = 0;     col.push_back(0);     for (int i = 1; i < s.size(); i++) {       if (s[i] >= s[zero]) {         col.push_back(0);         zero = i;       } else {         if (s[i] < s[one] && one != 0) {           cout <<  NO ;           return 0;         } else {           col.push_back(1);           one = i;         }       }     }     cout <<  YES  <<   n ;     for (auto i : col) cout << i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y;     cin >> x >> y;     if (y == 0) {       cout <<  No  << endl;       return 0;     }     y = y - 1;     if (y >= 1) {       x = x - y;       if (x >= 0 && x % 2 == 0) {         cout <<  Yes  << endl;       } else {         cout <<  No  << endl;       }     } else {       if (x == 0) {         cout <<  Yes  << endl;       } else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<1000001> L, R;   vector<int> H1, H2, V1, V2, res;   multiset<int> AA, BB;   int A[1000], B[1000];   bool solve(int *A, int s, int e, int S) {     int m = (s + e) >> 1;     if (s == e || S == 0) {       if (S) res.push_back(A[m]);       return true;     }     for (int i = 0; i <= S; i++) L[i] = R[i] = 0;     L[0] = R[0] = 1;     for (int i = s; i <= m; i++) L |= L << A[i];     for (int i = e; i > m; i--) R |= R << A[i];     for (int i = 0; i <= S; i++)       if (L[i] && R[S - i]) {         solve(A, s, m, i);         solve(A, m + 1, e, S - i);         return true;       }     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int T, N, M;     for (cin >> T; T--;) {       int H = 0, V = 0, x = 0, y = 0;       cin >> N;       AA.clear();       BB.clear();       for (int i = 0; i < N; i++) {         cin >> A[i];         H += A[i];         AA.insert(A[i]);       }       cin >> M;       for (int i = 0; i < M; i++) {         cin >> B[i];         V += B[i];         BB.insert(B[i]);       }       if ((H & 1) || (V & 1) || N != M || N == 1 || M == 1) {         cout <<  No n ;         continue;       }       sort(A, A + N);       sort(B, B + M);       res.clear();       if (!solve(A, 0, N - 1, H / 2)) {         cout <<  No n ;         continue;       }       H1.clear();       H2.clear();       for (auto v : res) {         H1.push_back(v);         AA.erase(AA.find(v));       }       for (auto v : AA) H2.push_back(v);       res.clear();       if (!solve(B, 0, M - 1, V / 2)) {         cout <<  No n ;         continue;       }       V1.clear();       V2.clear();       for (auto v : res) {         V1.push_back(v);         BB.erase(BB.find(v));       }       for (auto v : BB) V2.push_back(v);       if (V1.size() > V2.size()) swap(V1, V2);       if (H1.size() < H2.size()) swap(H1, H2);       reverse(V1.begin(), V1.end());       reverse(V2.begin(), V2.end());       cout <<  Yes n ;       for (auto &v : V1) v *= -1;       for (auto &h : H2) H1.push_back(-h);       for (auto v : V2) V1.push_back(v);       for (int i = 0; i < N; i++) {         y += V1[i];         cout << x <<     << y <<   n ;         x += H1[i];         cout << x <<     << y <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char board[2100][2100];   int mark[2100][2100];   class Graph {     int V;     list<int> *adj;     bool isCyclicUtil(int v, bool visited[], bool *rs);       public:     Graph(int V);     void addEdge(int v, int w);     bool isCyclic();   };   Graph::Graph(int V) {     this->V = V;     adj = new list<int>[V];   }   void Graph::addEdge(int v, int w) { adj[v].push_back(w); }   bool Graph::isCyclicUtil(int v, bool visited[], bool *recStack) {     if (visited[v] == false) {       visited[v] = true;       recStack[v] = true;       list<int>::iterator i;       for (i = adj[v].begin(); i != adj[v].end(); ++i) {         if (!visited[*i] && isCyclicUtil(*i, visited, recStack))           return true;         else if (recStack[*i])           return true;       }     }     recStack[v] = false;     return false;   }   bool Graph::isCyclic() {     bool *visited = new bool[V];     bool *recStack = new bool[V];     for (int i = 0; i < V; i++) {       visited[i] = false;       recStack[i] = false;     }     for (int i = 0; i < V; i++)       if (isCyclicUtil(i, visited, recStack)) return true;     return false;   }   int move(int i, int j) {     int i0 = i, j0 = j;     if (board[i][j] ==  # ) return 0;     int di = 0, dj = 0;     if (mark[i][j] != 0) {       return mark[i][j];     }     di = 0;     dj = 0;     if (board[i][j] ==  v ) di = 1;     if (board[i][j] ==  ^ ) di = -1;     if (board[i][j] ==  > ) dj = 1;     if (board[i][j] ==  < ) dj = -1;     i += di;     j += dj;     if (mark[i][j] != 0) {       mark[i0][j0] = mark[i][j] + 1;       return mark[i][j] + 1;     } else {       int d = move(i, j);       mark[i0][j0] = d + 1;       return d + 1;     }   }   bool check(int i1, int j1, int i2, int j2) {     if (board[i1][j1] ==  #  || board[i1][j2] ==  # ) return false;     int di1 = 0, dj1 = 0, di2 = 0, dj2 = 0;     while (board[i1][j1] !=  #  || board[i2][j2] !=  # ) {       di1 = 0;       dj1 = 0, di2 = 0, dj2 = 0;       if (board[i1][j1] ==  v ) di1 = 1;       if (board[i1][j1] ==  ^ ) di1 = -1;       if (board[i1][j1] ==  > ) dj1 = 1;       if (board[i1][j1] ==  < ) dj1 = -1;       i1 += di1;       j1 += dj1;       if (board[i2][j2] ==  v ) di2 = 1;       if (board[i2][j2] ==  ^ ) di2 = -1;       if (board[i2][j2] ==  > ) dj2 = 1;       if (board[i2][j2] ==  < ) dj2 = -1;       i2 += di2;       j2 += dj2;       if (i1 == i2 && j1 == j2)         if (board[i1][j1] !=  # ) return false;     }     return true;   }   Graph g(2000 * 2000);   int main() {     int n, m, max = 0, val = 0, maxi[2000], maxj[2000], num = 0, cnt = 0;     bool f = false;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> board[i][j];         if (board[i][j] ==  v  && cnt < 10000) {           g.addEdge(m * i + j, m * (i + 1) + j);           cnt++;         }         if (board[i][j] ==  ^  && cnt < 10000) {           g.addEdge(m * i + j, m * (i - 1) + j);           cnt++;         }         if (board[i][j] ==  >  && cnt < 10000) {           g.addEdge(m * i + j, m * i + j + 1);           cnt++;         }         if (board[i][j] ==  <  && cnt < 10000) {           g.addEdge(m * i + j, m * i + j - 1);           cnt++;         }       }     }     if (g.isCyclic()) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         val = move(i, j);         if (val == max && !f && max != 0) {           maxj[num] = j;           maxi[num] = i;           num++;         }         if (val > max) {           max = val;           maxi[0] = i;           maxj[0] = j;           num = 1;           f = false;         }       }     }     if (max == 0) {       cout << 0;       return 0;     }     if (num > 1) f = check(maxi[0], maxj[0], maxi[1], maxj[1]);     if (num > 2) {       for (int i = 2; i < num; i++) {         if (!f) {           f = check(maxi[1], maxj[1], maxi[i], maxj[i]);         }       }     }     if (f)       cout << max * 2;     else       cout << max * 2 - 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x;     long long k, count = 0;     char c;     cin >> n >> x;     for (int i = 1; i <= n; i++) {       cin >> c >> k;       if (c ==  + ) {         x += k;       } else {         if (x >= k) {           x -= k;         } else {           count++;         }       }     }     cout << x <<     << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long int temp, i, j, k, T;   int main() {     int n, a, b;     cin >> n >> a >> b;     int h[2007];     for (i = 0; i < n; i++) cin >> h[i];     sort(h, h + n);     int val = h[b - 1];     if (h[b] == val)       cout <<  0  << endl;     else       cout << h[b] - val << endl;     return 0;   }


#include <bits/stdc++.h>   void unionInit(int d[], int s) {     int i;     for (i = 0; i < s; i++) d[i] = i;   }   int unionGet(int d[], int n) {     int t = n, k;     while (d[t] != t) t = d[t];     while (d[n] != n) k = d[n], d[n] = t, n = k;     return n;   }   int unionConnect(int d[], int a, int b) {     a = unionGet(d, a);     b = unionGet(d, b);     if (a == b) return 0;     d[a] = b;     return 1;   }   int main() {     int i, j, k, l, m, n;     int ind[110000];     int res;     while (scanf( %d%d , &n, &m) == 2) {       unionInit(ind, n);       res = 1;       while (m--) {         scanf( %d%d , &i, &j);         i--;         j--;         if (unionConnect(ind, i, j) == 0) res = (res * 2) % 1000000009;         printf( %d n , (res + 1000000009 - 1) % 1000000009);       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105;   struct ANS {     int xa, ya, xb, yb, xc, yc;   };   struct PRE {     int p1, p2, s;   } pre[MAXN][2][2];   int T, n, m;   int a[MAXN][MAXN];   int f[MAXN][2][2];   char s[MAXN];   vector<ANS> ans;   int popcount(int v) { return v ? popcount(v - (v & -v)) + 1 : 0; }   void operate(int x, int y, int nx, int ny, bool flag = 0) {     if (flag) ans.push_back((ANS){0, 0, 0, 0, 0, 0});     for (int i = 0; i <= 1; i++)       for (int j = 0; j <= 1; j++)         if (x + i != nx || j + y != ny) {           if (flag) {             if (ans.back().xa) {               if (ans.back().xb) {                 ans.back().xc = x + i;                 ans.back().yc = y + j;               } else {                 ans.back().xb = x + i;                 ans.back().yb = y + j;               }             } else {               ans.back().xa = x + i;               ans.back().ya = y + j;             }           }           a[x + i][y + j] ^= 1;         }   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; i++) {         scanf( %s , s + 1);         for (int j = 1; j <= m; j++) a[i][j] = s[j] -  0 ;       }       ans.clear();       for (int i = 1; i <= n - 2; i++)         for (int j = 1; j <= m; j++)           if (a[i][j]) {             if (j < m)               operate(i, j, i, j + 1, 1);             else               operate(i, j - 1, i, j - 1, 1);           }       for (int i = 1; i <= m; i++)         for (int j = 0; j <= 1; j++)           for (int k = 0; k <= 1; k++) f[i][j][k] = 1e9;       f[1][a[n - 1][1]][a[n][1]] = 0;       for (int i = 1; i < m; i++)         for (int j = 0; j <= 1; j++)           for (int k = 0; k <= 1; k++)             if (f[i][j][k] != 1e9) {               int t1 = a[n - 1][i], t2 = a[n][i];               a[n - 1][i] = j;               a[n][i] = k;               for (int l = 0; l < 16; l++) {                 if (l & 1) operate(n - 1, i, n - 1, i);                 if (l >> 1 & 1) operate(n - 1, i, n, i);                 if (l >> 2 & 1) operate(n - 1, i, n - 1, i + 1);                 if (l >> 3 & 1) operate(n - 1, i, n, i + 1);                 if (!a[n - 1][i] && !a[n][i] &&                     f[i + 1][a[n - 1][i + 1]][a[n][i + 1]] >                         f[i][j][k] + popcount(l)) {                   f[i + 1][a[n - 1][i + 1]][a[n][i + 1]] =                       f[i][j][k] + popcount(l);                   pre[i + 1][a[n - 1][i + 1]][a[n][i + 1]] = (PRE){j, k, l};                 }                 if (l & 1) operate(n - 1, i, n - 1, i);                 if (l >> 1 & 1) operate(n - 1, i, n, i);                 if (l >> 2 & 1) operate(n - 1, i, n - 1, i + 1);                 if (l >> 3 & 1) operate(n - 1, i, n, i + 1);               }               a[n - 1][i] = t1;               a[n][i] = t2;             }       int t1 = 0, t2 = 0;       for (int i = m; i > 1; i--) {         int l = pre[i][t1][t2].s;         if (l & 1) operate(n - 1, i - 1, n - 1, i - 1, 1);         if (l >> 1 & 1) operate(n - 1, i - 1, n, i - 1, 1);         if (l >> 2 & 1) operate(n - 1, i - 1, n - 1, i, 1);         if (l >> 3 & 1) operate(n - 1, i - 1, n, i, 1);         int n1 = pre[i][t1][t2].p1, n2 = pre[i][t1][t2].p2;         t1 = n1;         t2 = n2;       }       printf( %d n , (int)ans.size());       for (int i = 0; i < ans.size(); i++)         printf( %d %d %d %d %d %d n , ans[i].xa, ans[i].ya, ans[i].xb, ans[i].yb,                ans[i].xc, ans[i].yc);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int t, n;   int main() {     cin >> n >> t;     long long int k = 0;     long long int a, b;     long long int res1 = 1;     long long int res;     cin >> a >> b;     long long int m = (t - a) / b;     if (a >= t)       res = a;     else if (m * b + a == t)       res = t;     else       res = (m + 1) * b + a;     for (int i = 1; i < n; i++) {       cin >> a >> b;       m = (t - a) / b;       if (a >= t) {         if (a < res) {           res = a;           res1 = i + 1;         }       } else if (m * b + a == t) {         res = t;         res1 = i + 1;       } else if ((m + 1) * b + a < res) {         res = (m + 1) * b + a;         res1 = i + 1;       }     }     cout << res1;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int man = 2e5 + 10;   const long long mod = 1e9 + 7;   struct edge {     int v;     int w;     int next;   } e[man << 1];   int head[man];   int cnt;   void init(int n) {     memset(head, 0, sizeof(int) * (n + 5));     cnt = 0;   }   void add(int u, int v, int w) {     e[++cnt].next = head[u];     e[cnt].v = v;     e[cnt].w = w;     head[u] = cnt;   }   int vis[man];   int dfs(int u, int fa) {     int num = 0;     int cnt = 0;     for (int i = head[u]; i; i = e[i].next) {       if (e[i].v == fa) continue;       ++cnt;       int tp = dfs(e[i].v, u);       num += tp;       vis[i] = tp;     }     if (!cnt) num++;     return num;   }   struct node {     long long w;     int cnt, va;     bool operator<(const node &a) const {       return 1ll * (va / 2 + va % 2) * cnt < 1ll * (a.va / 2 + a.va % 2) * a.cnt;     }   };   signed main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       long long s = 0;       long long sum = 0;       scanf( %d%lld , &n, &s);       for (int i = 1; i < n; ++i) {         int u, v, w;         scanf( %d%d%d , &u, &v, &w);         add(u, v, w);         add(v, u, w);       }       dfs(1, 1);       priority_queue<node> q;       for (int i = 1; i <= cnt; ++i) {         if (vis[i] == 0) continue;         sum += 1ll * e[i].w * vis[i];         q.push(node{1ll * e[i].w * vis[i], vis[i], e[i].w});       }       if (sum <= s) {         cout << 0 <<   n ;       } else {         int cnt = 0;         while (q.size()) {           node tp = q.top();           q.pop();           ++cnt;           int tpva = tp.va / 2 + tp.va % 2;           sum -= 1ll * tpva * tp.cnt;           tp.va -= tpva;           tp.w = 1ll * tp.cnt * tp.va;           if (tp.va) q.push(tp);           if (sum <= s) break;         }         cout << cnt <<   n ;       }       memset(vis, 0, sizeof(int) * (cnt + 5));       init(n);     }     return 0;   }


#include <queue>   #include <cstdio>   #include <algorithm>   const int Maxn=200;   const int Maxl=40;   const int Mod=998244353;   int n,m;   namespace Trie{    struct Trie_Node{     int ch[26];     bool pos;    }node[Maxl+5];    int id_tot;    void insert(char *s,int len){     int root=0;     for(int i=1;i<=len;i++){      if(node[root].ch[s[i]- a ]==0){       node[root].ch[s[i]- a ]=++id_tot;      }      root=node[root].ch[s[i]- a ];     }     node[root].pos=1;    }   }   struct Node{    int id,x,y;    Node(int _id=0,int _x=0,int _y=0){     id=_id,x=_x,y=_y;    }   };   std::queue<Node> q;   int id[Maxl+5][Maxl+5],id_tot;   int get_id(int x,int y){    if(x>y){     std::swap(x,y);    }    if(id[x][y]==0){     id[x][y]=++id_tot;     q.push(Node(id[x][y],x,y));    }    return id[x][y];   }   struct Matrix{    int a[Maxn+5][Maxn+5];    void init(){     for(int i=1;i<=id_tot;i++){      for(int j=1;j<=id_tot;j++){       a[i][j]=0;      }     }    }    friend Matrix operator *(Matrix a,Matrix b){     Matrix ans;     ans.init();     for(int i=1;i<=id_tot;i++){      for(int k=1;k<=id_tot;k++){       for(int j=1;j<=id_tot;j++){        ans.a[i][j]=(ans.a[i][j]+1ll*a.a[i][k]*b.a[k][j])%Mod;       }      }     }     return ans;    }   }g;   int main(){    scanf( %d%d ,&n,&m);    for(int i=1;i<=n;i++){     static char s[Maxl+5];     scanf( %s ,s+1);     int len=0;     while(s[++len]!=  0 );     len--;     Trie::insert(s,len);    }    get_id(0,0);    while(!q.empty()){     Node u=q.front();     q.pop();     for(int i=0;i<26;i++){      int a=Trie::node[u.x].ch[i],b=Trie::node[u.y].ch[i];      if(a==0||b==0){       continue;      }      g.a[u.id][get_id(a,b)]++;      if(Trie::node[a].pos){       g.a[u.id][get_id(0,b)]++;      }      if(Trie::node[b].pos){       g.a[u.id][get_id(a,0)]++;      }      if(Trie::node[a].pos&&Trie::node[b].pos){       g.a[u.id][get_id(0,0)]++;      }     }    }    Matrix ans;    ans.init();    for(int i=1;i<=id_tot;i++){     ans.a[i][i]=1;    }    while(m){     if(m&1){      ans=ans*g;     }     g=g*g;     m>>=1;    }    printf( %d n ,ans.a[1][1]);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, m, x, y, ans;   bool b;   int main() {     scanf( %d%d , &n, &k);     ans = n * 2 - k - 1;     for (int i = 1; i <= k; i++) {       scanf( %d , &m);       b = 0;       for (int j = 1; j <= m; j++) {         scanf( %d , &x);         if (j == 1 && x == 1) b = 1;         if ((b) && j > 1 && x > y + 1) {           ans -= (j - 2) * 2;           b = 0;         }         if ((b) && j == m) ans -= (m - 1) * 2;         y = x;       }     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = -1;   const int INF = 1.01e9;   const int MOD = 1e9 + 7;   long long rev(long long a, long long m) {     if (a == 0) return 0;     return ((1 - rev(m % a, a) * m) / a + m) % m;   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     vector<long long> fact(n + 1);     fact[0] = 1;     for (int i = 1; i <= n; i++) {       fact[i] = (fact[i - 1] * i) % MOD;     }     vector<long long> rfact(n + 1);     rfact[n] = rev(fact[n], MOD);     assert(fact[n] * rfact[n] % MOD == 1);     for (int i = n - 1; i >= 0; i--) {       rfact[i] = (rfact[i + 1] * (i + 1)) % MOD;     }     auto getC = [&](int nn, int kk) {       assert(0 <= kk && kk <= nn);       return fact[nn] * rfact[kk] % MOD * rfact[nn - kk] % MOD;     };     vector<long long> f(n + 1);     vector<long long> g(n + 1);     vector<long long> prefG(n + 1);     f[1] = 1;     g[1] = 1;     prefG[1] = 1;     for (int i = 2; i <= n; i++) {       long long tmp = prefG[i - 1];       if (i - k - 1 >= 1) {         tmp = (tmp - prefG[i - k - 1] + MOD) % MOD;       }       tmp = (tmp * fact[i - 2]) % MOD;       f[i] = tmp;       g[i] = f[i] * rfact[i - 1] % MOD;       prefG[i] = (prefG[i - 1] + g[i]) % MOD;     }     long long answer = 0;     for (int i = 1; i <= n; i++) {       answer = (answer + getC(n - 1, i - 1) * f[i] % MOD * fact[n - i]) % MOD;     }     cout << (fact[n] - answer + MOD) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int paths[5001][5001];   int ct[5001], top[5001], freq[5001];   int main() {     for (int i = 2; i <= 5000; i++) {       for (int j = 2; j <= 5000; j++) {         paths[i][j] = paths[i - 1][j];       }       int tmp = i;       for (int j = 2; j <= sqrt(tmp); j++) {         while (tmp > 0 && tmp % j == 0) {           tmp /= j;           paths[i][j]++;         }       }       if (tmp > 1) paths[i][tmp]++;     }     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int k;       cin >> k;       ct[k]++;     }     long long sol = 0;     fill(top, top + 5001, 1);     for (int i = 1; i <= 5000; i++) {       if (!ct[i]) continue;       for (int j = 1; j <= 5000; j++) {         sol += 1LL * paths[i][j] * ct[i];         if (paths[i][j]) top[i] = j;       }     }     while (true) {       memset(freq, 0, sizeof freq);       for (int i = 1; i <= 5000; i++) {         if (!ct[i]) continue;         freq[top[i]] += ct[i];       }       int most = max_element(freq, freq + 5001) - freq;       if (freq[most] * 2 <= n || most == 1) break;       sol -= freq[most];       sol += n - freq[most];       for (int i = 1; i <= 5000; i++) {         if (top[i] != most) {           top[i] = 1;         }         if (top[i] == 1) continue;         paths[i][top[i]]--;         while (top[i] > 1 && paths[i][top[i]] == 0) {           top[i]--;         }       }     }     cout << sol <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     long long int k, b, n, t;     while (cin >> k >> b >> n >> t) {       long long int s = 1;       long long int cas = 0;       while (s <= t && cas < n) {         s = s * k + b;         cas++;       }       if (cas == n && s <= t)         cout << 0 << endl;       else         cout << n - cas + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100005;   int nbs[maxn], ev[maxn * 2], next[maxn * 2], color[maxn], d[maxn], ans[maxn],       size[2], view[maxn], n, m, k;   void addedge(int x, int y) {     next[++k] = nbs[x];     ev[k] = y;     nbs[x] = k;   }   void init() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       addedge(x, y);       addedge(y, x);       ++d[x];       ++d[y];     }   }   void dfs(int x, int col) {     color[x] = col;     ++size[col];     for (int i = nbs[x]; i; i = next[i]) {       if (color[ev[i]] == -1) dfs(ev[i], col ^ 1);     }   }   void output(int x) {     int y = 0;     for (int i = 1; i <= n; ++i) {       if (!ans[i] && color[i] == 0) {         ans[i] = x;         ++y;         if (y % 3 == 0) ++x;       }     }     for (int i = 1; i <= n; ++i) {       if (!ans[i] && color[i] == 1) {         ans[i] = x;         ++y;         if (y % 3 == 0) ++x;       }     }     printf( YES n );     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     printf(  n );   }   void solve(int x, int y = 1) {     memset(view, 0, sizeof(view));     ans[x] = y;     for (int i = nbs[x]; i; i = next[i]) view[ev[i]] = 1;     int k = 0;     for (int i = 1; i <= n && k < 2; ++i) {       if (!ans[i] && color[i] != color[x] && !view[i]) {         ans[i] = y;         ++k;       }     }   }   void work() {     memset(color, -1, sizeof(color));     for (int i = 1; i <= n; ++i) {       if (color[i] == -1) dfs(i, 0);     }     if (size[0] % 3 == 0)       output(1);     else {       int col = size[0] % 3 - 1, find = 0;       for (int i = 1; i <= n && !find; ++i) {         if (color[i] == col && d[i] + 2 <= size[col ^ 1]) {           solve(i);           find = 1;         }       }       if (find)         output(find + 1);       else {         col ^= 1;         int t = 0;         for (int i = 1; i <= n && find < 2; ++i) {           if (color[i] == col && d[i] + 2 <= size[col ^ 1]) {             solve(i, find + 1);             ++find;           }         }         if (find == 2)           output(find + 1);         else           printf( NO n );       }     }   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> s(n), r(n);     for (int i = 0; i < n; i++) {       cin >> s[i] >> r[i];     }     vector<tuple<int, int, int>> T(n);     for (int i = 0; i < n; i++) {       T[i] = make_tuple(s[i], r[i], i);     }     sort(T.begin(), T.end(), greater<tuple<int, int, int>>());     vector<int> id(n);     for (int i = 0; i < n; i++) {       s[i] = get<0>(T[i]);       r[i] = get<1>(T[i]);       id[i] = get<2>(T[i]);     }     int mx = -1, ms = -1;     vector<int> s2, r2, id2;     vector<vector<int>> p;     int n2 = 0;     for (int i = 0; i < n; i++) {       if (r[i] > mx) {         mx = r[i];         ms = s[i];         s2.push_back(s[i]);         r2.push_back(r[i]);         id2.push_back(id[i]);         p.push_back(vector<int>(0));         n2++;       } else if (r[i] == mx && s[i] == ms) {         p.back().push_back(id[i]);       }     }     stack<int> st;     st.push(0);     if (n2 > 1) {       st.push(1);     }     for (int i = 2; i < n2; i++) {       while (st.size() >= 2) {         int b = st.top();         st.pop();         int a = st.top();         st.pop();         long long A =             (long long)s2[i] * r2[a] * (r2[b] - r2[i]) * (s2[b] - s2[a]);         long long B =             (long long)s2[a] * r2[i] * (r2[a] - r2[b]) * (s2[i] - s2[b]);         if (A <= B) {           st.push(a);           st.push(b);           break;         } else {           st.push(a);         }       }       st.push(i);     }     vector<int> ans;     while (!st.empty()) {       int x = st.top();       st.pop();       ans.push_back(id2[x]);       for (int y : p[x]) {         ans.push_back(y);       }     }     sort(ans.begin(), ans.end());     int cnt = ans.size();     for (int i = 0; i < cnt; i++) {       cout << ans[i] + 1;       if (i < cnt - 1) {         cout <<    ;       }     }     cout << endl;   }


#include <bits/stdc++.h>      #define MULTI_TEST false   #define int long long   #define double long double      //#pragma GCC optimize( Ofast )   //#pragma GCC optimize( no-stack-protector )   //#pragma GCC optimize( unroll-loops )   //#pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )      #define all(x) x.begin(), x.end()      using namespace std;      const int INF = 1e18;      int n, k;   vector<vector<int>> g;   vector<int> p;   vector<int> chainp, chainc;   vector<vector<int>> chains;   vector<vector<int>> g1;   vector<int> tin, tout;   vector<int> group;   vector<int> used, used1;   vector<int> ts;      int timer = 1;      int bad = 0;      void dfs(int v) {       used[v] = 1;       int x = chainc[v];       if (used[x] == 1) {           bad = 1;           return;       }       if (used[x] == 0) {           dfs(x);       }       used[v] = 2;   }      void dfs1(int v) {       used1[v] = 1;       for (auto &x: g1[v]) {           if (used1[x] == 1) {               bad = 1;               return;           }           if (used1[x] == 0) {               dfs1(x);           }       }       used1[v] = 2;       ts.push_back(v);   }      void solve() {       cin >> n >> k;       p.resize(n);       g.resize(n);       tin.resize(n, -1);       tout.resize(n, -1);       chainp.resize(n, -1);       chainc.resize(n, -1);       int q = 0;       for (int i = 0; i < n; i++) {           int x;           cin >> x;           x--;           p[i] = x;       }       for (int i = 0; i < k; i++) {           int x, y;           cin >> x >> y;           x--;           y--;           chainp[y] = x;           chainc[x] = y;       }       used.resize(n, 0);       used1.resize(n, 0);       group.resize(n, -1);       for (int i = 0; i < n; i++) {           if (used[i] == 0)               dfs(i);       }       if (bad == 1) {           cout << 0;           return;       }       for (int i = 0; i < n; i++) {           if (chainp[i] == -1) {               chains.emplace_back();               int v = i;               group[v] = chains.size() - 1;               chains.back().push_back(v);               while (chainc[v] != -1) {                   v = chainc[v];                   group[v] = chains.size() - 1;                   chains.back().push_back(v);               }           }       }       g1.resize(chains.size());       for (int i = 0; i < n; i++) {           if (p[i] != -1) {               int x = p[i];               if (group[x] != group[i]) {                   g1[group[x]].push_back(group[i]);               }           }       }       for (int i = 0; i < g1.size(); i++) {           if (used1[i] == 0) {               dfs1(i);           }       }       reverse(all(ts));       vector<int> fin;       if (bad == 1) {           cout << 0;           return;       }       for (auto &x: ts) {           for (auto &y: chains[x]) {               fin.push_back(y);           }       }       map<int, int> topos;       for (int i = 0; i < n; i++) {           topos[fin[i]] = i;       }       for (int i = 0; i < n; i++) {           if (p[i] != -1) {               int x = i;               int y = p[i];               if (topos[y] > topos[x])                   bad = 1;           }       }       if (bad == 1) {           cout << 0;           return;       }       for (auto &x: fin) {           cout << x + 1 <<    ;       }   }      signed main() {       cin.tie(0);       ios::sync_with_stdio(false);      #ifdef DEBUG       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif       int t = 1;       if (MULTI_TEST)           cin >> t;       while (t--)           solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j;     char c =  W ;     cin >> t;     for (i = 0; i < t; i++) {       for (j = 0; j < t; j++) {         cout << c;         if (c ==  B )           c =  W ;         else           c =  B ;       }       if (t % 2 == 0) {         if (c ==  B )           c =  W ;         else           c =  B ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   inline long long mod(long long n) {     if (n < 0) {       return (n % MOD + MOD) % 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; (1ll << 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 = 103;   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; (1ll << 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;   const long long MOD = 1000000007;   const long double EPS = 1e11;   const long long INFL = 1e16;   const int INF = 1e9 + 7;   mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());   int highdig(long long x) {     int ans = 0;     while (x > 0LL) {       x /= 2LL;       ++ans;     }     return ans;   }   long long umen(long long x, vector<long long>& ea, vector<long long>& eb,                  vector<char>& ec) {     long long cx = x;     long long highdigx = 1;     while (highdigx * 2LL <= x) {       highdigx *= 2LL;     }     while (cx % highdigx != 0LL) {       ea.push_back(cx);       eb.push_back(cx);       ec.push_back( + );       cx *= 2LL;     }     ea.push_back(x);     ea.push_back(x);     eb.push_back(cx);     eb.push_back(cx);     ec.push_back( + );     ec.push_back( ^ );     long long y2 = cx + x;     long long y3 = (cx ^ x);     ea.push_back(y2);     eb.push_back(y3);     ec.push_back( ^ );     cx = (y2 ^ y3);     while (highdig(cx) > highdig(x)) {       long long ccx = x;       while (highdig(ccx) < highdig(cx)) {         ea.push_back(ccx);         eb.push_back(ccx);         ec.push_back( + );         ccx *= 2LL;       }       ea.push_back(cx);       eb.push_back(ccx);       ec.push_back( ^ );       cx ^= ccx;     }     while (highdig(cx) < highdig(x)) {       ea.push_back(cx);       eb.push_back(cx);       ec.push_back( + );       cx *= 2LL;     }     ea.push_back(x);     eb.push_back(cx);     ec.push_back( ^ );     while ((x ^ cx) % 2 == 0) {       cx = cx;     }     return (x ^ cx);   }   long long trie(long long x, vector<long long>& ea, vector<long long>& eb,                  vector<char>& ec) {     ea.push_back(x);     eb.push_back(x);     ec.push_back( + );     long long y1 = x * 2LL;     ea.push_back(x);     eb.push_back(y1);     ec.push_back( + );     long long y2 = x + y1;     ea.push_back(y1);     eb.push_back(y1);     ec.push_back( + );     ea.push_back(y2);     eb.push_back(y1 * 2LL);     ec.push_back( ^ );     long long y3 = (y2 ^ (2 * y1));     ea.push_back(y2);     eb.push_back(y3);     ec.push_back( + );     long long y4 = y2 + y3;     ea.push_back(2 * y1);     eb.push_back(y4);     ec.push_back( ^ );     for (long long cd = 2LL; x > 1LL; cd *= 2LL) {       ea.push_back(x);       eb.push_back(cd);       ec.push_back( ^ );       ea.push_back(cd);       eb.push_back(cd);       ec.push_back( + );       x ^= cd;     }     return 1LL;   }   void solve() {     long long x;     cin >> x;     vector<long long> ea, eb;     vector<char> ec;     while (x > 1LL) {       if ((x & (x + 1LL)) > 0LL) {         x = umen(x, ea, eb, ec);       } else {         x = trie(x, ea, eb, ec);       }     }     cout << ea.size() <<   n ;     for (int i = 0; i < ea.size(); ++i) {       cout << ea[i] <<     << ec[i] <<     << eb[i] <<   n ;     }   }   int main() {     int t = 1;     for (int i = 0; i < t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i;     cin >> n;     i = 1;     while (n % i == 0) {       i = i * 3;     }     cout << n / i + 1;   }


#include <bits/stdc++.h>   int temp[500000], a[500000], indices[500000], increments[500000],       previous_appearance[500000], numbers_equal_c[500000];   void mergesort(int Array[], int indices[], int first, int last) {     if (first == last) return;     int middle = (first + last) / 2;     mergesort(Array, indices, first, middle);     mergesort(Array, indices, middle + 1, last);     int i, j, k;     for (i = first, j = first, k = middle + 1; i <= last; i++) {       if (j == middle + 1)         temp[i] = indices[k++];       else if (k == last + 1)         temp[i] = indices[j++];       else if (Array[indices[k]] < Array[indices[j]])         temp[i] = indices[k++];       else         temp[i] = indices[j++];     }     for (i = first; i <= last; i++) {       indices[i] = temp[i];     }   }   int main() {     int n, i, one_counter = 0, c, maximum_increament = 0, number_equal_to_c = 0;     scanf( %d %d , &n, &c);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       indices[i] = i;       previous_appearance[i] = -1;       numbers_equal_c[i] = 0;       increments[i] = 0;     }     mergesort(a, indices, 0, n - 1);     for (i = 1; i < n; i++) {       if (a[indices[i]] == a[indices[i - 1]]) {         previous_appearance[indices[i]] = indices[i - 1];       }     }     for (i = 0; i < n; i++) {       if (a[i] == c) {         number_equal_to_c++;       } else {         if (previous_appearance[i] == -1 ||             increments[previous_appearance[i]] - number_equal_to_c +                     numbers_equal_c[previous_appearance[i]] + 1 <=                 0)           increments[i] = 1;         else           increments[i] = increments[previous_appearance[i]] - number_equal_to_c +                           numbers_equal_c[previous_appearance[i]] + 1;         if (maximum_increament < increments[i])           maximum_increament = increments[i];       }       numbers_equal_c[i] = number_equal_to_c;     }     printf( %d , number_equal_to_c + maximum_increament);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       int ans = n;       for (int i = 1; i * i <= n; i++)         if (n % i == 0) {           if (i <= k) ans = min(ans, n / i);           if (n / i <= k) ans = min(ans, i);         }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, s, x;     scanf( %d%d%d , &t, &s, &x);     if (x < t) {       puts( NO );       return 0;     }     int temp = (x - t) % s;     if (temp == 0 || temp == 1) {       if (x == t + 1)         puts( NO );       else         puts( YES );     } else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<long long int> s;   int main() {     long long int n, m, i, ans = 0;     cin >> n >> m;     long long int a[n], c[200005] = {0};     for (i = 0; i < m; i++) s.insert(i);     for (i = 0; i < n; i++) {       long long int d, x;       cin >> a[i];       d = a[i] % m;       if (d > *s.rbegin())         x = *s.begin();       else         x = *s.lower_bound(d);       if (++c[x] == n / m) s.erase(x);       ans += (x - d + m) % m;       a[i] += (x - d + m) % m;     }     cout << ans << endl;     for (i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long mod = 1e9 + 7;   inline long long add(long long a, long long b) {     return (a % mod + b % mod) % mod;   }   inline long long sub(long long a, long long b) {     return (a % mod - b % mod + mod) % mod;   }   inline long long mul(long long a, long long b) {     return (a % mod * b % mod) % mod;   }   inline long long power(long long a, long long b, long long MOD) {     long long res = 1;     while (b) {       if (b & 1) {         res *= a;         res %= MOD;       }       a = a * a;       a %= MOD;       b >>= 1;     }     return res;   }   clock_t time_p = clock();   void time() {     time_p = clock() - time_p;     cerr <<  Time elapsed :   << (long double)(time_p) / CLOCKS_PER_SEC <<   n ;   }   bool go(string a, string b) {     if (a == b) return true;     long long n1 = a.length();     long long n2 = b.length();     if (n1 & 1 || n2 & 1) return false;     string a1, a2, b1, b2;     for (long long i = 0; i < n1 / 2; i++) a1 += a[i];     for (long long i = n1 / 2; i < n1; i++) a2 += a[i];     for (long long i = 0; i < n2 / 2; i++) b1 += b[i];     for (long long i = n2 / 2; i < n2; i++) b2 += b[i];     if (go(a1, b2) && go(a2, b1)) return true;     if (go(a1, b1) && go(a2, b2)) return true;     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     string a, b;     cin >> a >> b;     cout << (go(a, b) ?  YES  :  NO ) <<   n ;     time();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   int main() {     int l, t;     scanf( %d %d , &l, &t);     scanf( %s , s + 1);     s[0] =  0 ;     for (int i = 0; i <= l; i++) {       if (s[i] ==  . ) {         for (int j = i + 1; j <= l; j++)           if (s[j] >=  5 ) {             s[j] = 0;             bool roundup = true;             t--;             for (int k = j - 1; k > i; k--) {               if (roundup) {                 s[k]++;                 if (s[k] >=  5  && t) {                   s[k] = 0;                   t--;                   roundup = true;                 } else                   roundup = false;               }             }             if (roundup) {               s[i] = 0;               for (int k = i - 1; k >= 0; k--) {                 s[k]++;                 if (s[k] <=  9 )                   break;                 else                   s[k] =  0 ;               }             }             break;           }       }     }     if (s[0] !=  0 ) {       printf( %s n , s);     } else {       printf( %s n , s + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   string rep(char c, int x) {     string ret =   ;     for (int i = 0; i < x; i++) {       ret += c;     }     return ret;   }   int main() {     int n, k;     cin >> n >> k;     if (n == k) {       string ans =   ;       for (int i = 0; i < n; i++) {         ans +=  0 ;       }       cout << ans << endl;       return 0;     } else if (k == 1) {       string ans =  1  + rep( 0 , n - 1);       cout << ans << endl;       return 0;     } else {       int diff = n - k;       string repl =  1  + rep( 0 , diff / 2);       string ans =   ;       while (true) {         if (ans.size() + repl.size() > n) {           break;         }         ans += repl;       }       int rem = n - ans.size();       for (int i = 0; i < rem; i++) {         ans += repl[i];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int x, y, i;     if (b * c > a * d) {       x = b * c - a * d;       y = b * c;     } else {       x = a * d - b * c;       y = a * d;     }     while (1) {       int k = 0;       for (i = 2; i <= x; i++) {         if (x % i == 0 && y % i == 0) {           x = x / i;           y = y / i;           k++;         }       }       if (k == 0) break;     }     if (x == 0)       cout << x <<  /             <<  1 ;     else       cout << x <<  /  << y;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1000000007;   int N;   struct M {     int a[250][250];     M() { memset(a, 0, sizeof(a)); }   };   M I() {     M res;     for (int i = 0; i < N; i++) res.a[i][i] = 1;     return res;   }   M operator*(const M& a, const M& b) {     M ans;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++)         for (int k = 0; k < N; k++)           ans.a[i][j] = (ans.a[i][j] + 1ll * a.a[i][k] * b.a[k][j]) % Mod;     return ans;   }   int k, m;   int id(int x, int y) { return x * (1 << m) + y; }   M fpow(M a, int b) {     M ans = I(), t = a;     while (b) {       if (b & 1) ans = ans * t;       t = t * t;       b >>= 1;     }     return ans;   }   int cnt(int x) {     int ans = 0;     while (x) {       ans += (x & 1);       x >>= 1;     }     return ans;   }   int main() {     int n;     scanf( %d %d %d , &n, &k, &m);     N = (k + 1) * (1 << m);     M S, T;     S.a[0][0] = 1;     for (int c = 0; c <= k; c++)       for (int s = 0; s < (1 << m); s++) {         T.a[id(c, s)][id(c, s >> 1)]++;         if (c < k)           T.a[id(c, s)][id(c + 1, (s >> 1) | (1 << (m - 1)))] += cnt(s) + 1;       }     S = S * fpow(T, n);     int ans = 0;     for (int s = 0; s < (1 << m); s++) ans = (ans + S.a[0][id(k, s)]) % Mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, v;     cin >> n >> v;     vector<vector<int> > mat(n + 1, vector<int>(v + 1, INT_MAX));     for (int i = 1, j = 0; j <= v; j++) {       mat[i][j] = j;     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j <= v; j++) {         if (j < v) {           mat[i][j] = mat[i - 1][j + 1];         } else {           mat[i][j] = mat[i][j - 1] + i;         }       }     }     cout << mat[n][0] << endl;     return 0;   }


#include <bits/stdc++.h>   int n;   double sum, tmp, ans;   int main() {     scanf( %d , &n);     for (int div = 1; div <= n; div++) {       scanf( %lf , &tmp);       sum += tmp;       if (sum / div > ans) ans = sum / div;     }     printf( %.20lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie(0);     long long n, p = 0, q = 0, l = 0, i, flag = 0, k, m, t, j, r = 0, curr = 0, d;     cin >> n >> m;     long long a[n], b[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       cin >> b[i];     }     if (a[0] == 0) {       cout <<  NO ;       return 0;     }     if (a[0] != 0) {       if (a[m - 1] != 0) {         cout <<  YES ;         return 0;       }     }     if (a[m - 1] == 0) {       for (long long i = m; i < n; i++) {         if (a[i] == 1 && b[i] == 1) {           if (b[m - 1] == 1) {             flag = 1;             break;           }         }       }     }     if (flag == 1) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Mo = 1000000007LL;   long long f[60][60], g[60][60];   long long fac[70], inv[70];   int n, m;   void add(long long &a, long long b) {     a += b;     a %= Mo;   }   long long fpm(long long a, long long b) {     long long ans = 1LL;     for (; b; b >>= 1) {       if (b & 1LL) ans *= a, ans %= Mo;       a *= a;       a %= Mo;     }     return ans;   }   long long C(long long a, long long b) {     a += b - 1;     a %= Mo;     if (a < b) return 0LL;     long long ans = 1LL;     for (int i = a; i > a - b; i--) ans = ans * i % Mo;     ans *= inv[b];     return ans % Mo;   }   void solve() {     f[2][1] = 1;     for (int i = 1; i <= 52; i++) {       for (int x = 2; x <= i + 1; x++) {         int y = i + 3 - x;         for (int a = 1; a <= x; a++)           for (int b = 1; b <= y; b++) add(g[i][min(a, b)], f[x][a] * f[y][b]);       }       for (int x = 1; x <= i; x++)         for (int j = 52; j >= 2; j--) {           for (int k = 1; k * i + 2 <= j; k++) {             for (int y = x * k; y <= j; y++)               add(f[j][y], f[j - i * k][y - x * k] * C(g[i][x], k));           }         }     }   }   int main() {     fac[0] = 1;     for (int i = 1; i <= 60; i++) fac[i] = (fac[i - 1] * (long long)i) % Mo;     for (int i = 0; i <= 60; i++) inv[i] = fpm(fac[i], Mo - 2LL);     scanf( %d %d , &n, &m);     solve();     cout << f[n + 2][m] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x20202020;   const int mod = 1000000007;   inline void read(int &x) {     char ch;     bool f = 0;     int a = 0;     while (!((((ch = getchar()) >=  0 ) && (ch <=  9 )) || (ch ==  - )))       ;     if (ch !=  - )       a *= 10, a += ch -  0 ;     else       f = 1;     while (((ch = getchar()) >=  0 ) && (ch <=  9 )) a *= 10, a += ch -  0 ;     if (f) a = -a;     x = a;   }   const int DX[] = {1, 0, -1, 0}, DY[] = {0, 1, 0, -1};   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long powmod(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const int N = 111111, M = 111111;   int l, m, n, t, tot;   struct zcc {     int x, v;   } a[N];   inline bool cmp(const zcc &a, const zcc &b) { return a.v < b.v; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i].v), a[i].x = i, tot += a[i].v;     sort(a + 1, a + 1 + n, cmp);     if (n == 1 && m == tot) {       puts( Yes );       for (int i = 1; i <= 2 * a[1].v - 1; ++i) printf( %d  , a[1].x);       printf( %d n , a[1].x);     } else if (n >= 2 && m >= 2 && m <= tot) {       puts( Yes );       while (m > 2) {         if (a[1].v > 1)           a[1].v--, printf( %d %d  , a[1].x, a[1].x), m--;         else if (a[n].v)           a[n].v--, printf( %d %d  , a[n].x, a[n].x), m--;         else           n--;       }       if (a[2].v) {         a[2].v--;         a[1].v--;         printf( %d  , a[1].x);         for (int i = 2; i <= n; ++i)           for (int j = 1; j <= a[i].v; ++j) printf( %d %d  , a[i].x, a[i].x);         printf( %d  , a[1].x);         printf( %d  , a[2].x);         for (int i = 1; i <= a[1].v; ++i) printf( %d %d  , a[1].x, a[1].x);         printf( %d n , a[2].x);       } else {         printf( %d %d n , a[1].x, a[1].x);       }     } else if (n >= 2 && m == 1 && a[1].v == 1) {       puts( Yes );       printf( %d  , a[1].x);       for (int i = 2; i <= n; ++i)         for (int j = 1; j <= a[i].v; ++j) printf( %d %d  , a[i].x, a[i].x);       printf( %d n , a[1].x);     } else       puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j, x;   long long sum;   char s[30];   vector<int> a;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %s , s);       if (s[0] ==  s ) {         sum = 0;         for (j = 2; j < a.size(); j += 5) {           sum += a[j];         }         cout << sum;         printf(  n );       } else {         scanf( %d , &x);         if (s[0] ==  a )           a.insert(lower_bound(a.begin(), a.end(), x), x);         else           a.erase(lower_bound(a.begin(), a.end(), x));       }     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   const unsigned long long bigN = 1e18;   const long long mod9 = 1e9 + 9;   const long long mod7 = 1e9 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<int> a, b;     int n, l, r, x;     cin >> n >> l >> r;     for (int i = 1; i <= n; i++) {       cin >> x;       if (i >= l && i <= r) {         continue;       } else {         a.push_back(x);       }     }     for (int i = 1; i <= n; i++) {       cin >> x;       if (i >= l && i <= r) {         continue;       } else {         b.push_back(x);       }     }     if (a == b) {       cout <<  TRUTH ;     } else {       cout <<  LIE ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> M;   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string name, ip;       cin >> name >> ip;       M[ip] = name;     }     for (int i = 0; i < m; i++) {       string cmd, ip;       cin >> cmd >> ip;       ip.pop_back();       cout << cmd <<     << ip <<  ; #  << M[ip] << endl;     }   }


#include <bits/stdc++.h>   #define ll long long   using namespace std;   const ll N = 5005, MOD = 998244353;   vector<vector<ll>> dp(N, vector<ll>(N));   vector<vector<int>> edges(N);   vector<int> h(N);   int n, k;   void add(ll &x, ll y) {    if((x += y) >= MOD) {     x -= MOD;    }   }   void dfs(int x, int p) {    dp[x][0] = 1;     for(int to : edges[x]) {     if(to != p) {      dfs(to, x);      vector<ll> temp(N);      for(int L1 = 0; L1 <= min(h[x], k); ++L1) {       for(int L2 = 0; L2 <= h[to]; ++L2) {        ll ways = dp[x][L1] * dp[to][L2] % MOD;        if(L1 + L2 < k) add(temp[max(L1, L2+1)], ways);        add(temp[L1], ways);       }      }      dp[x] = temp;      h[x] = max(h[x], h[to]+1);     }    }   }   int main() {    ios::sync_with_stdio(0); cin.tie(0);    cin >> n >> k;    for(int i = 0; i < n - 1; ++i) {     int u, v; cin >> u >> v;     edges[u].push_back(v);     edges[v].push_back(u);    }    dfs(1, 0);    ll ans = 0;    for(int i = 0; i <= k; ++i) {     add(ans, dp[1][i]);    }    cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 2e5 + 9;   int a[maxn], b[maxn];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]);     }     long long ans = 1;     int l = n, r = n;     for (int i = m; i >= 1; i--) {       while (a[r] > b[i]) r--;       if (a[r] != b[i] || r == 0) {         ans = 0;         break;       }       l = r;       while (a[l] >= b[i]) l--;       if (i != 1)         ans = ans * (r - l) % mod;       else if (l != 0)         ans = 0;       r = l;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[5] = {}, b[5] = {};     for (int k = 0; k < n; k++) {       int x;       cin >> x;       a[x - 1]++;     }     for (int k = 0; k < n; k++) {       int x;       cin >> x;       b[x - 1]++;     }     int cnt = 0;     for (int k = 0; k < 5; k++) {       if ((a[k] + b[k]) % 2 != 0) {         cout << -1;         return 0;       }       cnt += (max(a[k], b[k]) - min(a[k], b[k])) / 2;     }     cout << (cnt % 2 == 0 ? cnt / 2 : -1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     unordered_map<int, int> m;     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       m[x]++;     }     int ans = 0;     for (pair<int, int> x : m) ans += x.second / 2;     printf( %d n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1000000 + 5;   const long long inf = 1e9;   const long long mod = 1e9 + 7;   int a[MX], k;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, p, x, y, tc;     cin >> tc;     while (tc--) {       cin >> n >> p >> k;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + n + 1);       int rs = 0, pre = 0;       for (int i = 1; i <= k; i++) {         int sm = pre;         if (pre > p) break;         rs = max(rs, i - 1);         for (int j = i + k - 1; j <= n; j += k) {           sm += a[j];           if (sm > p) break;           rs = max(rs, j);         }         pre += a[i];       }       cout << rs << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     unordered_map<string, long long> m;     m[ Tetrahedron ] = 4;     m[ Cube ] = 6;     m[ Octahedron ] = 8;     m[ Dodecahedron ] = 12;     m[ Icosahedron ] = 20;     long long n;     cin >> n;     long long count = 0;     while (n--) {       string str;       cin >> str;       count += m[str];     }     cout << count << endl;     return 0;   }


#include<bits/stdc++.h>   using namespace std;   namespace Acc{    const int N = 1e2+10;    string a,b;       int n;       void work(){           queue<pair<string,int> >q;           cin>>n>>a,q.push({b,0});           while(1){               auto[u,pos]=q.front();q.pop();               u.resize(pos+1);               for(int i=0;i<26;i++){                   u[pos]=(char)( a +i);                   if(a.find(u)==string::npos)return (void)(cout<<u);                   q.push({u,pos+1});               }           }       }   }   int main(){    int T;    for(cin>>T;T--;puts(  ))Acc::work();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long par[27];   long long parent(long long x) {     while (x != par[x]) {       par[x] = par[par[x]];       x = par[x];     }     return x;   }   void uni(long long x, long long y) {     long long px = parent(x);     long long py = parent(y);     par[y] = px;   }   int main() {     long long t = 1;     while (t--) {       long long n;       cin >> n;       set<long long> st;       for (long long i = 0; i < 27; i++) par[i] = i;       for (long long i = 0; i < n; i++) {         string s;         cin >> s;         st.insert(s[0] -  a );         for (long long i = 1; i < s.length(); i++) {           st.insert(s[i] -  a );           uni(s[0] -  a , s[i] -  a );         }       }       long long ans = 0;       for (long long i = 0; i < 26; i++)         if (parent(i) == i && st.find(i) != st.end()) ans++;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   const long long INF(0x3f3f3f3f3f3f3f3fll);   const long long inf(0x3f3f3f3f);   template <typename T>   void read(T &res) {     bool flag = false;     char ch;     while (!isdigit(ch = getchar())) (ch ==  - ) && (flag = true);     for (res = ch - 48; isdigit(ch = getchar());          res = (res << 1) + (res << 3) + ch - 48)       ;     flag && (res = -res);   }   template <typename T>   void Out(T x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) Out(x / 10);     putchar(x % 10 +  0 );   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long pow_mod(long long x, long long n, long long mod) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   long long fact_pow(long long n, long long p) {     long long res = 0;     while (n) {       n /= p;       res += n;     }     return res;   }   long long mult(long long a, long long b, long long p) {     a %= p;     b %= p;     long long r = 0, v = a;     while (b) {       if (b & 1) {         r += v;         if (r > p) r -= p;       }       v <<= 1;       if (v > p) v -= p;       b >>= 1;     }     return r;   }   long long quick_pow(long long a, long long b, long long p) {     long long r = 1, v = a % p;     while (b) {       if (b & 1) r = mult(r, v, p);       v = mult(v, v, p);       b >>= 1;     }     return r;   }   bool CH(long long a, long long n, long long x, long long t) {     long long r = quick_pow(a, x, n);     long long z = r;     for (long long i = 1; i <= t; i++) {       r = mult(r, r, n);       if (r == 1 && z != 1 && z != n - 1) return true;       z = r;     }     return r != 1;   }   bool Miller_Rabin(long long n) {     if (n < 2) return false;     if (n == 2) return true;     if (!(n & 1)) return false;     long long x = n - 1, t = 0;     while (!(x & 1)) {       x >>= 1;       t++;     }     srand(time(NULL));     long long o = 8;     for (long long i = 0; i < o; i++) {       long long a = rand() % (n - 1) + 1;       if (CH(a, n, x, t)) return false;     }     return true;   }   long long exgcd1(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long t = exgcd1(b, a % b, y, x);     y -= a / b * x;     return t;   }   long long get_inv(long long a, long long mod) {     long long x, y;     long long d = exgcd1(a, mod, x, y);     return d == 1 ? (x % mod + mod) % mod : -1;   }   void exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return;     }     exgcd(b, a % b, x, y);     long long t = x;     x = y, y = t - (a / b) * y;   }   long long INV(long long a, long long b) {     long long x, y;     return exgcd(a, b, x, y), (x % b + b) % b;   }   long long crt(long long x, long long p, long long mod) {     return INV(p / mod, mod) * (p / mod) * x;   }   long long FAC(long long x, long long a, long long b) {     if (!x) return 1;     long long ans = 1;     for (long long i = 1; i <= b; i++)       if (i % a) ans *= i, ans %= b;     ans = pow_mod(ans, x / b, b);     for (long long i = 1; i <= x % b; i++)       if (i % a) ans *= i, ans %= b;     return ans * FAC(x / a, a, b) % b;   }   long long C(long long n, long long m, long long a, long long b) {     long long N = FAC(n, a, b), M = FAC(m, a, b), Z = FAC(n - m, a, b), sum = 0,               i;     for (i = n; i; i = i / a) sum += i / a;     for (i = m; i; i = i / a) sum -= i / a;     for (i = n - m; i; i = i / a) sum -= i / a;     return N * pow_mod(a, sum, b) % b * INV(M, b) % b * INV(Z, b) % b;   }   long long exlucas(long long n, long long m, long long p) {     long long t = p, ans = 0, i;     for (i = 2; i * i <= p; i++) {       long long k = 1;       while (t % i == 0) {         k *= i, t /= i;       }       ans += crt(C(n, m, i, k), p, k), ans %= p;     }     if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p;     return ans % p;   }   const long long N = 1e6 + 10;   long long tree[N << 2];   long long n, m;   long long a[N], sum[N];   map<long long, long long> pos;   long long lowbit(long long x) { return x & (-x); }   void add(long long pos, long long val) {     while (pos <= n) {       tree[pos] ^= val;       pos += lowbit(pos);     }   }   long long get(long long pos) {     long long res = 0;     while (pos) {       res ^= tree[pos];       pos -= lowbit(pos);     }     return res;   }   long long get_sum(long long l, long long r) { return get(r) ^ get(l - 1); }   struct Q {     long long l, r, ans, id;     bool operator<(const Q &a) const { return r < a.r; }   } q[N];   bool cmp(Q a, Q b) { return a.id < b.id; }   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] ^ a[i];     cin >> m;     for (long long i = 1; i <= m; i++) cin >> q[i].l >> q[i].r, q[i].id = i;     sort(q + 1, q + 1 + m);     long long now = 1;     for (long long i = 1; i <= m; i++) {       long long l = q[i].l, r = q[i].r, id = q[i].id;       while (now <= r) {         if (pos[a[now]]) add(pos[a[now]], a[now]);         pos[a[now]] = now;         add(pos[a[now]], a[now]);         now++;       }       q[i].ans = (sum[r] ^ sum[l - 1]) ^ get_sum(l, r);     }     sort(q + 1, q + 1 + m, cmp);     for (long long i = 1; i <= m; i++) cout << q[i].ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   long long int fast_pow(long long int base, long long int exp,                          long long int M = 1000000007) {     base = base % M;     long long int result = 1;     while (exp > 0) {       if (exp % 2 == 1) result = (result * base) % M;       base = (base * base) % M;       exp = exp / 2;     }     return result;   }   long long int modInverse(long long int A, long long int M = 1000000007) {     return fast_pow(A, M - 2, M);   }   long long int maxSubArraySum(long long int a[], long long int size) {     long long int max_so_far = INT_MIN, max_ending_here = 0;     for (long long int i = 0; i < size; i++) {       max_ending_here = max_ending_here + a[i];       if (max_so_far < max_ending_here) max_so_far = max_ending_here;       if (max_ending_here < 0) max_ending_here = 0;     }     return max_so_far;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       long long int yass = 0;       cin >> n;       long long int v[n];       for (long long int i = 0; i <= n - 1; i++) {         cin >> v[i];         yass += v[i];       }       long long int m1 = maxSubArraySum(v, n - 1);       long long int m2 = maxSubArraySum(v + 1, n - 1);       ;       long long int adel = max(m1, m2);       if (yass > adel) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k % 3 == 0) {         if (n >= k) {           n = n % (k + 1);           if (n == k)             cout <<  Alice n ;           else {             if ((n) % 3 != 0) {               cout <<  Alice n ;             } else {               cout <<  Bob n ;             }           }         } else {           if ((n) % 3 != 0) {             cout <<  Alice n ;           } else {             cout <<  Bob n ;           }         }       } else {         if ((n) % 3 != 0) {           cout <<  Alice n ;         } else {           cout <<  Bob n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define mod 1000000007   typedef long long ll;   #define MAXN 300005   #define mod 1000000007         int main(){       int n;       cin>>n;       vector<int>ar(n+1);       for(int i=1;i<=n;i++)cin>>ar[i];       vector<pair<int,pair<int,int> > >supp;       for(int i=1;i<=n;i++){           for(int j=i+1;j<=n;j++){               supp.push_back({abs(ar[i]-ar[j]),{i,j}});           }       }       sort(supp.rbegin(),supp.rend());       for(int i=0;i<(int)supp.size();i++){           pair<int,int>tmp=supp[i].second;           if(ar[tmp.first]<ar[tmp.second])swap(tmp.first,tmp.second);           cout<< ?  <<tmp.first<<   <<tmp.second<<endl;           string ok;           cin>>ok;           if(ok== Yes ){               cout<< !  <<tmp.first<<   <<tmp.second<<endl;               return 0;           }       }       cout<< ! 0 0 <<endl;      }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k;     cin >> n >> m >> k;     int a[m + 1];     for (int i = 0; i < m + 1; i++) {       cin >> a[i];     }     int ans = 0;     for (int i = 0; i < m; i++) {       int count = 0;       for (int j = 0; j < n; j++) {         if (((a[m] >> j) & 1) != ((a[i] >> j) & 1)) {           count++;         }       }       if (count <= k) ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long mod = 1e9 + 7;   int n, m;   vector<int> depth;   vector<bool> visited;   vector<vector<int>> adj;   void dfs(int curr, int dt) {     depth[curr] = (dt) % 2;     visited[curr] = true;     for (int i = 0; i < adj[curr].size(); i++) {       if (!visited[adj[curr][i]]) {         dfs(adj[curr][i], dt + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> n >> m;       adj = vector<vector<int>>(n + 1);       depth = vector<int>(n + 1);       visited = vector<bool>(n + 1, false);       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       dfs(1, 0);       vector<int> v1;       vector<int> v2;       for (int i = 1; i <= n; i++) {         if (depth[i] % 2) {           v1.push_back(i);         } else {           v2.push_back(i);         }       }       if (v1.size() < v2.size()) {         cout << v1.size() << endl;         for (int i = 0; i < v1.size(); i++) {           cout << v1[i] <<    ;         }       } else {         cout << v2.size() << endl;         for (int i = 0; i < v2.size(); i++) {           cout << v2[i] <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   void self_add(long long &x, long long y) { x = (x + y) % mod; }   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = (res * a) % mod;       n >>= 1;       a = (a * a) % mod;     }     return res;   }   int main() {     long long n;     cin >> n;     long long fact = 1;     for (long long i = 2; i <= n; i++) {       fact = (fact * (i)) % mod;     }     long long power = binpow(2, n - 1);     long long ans = (fact - power) % mod;     if (ans < 0) ans += mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int v;     cin >> v;     int a[9];     int t = 100000, x;     for (long long i = 0; i < 9; ++i) {       cin >> a[i];       t = min(t, a[i]);     }     if (t > v) {       cout << -1;       return;     }     x = v / t;     while (x--) {       for (int i = 8; i >= 0; i--) {         if (a[i] <= v && (v - a[i]) / t == x) {           cout << i + 1;           v -= a[i];           break;         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   int main() {     int n, b = 1, i = 1;     scanf( %d , &n);     for (i = 1; i < n; i++) {       b = b + i;       if (b > n) b = b % n;       printf( %d n , b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, head[100005], tot, d[100005], fa[100005], vis[100005], lf[100005], cnt;   struct node {     int v, nxt;   } edg[100005 << 1];   inline void addedg(int u, int v) {     edg[tot].v = v;     edg[tot].nxt = head[u];     head[u] = tot++;   }   inline void init() {     memset(head, -1, sizeof(int) * (n + 1));     tot = cnt = 0;   }   inline void dfs1(int u, int f) {     int v;     d[u] = 0;     for (int i = head[u]; i != -1; i = edg[i].nxt) {       v = edg[i].v;       ++d[u];       if (v == f) continue;       dfs1(v, u);     }   }   inline void dfs2(int u, int f, int dis) {     int v;     fa[u] = f;     d[u] = dis;     for (int i = head[u]; i != -1; i = edg[i].nxt) {       v = edg[i].v;       if (f == v) continue;       dfs2(v, u, dis + 1);     }   }   inline bool cmp(int u, int v) { return d[u] > d[v]; }   set<int> se;   int main() {     scanf( %d , &n);     init();     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d%d , &u, &v);       addedg(u, v);       addedg(v, u);     }     dfs1(1, 1);     for (int i = 1; i <= n; ++i) {       if (d[i] == 1) lf[cnt++] = i;     }     int root = lf[0];     dfs2(root, root, 0);     vis[root] = 1;     int maxn = 0, minn = 1;     for (int i = 1; i < cnt; ++i) {       if (d[lf[i]] & 1) minn = 3;     }     fa[root] = edg[head[root]].v;     maxn = n - 1 - cnt;     for (int i = 0; i < cnt; ++i) se.insert(fa[lf[i]]);     maxn += se.size();     printf( %d %d n , minn, maxn);     return 0;   }